Random things

This commit is contained in:
mcrcortex
2025-03-04 12:05:30 +10:00
parent fc55d5fc3b
commit 743c423ba5
4 changed files with 31 additions and 6 deletions

View File

@@ -87,7 +87,6 @@ public class VoxelCore {
Capabilities.init();//Ensure clinit is called Capabilities.init();//Ensure clinit is called
this.renderer = new RenderService(this.world, this.serviceThreadPool); this.renderer = new RenderService(this.world, this.serviceThreadPool);
Logger.info("Using " + this.renderer.getClass().getSimpleName());
this.postProcessing = new PostProcessing(); this.postProcessing = new PostProcessing();
Logger.info("Voxy core initialized"); Logger.info("Voxy core initialized");
@@ -430,7 +429,7 @@ public class VoxelCore {
} }
} }
long delta = (System.currentTimeMillis()-start); 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) if (false)
break; break;
} }

View File

@@ -10,11 +10,19 @@ public class VoxelizedSection {
public int x; public int x;
public int y; public int y;
public int z; public int z;
final long[] section; public final long[] section;
public VoxelizedSection(long[] section) { public VoxelizedSection(long[] section) {
this.section = 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) { public VoxelizedSection setPosition(int x, int y, int z) {
this.x = x; this.x = x;
this.y = y; this.y = y;

View File

@@ -92,7 +92,7 @@ public class WorldConversionFactory {
} }
pc[0] = blockId; pc[0] = blockId;
} else { } else {
Logger.error("Unknown palette type: " + vp); throw new IllegalStateException("Unknown palette type: " + vp);
} }
} }
} }

View File

@@ -136,6 +136,25 @@ public class WorldEngine {
int nonAirCountDelta = 0; int nonAirCountDelta = 0;
boolean didStateChange = false; 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 y = by; y < (16>>lvl)+by; y++) {
for (int z = bz; z < (16>>lvl)+bz; z++) { for (int z = bz; z < (16>>lvl)+bz; z++) {
for (int x = bx; x < (16>>lvl)+bx; x++) { for (int x = bx; x < (16>>lvl)+bx; x++) {
@@ -143,10 +162,9 @@ public class WorldEngine {
long oldId = worldSection.set(x, y, z, newId); long oldId = worldSection.set(x, y, z, newId);
nonAirCountDelta += Mapper.isAir(oldId)==Mapper.isAir(newId)?0:(Mapper.isAir(newId)?-1:1 ); nonAirCountDelta += Mapper.isAir(oldId)==Mapper.isAir(newId)?0:(Mapper.isAir(newId)?-1:1 );
didStateChange |= newId != oldId; didStateChange |= newId != oldId;
//if (newId != oldId) {VoxyCommon.breakpoint();}
}
} }
} }
}*/
if (nonAirCountDelta != 0) { if (nonAirCountDelta != 0) {
worldSection.addNonEmptyBlockCount(nonAirCountDelta); worldSection.addNonEmptyBlockCount(nonAirCountDelta);