Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jan 25, 2025
1 parent 15ba646 commit fa87819
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 67 deletions.
12 changes: 3 additions & 9 deletions src/game/Entities/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ void Creature::RemoveCorpse(bool inPlace)

m_corpseExpirationTime = TimePoint();
SetDeathState(DEAD);
UpdateObjectVisibility();

delete m_loot;
m_loot = nullptr;
Expand Down Expand Up @@ -304,14 +303,9 @@ void Creature::RemoveCorpse(bool inPlace)
GetRespawnCoord(x, y, z, &o);
GetMap()->CreatureRelocation(this, x, y, z, o);

// forced recreate creature object at clients
UnitVisibility currentVis = GetVisibility();
SetVisibility(VISIBILITY_REMOVE_CORPSE);
UpdateObjectVisibility();
SetVisibility(currentVis); // restore visibility state
UpdateObjectVisibility();

if (IsUsingNewSpawningSystem())
if (!IsUsingNewSpawningSystem()) // schedule out of range
GetMap()->AddUpdateRemoveObject(GetClientGuidsIAmAt(), GetObjectGuid());
else
AddObjectToRemoveList();
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void GameObject::Update(const uint32 diff)

// can be not in world at pool despawn
if (IsInWorld())
UpdateObjectVisibility();
GetMap()->AddUpdateObject(this);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ bool Item::IsBindedNotWith(Player const* player) const
void Item::AddToClientUpdateList()
{
if (Player* pl = GetOwner())
pl->GetMap()->AddUpdateObject(this);
pl->GetMap()->AddUpdateCreateObject(this);
}

void Item::RemoveFromClientUpdateList()
Expand Down
4 changes: 2 additions & 2 deletions src/game/Entities/NPCHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ void WorldSession::SendSpiritResurrect() const
else
{
_player->GetCamera().UpdateVisibilityForOwner();
_player->UpdateObjectVisibility();
_player->GetMap()->AddUpdateMovementObject(_player);
}
}
// or update at original position
else
{
_player->GetCamera().UpdateVisibilityForOwner();
_player->UpdateObjectVisibility();
_player->GetMap()->AddUpdateObject(_player);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/game/Entities/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ class Object
virtual bool HasQuest(uint32 /* quest_id */) const { return false; }
virtual bool HasInvolvedQuest(uint32 /* quest_id */) const { return false; }
void SetItsNewObject(bool enable) { m_itsNewObject = enable; }
bool ItsNewObject() const { return m_itsNewObject; }

Loot* m_loot;

Expand Down
14 changes: 8 additions & 6 deletions src/game/Entities/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20060,6 +20060,7 @@ void Player::HandleStealthedUnitsDetection()
WorldObject const* viewPoint = GetCamera().GetBody();

UpdateData data;
std::vector<Unit*> added;
for (UnitList::const_iterator i = stealthedUnits.begin(); i != stealthedUnits.end(); ++i)
{
Unit* target = *i;
Expand All @@ -20076,13 +20077,9 @@ void Player::HandleStealthedUnitsDetection()
ObjectGuid i_guid = (*i)->GetObjectGuid();
target->SendCreateUpdateToPlayer(this, data);
AddAtClient((*i));
added.push_back((*i));

DEBUG_FILTER_LOG(LOG_FILTER_VISIBILITY_CHANGES, "%s is detected in stealth by player %u. Distance = %f", i_guid.GetString().c_str(), GetGUIDLow(), GetDistance(*i));

// target aura duration for caster show only if target exist at caster client
// send data at target visibility change (adding to client)
if ((*i) != this && (*i)->isType(TYPEMASK_UNIT))
SendAurasForTarget(*i);
}
}
else
Expand All @@ -20096,7 +20093,12 @@ void Player::HandleStealthedUnitsDetection()
}
}
}
data.SendData(*GetSession());
if (!added.empty())
{
data.SendData(*GetSession());
for (Unit* newUnit : added)
SendAurasForTarget(newUnit);
}
}

bool Player::ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc /*= nullptr*/, uint32 spellid /*= 0*/)
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12379,7 +12379,7 @@ void Unit::OnRelocated()
if (!IsBoarded() && IsVehicle()) // must update passengers for visibility reasons
m_vehicleInfo->UpdateGlobalPositions();
GetViewPoint().Call_UpdateVisibilityForOwner();
UpdateObjectVisibility();
GetMap()->AddUpdateMovementObject(this);
}
ScheduleAINotify(World::GetRelocationAINotifyDelay());
}
Expand Down
15 changes: 0 additions & 15 deletions src/game/Grids/GridNotifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ void VisibleNotifier::Notify()
// send create/outofrange packet to player (except player create updates that already sent using SendUpdateToPlayer)
if (i_processSend)
i_data.SendData(*player.GetSession());

