Assume chunks are dirty by default

having them be clean by default makes no sense. It only makes sense for them to be clean if they were loaded directly from disk without any alterations.

Default clean is a footgun.
This commit is contained in:
Dylan K. Taylor 2023-05-29 17:22:39 +01:00
parent c10be0f346
commit ce5e663a73
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 9 additions and 15 deletions

View File

@ -2717,7 +2717,13 @@ class World implements ChunkManager{
return null;
}
$this->chunks[$chunkHash] = $loadedChunkData->getData()->getChunk();
$chunk = $loadedChunkData->getData()->getChunk();
if(!$loadedChunkData->isUpgraded()){
$chunk->clearTerrainDirtyFlags();
}else{
$this->logger->debug("Chunk $x $z has been upgraded, will be saved at the next autosave opportunity");
}
$this->chunks[$chunkHash] = $chunk;
unset($this->blockCache[$chunkHash]);
$this->initChunk($x, $z, $loadedChunkData->getData());

View File

@ -44,7 +44,7 @@ class Chunk{
public const COORD_BIT_SIZE = SubChunk::COORD_BIT_SIZE;
public const COORD_MASK = SubChunk::COORD_MASK;
private int $terrainDirtyFlags = 0;
private int $terrainDirtyFlags = ~0;
protected ?bool $lightPopulated = false;
protected bool $terrainPopulated = false;

View File

@ -695,18 +695,8 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
//TODO: tile ticks, biome states (?)
$chunk = new Chunk(
$subChunks,
$terrainPopulated
);
if($hasBeenUpgraded){
$logger->debug("Flagging chunk as dirty due to upgraded data");
$chunk->setTerrainDirty(); //trigger rewriting chunk to disk if it was converted from an older format
}
return new LoadedChunkData(
data: new ChunkData($chunk, $entities, $tiles),
data: new ChunkData(new Chunk($subChunks, $terrainPopulated), $entities, $tiles),
upgraded: $hasBeenUpgraded,
fixerFlags: LoadedChunkData::FIXER_FLAG_ALL //TODO: fill this by version rather than just setting all flags
);

View File

@ -117,8 +117,6 @@ class PopulationTask extends AsyncTask{
if($chunk === null){
throw new AssumptionFailedError("We just set this chunk, so it must exist");
}
$chunk->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_BLOCKS, true);
$chunk->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_BIOMES, true);
}
return $chunk;
}