OregonCore  revision fb2a440-git
Your Favourite TBC server
GridStates.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 
23 { }
24 
25 void ActiveState::Update(Map& map, NGridType& grid, GridInfo& info, const uint32 diff) const
26 {
27  // Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle
28  info.UpdateTimeTracker(diff);
29  if (info.getTimeTracker().Passed())
30  {
31  if (!grid.GetWorldObjectCountInNGrid<Player>() && !map.ActiveObjectsNearGrid(grid))
32  {
33  ObjectGridStoper worker;
35  grid.VisitAllGrids(visitor);
37  sLog.outDebug("Grid[%u, %u] on map %u moved to IDLE state", grid.getX(), grid.getY(), map.GetId());
38  }
39  else
40  map.ResetGridExpiry(grid, 0.1f);
41  }
42 }
43 
44 void IdleState::Update(Map& map, NGridType& grid, GridInfo&, const uint32) const
45 {
46  map.ResetGridExpiry(grid);
48  sLog.outDebug("Grid[%u, %u] on map %u moved to REMOVAL state", grid.getX(), grid.getY(), map.GetId());
49 }
50 
51 void RemovalState::Update(Map& map, NGridType& grid, GridInfo& info, const uint32 diff) const
52 {
53  if (!info.getUnloadLock())
54  {
55  info.UpdateTimeTracker(diff);
56  if (info.getTimeTracker().Passed() && !map.UnloadGrid(grid, false))
57  {
58  sLog.outDebug("Grid[%u, %u] for map %u differed unloading due to players or active objects nearby", grid.getX(), grid.getY(), map.GetId());
59  map.ResetGridExpiry(grid);
60  }
61  }
62 }
63 
Definition: NGrid.h:75
void UpdateTimeTracker(time_t diff)
Definition: NGrid.h:48
Definition: NGrid.h:30
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const override
Definition: GridStates.cpp:44
bool Passed(void) const
Definition: Timer.h:148
#define sLog
Log class singleton.
Definition: Log.h:187
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const override
Definition: GridStates.cpp:51
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const override
Definition: GridStates.cpp:25
bool ActiveObjectsNearGrid(NGridType const &ngrid) const
Definition: Map.cpp:2130
uint32 GetWorldObjectCountInNGrid() const
Definition: NGrid.h:138
uint32 GetId(void) const
Definition: Map.h:333
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const override
Definition: GridStates.cpp:22
const TimeTracker & getTimeTracker() const
Definition: NGrid.h:39
void VisitAllGrids(TypeContainerVisitor< T, TypeMapContainer< TT > > &visitor)
Definition: NGrid.h:123
void SetGridState(grid_state_t s)
Definition: NGrid.h:100
Definition: Map.h:266
bool UnloadGrid(NGridType &ngrid, bool pForce)
Definition: Map.cpp:900
int32 getY() const
Definition: NGrid.h:102
bool getUnloadLock() const
Definition: NGrid.h:40
int32 getX() const
Definition: NGrid.h:101
ACE_UINT32 uint32
Definition: Define.h:71
void ResetGridExpiry(NGridType &grid, float factor=1) const
Definition: Map.h:324
Definition: Player.h:922