Skip to content

Commit

Permalink
Load dungeon map grids before adding the player.
Browse files Browse the repository at this point in the history
This should speed up MSG_MOVE_WORLDPORT_ACK handling a lot.
  • Loading branch information
ratkosrb committed Sep 28, 2024
1 parent a9321a4 commit b829db5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,18 @@ bool Map::EnsureGridLoaded(Cell const& cell)
return false;
}

void Map::ForceLoadGridsAroundPosition(float x, float y)
{
if (!IsLoaded(x, y))
{
CellPair p = MaNGOS::ComputeCellPair(x, y);
Cell cell(p);
EnsureGridLoadedAtEnter(cell);
NULLNotifier notifier = NULLNotifier();
Cell::VisitAllObjects(x, y, this, notifier, GetGridActivationDistance(), false);
}
}

void Map::LoadGrid(Cell const& cell, bool no_unload)
{
EnsureGridLoaded(cell);
Expand Down
1 change: 1 addition & 0 deletions src/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class Map : public GridRefManager<NGridType>

bool GetUnloadLock(GridPair const& p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); }
void SetUnloadLock(GridPair const& p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); }
void ForceLoadGridsAroundPosition(float x, float y);
void LoadGrid(Cell const& cell, bool no_unload = false);
bool UnloadGrid(uint32 const& x, uint32 const& y, bool pForce);
virtual void UnloadAll(bool pForce);
Expand Down
1 change: 1 addition & 0 deletions src/game/Maps/MapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ void MapManager::CreateNewInstancesForPlayers()
DungeonMap* pMap = static_cast<DungeonMap*>(CreateInstance(dest.mapId, player));
if (pMap->CanEnter(player))
{
pMap->ForceLoadGridsAroundPosition(dest.x, dest.y);
pMap->BindPlayerOrGroupOnEnter(player);
player->SendNewWorld();
}
Expand Down
7 changes: 0 additions & 7 deletions src/game/Objects/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3460,13 +3460,6 @@ void WorldObject::Update(uint32 update_diff, uint32 /*time_diff*/)
ExecuteDelayedActions();
}

class NULLNotifier
{
public:
template<class T> void Visit(GridRefManager<T>& m) {}
void Visit(CameraMapType&) {}
};

void WorldObject::LoadMapCellsAround(float dist) const
{
ASSERT(IsInWorld());
Expand Down
7 changes: 7 additions & 0 deletions src/game/Objects/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class GenericTransport;
struct FactionEntry;
struct FactionTemplateEntry;

class NULLNotifier
{
public:
template<class T> void Visit(GridRefManager<T>& m) {}
void Visit(CameraMapType&) {}
};

typedef std::unordered_map<Player*, UpdateData> UpdateDataMapType;

//use this class to measure time between world update ticks
Expand Down

0 comments on commit b829db5

Please sign in to comment.