Skip to content

Commit

Permalink
Performance: Only update biomes when a chunk first loads. (#30)
Browse files Browse the repository at this point in the history
* Only check biomes when a chunk is first loaded.

* bump

* Revert "bump"

This reverts commit bda3ad5.
  • Loading branch information
sisby-folk authored Aug 19, 2023
1 parent 306bcbe commit cc93872
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/dev/lambdaurora/lambdamap/LambdaMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.WorldChunk;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -236,7 +237,11 @@ public void updateChunk(World world, int chunkX, int chunkZ) {
}

var mapColor = searcher.getState().getMapColor(world, searcher.pos);
var biome = world.getBiome(searcher.pos);
Biome biome = null;
if (chunk instanceof WorldChunkExtension extendedChunk && extendedChunk.lambdamap$isBiomeDirty()) {
biome = world.getBiome(searcher.pos).value();
}

int shade;

if (mapColor == MapColor.WATER) {
Expand All @@ -263,7 +268,7 @@ public void updateChunk(World world, int chunkX, int chunkZ) {
lastHeights[xOffset] = searcher.getHeight();
int x = mapChunkStartX + xOffset;
int z = mapChunkStartZ + zOffset;
if (mapChunk.putPixelAndPreserve(x, z, (byte) (mapColor.id * 4 + shade), biome.value(), searcher.getState())) {
if (mapChunk.putPixelAndPreserve(x, z, (byte) (mapColor.id * 4 + shade), biome, searcher.getState())) {
this.hud.markDirty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

public interface WorldChunkExtension {
boolean lambdamap$isDirty();
boolean lambdamap$isBiomeDirty();

void lambdamap$markDirty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@
public class WorldChunkMixin implements WorldChunkExtension {
@Unique
private boolean lambdamap$dirty;
@Unique
private boolean lambdamap$biomeDirty = true;

@Override
public boolean lambdamap$isDirty() {
return this.lambdamap$dirty;
}

@Override
public boolean lambdamap$isBiomeDirty() {
return this.lambdamap$biomeDirty;
}

@Override
public void lambdamap$markDirty() {
this.lambdamap$dirty = true;
Expand All @@ -40,5 +47,6 @@ public class WorldChunkMixin implements WorldChunkExtension {
@Override
public void lambdamap$markClean() {
this.lambdamap$dirty = false;
this.lambdamap$biomeDirty = false;
}
}

0 comments on commit cc93872

Please sign in to comment.