From fa42ad5a031346a2acb60ee0d4c563e60cfb269a Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 10 Jun 2025 19:25:56 +1000 Subject: [PATCH] remove copies --- .../core/rendering/building/RenderDataFactory.java | 8 ++++---- .../me/cortex/voxy/common/world/SaveLoadSystem3.java | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java index 5b4a9202..d1f3b40f 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java @@ -207,7 +207,7 @@ public class RenderDataFactory { return quadData; } - private int prepareSectionData() { + private int prepareSectionData(final long[] rawSectionData) { final var sectionData = this.sectionData; final var rawModelIds = this.modelMan._unsafeRawAccess(); int opaque = 0; @@ -217,7 +217,7 @@ public class RenderDataFactory { int neighborAcquireMsk = 0;//-+x, -+y, -+Z for (int i = 0; i < 32*32*32;) { - long block = sectionData[i + 32 * 32 * 32];//Get the block mapping + long block = rawSectionData[i];//Get the block mapping if (Mapper.isAir(block)) {//If it is air, just emit lighting sectionData[i * 2] = (block&(0xFFL<<56))>>1; sectionData[i * 2 + 1] = 0; @@ -1542,7 +1542,7 @@ public class RenderDataFactory { //THE EXCEPTION THAT THIS THROWS CAUSES MAJOR ISSUES //Copy section data to end of array so that can mutate array while reading safely - section.copyDataTo(this.sectionData, 32*32*32); + //section.copyDataTo(this.sectionData, 32*32*32); //We must reset _everything_ that could have changed as we dont exactly know the state due to how the model id exception // throwing system works @@ -1578,7 +1578,7 @@ public class RenderDataFactory { Arrays.fill(this.fluidMasks, 0); //Prepare everything - int neighborMsk = this.prepareSectionData(); + int neighborMsk = this.prepareSectionData(section._unsafeGetRawDataArray()); if (neighborMsk>>31!=0) {//We failed to get everything so throw exception throw new IdNotYetComputedException(neighborMsk&(~(1<<31)), true); } diff --git a/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem3.java b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem3.java index a71f4a9e..05b1c41f 100644 --- a/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem3.java +++ b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem3.java @@ -10,11 +10,9 @@ import me.cortex.voxy.commonImpl.VoxyCommon; import org.lwjgl.system.MemoryUtil; public class SaveLoadSystem3 { - private record SerializationCache(long[] blockStateCache, Long2ShortOpenHashMap lutMapCache, MemoryBuffer memoryBuffer) { + private record SerializationCache(Long2ShortOpenHashMap lutMapCache, MemoryBuffer memoryBuffer) { public SerializationCache() { - this(new long[WorldSection.SECTION_VOLUME], - new Long2ShortOpenHashMap(512), - ThreadLocalMemoryBuffer.create(WorldSection.SECTION_VOLUME*2+WorldSection.SECTION_VOLUME*8+1024)); + this(new Long2ShortOpenHashMap(512), ThreadLocalMemoryBuffer.create(WorldSection.SECTION_VOLUME*2+WorldSection.SECTION_VOLUME*8+1024)); this.lutMapCache.defaultReturnValue((short) -1); } } @@ -39,8 +37,7 @@ public class SaveLoadSystem3 { //TODO: Cache like long2short and the short and other data to stop allocs public static MemoryBuffer serialize(WorldSection section) { var cache = CACHE.get(); - var data = cache.blockStateCache; - section.copyDataTo(data); + var data = section.data; Long2ShortOpenHashMap LUT = cache.lutMapCache; LUT.clear();