// send out of range to other players if need
GuidSet const& oor = i_data.GetOutOfRangeGUIDs();
for (auto iter : oor)
{
if (!iter.IsPlayer())
continue;

if (Player* plr = ObjectAccessor::FindPlayer(iter))
{
UpdateData data;
plr->UpdateVisibilityOf(plr->GetCamera().GetBody(), &player, data);
data.SendData(*plr->GetSession()); // TODO: This has to be aggregated elsewhere
}
}
}

// Now do operations that required done at object visibility change to visible
Expand Down
51 changes: 31 additions & 20 deletions src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void Map::CreatePlayerOnClient(Player* player)

NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
player->GetViewPoint().Event_AddedToWorld(&(*grid)(cell.CellX(), cell.CellY()), updateData);
UpdateObjectVisibility(player, cell, p);
AddUpdateCreateObject(player);

SendInitSelf(player, updateData);
updateData.SendData(*player->GetSession());
Expand All @@ -510,7 +510,7 @@ bool Map::Add(Player* player)

NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
player->GetViewPoint().Event_AddedToWorld(&(*grid)(cell.CellX(), cell.CellY()), updateData);
UpdateObjectVisibility(player, cell, p);
AddUpdateObject(player);

SendInitSelf(player, updateData);
updateData.SendData(*player->GetSession());
Expand Down Expand Up @@ -558,8 +558,7 @@ void Map::Add(T* obj)
UpdateData updateData;
obj->GetViewPoint().Event_AddedToWorld(&(*grid)(cell.CellX(), cell.CellY()), updateData);
obj->SetItsNewObject(true);
UpdateObjectVisibility(obj, cell, p);
obj->SetItsNewObject(false);
AddUpdateObject(obj);
}

void Map::MessageBroadcast(Player const* player, WorldPacket const& msg, bool to_self)
Expand Down Expand Up @@ -1062,10 +1061,13 @@ void Map::Update(const uint32& t_diff)

// Send world objects and item update field changes
m_clientUpdateTimer += t_diff;
if (m_clientUpdateTimer >= 333)
if (m_clientUpdateTimer >= UPDATE_TICK)
{
m_clientUpdateTimer -= 333;
SendObjectUpdates();
m_clientUpdateTimer -= UPDATE_TICK;
++m_clientUpdateTick;
SendObjectUpdates(m_clientUpdateTick >= 3);
if (m_clientUpdateTick >= 3)
m_clientUpdateTick = 0;
}

// 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 !
Expand Down Expand Up @@ -1097,6 +1099,9 @@ void Map::Remove(Player* player, bool remove)
if (i_data)
i_data->OnPlayerLeave(player);

m_objectsToClientUpdate.erase(player);
m_objectsToClientMovementUpdate.erase(player);

if (IsRaid())
for (auto& playerRef : GetPlayers())
playerRef.getSource()->RemoveAllGroupBuffsFromCaster(player->GetObjectGuid());
Expand Down Expand Up @@ -1141,7 +1146,7 @@ void Map::Remove(Player* player, bool remove)
RemoveFromGrid(player, grid, cell);

SendRemoveTransports(player);
UpdateObjectVisibility(player, cell, p);
AddUpdateRemoveObject(player->GetClientGuidsIAmAt(), player->GetObjectGuid());

player->ResetMap();
if (remove)
Expand All @@ -1166,6 +1171,9 @@ void Map::Remove(T* obj, bool remove)
NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
MANGOS_ASSERT(grid != nullptr);

m_objectsToClientUpdate.erase(obj);
m_objectsToClientMovementUpdate.erase(obj);

if (obj->isActiveObject())
RemoveFromActive(obj);

Expand All @@ -1174,7 +1182,7 @@ void Map::Remove(T* obj, bool remove)
else
obj->RemoveFromWorld();

UpdateObjectVisibility(obj, cell, p); // i think will be better to call this function while object still in grid, this changes nothing but logically is better(as for me)
AddUpdateRemoveObject(obj->GetClientGuidsIAmAt(), obj->GetObjectGuid());
RemoveFromGrid(obj, grid, cell);

m_objRemoveList.insert(obj->GetObjectGuid());
Expand Down Expand Up @@ -1278,7 +1286,7 @@ void Map::GameObjectRelocation(GameObject* go, float x, float y, float z, float

go->Relocate(x, y, z, orientation);
go->UpdateModelPosition();
go->UpdateObjectVisibility();
AddUpdateMovementObject(go);
}

void Map::DynamicObjectRelocation(DynamicObject* dynObj, float x, float y, float z, float orientation)
Expand Down Expand Up @@ -1311,7 +1319,7 @@ void Map::DynamicObjectRelocation(DynamicObject* dynObj, float x, float y, float
else
{
dynObj->Relocate(x, y, z, orientation);
dynObj->UpdateObjectVisibility();
AddUpdateMovementObject(dynObj);
}
}

