From c18cba4faf76dfdfb96f16187bcf502731dbb102 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Thu, 14 Nov 2024 05:45:53 -0600 Subject: [PATCH] More changes --- zone/bot.cpp | 33 ------------------- zone/client.cpp | 55 +++++++++++++++++++++---------- zone/client.h | 1 + zone/client_process.cpp | 2 +- zone/effects.cpp | 2 +- zone/entity.cpp | 17 ++-------- zone/entity.h | 2 -- zone/mob_movement_manager.cpp | 2 +- zone/zone.cpp | 61 ----------------------------------- zone/zone.h | 3 -- 10 files changed, 44 insertions(+), 134 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index aa746e767..b0f32b406 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -7390,39 +7390,6 @@ void EntityList::ShowSpawnWindow(Client* client, int Distance, bool NamedOnly) { return; } -/** - * @param close_mobs - * @param scanning_mob - */ -void EntityList::ScanCloseClientMobs(std::unordered_map& close_mobs, Mob* scanning_mob) -{ - float scan_range = RuleI(Range, MobCloseScanDistance) * RuleI(Range, MobCloseScanDistance); - - close_mobs.clear(); - - for (auto& e : mob_list) { - auto mob = e.second; - - if (!mob->IsClient()) { - continue; - } - - if (mob->GetID() <= 0) { - continue; - } - - float distance = DistanceSquared(scanning_mob->GetPosition(), mob->GetPosition()); - if (distance <= scan_range) { - close_mobs.insert(std::pair(mob->GetID(), mob)); - } - else if (mob->GetAggroRange() >= scan_range) { - close_mobs.insert(std::pair(mob->GetID(), mob)); - } - } - - LogAIScanCloseDetail("Close Client Mob List Size [{}] for mob [{}]", close_mobs.size(), scanning_mob->GetCleanName()); -} - uint8 Bot::GetNumberNeedingHealedInGroup(uint8 hpr, bool includePets, Raid* raid) { uint8 need_healed = 0; diff --git a/zone/client.cpp b/zone/client.cpp index f6286f47c..8ae081fee 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -12939,17 +12939,10 @@ void Client::SendTopLevelInventory() } } -// On a normal basis we limit mob movement updates based on distance -// This ensures we send a periodic full zone update to a client that has started moving after 5 or so minutes -// -// For very large zones we will also force a full update based on distance -// -// We ignore a small distance around us so that we don't interrupt already pathing deltas as those npcs will appear -// to full stop when they are actually still pathing void Client::CheckSendBulkClientPositionUpdate() { float distance_moved = DistanceNoZ(m_last_position_before_bulk_update, GetPosition()); - bool moved_far_enough_before_bulk_update = distance_moved >= zone->GetNpcPositionUpdateDistance(); + bool moved_far_enough_before_bulk_update = distance_moved >= zone->GetMaxUpdateRange(); bool is_ready_to_update = ( m_client_zone_wide_full_position_update_timer.Check() || moved_far_enough_before_bulk_update ); @@ -12958,25 +12951,33 @@ void Client::CheckSendBulkClientPositionUpdate() LogDebug("[[{}]] Client Zone Wide Position Update NPCs", GetCleanName()); auto &mob_movement_manager = MobMovementManager::Get(); - auto &mob_list = entity_list.GetMobList(); - for (auto &it : mob_list) { - Mob *entity = it.second; - if (!entity->IsNPC()) { + for (auto &e: entity_list.GetMobList()) { + Mob *mob = e.second; + if (!mob->IsNPC()) { continue; } int animation_speed = 0; - if (entity->IsMoving()) { - if (entity->IsRunning()) { - animation_speed = (entity->IsFeared() ? entity->GetFearSpeed() : entity->GetRunspeed()); + if (mob->IsMoving()) { + if (mob->IsRunning()) { + animation_speed = (mob->IsFeared() ? mob->GetFearSpeed() : mob->GetRunspeed()); } else { - animation_speed = entity->GetWalkspeed(); + animation_speed = mob->GetWalkspeed(); } } - mob_movement_manager.SendCommandToClients(entity, 0.0, 0.0, 0.0, 0.0, animation_speed, ClientRangeAny, this); + mob_movement_manager.SendCommandToClients( + mob, + 0.0, + 0.0, + 0.0, + 0.0, + animation_speed, + ClientRangeAny, + this + ); } m_last_position_before_bulk_update = GetPosition(); @@ -13123,3 +13124,23 @@ void Client::SetAAEXPPercentage(uint8 percentage) SendAlternateAdvancementStats(); SendAlternateAdvancementTable(); } + +void Client::BroadcastPositionUpdate() +{ + EQApplicationPacket outapp(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct)); + PlayerPositionUpdateServer_Struct *spu = (PlayerPositionUpdateServer_Struct *) outapp.pBuffer; + + memset(spu, 0x00, sizeof(PlayerPositionUpdateServer_Struct)); + spu->spawn_id = GetID(); + spu->x_pos = FloatToEQ19(GetX()); + spu->y_pos = FloatToEQ19(GetY()); + spu->z_pos = FloatToEQ19(GetZ()); + spu->heading = FloatToEQ12(GetHeading()); + spu->delta_x = FloatToEQ13(0); + spu->delta_y = FloatToEQ13(0); + spu->delta_z = FloatToEQ13(0); + spu->delta_heading = FloatToEQ10(0); + spu->animation = 0; + + entity_list.QueueCloseClients(this, &outapp, true, zone->GetMaxUpdateRange()); +} diff --git a/zone/client.h b/zone/client.h index e8a93bac5..b45651451 100644 --- a/zone/client.h +++ b/zone/client.h @@ -2087,6 +2087,7 @@ private: Timer m_client_npc_aggro_scan_timer; void CheckClientToNpcAggroTimer(); void ClientToNpcAggroProcess(); + void BroadcastPositionUpdate(); // bulk position updates glm::vec4 m_last_position_before_bulk_update; diff --git a/zone/client_process.cpp b/zone/client_process.cpp index fd0028268..2894fb354 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -122,7 +122,7 @@ bool Client::Process() { /* I haven't naturally updated my position in 10 seconds, updating manually */ if (!IsMoving() && m_position_update_timer.Check()) { - SentPositionPacket(0.0f, 0.0f, 0.0f, 0.0f, 0); + CastToClient()->BroadcastPositionUpdate(); } if (mana_timer.Check()) diff --git a/zone/effects.cpp b/zone/effects.cpp index 63e349f1b..7329ce2f0 100644 --- a/zone/effects.cpp +++ b/zone/effects.cpp @@ -1122,7 +1122,7 @@ void EntityList::AESpell( LogAoeCast( "Close scan distance [{}] cast distance [{}]", - RuleI(Range, MobCloseScanDistance), + zone->GetMaxUpdateRange(), distance ); diff --git a/zone/entity.cpp b/zone/entity.cpp index 2d1cdeaba..f58d1ce7e 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -1717,15 +1717,6 @@ void EntityList::QueueClientsByXTarget(Mob *sender, const EQApplicationPacket *a } } -/** - * @param sender - * @param app - * @param ignore_sender - * @param distance - * @param skipped_mob - * @param is_ack_required - * @param filter - */ void EntityList::QueueCloseClients( Mob *sender, const EQApplicationPacket *app, @@ -1742,7 +1733,7 @@ void EntityList::QueueCloseClients( } if (distance <= 0) { - distance = 600; + distance = zone->GetMaxUpdateRange(); } float distance_squared = distance * distance; @@ -5852,14 +5843,10 @@ void EntityList::ReloadMerchants() { * then we return the full list * * See comments @EntityList::ScanCloseMobs for system explanation - * - * @param mob - * @param distance - * @return */ std::unordered_map &EntityList::GetCloseMobList(Mob *mob, float distance) { - if (distance <= RuleI(Range, MobCloseScanDistance)) { + if (distance <= zone->GetMaxUpdateRange()) { return mob->m_close_mobs; } diff --git a/zone/entity.h b/zone/entity.h index f52ae8c3c..b897eb704 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -632,8 +632,6 @@ private: bool Bot_AICheckCloseBeneficialSpells(Bot* caster, uint8 iChance, float iRange, uint32 iSpellTypes); // TODO: Evaluate this closesly in hopes to eliminate void ShowSpawnWindow(Client* client, int Distance, bool NamedOnly); // TODO: Implement ShowSpawnWindow in the bot class but it needs entity list stuff - void ScanCloseClientMobs(std::unordered_map& close_mobs, Mob* scanning_mob); - void GetBotList(std::list &b_list); private: std::list bot_list; diff --git a/zone/mob_movement_manager.cpp b/zone/mob_movement_manager.cpp index 3bb5996a2..7f21ff07c 100644 --- a/zone/mob_movement_manager.cpp +++ b/zone/mob_movement_manager.cpp @@ -856,7 +856,7 @@ void MobMovementManager::SendCommandToClients( } else { float short_range = RuleR(Pathing, ShortMovementUpdateRange); - float long_range = zone->GetNpcPositionUpdateDistance(); + float long_range = zone->GetMaxUpdateRange(); for (auto &c : _impl->Clients) { if (single_client && c != single_client) { diff --git a/zone/zone.cpp b/zone/zone.cpp index cc78a907f..e6438d96b 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -1091,7 +1091,6 @@ Zone::Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name) mMovementManager = &MobMovementManager::Get(); - SetNpcPositionUpdateDistance(0); SetQuestHotReloadQueued(false); } @@ -1538,10 +1537,6 @@ bool Zone::Process() { if (adv_data && !did_adventure_actions) { DoAdventureActions(); } - - if (GetNpcPositionUpdateDistance() == 0) { - CalculateNpcUpdateDistanceSpread(); - } } if (hot_reload_timer.Check() && IsQuestHotReloadQueued()) { @@ -2735,62 +2730,6 @@ void Zone::SetUCSServerAvailable(bool ucss_available, uint32 update_timestamp) { m_ucss_available = ucss_available; } -int Zone::GetNpcPositionUpdateDistance() const -{ - return npc_position_update_distance; -} - -void Zone::SetNpcPositionUpdateDistance(int in_npc_position_update_distance) -{ - Zone::npc_position_update_distance = in_npc_position_update_distance; -} - -void Zone::CalculateNpcUpdateDistanceSpread() -{ - float max_x = 0; - float max_y = 0; - float min_x = 0; - float min_y = 0; - - auto &mob_list = entity_list.GetMobList(); - - for (auto &it : mob_list) { - Mob *entity = it.second; - if (!entity->IsNPC()) { - continue; - } - - if (entity->GetX() <= min_x) { - min_x = entity->GetX(); - } - - if (entity->GetY() <= min_y) { - min_y = entity->GetY(); - } - - if (entity->GetX() >= max_x) { - max_x = entity->GetX(); - } - - if (entity->GetY() >= max_y) { - max_y = entity->GetY(); - } - } - - int x_spread = int(std::abs(max_x - min_x)); - int y_spread = int(std::abs(max_y - min_y)); - int combined_spread = int(std::abs((x_spread + y_spread) / 2)); - int update_distance = EQ::ClampLower(int(combined_spread / 4), int(zone->GetMaxUpdateRange())); - - SetNpcPositionUpdateDistance(update_distance); - - Log(Logs::General, Logs::Debug, - "NPC update spread distance set to [%i] combined_spread [%i]", - update_distance, - combined_spread - ); -} - bool Zone::IsQuestHotReloadQueued() const { return quest_hot_reload_queued; diff --git a/zone/zone.h b/zone/zone.h index a86987f1f..c38126cb9 100755 --- a/zone/zone.h +++ b/zone/zone.h @@ -156,9 +156,6 @@ public: bool SaveZoneCFG(); bool DoesAlternateCurrencyExist(uint32 currency_id); - int GetNpcPositionUpdateDistance() const; - void SetNpcPositionUpdateDistance(int in_npc_position_update_distance); - char *adv_data; const char *GetSpellBlockedMessage(uint32 spell_id, const glm::vec3 &location);