mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Revert "Chunk: added modification counter"
This reverts commit a5418a019dc2a83210084632130db8ce06f529ea. The more I assessed this, the more I realized that this implementation doesn't actually offer any value. Since modcounters don't persist after chunk unload + reload, they can't be reliably used to detect changes in chunks without additional event subscriptions. For the purpose I actually intended to use them for (population task cancellation) there's a) another solution, and b) modcounts are unreliable for that too, because of the aforementioned potential for chunks to get unloaded and reloaded. For the case of detecting dirty chunks within PopulationTask itself, they are also unnecessary, since the dirty flags are sufficient within there, since FastChunkSerializer doesn't copy dirty flags. In conclusion, this was a misbegotten addition with little real value, but does impact performance in hot paths.
This commit is contained in:
parent
5db3915aad
commit
a62ce64fdd
@ -41,8 +41,6 @@ class Chunk{
|
||||
public const COORD_BIT_SIZE = SubChunk::COORD_BIT_SIZE;
|
||||
public const COORD_MASK = SubChunk::COORD_MASK;
|
||||
|
||||
private int $modificationCount;
|
||||
|
||||
/** @var int */
|
||||
private $terrainDirtyFlags = 0;
|
||||
|
||||
@ -69,7 +67,7 @@ class Chunk{
|
||||
/**
|
||||
* @param SubChunk[] $subChunks
|
||||
*/
|
||||
public function __construct(array $subChunks, BiomeArray $biomeIds, bool $terrainPopulated, int $modificationCount = 0){
|
||||
public function __construct(array $subChunks, BiomeArray $biomeIds, bool $terrainPopulated){
|
||||
$this->subChunks = new \SplFixedArray(Chunk::MAX_SUBCHUNKS);
|
||||
|
||||
foreach($this->subChunks as $y => $null){
|
||||
@ -81,7 +79,6 @@ class Chunk{
|
||||
$this->biomeIds = $biomeIds;
|
||||
|
||||
$this->terrainPopulated = $terrainPopulated;
|
||||
$this->modificationCount = $modificationCount;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +107,6 @@ class Chunk{
|
||||
public function setFullBlock(int $x, int $y, int $z, int $block) : void{
|
||||
$this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->setFullBlock($x, $y & SubChunk::COORD_MASK, $z, $block);
|
||||
$this->terrainDirtyFlags |= self::DIRTY_FLAG_TERRAIN;
|
||||
$this->modificationCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,7 +170,6 @@ class Chunk{
|
||||
public function setBiomeId(int $x, int $z, int $biomeId) : void{
|
||||
$this->biomeIds->set($x, $z, $biomeId);
|
||||
$this->terrainDirtyFlags |= self::DIRTY_FLAG_BIOMES;
|
||||
$this->modificationCount++;
|
||||
}
|
||||
|
||||
public function isLightPopulated() : ?bool{
|
||||
@ -192,7 +187,6 @@ class Chunk{
|
||||
public function setPopulated(bool $value = true) : void{
|
||||
$this->terrainPopulated = $value;
|
||||
$this->terrainDirtyFlags |= self::DIRTY_FLAG_TERRAIN;
|
||||
$this->modificationCount++;
|
||||
}
|
||||
|
||||
public function addTile(Tile $tile) : void{
|
||||
@ -275,24 +269,16 @@ class Chunk{
|
||||
}else{
|
||||
$this->terrainDirtyFlags &= ~$flag;
|
||||
}
|
||||
$this->modificationCount++;
|
||||
}
|
||||
|
||||
public function setTerrainDirty() : void{
|
||||
$this->terrainDirtyFlags = ~0;
|
||||
$this->modificationCount++;
|
||||
}
|
||||
|
||||
public function clearTerrainDirtyFlags() : void{
|
||||
$this->terrainDirtyFlags = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the modcount for this chunk. Any saveable change to the chunk will cause this number to be incremented,
|
||||
* so you can use this to detect when the chunk has been modified.
|
||||
*/
|
||||
public function getModificationCount() : int{ return $this->modificationCount; }
|
||||
|
||||
public function getSubChunk(int $y) : SubChunk{
|
||||
if($y < 0 || $y >= $this->subChunks->getSize()){
|
||||
throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y");
|
||||
|
@ -51,8 +51,6 @@ final class FastChunkSerializer{
|
||||
*/
|
||||
public static function serializeTerrain(Chunk $chunk) : string{
|
||||
$stream = new BinaryStream();
|
||||
$stream->putLong($chunk->getModificationCount());
|
||||
|
||||
$stream->putByte(
|
||||
($chunk->isPopulated() ? self::FLAG_POPULATED : 0)
|
||||
);
|
||||
@ -90,7 +88,6 @@ final class FastChunkSerializer{
|
||||
*/
|
||||
public static function deserializeTerrain(string $data) : Chunk{
|
||||
$stream = new BinaryStream($data);
|
||||
$modificationCounter = $stream->getLong();
|
||||
|
||||
$flags = $stream->getByte();
|
||||
$terrainPopulated = (bool) ($flags & self::FLAG_POPULATED);
|
||||
@ -118,6 +115,6 @@ final class FastChunkSerializer{
|
||||
|
||||
$biomeIds = new BiomeArray($stream->get(256));
|
||||
|
||||
return new Chunk($subChunks, $biomeIds, $terrainPopulated, $modificationCounter);
|
||||
return new Chunk($subChunks, $biomeIds, $terrainPopulated);
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ class PopulationTask extends AsyncTask{
|
||||
fn(?string $serialized) => $serialized !== null ? FastChunkSerializer::deserializeTerrain($serialized) : null,
|
||||
$serialChunks
|
||||
);
|
||||
$oldModCounts = array_map(fn(?Chunk $chunk) => $chunk !== null ? $chunk->getModificationCount() : null, $chunks);
|
||||
|
||||
self::setOrGenerateChunk($manager, $generator, $this->chunkX, $this->chunkZ, $chunk);
|
||||
|
||||
@ -105,7 +104,7 @@ class PopulationTask extends AsyncTask{
|
||||
|
||||
$serialChunks = [];
|
||||
foreach($chunks as $i => $c){
|
||||
$serialChunks[$i] = $oldModCounts[$i] !== $c->getModificationCount() ? FastChunkSerializer::serializeTerrain($c) : null;
|
||||
$serialChunks[$i] = $c->isTerrainDirty() ? FastChunkSerializer::serializeTerrain($c) : null;
|
||||
}
|
||||
$this->adjacentChunks = igbinary_serialize($serialChunks) ?? throw new AssumptionFailedError("igbinary_serialize() returned null");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user