diff --git a/src/game/GridStates.cpp b/src/game/GridStates.cpp index 339dad86e..392829737 100644 --- a/src/game/GridStates.cpp +++ b/src/game/GridStates.cpp @@ -34,7 +34,7 @@ ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 &x, c info.UpdateTimeTracker(t_diff); if( info.getTimeTracker().Passed() ) { - if( grid.ActiveObjectsInGrid() == 0 && !ObjectAccessor::Instance().PlayersNearGrid(x, y, m.GetId(), m.GetInstanceId()) ) + if( grid.ActiveObjectsInGrid() == 0 && !m.PlayersNearGrid(x, y) ) { ObjectGridStoper stoper(grid); stoper.StopN(); diff --git a/src/game/Map.cpp b/src/game/Map.cpp index d583551eb..59c99e61a 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -920,7 +920,7 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce) assert( grid != NULL); { - if(!pForce && ObjectAccessor::Instance().PlayersNearGrid(x, y, i_id, i_InstanceId) ) + if(!pForce && PlayersNearGrid(x, y) ) return false; DEBUG_LOG("Unloading grid[%u,%u] for map %u", x,y, i_id); @@ -1444,6 +1444,28 @@ void Map::SendToPlayers(WorldPacket const* data) const itr->getSource()->GetSession()->SendPacket(data); } +bool Map::PlayersNearGrid(uint32 x, uint32 y) 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); + cell_min << 2; + cell_min -= 2; + cell_max >> 2; + cell_max += 2; + + for(MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) + { + Player* plr = iter->getSource(); + + CellPair p = MaNGOS::ComputeCellPair(plr->GetPositionX(), plr->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; +} + template void Map::Add(Corpse *); template void Map::Add(Creature *); template void Map::Add(GameObject *); diff --git a/src/game/Map.h b/src/game/Map.h index 889efecf7..b3f85215b 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -236,6 +236,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager, public MaNGOS::Obj bool HavePlayers() const { return !m_mapRefManager.isEmpty(); } uint32 GetPlayersCountExceptGMs() const; + bool PlayersNearGrid(uint32 x,uint32 y) const; void SendToPlayers(WorldPacket const* data) const; diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index b32743b28..26b5be0e4 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -511,32 +511,6 @@ ObjectAccessor::UpdatePlayers(uint32 diff) iter->second->Update(diff); } -bool -ObjectAccessor::PlayersNearGrid(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); - cell_min << 2; - cell_min -= 2; - cell_max >> 2; - cell_max += 2; - - //TODO: Guard player - HashMapHolder::MapType& playerMap = HashMapHolder::GetContainer(); - for(HashMapHolder::MapType::const_iterator iter=playerMap.begin(); iter != playerMap.end(); ++iter) - { - if( m_id != iter->second->GetMapId() || i_id != iter->second->GetInstanceId() ) - continue; - - CellPair p = MaNGOS::ComputeCellPair(iter->second->GetPositionX(), iter->second->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; -} - void ObjectAccessor::WorldObjectChangeAccumulator::Visit(PlayerMapType &m) { diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index 628312901..6b724408a 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -192,8 +192,6 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton