[11193] Optimize visibility update and AI notification code. Optimization decreases amount of visibility and AI notification operations in 8-10 times, and as a result, lowers CPU usage by 30-40%

You need to update your config file, new "Visibility.RelocationLowerLimit" and "Visibility.AIRelocationNotifyDelay' options added

Special thanks to Ambal for code hints and advices
Thanks to Undergarun and kero99 for making tests
This commit is contained in:
SilverIce 2011-02-22 02:32:49 +02:00
parent 60b2e2c8ba
commit 724092d9e5
10 changed files with 117 additions and 62 deletions

View file

@ -207,13 +207,13 @@ void Map::AddNotifier(T* , Cell const& , CellPair const& )
template<>
void Map::AddNotifier(Player* obj, Cell const& cell, CellPair const& cellpair)
{
PlayerRelocationNotify(obj,cell,cellpair);
obj->SheduleAINotify(0);
}
template<>
void Map::AddNotifier(Creature* obj, Cell const&, CellPair const&)
{
obj->SetNeedNotify();
obj->SheduleAINotify(0);
}
void
@ -708,10 +708,7 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati
player->GetViewPoint().Event_GridChanged(&(*newGrid)(new_cell.CellX(),new_cell.CellY()));
}
player->GetViewPoint().Call_UpdateVisibilityForOwner();
// if move then update what player see and who seen
UpdateObjectVisibility(player, new_cell, new_val);
PlayerRelocationNotify(player,new_cell,new_val);
player->OnRelocated();
NGridType* newGrid = getNGrid(new_cell.GridX(), new_cell.GridY());
if( !same_cell && newGrid->GetGridState()!= GRID_STATE_ACTIVE )
@ -731,39 +728,31 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
CellPair new_val = MaNGOS::ComputeCellPair(x, y);
Cell new_cell(new_val);
// delay creature move for grid/cell to grid/cell moves
if (old_cell.DiffCell(new_cell) || old_cell.DiffGrid(new_cell))
{
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) added to moving list from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", creature->GetGUIDLow(), creature->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
// do move or do move to respawn or remove creature if previous all fail
if(CreatureCellRelocation(creature,new_cell))
if (CreatureCellRelocation(creature,new_cell))
{
// update pos
creature->Relocate(x, y, z, ang);
// in diffcell/diffgrid case notifiers called in Creature::Update
creature->SetNeedNotify();
creature->OnRelocated();
}
else
// if creature can't be move in new cell/grid (not loaded) move it to repawn cell/grid
// creature coordinates will be updated and notifiers send
else if (!CreatureRespawnRelocation(creature))
{
// if creature can't be move in new cell/grid (not loaded) move it to repawn cell/grid
// creature coordinates will be updated and notifiers send
if(!CreatureRespawnRelocation(creature))
{
// ... or unload (if respawn grid also not loaded)
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u ) can't be move to unloaded respawn grid.",creature->GetGUIDLow(),creature->GetEntry());
creature->SetNeedNotify();
}
// ... or unload (if respawn grid also not loaded)
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u ) can't be move to unloaded respawn grid.",creature->GetGUIDLow(),creature->GetEntry());
}
}
else
{
creature->Relocate(x, y, z, ang);
creature->SetNeedNotify();
creature->OnRelocated();
}
creature->GetViewPoint().Call_UpdateVisibilityForOwner();
MANGOS_ASSERT(CheckGridIntegrity(creature,true));
}
@ -847,7 +836,7 @@ bool Map::CreatureRespawnRelocation(Creature *c)
{
c->Relocate(resp_x, resp_y, resp_z, resp_o);
c->GetMotionMaster()->Initialize(); // prevent possible problems with default move generators
c->SetNeedNotify();
c->OnRelocated();
return true;
}
else