Core: build no object update packets for bot sessions
A bot session has no client: BotSession::SendPacket throws every packet away. The server still built a create, values, out of range or destroy block for each bot that sees an object, for every changed object, every map update. On a bot realm nearly every player in view is a bot, so a 40 player raid wrote each changing unit about 40 times per step for nobody. With Bots.SkipClientPackets = 1 (default) those blocks are not built for a bot: BaseEntity::BuildFieldsUpdate, SendUpdateToPlayer, DestroyForPlayer, SendOutOfRangeForPlayer, Player::UpdateVisibilityOf, VisibleNotifier and SendInitialVisiblePackets return before writing anything for it. The player's client guid list (HaveAtClient) is still kept exactly as before, so group, spell and visibility rules see no difference. Human players are not touched. 0 builds them as before, so the same build can be timed both ways with .reload config.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "DB2Structure.h"
|
||||
#include "Errors.h"
|
||||
#include "GameTime.h"
|
||||
#include "HeadlessPackets.h"
|
||||
#include "Log.h"
|
||||
#include "MovementPackets.h"
|
||||
#include "Player.h"
|
||||
@@ -27,6 +28,7 @@
|
||||
#include "Transport.h"
|
||||
#include "UpdateData.h"
|
||||
#include "Vehicle.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
namespace WowCS
|
||||
{
|
||||
@@ -144,6 +146,9 @@ void BaseEntity::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* targe
|
||||
|
||||
void BaseEntity::SendUpdateToPlayer(Player* player) const
|
||||
{
|
||||
if (Trinity::HeadlessPackets::Skip(player))
|
||||
return;
|
||||
|
||||
// send create update to player
|
||||
UpdateData upd(player->GetMapId());
|
||||
WorldPacket packet;
|
||||
@@ -220,6 +225,9 @@ void BaseEntity::DestroyForPlayer(Player const* target) const
|
||||
{
|
||||
ASSERT(target);
|
||||
|
||||
if (Trinity::HeadlessPackets::Skip(target))
|
||||
return;
|
||||
|
||||
UpdateData updateData(target->GetMapId());
|
||||
BuildDestroyUpdateBlock(&updateData);
|
||||
WorldPacket packet;
|
||||
@@ -231,6 +239,9 @@ void BaseEntity::SendOutOfRangeForPlayer(Player const* target) const
|
||||
{
|
||||
ASSERT(target);
|
||||
|
||||
if (Trinity::HeadlessPackets::Skip(target))
|
||||
return;
|
||||
|
||||
UpdateData updateData(target->GetMapId());
|
||||
BuildOutOfRangeUpdateBlock(&updateData);
|
||||
WorldPacket packet;
|
||||
@@ -703,6 +714,9 @@ void BaseEntity::BuildUpdateChangesMask()
|
||||
|
||||
void BaseEntity::BuildFieldsUpdate(Player* player, UpdateDataMapType& data_map) const
|
||||
{
|
||||
if (Trinity::HeadlessPackets::Skip(player))
|
||||
return;
|
||||
|
||||
UpdateDataMapType::iterator iter = data_map.emplace(player, player->GetMapId()).first;
|
||||
BuildValuesUpdateBlockForPlayer(&iter->second, iter->first);
|
||||
}
|
||||
@@ -711,3 +725,16 @@ std::string BaseEntity::GetDebugInfo() const
|
||||
{
|
||||
return Trinity::StringFormat("{}", GetGUID());
|
||||
}
|
||||
|
||||
namespace Trinity::HeadlessPackets
|
||||
{
|
||||
std::atomic<bool> Enabled{ true };
|
||||
|
||||
bool Skip(Player const* receiver)
|
||||
{
|
||||
if (!Enabled.load(std::memory_order_relaxed) || !receiver)
|
||||
return false;
|
||||
WorldSession const* session = receiver->GetSession();
|
||||
return session && session->IsBot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRINITYCORE_HEADLESS_PACKETS_H
|
||||
#define TRINITYCORE_HEADLESS_PACKETS_H
|
||||
|
||||
#include "Define.h"
|
||||
#include <atomic>
|
||||
|
||||
class Player;
|
||||
|
||||
// A bot session has no client: every object update the server builds for it is thrown away in its SendPacket. Building those
|
||||
// updates is most of the cost of a busy map (each changed unit is written once for every player that sees it, and nearly every
|
||||
// player on a bot realm is a bot). When this is on, the create, values, out of range and destroy blocks are not built for a bot at
|
||||
// all. What the server knows about visibility (the player's client guid list, HaveAtClient) is kept exactly as before, so no game
|
||||
// rule sees a difference. Config: Bots.SkipClientPackets (worldserver.conf, default 1, `.reload config` applies it).
|
||||
namespace Trinity::HeadlessPackets
|
||||
{
|
||||
TC_GAME_API extern std::atomic<bool> Enabled;
|
||||
|
||||
// True when no update packet needs to be built for this player (a bot session with the switch on).
|
||||
TC_GAME_API bool Skip(Player const* receiver);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -76,6 +76,7 @@
|
||||
#include "GridNotifiersImpl.h"
|
||||
#include "Group.h"
|
||||
#include "GroupMgr.h"
|
||||
#include "HeadlessPackets.h"
|
||||
#include "GameTables.h"
|
||||
#include "GameTime.h"
|
||||
#include "Guild.h"
|
||||
@@ -26159,6 +26160,9 @@ void Player::UpdateTriggerVisibility()
|
||||
|
||||
void Player::SendInitialVisiblePackets(WorldObject* target) const
|
||||
{
|
||||
if (Trinity::HeadlessPackets::Skip(this))
|
||||
return;
|
||||
|
||||
auto sendVignette = [](Vignettes::VignetteData const& vignette, Player const* where)
|
||||
{
|
||||
if (!vignette.Data->IsInfiniteAOI() && Vignettes::CanSee(where, vignette))
|
||||
@@ -26197,10 +26201,13 @@ void Player::UpdateVisibilityOf(T* target, UpdateData& data, std::set<WorldObjec
|
||||
{
|
||||
BeforeVisibilityDestroy<T>(target, this);
|
||||
|
||||
if (!target->IsDestroyedObject())
|
||||
target->BuildOutOfRangeUpdateBlock(&data);
|
||||
else
|
||||
target->BuildDestroyUpdateBlock(&data);
|
||||
if (!Trinity::HeadlessPackets::Skip(this)) // a bot has no client: only the guid list below changes
|
||||
{
|
||||
if (!target->IsDestroyedObject())
|
||||
target->BuildOutOfRangeUpdateBlock(&data);
|
||||
else
|
||||
target->BuildDestroyUpdateBlock(&data);
|
||||
}
|
||||
|
||||
m_clientGUIDs.erase(target->GetGUID());
|
||||
|
||||
@@ -26213,12 +26220,15 @@ void Player::UpdateVisibilityOf(T* target, UpdateData& data, std::set<WorldObjec
|
||||
{
|
||||
if (CanSeeOrDetect(target, { .DistanceCheck = true }))
|
||||
{
|
||||
if (_combatPlateOn)
|
||||
if (Creature const* creature = target->ToCreature())
|
||||
RefreshCombatPlate(creature, GetPet()); // the create block carries the plate state from the start
|
||||
target->BuildCreateUpdateBlockForPlayer(&data, this);
|
||||
m_clientGUIDs.insert(target->GetGUID());
|
||||
visibleNow.insert(target);
|
||||
if (!Trinity::HeadlessPackets::Skip(this))
|
||||
{
|
||||
if (_combatPlateOn)
|
||||
if (Creature const* creature = target->ToCreature())
|
||||
RefreshCombatPlate(creature, GetPet()); // the create block carries the plate state from the start
|
||||
target->BuildCreateUpdateBlockForPlayer(&data, this);
|
||||
visibleNow.insert(target);
|
||||
}
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
TC_LOG_DEBUG("maps", "Object {} is visible now for player {}. Distance = {}", target->GetGUID().ToString(), GetGUID().ToString(), GetDistance(target));
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "CellImpl.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "GridNotifiersImpl.h"
|
||||
#include "HeadlessPackets.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "Transport.h"
|
||||
#include "UpdateData.h"
|
||||
@@ -68,10 +69,12 @@ void VisibleNotifier::SendToSelf()
|
||||
}
|
||||
}
|
||||
|
||||
bool const skipPackets = Trinity::HeadlessPackets::Skip(&i_player);
|
||||
for (ObjectGuid const& outOfRangeGuid : vis_guids)
|
||||
{
|
||||
i_player.m_clientGUIDs.erase(outOfRangeGuid);
|
||||
i_data.AddOutOfRangeGUID(outOfRangeGuid);
|
||||
if (!skipPackets)
|
||||
i_data.AddOutOfRangeGUID(outOfRangeGuid);
|
||||
|
||||
if (outOfRangeGuid.IsPlayer())
|
||||
{
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include "GridNotifiersImpl.h"
|
||||
#include "GroupMgr.h"
|
||||
#include "GuildMgr.h"
|
||||
#include "HeadlessPackets.h"
|
||||
#include "HandcraftedRoadStorage.h"
|
||||
#include "IPLocation.h"
|
||||
#include "InstanceLockMgr.h"
|
||||
@@ -593,6 +594,7 @@ void World::LoadConfigSettings(bool reload)
|
||||
|
||||
TC_LOG_INFO("server.loading", "Using {} DBC Locale", localeNames[m_defaultDbcLocale]);
|
||||
|
||||
Trinity::HeadlessPackets::Enabled.store(sConfigMgr->GetBoolDefault("Bots.SkipClientPackets"sv, true), std::memory_order_relaxed);
|
||||
Trinity::WorldTickStats::Get().enabled.store(sConfigMgr->GetBoolDefault("WorldTickStats.Log"sv, false), std::memory_order_relaxed);
|
||||
|
||||
///- Read the player limit and the Message of the day from the config file
|
||||
|
||||
@@ -640,6 +640,17 @@ AddonChannel = 1
|
||||
|
||||
MapUpdate.Threads = 1
|
||||
|
||||
#
|
||||
# Bots.SkipClientPackets
|
||||
# Description: Do not build object update packets (create, values, out of range, destroy) for bot
|
||||
# sessions. A bot has no client, so these packets were built and then thrown away; on a
|
||||
# busy bot realm that is a large part of every map update. What the server knows about
|
||||
# visibility is kept as before. No effect on a realm without bots.
|
||||
# Default: 1 - (Enabled)
|
||||
# 0 - (Disabled, build them as before; for comparing timings)
|
||||
|
||||
Bots.SkipClientPackets = 1
|
||||
|
||||
#
|
||||
# WorldTickStats.Log
|
||||
# Description: Once a minute, write a [world_tick] line to the server log: how long a game step took
|
||||
|
||||
Reference in New Issue
Block a user