From 584028ae7a50acbe7b477bd67ae4e029278f37a2 Mon Sep 17 00:00:00 2001 From: mcrcortex <{ID}+{username}@users.noreply.github.com> Date: Sun, 12 May 2024 08:56:03 +1000 Subject: [PATCH] Tweeks --- src/main/java/me/cortex/voxy/client/core/VoxelCore.java | 2 +- .../me/cortex/voxy/client/core/rendering/RenderTracker.java | 6 ++++++ .../me/cortex/voxy/client/saver/ContextSelectionSystem.java | 2 +- .../voxy/common/voxelization/WorldConversionFactory.java | 2 ++ .../java/me/cortex/voxy/common/world/SaveLoadSystem.java | 3 ++- src/main/java/me/cortex/voxy/common/world/other/Mapper.java | 3 +++ 6 files changed, 15 insertions(+), 3 deletions(-) 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 32db5f19..515b7376 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java @@ -121,7 +121,7 @@ public class VoxelCore { } private AbstractFarWorldRenderer createRenderBackend() { - if (true) { + if (false) { System.out.println("Using Gl46MeshletFarWorldRendering"); return new Gl46MeshletsFarWorldRenderer(VoxyConfig.CONFIG.geometryBufferSize, VoxyConfig.CONFIG.maxSections); } else { diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/RenderTracker.java b/src/main/java/me/cortex/voxy/client/core/rendering/RenderTracker.java index 123f16f3..349fd5b0 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/RenderTracker.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/RenderTracker.java @@ -63,6 +63,8 @@ public class RenderTracker { } } + //TODO: replace this:: with a class cached lambda ref (cause doing this:: still does a lambda allocation) + //Adds a lvl 0 section into the world renderer public void addLvl0(int x, int y, int z) { this.put(WorldEngine.getWorldSectionId(0, x, y, z)); @@ -92,6 +94,7 @@ public class RenderTracker { // concurrent hashmap or something, this is so that e.g. the build data position // can be updated + //TODO: replace this:: with a class cached lambda ref (cause doing this:: still does a lambda allocation) this.renderGen.enqueueTask(lvl, x, y, z, this::shouldStillBuild); this.renderer.enqueueResult(new BuiltSection(WorldEngine.getWorldSectionId(lvl-1, (x<<1), (y<<1), (z<<1)))); @@ -129,6 +132,7 @@ public class RenderTracker { this.renderer.enqueueResult(new BuiltSection(WorldEngine.getWorldSectionId(lvl, x, y, z))); this.renderGen.removeTask(lvl, x, y, z); + //TODO: replace this:: with a class cached lambda ref (cause doing this:: still does a lambda allocation) this.renderGen.enqueueTask(lvl - 1, (x<<1), (y<<1), (z<<1), this::shouldStillBuild); this.renderGen.enqueueTask(lvl - 1, (x<<1), (y<<1), (z<<1)+1, this::shouldStillBuild); this.renderGen.enqueueTask(lvl - 1, (x<<1), (y<<1)+1, (z<<1), this::shouldStillBuild); @@ -157,6 +161,7 @@ public class RenderTracker { public void add(int lvl, int x, int y, int z) { this.put(WorldEngine.getWorldSectionId(lvl, x, y, z)); + //TODO: replace this:: with a class cached lambda ref (cause doing this:: still does a lambda allocation) this.renderGen.enqueueTask(lvl, x, y, z, this::shouldStillBuild); } @@ -173,6 +178,7 @@ public class RenderTracker { this.renderGen.clearCache(section.lvl, section.x+1, section.y, section.z); this.renderGen.clearCache(section.lvl, section.x, section.y, section.z-1); this.renderGen.clearCache(section.lvl, section.x, section.y, section.z+1); + //TODO: replace this:: with a class cached lambda ref (cause doing this:: still does a lambda allocation) this.renderGen.enqueueTask(section.lvl, section.x, section.y, section.z, this::shouldStillBuild); this.renderGen.enqueueTask(section.lvl, section.x-1, section.y, section.z, this::shouldStillBuild); this.renderGen.enqueueTask(section.lvl, section.x+1, section.y, section.z, this::shouldStillBuild); diff --git a/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java b/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java index 7a926db2..91c4caf0 100644 --- a/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java +++ b/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java @@ -84,7 +84,7 @@ public class ContextSelectionSystem { throw new RuntimeException("Failed to deserialize the default config, aborting!", e); } if (this.config == null) { - throw new IllegalStateException("Config is still null"); + throw new IllegalStateException("Config is still null: \n"+VoxyConfig.CONFIG.defaultSaveConfig); } } 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 a545c3dd..6eb373c5 100644 --- a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java +++ b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java @@ -52,6 +52,8 @@ public class WorldConversionFactory { } } data[G(x, y, z)] = Mapper.composeMappingId(light, blockId, biomeId); + } else { + data[G(x, y, z)] = Mapper.AIR; } } } diff --git a/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java index befb2f2b..1df68b0a 100644 --- a/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java +++ b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java @@ -10,10 +10,11 @@ import static org.lwjgl.util.zstd.Zstd.*; public class SaveLoadSystem { + //TODO: Cache like long2short and the short and other data to stop allocs public static ByteBuffer serialize(WorldSection section) { var data = section.copyData(); var compressed = new short[data.length]; - Long2ShortOpenHashMap LUT = new Long2ShortOpenHashMap(); + Long2ShortOpenHashMap LUT = new Long2ShortOpenHashMap(data.length); LongArrayList LUTVAL = new LongArrayList(); for (int i = 0; i < data.length; i++) { long block = data[i]; diff --git a/src/main/java/me/cortex/voxy/common/world/other/Mapper.java b/src/main/java/me/cortex/voxy/common/world/other/Mapper.java index 2fd71f65..cfb52069 100644 --- a/src/main/java/me/cortex/voxy/common/world/other/Mapper.java +++ b/src/main/java/me/cortex/voxy/common/world/other/Mapper.java @@ -183,10 +183,13 @@ public class Mapper { return this.blockId2stateEntry.get(blockId).state; } + //TODO: replace lambda with a class cached lambda ref (cause doing this:: still does a lambda allocation) public int getIdForBlockState(BlockState state) { return this.block2stateEntry.computeIfAbsent(state, this::registerNewBlockState).id; } + + //TODO: replace lambda with a class cached lambda ref (cause doing this:: still does a lambda allocation) public int getIdForBiome(RegistryEntry biome) { String biomeId = biome.getKey().get().getValue().toString(); return this.biome2biomeEntry.computeIfAbsent(biomeId, this::registerNewBiome).id;