PreSpawnPacketHandler: added dedicated timer for the humongous amount of crap that has to be sent pre-spawn

This commit is contained in:
Dylan K. Taylor 2023-04-05 20:58:49 +01:00
parent b2f755720d
commit 61b0ad3e7f
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 82 additions and 74 deletions

View File

@ -44,6 +44,7 @@ use pocketmine\network\mcpe\protocol\types\PlayerMovementType;
use pocketmine\network\mcpe\protocol\types\SpawnSettings;
use pocketmine\player\Player;
use pocketmine\Server;
use pocketmine\timings\Timings;
use pocketmine\VersionInfo;
use Ramsey\Uuid\Uuid;
use function sprintf;
@ -60,89 +61,94 @@ class PreSpawnPacketHandler extends PacketHandler{
){}
public function setUp() : void{
$location = $this->player->getLocation();
$world = $location->getWorld();
Timings::$playerNetworkSendPreSpawnGameData->startTiming();
try{
$location = $this->player->getLocation();
$world = $location->getWorld();
$this->session->getLogger()->debug("Preparing StartGamePacket");
$levelSettings = new LevelSettings();
$levelSettings->seed = -1;
$levelSettings->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly
$levelSettings->worldGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($this->server->getGamemode());
$levelSettings->difficulty = $world->getDifficulty();
$levelSettings->spawnPosition = BlockPosition::fromVector3($world->getSpawnLocation());
$levelSettings->hasAchievementsDisabled = true;
$levelSettings->time = $world->getTime();
$levelSettings->eduEditionOffer = 0;
$levelSettings->rainLevel = 0; //TODO: implement these properly
$levelSettings->lightningLevel = 0;
$levelSettings->commandsEnabled = true;
$levelSettings->gameRules = [
"naturalregeneration" => new BoolGameRule(false, false) //Hack for client side regeneration
];
$levelSettings->experiments = new Experiments([], false);
$this->session->getLogger()->debug("Preparing StartGamePacket");
$levelSettings = new LevelSettings();
$levelSettings->seed = -1;
$levelSettings->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly
$levelSettings->worldGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($this->server->getGamemode());
$levelSettings->difficulty = $world->getDifficulty();
$levelSettings->spawnPosition = BlockPosition::fromVector3($world->getSpawnLocation());
$levelSettings->hasAchievementsDisabled = true;
$levelSettings->time = $world->getTime();
$levelSettings->eduEditionOffer = 0;
$levelSettings->rainLevel = 0; //TODO: implement these properly
$levelSettings->lightningLevel = 0;
$levelSettings->commandsEnabled = true;
$levelSettings->gameRules = [
"naturalregeneration" => new BoolGameRule(false, false) //Hack for client side regeneration
];
$levelSettings->experiments = new Experiments([], false);
$this->session->sendDataPacket(StartGamePacket::create(
$this->player->getId(),
$this->player->getId(),
TypeConverter::getInstance()->coreGameModeToProtocol($this->player->getGamemode()),
$this->player->getOffsetPosition($location),
$location->pitch,
$location->yaw,
new CacheableNbt(CompoundTag::create()), //TODO: we don't care about this right now
$levelSettings,
"",
$this->server->getMotd(),
"",
false,
new PlayerMovementSettings(PlayerMovementType::SERVER_AUTHORITATIVE_V1, 0, false),
0,
0,
"",
true,
sprintf("%s %s", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true)),
Uuid::fromString(Uuid::NIL),
false,
[],
0,
GlobalItemTypeDictionary::getInstance()->getDictionary()->getEntries(),
));
$this->session->sendDataPacket(StartGamePacket::create(
$this->player->getId(),
$this->player->getId(),
TypeConverter::getInstance()->coreGameModeToProtocol($this->player->getGamemode()),
$this->player->getOffsetPosition($location),
$location->pitch,
$location->yaw,
new CacheableNbt(CompoundTag::create()), //TODO: we don't care about this right now
$levelSettings,
"",
$this->server->getMotd(),
"",
false,
new PlayerMovementSettings(PlayerMovementType::SERVER_AUTHORITATIVE_V1, 0, false),
0,
0,
"",
true,
sprintf("%s %s", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true)),
Uuid::fromString(Uuid::NIL),
false,
[],
0,
GlobalItemTypeDictionary::getInstance()->getDictionary()->getEntries(),
));
$this->session->getLogger()->debug("Sending actor identifiers");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers());
$this->session->getLogger()->debug("Sending actor identifiers");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers());
$this->session->getLogger()->debug("Sending biome definitions");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getBiomeDefs());
$this->session->getLogger()->debug("Sending biome definitions");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getBiomeDefs());
$this->session->getLogger()->debug("Sending attributes");
$this->session->getEntityEventBroadcaster()->syncAttributes([$this->session], $this->player, $this->player->getAttributeMap()->getAll());
$this->session->getLogger()->debug("Sending attributes");
$this->session->getEntityEventBroadcaster()->syncAttributes([$this->session], $this->player, $this->player->getAttributeMap()->getAll());
$this->session->getLogger()->debug("Sending available commands");
$this->session->syncAvailableCommands();
$this->session->getLogger()->debug("Sending available commands");
$this->session->syncAvailableCommands();
$this->session->getLogger()->debug("Sending abilities");
$this->session->syncAbilities($this->player);
$this->session->syncAdventureSettings();
$this->session->getLogger()->debug("Sending abilities");
$this->session->syncAbilities($this->player);
$this->session->syncAdventureSettings();
$this->session->getLogger()->debug("Sending effects");
foreach($this->player->getEffects()->all() as $effect){
$this->session->getEntityEventBroadcaster()->onEntityEffectAdded([$this->session], $this->player, $effect, false);
$this->session->getLogger()->debug("Sending effects");
foreach($this->player->getEffects()->all() as $effect){
$this->session->getEntityEventBroadcaster()->onEntityEffectAdded([$this->session], $this->player, $effect, false);
}
$this->session->getLogger()->debug("Sending actor metadata");
$this->player->sendData([$this->player]);
$this->session->getLogger()->debug("Sending inventory");
$this->inventoryManager->syncAll();
$this->inventoryManager->syncSelectedHotbarSlot();
$this->session->getLogger()->debug("Sending creative inventory data");
$this->inventoryManager->syncCreative();
$this->session->getLogger()->debug("Sending crafting data");
$this->session->sendDataPacket(CraftingDataCache::getInstance()->getCache($this->server->getCraftingManager()));
$this->session->getLogger()->debug("Sending player list");
$this->session->syncPlayerList($this->server->getOnlinePlayers());
}finally{
Timings::$playerNetworkSendPreSpawnGameData->stopTiming();
}
$this->session->getLogger()->debug("Sending actor metadata");
$this->player->sendData([$this->player]);
$this->session->getLogger()->debug("Sending inventory");
$this->inventoryManager->syncAll();
$this->inventoryManager->syncSelectedHotbarSlot();
$this->session->getLogger()->debug("Sending creative inventory data");
$this->inventoryManager->syncCreative();
$this->session->getLogger()->debug("Sending crafting data");
$this->session->sendDataPacket(CraftingDataCache::getInstance()->getCache($this->server->getCraftingManager()));
$this->session->getLogger()->debug("Sending player list");
$this->session->syncPlayerList($this->server->getOnlinePlayers());
}
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{

View File

@ -68,6 +68,7 @@ abstract class Timings{
public static $playerNetworkSendEncrypt;
public static TimingsHandler $playerNetworkSendInventorySync;
public static TimingsHandler $playerNetworkSendPreSpawnGameData;
/** @var TimingsHandler */
public static $playerNetworkReceive;
@ -187,6 +188,7 @@ abstract class Timings{
self::$playerNetworkSendCompressSessionBuffer = new TimingsHandler("Player Network Send - Compression (Session Buffer)", self::$playerNetworkSendCompress, group: self::GROUP_BREAKDOWN);
self::$playerNetworkSendEncrypt = new TimingsHandler("Player Network Send - Encryption", self::$playerNetworkSend, group: self::GROUP_BREAKDOWN);
self::$playerNetworkSendInventorySync = new TimingsHandler("Player Network Send - Inventory Sync", self::$playerNetworkSend, group: self::GROUP_BREAKDOWN);
self::$playerNetworkSendPreSpawnGameData = new TimingsHandler("Player Network Send - Pre-Spawn Game Data", self::$playerNetworkSend, group: self::GROUP_BREAKDOWN);
self::$playerNetworkReceive = new TimingsHandler("Player Network Receive", self::$connection);
self::$playerNetworkReceiveDecompress = new TimingsHandler("Player Network Receive - Decompression", self::$playerNetworkReceive, group: self::GROUP_BREAKDOWN);