Expand Down Expand Up @@ -2625,24 +2633,22 @@ WorldObject* Map::GetWorldObject(ObjectGuid guid)
return nullptr;
}

void Map::SendObjectUpdates()
void Map::SendObjectUpdates(bool movement)
{
UpdateDataMapType update_players;

while (!i_objectsToClientUpdate.empty())
while (!m_objectsToClientUpdate.empty())
{
Object* obj = *i_objectsToClientUpdate.begin();
i_objectsToClientUpdate.erase(i_objectsToClientUpdate.begin());
Object* obj = *m_objectsToClientUpdate.begin();
m_objectsToClientUpdate.erase(m_objectsToClientUpdate.begin());
obj->BuildUpdateData(update_players);
if (obj->ItsNewObject())
obj->SetItsNewObject(false);
}

for (auto& update_player : update_players)
{
for (size_t i = 0; i < update_player.second.GetPacketCount(); ++i)
{
WorldPacket packet = update_player.second.BuildPacket(i);
update_player.first->GetSession()->SendPacket(packet);
}
update_player.second.SendData(*update_player.first->GetSession());
}
}

Expand Down Expand Up @@ -2766,6 +2772,11 @@ void Map::RemoveStringIdObject(uint32 stringId, WorldObject* obj)
data.gameobjects.erase(std::remove(data.gameobjects.begin(), data.gameobjects.end(), static_cast<GameObject*>(obj)), data.gameobjects.end());
}

void Map::AddUpdateRemoveObject(GuidSet& visible, ObjectGuid guid)
{
m_objectsToClientRemove.emplace_back(visible, guid);
}

uint32 Map::GenerateLocalLowGuid(HighGuid guidhigh)
{
// TODO: for map local guid counters possible force reload map instead shutdown server at guid counter overflow
Expand Down
31 changes: 19 additions & 12 deletions src/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct ZoneDynamicInfo
#endif

#define MIN_UNLOAD_DELAY 1 // immediate unload
#define UPDATE_TICK 400

typedef std::unordered_map<uint32 /*zoneId*/, ZoneDynamicInfo> ZoneDynamicInfoMap;

Expand Down Expand Up @@ -330,16 +331,18 @@ class Map : public GridRefManager<NGridType>
MapStoredObjectTypesContainer& GetObjectsStore() { return m_objectsStore; }
std::map<uint32, uint32>& GetTempCreatures() { return m_tempCreatures; }
std::map<uint32, uint32>& GetTempPets() { return m_tempPets; }

void AddUpdateObject(Object* obj)
{
i_objectsToClientUpdate.insert(obj);
}

void RemoveUpdateObject(Object* obj)
{
i_objectsToClientUpdate.erase(obj);
}

// schedule for update object create change
void AddUpdateCreateObject(Object* obj) { m_objectsToClientCreateUpdate.insert(obj); }
void RemoveUpdateCreateObject(Object* obj) { m_objectsToClientCreateUpdate.erase(obj); }
// schedule for update object values change
void AddUpdateObject(Object* obj) { m_objectsToClientUpdate.insert(obj); }
void RemoveUpdateObject(Object* obj) { m_objectsToClientUpdate.erase(obj); }
// schedule for update object visibility change
void AddUpdateMovementObject(Object* obj) { m_objectsToClientMovementUpdate.insert(obj); }
void RemoveUpdateMovementObject(Object* obj) { m_objectsToClientMovementUpdate.erase(obj); }
// schedule update object destruction of object
void AddUpdateRemoveObject(GuidSet& visible, ObjectGuid guid);

// DynObjects currently
uint32 GenerateLocalLowGuid(HighGuid guidhigh);
Expand Down Expand Up @@ -485,8 +488,11 @@ class Map : public GridRefManager<NGridType>
void setNGrid(NGridType* grid, uint32 x, uint32 y);
void ScriptsProcess();

void SendObjectUpdates();
std::set<Object*> i_objectsToClientUpdate;
void SendObjectUpdates(bool movement);
std::set<Object*> m_objectsToClientUpdate;
std::set<Object*> m_objectsToClientCreateUpdate;
std::set<Object*> m_objectsToClientMovementUpdate;
std::vector<std::pair<GuidSet, ObjectGuid>> m_objectsToClientRemove;

protected:
MapEntry const* i_mapEntry;
Expand All @@ -496,6 +502,7 @@ class Map : public GridRefManager<NGridType>
MaNGOS::unique_weak_ptr<Map> m_weakRef;
uint32 m_unloadTimer;
uint32 m_clientUpdateTimer;
uint32 m_clientUpdateTick;
float m_VisibleDistance;
MapPersistentState* m_persistentState;

Expand Down

0 comments on commit fa87819

Please sign in to comment.