aboutsummaryrefslogtreecommitdiff
path: root/src/game/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Map.cpp')
-rw-r--r--src/game/Map.cpp60
1 files changed, 54 insertions, 6 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index f8201f53219..246af3792fb 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -594,7 +594,7 @@ bool Map::loaded(const GridPair &p) const
return ( getNGrid(p.x_coord, p.y_coord) && isGridObjectDataLoaded(p.x_coord, p.y_coord) );
}
-void Map::UpdateActiveCells(const float &x, const float &y, const uint32 &t_diff)
+/*void Map::UpdateActiveCells(const float &x, const float &y, const uint32 &t_diff)
{
CellPair standing_cell(Trinity::ComputeCellPair(x, y));
@@ -635,27 +635,75 @@ void Map::UpdateActiveCells(const float &x, const float &y, const uint32 &t_diff
}
}
}
-}
+}*/
void Map::Update(const uint32 &t_diff)
{
resetMarkedCells();
// update cells around players
- for(MapRefManager::iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter)
+ /*for(MapRefManager::iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter)
{
Player* plr = iter->getSource();
if(plr->IsInWorld())
UpdateActiveCells(plr->GetPositionX(), plr->GetPositionY(), t_diff);
- }
+ }*/
// update cells around active objects
// clone the active object list, because update might remove from it
std::set<WorldObject *> activeObjects(i_activeObjects);
+ for(MapRefManager::iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter)
+ {
+ Player* plr = iter->getSource();
+ if(plr->IsInWorld())
+ activeObjects.insert(plr);
+ }
+
+ Trinity::ObjectUpdater updater(t_diff);
+ // for creature
+ TypeContainerVisitor<Trinity::ObjectUpdater, GridTypeMapContainer > grid_object_update(updater);
+ // for pets
+ TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer > world_object_update(updater);
+
for(std::set<WorldObject *>::iterator iter = activeObjects.begin(); iter != activeObjects.end(); ++iter)
{
- if((*iter)->IsInWorld())
- UpdateActiveCells((*iter)->GetPositionX(), (*iter)->GetPositionY(), t_diff);
+ if(!(*iter)->IsInWorld())
+ continue;
+
+ CellPair standing_cell(Trinity::ComputeCellPair((*iter)->GetPositionX(), (*iter)->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)
+ continue;
+
+ // the overloaded operators handle range checking
+ // so ther's no need for range checking inside the loop
+ CellPair begin_cell(standing_cell), end_cell(standing_cell);
+ begin_cell << 1; begin_cell -= 1; // upper left
+ end_cell >> 1; end_cell += 1; // lower right
+
+ for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x)
+ {
+ for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y)
+ {
+ // marked cells are those that have been visited
+ // don't visit the same cell twice
+ uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x;
+ if(!isCellMarked(cell_id))
+ {
+ markCell(cell_id);
+ CellPair pair(x,y);
+ Cell cell(pair);
+ cell.data.Part.reserved = CENTER_DISTRICT;
+ cell.SetNoCreate();
+ CellLock<NullGuard> cell_lock(cell, pair);
+ cell_lock->Visit(cell_lock, grid_object_update, *this);
+ cell_lock->Visit(cell_lock, world_object_update, *this);
+ }
+ }
+ }
+
+ // UpdateActiveCells((*iter)->GetPositionX(), (*iter)->GetPositionY(), t_diff);
}
// Don't unload grids if it's battleground, since we may have manually added GOs,creatures, those doesn't load from DB at grid re-load !