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 099e359e..d6086120 100644 --- a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java +++ b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java @@ -154,28 +154,24 @@ public class WorldConversionFactory { long sample = 0; int c = 0; int dec = 0; - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - for (int x = 0; x < 16; x++) { - if (dec-- == 0) { - sample = bDat[c++]; - dec = iterPerLong; - } - int bId; - if (bps == null) { - bId = pc[(int) (sample & MSK)]; - } else { - bId = stateMapper.getIdForBlockState(bps.get((int) (sample&MSK))); - } - sample >>>= eBits; + for (int i = 0; i < 0xFFF; i++) { + if (dec-- == 0) { + sample = bDat[c++]; + dec = iterPerLong; + } + int bId; + if (bps == null) { + bId = pc[(int) (sample & MSK)]; + } else { + bId = stateMapper.getIdForBlockState(bps.get((int) (sample&MSK))); + } + sample >>>= eBits; - byte light = lightSupplier.supply(x, y, z); - if (!(bId == 0 && (light == 0))) { - data[G(x, y, z)] = Mapper.composeMappingId(light, bId, biomes[((y & 0b1100) << 2) | (z & 0b1100) | (x >> 2)]); - } else { - data[G(x, y, z)] = Mapper.AIR; - } - } + byte light = lightSupplier.supply(i&0xF, (i>>8)&0xF, (i>>4)&0xF); + if (!(bId == 0 && (light == 0))) { + data[i] = Mapper.composeMappingId(light, bId, biomes[Integer.compress(i,0b1100_1100_1100)]); + } else { + data[i] = Mapper.AIR; } } } else { @@ -183,15 +179,17 @@ public class WorldConversionFactory { throw new IllegalStateException(); } int bId = pc[0]; - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - for (int x = 0; x < 16; x++) { - byte light = lightSupplier.supply(x, y, z); - if (!(bId == 0 && (light == 0))) { - data[G(x, y, z)] = Mapper.composeMappingId(light, bId, biomes[((y & 0b1100) << 2) | (z & 0b1100) | (x >> 2)]); - } else { - data[G(x, y, z)] = Mapper.AIR; - } + if (bId == 0) {//Its air + for (int i = 0; i < 0xFFF; i++) { + data[i] = Mapper.airWithLight(lightSupplier.supply(i&0xF, (i>>8)&0xF, (i>>4)&0xF)); + } + } else { + for (int i = 0; i < 0xFFF; i++) { + byte light = lightSupplier.supply(i&0xF, (i>>8)&0xF, (i>>4)&0xF); + if (light != 0) { + data[i] = Mapper.composeMappingId(light, bId, biomes[Integer.compress(i,0b1100_1100_1100)]); + } else { + data[i] = Mapper.AIR; } } } @@ -199,6 +197,14 @@ public class WorldConversionFactory { return section; } + + + + + + + + private static int G(int x, int y, int z) { return ((y<<8)|(z<<4)|x); } diff --git a/src/main/java/me/cortex/voxy/common/world/WorldUpdater.java b/src/main/java/me/cortex/voxy/common/world/WorldUpdater.java index 341798f6..137df550 100644 --- a/src/main/java/me/cortex/voxy/common/world/WorldUpdater.java +++ b/src/main/java/me/cortex/voxy/common/world/WorldUpdater.java @@ -14,6 +14,7 @@ public class WorldUpdater { if (!into.isLive) throw new IllegalStateException("World is not live"); boolean shouldCheckEmptiness = false; WorldSection previousSection = null; + final var vdat = section.section; for (int lvl = 0; lvl < MAX_LOD_LAYER+1; lvl++) { var worldSection = into.acquire(lvl, section.x >> (lvl + 1), section.y >> (lvl + 1), section.z >> (lvl + 1)); @@ -45,9 +46,9 @@ public class WorldUpdater { 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 newId = vdat[baseVIdx+i]; long oldId = secD[secIdx]; secD[secIdx] = newId; - nonAirCountDelta += Mapper.isAir(oldId) == Mapper.isAir(newId) ? 0 : (Mapper.isAir(newId) ? -1 : 1); + nonAirCountDelta += (Mapper.isAir(newId)?1:0)-(Mapper.isAir(oldId)?1:0); didStateChange |= newId != oldId; } } @@ -87,4 +88,16 @@ public class WorldUpdater { previousSection.release(); } } + + public static void main(String[] args) { + int MSK = 0b110110010100; + int iMSK = ~MSK; + int iMSK1 = iMSK+1; + int i = 0; + do { + System.err.println(Integer.toBinaryString(i)); + if (i==MSK) break; + i = (i+iMSK1)&MSK; + } while (true); + } } 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 94f613aa..27045363 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 @@ -74,6 +74,10 @@ public class Mapper { return (id&(~(0xFFL<<56)))|(Integer.toUnsignedLong(light&0xFF)<<56); } + public static long airWithLight(int light) { + return Integer.toUnsignedLong(light&0xFF)<<56; + } + public void setStateCallback(Consumer stateCallback) { this.newStateCallback = stateCallback; } diff --git a/src/main/java/me/cortex/voxy/commonImpl/importers/DHImporter.java b/src/main/java/me/cortex/voxy/commonImpl/importers/DHImporter.java index e203ac0a..ad57399f 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/importers/DHImporter.java +++ b/src/main/java/me/cortex/voxy/commonImpl/importers/DHImporter.java @@ -291,10 +291,12 @@ public class DHImporter implements IDataImporter { // int a = 0; //} //Insert all entries into data cache - for (int y = startY; y < endY; y++) { - int idx = Integer.expand(y, 0b11111111_00_1111_0000_0000) | bPos; - storage[idx] = mEntry; - + startY = Integer.expand(startY, 0b11111111_00_1111_0000_0000); + endY = Integer.expand(endY, 0b11111111_00_1111_0000_0000); + final int Msk = 0b11111111_00_1111_0000_0000; + final int iMsk1 = (~Msk)+1; + for (int y = startY; y != endY; y = (y+iMsk1)&Msk) { + storage[y+bPos] = mEntry; //touched[(idx >>> 12)>>6] |= 1L<<(idx&0x3f); } }