remove copies

This commit is contained in:
mcrcortex
2025-06-10 19:25:56 +10:00
parent 22553eb1f9
commit fa42ad5a03
2 changed files with 7 additions and 10 deletions

View File

@@ -207,7 +207,7 @@ public class RenderDataFactory {
return quadData; return quadData;
} }
private int prepareSectionData() { private int prepareSectionData(final long[] rawSectionData) {
final var sectionData = this.sectionData; final var sectionData = this.sectionData;
final var rawModelIds = this.modelMan._unsafeRawAccess(); final var rawModelIds = this.modelMan._unsafeRawAccess();
int opaque = 0; int opaque = 0;
@@ -217,7 +217,7 @@ public class RenderDataFactory {
int neighborAcquireMsk = 0;//-+x, -+y, -+Z int neighborAcquireMsk = 0;//-+x, -+y, -+Z
for (int i = 0; i < 32*32*32;) { 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 if (Mapper.isAir(block)) {//If it is air, just emit lighting
sectionData[i * 2] = (block&(0xFFL<<56))>>1; sectionData[i * 2] = (block&(0xFFL<<56))>>1;
sectionData[i * 2 + 1] = 0; sectionData[i * 2 + 1] = 0;
@@ -1542,7 +1542,7 @@ public class RenderDataFactory {
//THE EXCEPTION THAT THIS THROWS CAUSES MAJOR ISSUES //THE EXCEPTION THAT THIS THROWS CAUSES MAJOR ISSUES
//Copy section data to end of array so that can mutate array while reading safely //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 //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 // throwing system works
@@ -1578,7 +1578,7 @@ public class RenderDataFactory {
Arrays.fill(this.fluidMasks, 0); Arrays.fill(this.fluidMasks, 0);
//Prepare everything //Prepare everything
int neighborMsk = this.prepareSectionData(); int neighborMsk = this.prepareSectionData(section._unsafeGetRawDataArray());
if (neighborMsk>>31!=0) {//We failed to get everything so throw exception if (neighborMsk>>31!=0) {//We failed to get everything so throw exception
throw new IdNotYetComputedException(neighborMsk&(~(1<<31)), true); throw new IdNotYetComputedException(neighborMsk&(~(1<<31)), true);
} }

View File

@@ -10,11 +10,9 @@ import me.cortex.voxy.commonImpl.VoxyCommon;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
public class SaveLoadSystem3 { public class SaveLoadSystem3 {
private record SerializationCache(long[] blockStateCache, Long2ShortOpenHashMap lutMapCache, MemoryBuffer memoryBuffer) { private record SerializationCache(Long2ShortOpenHashMap lutMapCache, MemoryBuffer memoryBuffer) {
public SerializationCache() { public SerializationCache() {
this(new long[WorldSection.SECTION_VOLUME], this(new Long2ShortOpenHashMap(512), ThreadLocalMemoryBuffer.create(WorldSection.SECTION_VOLUME*2+WorldSection.SECTION_VOLUME*8+1024));
new Long2ShortOpenHashMap(512),
ThreadLocalMemoryBuffer.create(WorldSection.SECTION_VOLUME*2+WorldSection.SECTION_VOLUME*8+1024));
this.lutMapCache.defaultReturnValue((short) -1); 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 //TODO: Cache like long2short and the short and other data to stop allocs
public static MemoryBuffer serialize(WorldSection section) { public static MemoryBuffer serialize(WorldSection section) {
var cache = CACHE.get(); var cache = CACHE.get();
var data = cache.blockStateCache; var data = section.data;
section.copyDataTo(data);
Long2ShortOpenHashMap LUT = cache.lutMapCache; LUT.clear(); Long2ShortOpenHashMap LUT = cache.lutMapCache; LUT.clear();