TrinityCore
Loading...
Searching...
No Matches
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
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 {
34 if (!grid.HasWorldObjectsInNGrid<Player>() && !map.ActiveObjectsNearGrid(grid))
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:154
#define TC_LOG_DEBUG(filterType__, message__,...)
Definition Log.h:181
@ GRID_STATE_REMOVAL
Definition NGrid.h:59
@ GRID_STATE_IDLE
Definition NGrid.h:58
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
TimeTracker const & getTimeTracker() const
Definition NGrid.h:36
bool getUnloadLock() const
Definition NGrid.h:37
void UpdateTimeTracker(time_t diff)
Definition NGrid.h:44
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
Definition Map.h:225
bool UnloadGrid(NGridType &ngrid, bool pForce)
Definition Map.cpp:1567
bool ActiveObjectsNearGrid(NGridType const &ngrid) const
Definition Map.cpp:2694
void ResetGridExpiry(NGridType &grid, float factor=1) const
Definition Map.h:289
uint32 GetId() const
Definition Map.cpp:3257
Definition NGrid.h:70
void SetGridState(grid_state_t s)
Definition NGrid.h:92
void VisitAllGrids(TypeContainerVisitor< VISITOR, WORLD_OBJECT_CONTAINER > &visitor)
Definition NGrid.h:136
bool HasWorldObjectsInNGrid() const
Definition NGrid.h:185
int32 getX() const
Definition NGrid.h:93
int32 getY() const
Definition NGrid.h:94
void Update(Map &, NGridType &, GridInfo &, uint32 t_diff) const override
bool Passed() const
Definition Timer.h:131