Skip to content

Commit fa42ad5

Browse files
committed
remove copies
1 parent 22553eb commit fa42ad5

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static long packPartialQuadData(int modelId, long state, long metadata)
207207
return quadData;
208208
}
209209

210-
private int prepareSectionData() {
210+
private int prepareSectionData(final long[] rawSectionData) {
211211
final var sectionData = this.sectionData;
212212
final var rawModelIds = this.modelMan._unsafeRawAccess();
213213
int opaque = 0;
@@ -217,7 +217,7 @@ private int prepareSectionData() {
217217

218218
int neighborAcquireMsk = 0;//-+x, -+y, -+Z
219219
for (int i = 0; i < 32*32*32;) {
220-
long block = sectionData[i + 32 * 32 * 32];//Get the block mapping
220+
long block = rawSectionData[i];//Get the block mapping
221221
if (Mapper.isAir(block)) {//If it is air, just emit lighting
222222
sectionData[i * 2] = (block&(0xFFL<<56))>>1;
223223
sectionData[i * 2 + 1] = 0;
@@ -1542,7 +1542,7 @@ public BuiltSection generateMesh(WorldSection section) {
15421542
//THE EXCEPTION THAT THIS THROWS CAUSES MAJOR ISSUES
15431543

15441544
//Copy section data to end of array so that can mutate array while reading safely
1545-
section.copyDataTo(this.sectionData, 32*32*32);
1545+
//section.copyDataTo(this.sectionData, 32*32*32);
15461546

15471547
//We must reset _everything_ that could have changed as we dont exactly know the state due to how the model id exception
15481548
// throwing system works
@@ -1578,7 +1578,7 @@ public BuiltSection generateMesh(WorldSection section) {
15781578
Arrays.fill(this.fluidMasks, 0);
15791579

15801580
//Prepare everything
1581-
int neighborMsk = this.prepareSectionData();
1581+
int neighborMsk = this.prepareSectionData(section._unsafeGetRawDataArray());
15821582
if (neighborMsk>>31!=0) {//We failed to get everything so throw exception
15831583
throw new IdNotYetComputedException(neighborMsk&(~(1<<31)), true);
15841584
}

src/main/java/me/cortex/voxy/common/world/SaveLoadSystem3.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
import org.lwjgl.system.MemoryUtil;
1111

1212
public class SaveLoadSystem3 {
13-
private record SerializationCache(long[] blockStateCache, Long2ShortOpenHashMap lutMapCache, MemoryBuffer memoryBuffer) {
13+
private record SerializationCache(Long2ShortOpenHashMap lutMapCache, MemoryBuffer memoryBuffer) {
1414
public SerializationCache() {
15-
this(new long[WorldSection.SECTION_VOLUME],
16-
new Long2ShortOpenHashMap(512),
17-
ThreadLocalMemoryBuffer.create(WorldSection.SECTION_VOLUME*2+WorldSection.SECTION_VOLUME*8+1024));
15+
this(new Long2ShortOpenHashMap(512), ThreadLocalMemoryBuffer.create(WorldSection.SECTION_VOLUME*2+WorldSection.SECTION_VOLUME*8+1024));
1816
this.lutMapCache.defaultReturnValue((short) -1);
1917
}
2018
}
@@ -39,8 +37,7 @@ public static int z2lin(int i) {
3937
//TODO: Cache like long2short and the short and other data to stop allocs
4038
public static MemoryBuffer serialize(WorldSection section) {
4139
var cache = CACHE.get();
42-
var data = cache.blockStateCache;
43-
section.copyDataTo(data);
40+
var data = section.data;
4441

4542
Long2ShortOpenHashMap LUT = cache.lutMapCache; LUT.clear();
4643

0 commit comments

Comments
 (0)