root/trunk/src/game/GridStates.cpp @ 219

Revision 120, 2.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Allow WorldObjects? to keep the grid active, and prevent it from being unloaded. This can be done through calling WorldObject::setActive(bool) from the scripting library. Note that entire instances are still unloaded if no player is present on that map to save resources. This behavior can be changed if the need arises.

Original author: w12x
Date: 2008-10-27 08:41:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "GridStates.h"
22#include "GridNotifiers.h"
23#include "ObjectAccessor.h"
24#include "GameSystem/Grid.h"
25#include "Log.h"
26
27void
28InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32 &/*x*/, const uint32 &/*y*/, const uint32 &) const
29{
30}
31
32void
33ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 &x, const uint32 &y, const uint32 &t_diff) const
34{
35    // Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle
36    info.UpdateTimeTracker(t_diff);
37    if( info.getTimeTracker().Passed() )
38    {
39        if( grid.ActiveObjectsInGrid() == 0 && !ObjectAccessor::Instance().ActiveObjectsNearGrid(x, y, m.GetId(), m.GetInstanceId()) )
40        {
41            ObjectGridStoper stoper(grid);
42            stoper.StopN();
43            grid.SetGridState(GRID_STATE_IDLE);
44        }
45        else
46        {
47            m.ResetGridExpiry(grid, 0.1f);
48        }
49    }
50}
51
52void
53IdleState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 &x, const uint32 &y, const uint32 &) const
54{
55    m.ResetGridExpiry(grid);
56    grid.SetGridState(GRID_STATE_REMOVAL);
57    sLog.outDebug("Grid[%u,%u] on map %u moved to IDLE state", x, y, m.GetId());
58}
59
60void
61RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 &x, const uint32 &y, const uint32 &t_diff) const
62{
63    if(info.getUnloadFlag())
64    {
65        info.UpdateTimeTracker(t_diff);
66        if( info.getTimeTracker().Passed() )
67        {
68            if( !m.UnloadGrid(x, y, false) )
69            {
70                sLog.outDebug("Grid[%u,%u] for map %u differed unloading due to players nearby", x, y, m.GetId());
71                m.ResetGridExpiry(grid);
72            }
73        }
74    }
75}
Note: See TracBrowser for help on using the browser.