mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 20:28:31 +00:00
Use a falling block entity to improve client side performance of FloatingTextParticle (#4714)
Performance tests show that this has a considerable client-side performance advantage over using players. In my local tests, using 1000 floating texts in a 10x10x10 area, I observed an FPS increase from 1.5 to 8.0.
This commit is contained in:
parent
5e3b3a0700
commit
eb916fe43d
@ -23,29 +23,20 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\world\particle;
|
namespace pocketmine\world\particle;
|
||||||
|
|
||||||
|
use pocketmine\block\VanillaBlocks;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\entity\Skin;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\network\mcpe\convert\SkinAdapterSingleton;
|
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
|
||||||
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
|
use pocketmine\network\mcpe\protocol\AddActorPacket;
|
||||||
use pocketmine\network\mcpe\protocol\PlayerListPacket;
|
|
||||||
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
|
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
|
||||||
use pocketmine\network\mcpe\protocol\types\command\CommandPermissions;
|
use pocketmine\network\mcpe\protocol\types\entity\ByteMetadataProperty;
|
||||||
use pocketmine\network\mcpe\protocol\types\DeviceOS;
|
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
|
||||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||||
use pocketmine\network\mcpe\protocol\types\entity\FloatMetadataProperty;
|
use pocketmine\network\mcpe\protocol\types\entity\FloatMetadataProperty;
|
||||||
|
use pocketmine\network\mcpe\protocol\types\entity\IntMetadataProperty;
|
||||||
use pocketmine\network\mcpe\protocol\types\entity\LongMetadataProperty;
|
use pocketmine\network\mcpe\protocol\types\entity\LongMetadataProperty;
|
||||||
use pocketmine\network\mcpe\protocol\types\GameMode;
|
use pocketmine\network\mcpe\protocol\types\entity\StringMetadataProperty;
|
||||||
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
|
|
||||||
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
|
|
||||||
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
|
||||||
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
|
||||||
use pocketmine\network\mcpe\protocol\types\UpdateAbilitiesPacketLayer;
|
|
||||||
use pocketmine\network\mcpe\protocol\UpdateAbilitiesPacket;
|
|
||||||
use Ramsey\Uuid\Uuid;
|
|
||||||
use function array_fill;
|
|
||||||
use function str_repeat;
|
|
||||||
|
|
||||||
class FloatingTextParticle implements Particle{
|
class FloatingTextParticle implements Particle{
|
||||||
//TODO: HACK!
|
//TODO: HACK!
|
||||||
@ -98,45 +89,34 @@ class FloatingTextParticle implements Particle{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->invisible){
|
if(!$this->invisible){
|
||||||
$uuid = Uuid::uuid4();
|
|
||||||
$name = $this->title . ($this->text !== "" ? "\n" . $this->text : "");
|
$name = $this->title . ($this->text !== "" ? "\n" . $this->text : "");
|
||||||
|
|
||||||
$p[] = PlayerListPacket::add([PlayerListEntry::createAdditionEntry($uuid, $this->entityId, $name, SkinAdapterSingleton::get()->toSkinData(new Skin("Standard_Custom", str_repeat("\x00", 8192))))]);
|
|
||||||
|
|
||||||
$actorFlags = (
|
$actorFlags = (
|
||||||
1 << EntityMetadataFlags::IMMOBILE
|
1 << EntityMetadataFlags::IMMOBILE
|
||||||
);
|
);
|
||||||
$actorMetadata = [
|
$actorMetadata = [
|
||||||
EntityMetadataProperties::FLAGS => new LongMetadataProperty($actorFlags),
|
EntityMetadataProperties::FLAGS => new LongMetadataProperty($actorFlags),
|
||||||
EntityMetadataProperties::SCALE => new FloatMetadataProperty(0.01) //zero causes problems on debug builds
|
EntityMetadataProperties::SCALE => new FloatMetadataProperty(0.01), //zero causes problems on debug builds
|
||||||
|
EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0),
|
||||||
|
EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0),
|
||||||
|
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($name),
|
||||||
|
EntityMetadataProperties::VARIANT => new IntMetadataProperty(RuntimeBlockMapping::getInstance()->toRuntimeId(VanillaBlocks::AIR()->getFullId())),
|
||||||
|
EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1),
|
||||||
];
|
];
|
||||||
$p[] = AddPlayerPacket::create(
|
$p[] = AddActorPacket::create(
|
||||||
$uuid,
|
|
||||||
$name,
|
|
||||||
$this->entityId, //TODO: actor unique ID
|
$this->entityId, //TODO: actor unique ID
|
||||||
"",
|
$this->entityId,
|
||||||
$pos, //TODO: check offset
|
EntityIds::FALLING_BLOCK,
|
||||||
|
$pos, //TODO: check offset (0.49?)
|
||||||
null,
|
null,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
ItemStackWrapper::legacy(ItemStack::null()),
|
0,
|
||||||
GameMode::SURVIVAL,
|
|
||||||
$actorMetadata,
|
|
||||||
UpdateAbilitiesPacket::create(CommandPermissions::NORMAL, PlayerPermissions::VISITOR, $this->entityId, [
|
|
||||||
new UpdateAbilitiesPacketLayer(
|
|
||||||
UpdateAbilitiesPacketLayer::LAYER_BASE,
|
|
||||||
array_fill(0, UpdateAbilitiesPacketLayer::NUMBER_OF_ABILITIES, false),
|
|
||||||
0.0,
|
|
||||||
0.0
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
[],
|
[],
|
||||||
"",
|
$actorMetadata,
|
||||||
DeviceOS::UNKNOWN
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
$p[] = PlayerListPacket::remove([PlayerListEntry::createRemovalEntry($uuid)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $p;
|
return $p;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user