experimental: use morton code to represent chunks
This avoids creating new objects (for vec3 or string) for each chunk, and just returns an int. For now, using 10bits is kind of limiting, and some other way of easily expressing ints longer than 32bits is neededtreemaps-chunkstates-spacefilling
parent
ad2c5c2c18
commit
be8cb056d3
|
@ -8,6 +8,7 @@ import java.util.concurrent.LinkedBlockingDeque;
|
|||
import com.emamaker.voxeltest.intervaltrees.Voxel;
|
||||
import com.emamaker.voxeltest.intervaltrees.renderer.ChunkRenderer;
|
||||
import com.emamaker.voxeltest.intervaltrees.utils.Config;
|
||||
import com.emamaker.voxeltest.intervaltrees.utils.SpaceFilling;
|
||||
import com.emamaker.voxeltest.intervaltrees.utils.Utils;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Node;
|
||||
|
@ -22,7 +23,7 @@ public class WorldManager {
|
|||
|
||||
Node worldNode = new Node();
|
||||
|
||||
ConcurrentHashMap<String, Chunk> chunks = new ConcurrentHashMap<>();
|
||||
ConcurrentHashMap<Integer, Chunk> chunks = new ConcurrentHashMap<>();
|
||||
|
||||
public WorldManager(final Voxel game_) {
|
||||
this.game = game_;
|
||||
|
@ -31,8 +32,8 @@ public class WorldManager {
|
|||
public void initWorld() {
|
||||
}
|
||||
|
||||
String s;
|
||||
int chunkX, chunkY, chunkZ;
|
||||
int index;
|
||||
public boolean generated = false, meshed = false;
|
||||
|
||||
public void update() {
|
||||
|
@ -57,8 +58,8 @@ public class WorldManager {
|
|||
for (int k = Math.max(0, chunkZ - Config.RENDER_DISTANCE); k < chunkZ + Config.RENDER_DISTANCE; k++) {
|
||||
if(!Utils.withinDistance(chunkX, chunkY, chunkZ, i,j,k,Config.RENDER_DISTANCE)) continue;
|
||||
|
||||
s = i + "," + j + "," + k;
|
||||
if (!chunks.containsKey(s)) chunks.put(s, new Chunk(i,j,k));
|
||||
index = SpaceFilling.Morton_3D_Encode_10bit((short)i, (short)j, (short)k);
|
||||
if (!chunks.containsKey(index)) chunks.put(index, new Chunk(i,j,k));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +92,7 @@ public class WorldManager {
|
|||
}
|
||||
if(!Utils.withinDistance(chunkX, chunkY, chunkZ, (int)c.posx, (int)c.posy, (int)c.posz, Config.RENDER_DISTANCE)){
|
||||
c.chunkNode.removeFromParent();
|
||||
chunks.remove(c.posx + "," + c.posy + "," + c.posz);
|
||||
chunks.remove(SpaceFilling.Morton_3D_Encode_10bit((short)c.posx, (short)c.posy, (short)c.posz));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue