TrinityCore
GridStates.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "GridStates.h"
19#include "GridNotifiers.h"
20#include "Log.h"
21#include "Map.h"
22#include "ObjectGridLoader.h"
23
25{
26}
27
28void ActiveState::Update(Map& map, NGridType& grid, GridInfo& info, uint32 diff) const
29{
30 // Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle
31 info.UpdateTimeTracker(diff);
32 if (info.getTimeTracker().Passed())
33 {
35 {
36 ObjectGridStoper worker;
38 grid.VisitAllGrids(visitor);
40 TC_LOG_DEBUG("maps", "Grid[{}, {}] on map {} moved to IDLE state", grid.getX(), grid.getY(), map.GetId());
41 }
42 else
43 map.ResetGridExpiry(grid, 0.1f);
44 }
45}
46
47void IdleState::Update(Map& map, NGridType& grid, GridInfo&, uint32) const
48{
49 map.ResetGridExpiry(grid);
51 TC_LOG_DEBUG("maps", "Grid[{}, {}] on map {} moved to REMOVAL state", grid.getX(), grid.getY(), map.GetId());
52}
53
54void RemovalState::Update(Map& map, NGridType& grid, GridInfo& info, uint32 diff) const
55{
56 if (!info.getUnloadLock())
57 {
58 info.UpdateTimeTracker(diff);
59 if (info.getTimeTracker().Passed() && !map.UnloadGrid(grid, false))
60 {
61 TC_LOG_DEBUG("maps", "Grid[{}, {}] for map {} differed unloading due to players or active objects nearby", grid.getX(), grid.getY(), map.GetId());
62 map.ResetGridExpiry(grid);
63 }
64 }
65}
uint32_t uint32
Definition: Define.h:142
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
@ GRID_STATE_REMOVAL
Definition: NGrid.h:58
@ GRID_STATE_IDLE
Definition: NGrid.h:57
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
Definition: GridStates.cpp:28
Definition: NGrid.h:31
TimeTracker const & getTimeTracker() const
Definition: NGrid.h:35
bool getUnloadLock() const
Definition: NGrid.h:36
void UpdateTimeTracker(time_t diff)
Definition: NGrid.h:43
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
Definition: GridStates.cpp:47
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
Definition: GridStates.cpp:24
Definition: Map.h:189
bool UnloadGrid(NGridType &ngrid, bool pForce)
Definition: Map.cpp:1599
bool ActiveObjectsNearGrid(NGridType const &ngrid) const
Definition: Map.cpp:2696
void ResetGridExpiry(NGridType &grid, float factor=1) const
Definition: Map.h:253
uint32 GetId() const
Definition: Map.cpp:3228
Definition: NGrid.h:70
int32 getX() const
Definition: NGrid.h:93
uint32 GetWorldObjectCountInNGrid() const
Definition: NGrid.h:164
void SetGridState(grid_state_t s)
Definition: NGrid.h:92
int32 getY() const
Definition: NGrid.h:94
void VisitAllGrids(TypeContainerVisitor< T, TypeMapContainer< TT > > &visitor)
Definition: NGrid.h:136
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
Definition: GridStates.cpp:54
bool Passed() const
Definition: Timer.h:131