Mob position updates now completely only send to 600 units range defined by Range:MobPositionUpdates

Client updates nearby clients more often because they will disappear after 10 seconds without a position update to the client
This results in a massive reduction in unnecessary traffic as we only update clients of their relevance around them
This also resembles live-like packet sending behavior of positions
This commit is contained in:
Akkadius
2017-07-10 23:03:40 -05:00
parent dceb79ad69
commit ec00daa5be
7 changed files with 73 additions and 69 deletions
+22 -10
View File
@@ -256,17 +256,29 @@ bool Client::Process() {
close_npcs.clear();
auto &npc_list = entity_list.GetNPCList();
auto &mob_list = entity_list.GetMobList();
float scan_range = (RuleI(Range, ClientNPCScan) * RuleI(Range, ClientNPCScan));
float client_update_range = (RuleI(Range, MobPositionUpdates) * RuleI(Range, MobPositionUpdates));
float scan_range = RuleI(Range, ClientNPCScan);
for (auto itr = npc_list.begin(); itr != npc_list.end(); ++itr) {
NPC* npc = itr->second;
float distance = DistanceNoZ(m_Position, npc->GetPosition());
if(distance <= scan_range) {
close_npcs.insert(std::pair<NPC *, float>(npc, distance));
for (auto itr = mob_list.begin(); itr != mob_list.end(); ++itr) {
Mob* mob = itr->second;
float distance = DistanceSquared(m_Position, mob->GetPosition());
if (mob->IsNPC()) {
if (distance <= scan_range) {
close_npcs.insert(std::pair<NPC *, float>(mob->CastToNPC(), distance));
}
else if (mob->GetAggroRange() > scan_range) {
close_npcs.insert(std::pair<NPC *, float>(mob->CastToNPC(), distance));
}
}
else if (npc->GetAggroRange() > scan_range) {
close_npcs.insert(std::pair<NPC *, float>(npc, distance));
/* Clients need to be kept up to date for position updates more often otherwise they disappear */
if (mob->IsClient() && this != mob && distance <= client_update_range) {
auto app = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
PlayerPositionUpdateServer_Struct* spawn_update = (PlayerPositionUpdateServer_Struct*)app->pBuffer;
mob->MakeSpawnUpdateNoDelta(spawn_update);
this->FastQueuePacket(&app, false);
safe_delete(app);
}
}
}
@@ -455,7 +467,7 @@ bool Client::Process() {
// Send a position packet every 8 seconds - if not done, other clients
// see this char disappear after 10-12 seconds of inactivity
if (position_timer_counter >= 36) { // Approx. 4 ticks per second
entity_list.SendPositionUpdates(this, pLastUpdateWZ, 500, GetTarget(), true);
entity_list.SendPositionUpdates(this, pLastUpdateWZ, RuleI(Range, MobPositionUpdates), GetTarget(), true);
pLastUpdate = Timer::GetCurrentTime();
pLastUpdateWZ = pLastUpdate;
position_timer_counter = 0;