diff --git a/src/main/java/com/github/halotroop/litecraft/world/DynamicChunkLoader.java b/src/main/java/com/github/halotroop/litecraft/world/DynamicChunkLoader.java index 10fbb91..73386fe 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/DynamicChunkLoader.java +++ b/src/main/java/com/github/halotroop/litecraft/world/DynamicChunkLoader.java @@ -3,9 +3,11 @@ package com.github.halotroop.litecraft.world; import java.util.*; import java.util.function.LongConsumer; +import com.github.hydos.multiThreading.GingerThread; + import it.unimi.dsi.fastutil.longs.*; -public class DynamicChunkLoader extends Thread{ +public class DynamicChunkLoader extends GingerThread{ public int chunkX, chunkY, chunkZ; public World world; @@ -15,6 +17,7 @@ public class DynamicChunkLoader extends Thread{ this.chunkY = chunkY; this.chunkZ = chunkZ; this.world = world; + this.setName("DynamicChunk thread"); } @Override @@ -23,7 +26,7 @@ public class DynamicChunkLoader extends Thread{ // loop over rendered area, adding chunks that are needed for (int x = chunkX - this.world.renderBound; x < chunkX + this.world.renderBound; x++) for (int z = chunkZ - this.world.renderBound; z < chunkZ + this.world.renderBound; z++) - for (int y = chunkY - this.world.renderBoundVertical; y < chunkY + this.world.renderBoundVertical; y++) + for (int y = chunkY - this.world.renderBound; y < chunkY + this.world.renderBound; y++) toKeep.add(this.world.getChunkToLoad(x, y, z)); // list of keys to remove LongList toRemove = new LongArrayList(); diff --git a/src/main/java/com/github/halotroop/litecraft/world/World.java b/src/main/java/com/github/halotroop/litecraft/world/World.java index fa8f7a3..0c8c9da 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/World.java +++ b/src/main/java/com/github/halotroop/litecraft/world/World.java @@ -29,9 +29,11 @@ public class World implements BlockAccess, WorldGenConstants int renderBound; int renderBoundVertical; private final BlockInstance dummy; + private DynamicChunkLoader chunkLoader; public World(long seed, int renderSize, Dimension dim, LitecraftSave save) { + this.chunkLoader = new DynamicChunkLoader(0, 0, 0, this); this.dummy = new BlockInstance(Blocks.ANDESITE, new Vector3f(0, 0, 0)); this.dummy.isVisible = false; this.chunks = new Long2ObjectArrayMap<>(); @@ -183,8 +185,12 @@ public class World implements BlockAccess, WorldGenConstants public void updateLoadedChunks(int chunkX, int chunkY, int chunkZ) { - DynamicChunkLoader chunkLoader = new DynamicChunkLoader(chunkX, chunkY, chunkZ, this); - chunkLoader.start(); + if(!chunkLoader.isAlive()) { + chunkLoader.chunkX = chunkX; + chunkLoader.chunkY = chunkY; + chunkLoader.chunkZ = chunkZ; + chunkLoader.start(); + } } private static final class GenerationWorld implements BlockAccess, WorldGenConstants