aboutsummaryrefslogtreecommitdiff
path: root/src/game/ObjectAccessor.cpp
diff options
context:
space:
mode:
authorw12x <none@none>2008-10-27 08:41:55 -0500
committerw12x <none@none>2008-10-27 08:41:55 -0500
commite72a13c3dd10922a18d9ee59a7f62fbfb6b69c03 (patch)
treeddc7ef24aa60c78b749a6e7e4e8880f56c42e618 /src/game/ObjectAccessor.cpp
parent0e18e4330c0ab109080d5b7f18a3f9f83412e65a (diff)
[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.
--HG-- branch : trunk
Diffstat (limited to 'src/game/ObjectAccessor.cpp')
-rw-r--r--src/game/ObjectAccessor.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp
index ecfff85d055..631ccc7fe6b 100644
--- a/src/game/ObjectAccessor.cpp
+++ b/src/game/ObjectAccessor.cpp
@@ -505,22 +505,40 @@ ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid)
}
void
+ObjectAccessor::AddActiveObject( WorldObject * obj )
+{
+ i_activeobjects.insert(obj);
+}
+
+void
+ObjectAccessor::RemoveActiveObject( WorldObject * obj )
+{
+ i_activeobjects.erase(obj);
+}
+
+void
ObjectAccessor::Update(uint32 diff)
{
{
- typedef std::multimap<uint32, Player *> CreatureLocationHolderType;
- CreatureLocationHolderType creature_locations;
- //TODO: Player guard
+ // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects.
HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer();
for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter)
{
if(iter->second->IsInWorld())
{
iter->second->Update(diff);
- creature_locations.insert( CreatureLocationHolderType::value_type(iter->second->GetMapId(), iter->second) );
}
}
+ // clone the active object list, because update might remove from it
+ std::set<WorldObject *> activeobjects(i_activeobjects);
+
+ std::set<WorldObject *>::const_iterator itr;
+ for(itr = activeobjects.begin(); itr != activeobjects.end(); ++itr)
+ {
+ (*itr)->GetMap()->resetMarkedCells();
+ }
+
Map *map;
Trinity::ObjectUpdater updater(diff);
@@ -529,17 +547,12 @@ ObjectAccessor::Update(uint32 diff)
// for pets
TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer > world_object_update(updater);
- for(CreatureLocationHolderType::iterator iter=creature_locations.begin(); iter != creature_locations.end(); ++iter)
+ for(itr = activeobjects.begin(); itr != activeobjects.end(); ++itr)
{
- MapManager::Instance().GetMap((*iter).first, (*iter).second)->resetMarkedCells();
- }
-
- for(CreatureLocationHolderType::iterator iter=creature_locations.begin(); iter != creature_locations.end(); ++iter)
- {
- Player *player = (*iter).second;
- map = MapManager::Instance().GetMap((*iter).first, player);
+ WorldObject *obj = (*itr);
+ map = obj->GetMap();
- CellPair standing_cell(Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()));
+ CellPair standing_cell(Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()));
// Check for correctness of standing_cell, it also avoids problems with update_cell
if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
@@ -576,7 +589,7 @@ ObjectAccessor::Update(uint32 diff)
}
bool
-ObjectAccessor::PlayersNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) const
+ObjectAccessor::ActiveObjectsNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) const
{
CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS);
CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS);
@@ -585,17 +598,16 @@ ObjectAccessor::PlayersNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) co
cell_max >> 2;
cell_max += 2;
- //TODO: Guard player
- HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer();
- for(HashMapHolder<Player>::MapType::const_iterator iter=playerMap.begin(); iter != playerMap.end(); ++iter)
+ for(std::set<WorldObject*>::const_iterator itr = i_activeobjects.begin(); itr != i_activeobjects.end(); ++itr)
{
- if( m_id != iter->second->GetMapId() || i_id != iter->second->GetInstanceId() )
+ if( m_id != (*itr)->GetMapId() || i_id != (*itr)->GetInstanceId() )
continue;
- CellPair p = Trinity::ComputeCellPair(iter->second->GetPositionX(), iter->second->GetPositionY());
+ CellPair p = Trinity::ComputeCellPair((*itr)->GetPositionX(), (*itr)->GetPositionY());
if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) &&
(cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) )
return true;
+
}
return false;