diff --git a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java index b7ce9e04..fd115371 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java @@ -87,7 +87,6 @@ public class VoxelCore { Capabilities.init();//Ensure clinit is called this.renderer = new RenderService(this.world, this.serviceThreadPool); - Logger.info("Using " + this.renderer.getClass().getSimpleName()); this.postProcessing = new PostProcessing(); Logger.info("Voxy core initialized"); @@ -430,7 +429,7 @@ public class VoxelCore { } } long delta = (System.currentTimeMillis()-start); - System.out.println("Time "+delta+"ms count: " + completedCounter.get() + " avg per mesh: " + ((double)delta/completedCounter.get())); + System.out.println("Time "+delta+"ms count: " + completedCounter.get() + " avg per mesh: " + ((double)delta/completedCounter.get()) + "ms"); if (false) break; } diff --git a/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java b/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java index 72a594b4..25934d67 100644 --- a/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java +++ b/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java @@ -10,11 +10,19 @@ public class VoxelizedSection { public int x; public int y; public int z; - final long[] section; + public final long[] section; public VoxelizedSection(long[] section) { this.section = section; } + public static int getBaseIndexForLevel(int lvl) { + int offset = lvl==1?(1<<12):0; + offset |= lvl==2?(1<<12)|(1<<9):0; + offset |= lvl==3?(1<<12)|(1<<9)|(1<<6):0; + offset |= lvl==4?(1<<12)|(1<<9)|(1<<6)|(1<<3):0; + return offset; + } + public VoxelizedSection setPosition(int x, int y, int z) { this.x = x; this.y = y; diff --git a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java index ac029028..3019077c 100644 --- a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java +++ b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java @@ -92,7 +92,7 @@ public class WorldConversionFactory { } pc[0] = blockId; } else { - Logger.error("Unknown palette type: " + vp); + throw new IllegalStateException("Unknown palette type: " + vp); } } } diff --git a/src/main/java/me/cortex/voxy/common/world/WorldEngine.java b/src/main/java/me/cortex/voxy/common/world/WorldEngine.java index fa0be47f..38829222 100644 --- a/src/main/java/me/cortex/voxy/common/world/WorldEngine.java +++ b/src/main/java/me/cortex/voxy/common/world/WorldEngine.java @@ -136,6 +136,25 @@ public class WorldEngine { int nonAirCountDelta = 0; boolean didStateChange = false; + + + {//Do a bunch of funny math + int baseVIdx = VoxelizedSection.getBaseIndexForLevel(lvl); + int baseSec = bx | (bz << 5) | (by << 10); + int secMsk = 0xF >> lvl; + secMsk |= (secMsk << 5) | (secMsk << 10); + var secD = worldSection.data; + for (int i = 0; i < 0xFFF >> (lvl * 3); i++) { + int secIdx = Integer.expand(i, secMsk)+baseSec; + long newId = section.section[baseVIdx+i]; + long oldId = secD[secIdx]; secD[secIdx] = newId; + nonAirCountDelta += Mapper.isAir(oldId) == Mapper.isAir(newId) ? 0 : (Mapper.isAir(newId) ? -1 : 1); + didStateChange |= newId != oldId; + } + } + /* + //This loop can be heavily optimized, the get and set can be extracted and manually done + // the 3 for loops can be replaced by a single loop that iterates over a bitmask for (int y = by; y < (16>>lvl)+by; y++) { for (int z = bz; z < (16>>lvl)+bz; z++) { for (int x = bx; x < (16>>lvl)+bx; x++) { @@ -143,10 +162,9 @@ public class WorldEngine { long oldId = worldSection.set(x, y, z, newId); nonAirCountDelta += Mapper.isAir(oldId)==Mapper.isAir(newId)?0:(Mapper.isAir(newId)?-1:1 ); didStateChange |= newId != oldId; - //if (newId != oldId) {VoxyCommon.breakpoint();} } } - } + }*/ if (nonAirCountDelta != 0) { worldSection.addNonEmptyBlockCount(nonAirCountDelta);