diff --git a/build.gradle b/build.gradle index 377a8de3..6423647b 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,12 @@ dependencies { modImplementation(fabricApi.module("fabric-command-api-v2", project.fabric_version)) modImplementation("net.fabricmc.fabric-api:fabric-rendering-data-attachment-v1:0.3.38+73761d2e9a") + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modImplementation "maven.modrinth:sodium:mc1.20.3-0.5.5" + + modImplementation("maven.modrinth:cloth-config:13.0.121+fabric") + modImplementation("maven.modrinth:modmenu:9.0.0") } diff --git a/src/main/java/me/cortex/zenith/client/config/ScreenFactory.java b/src/main/java/me/cortex/zenith/client/config/ScreenFactory.java new file mode 100644 index 00000000..2c236e90 --- /dev/null +++ b/src/main/java/me/cortex/zenith/client/config/ScreenFactory.java @@ -0,0 +1,11 @@ +package me.cortex.zenith.client.config; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; + +public class ScreenFactory implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parent -> null; + } +} diff --git a/src/main/java/me/cortex/zenith/client/config/ZenithConfig.java b/src/main/java/me/cortex/zenith/client/config/ZenithConfig.java new file mode 100644 index 00000000..d96ac4a9 --- /dev/null +++ b/src/main/java/me/cortex/zenith/client/config/ZenithConfig.java @@ -0,0 +1,15 @@ +package me.cortex.zenith.client.config; + +public class ZenithConfig { + int qualityScale; + int ingestThreads; + int savingThreads; + int renderThreads; + int savingCompressionLevel; + StorageConfig storageConfig; + + public static abstract class StorageConfig { } + public static class FragmentedStorageConfig extends StorageConfig { } + public static class LmdbStorageConfig extends StorageConfig { } + +} diff --git a/src/main/java/me/cortex/zenith/client/config/ZenithConfigScreenFactory.java b/src/main/java/me/cortex/zenith/client/config/ZenithConfigScreenFactory.java new file mode 100644 index 00000000..1097564d --- /dev/null +++ b/src/main/java/me/cortex/zenith/client/config/ZenithConfigScreenFactory.java @@ -0,0 +1,7 @@ +package me.cortex.zenith.client.config; + +import com.terraformersmc.modmenu.api.ModMenuApi; + +public class ZenithConfigScreenFactory implements ModMenuApi { + +} diff --git a/src/main/java/me/cortex/zenith/client/core/VoxelCore.java b/src/main/java/me/cortex/zenith/client/core/VoxelCore.java index 9352971a..60341f95 100644 --- a/src/main/java/me/cortex/zenith/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/zenith/client/core/VoxelCore.java @@ -9,6 +9,7 @@ import me.cortex.zenith.client.core.other.BlockStateColour; import me.cortex.zenith.client.core.other.ColourResolver; import me.cortex.zenith.common.world.other.Mapper; import me.cortex.zenith.client.importers.WorldImporter; +import me.cortex.zenith.common.world.storage.SplicedStorageBackendAdaptor; import me.cortex.zenith.common.world.storage.lmdb.LMDBStorageBackend; import net.minecraft.block.Block; import net.minecraft.block.Blocks; @@ -65,17 +66,17 @@ public class VoxelCore { SharedIndexBuffer.INSTANCE.id(); this.renderer = new Gl46FarWorldRenderer(); System.out.println("Renderer initialized"); - this.world = new WorldEngine(new LMDBStorageBackend(new File("storagefile.db")), 2, 20, 5);//"storagefile.db"//"ethoslab.db" + this.world = new WorldEngine(new SplicedStorageBackendAdaptor(), 2, 20, 5);//"storagefile.db"//"ethoslab.db" System.out.println("World engine"); this.renderTracker = new RenderTracker(this.world, this.renderer); - this.renderGen = new RenderGenerationService(this.world,5, this.renderTracker::processBuildResult); + this.renderGen = new RenderGenerationService(this.world,7, this.renderTracker::processBuildResult); this.world.setDirtyCallback(this.renderTracker::sectionUpdated); this.renderTracker.setRenderGen(this.renderGen); System.out.println("Render tracker and generator initialized"); //To get to chunk scale multiply the scale by 2, the scale is after how many chunks does the lods halve - this.distanceTracker = new DistanceTracker(this.renderTracker, 5, 20);//16 + this.distanceTracker = new DistanceTracker(this.renderTracker, 5, 64);//16 System.out.println("Distance tracker initialized"); this.postProcessing = null;//new PostProcessing(); diff --git a/src/main/java/me/cortex/zenith/client/core/rendering/Gl46FarWorldRenderer.java b/src/main/java/me/cortex/zenith/client/core/rendering/Gl46FarWorldRenderer.java index d126d7ed..e7dae17f 100644 --- a/src/main/java/me/cortex/zenith/client/core/rendering/Gl46FarWorldRenderer.java +++ b/src/main/java/me/cortex/zenith/client/core/rendering/Gl46FarWorldRenderer.java @@ -23,26 +23,27 @@ import static org.lwjgl.opengl.GL42.*; import static org.lwjgl.opengl.GL42.GL_FRAMEBUFFER_BARRIER_BIT; import static org.lwjgl.opengl.GL43.*; import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER; +import static org.lwjgl.opengl.NVRepresentativeFragmentTest.GL_REPRESENTATIVE_FRAGMENT_TEST_NV; public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { private final Shader commandGen = Shader.make() - .add(ShaderType.COMPUTE, "voxelmon:lod/gl46/cmdgen.comp") + .add(ShaderType.COMPUTE, "zenith:lod/gl46/cmdgen.comp") .compile(); private final Shader lodShader = Shader.make() - .add(ShaderType.VERTEX, "voxelmon:lod/gl46/quads.vert") - .add(ShaderType.FRAGMENT, "voxelmon:lod/gl46/quads.frag") + .add(ShaderType.VERTEX, "zenith:lod/gl46/quads.vert") + .add(ShaderType.FRAGMENT, "zenith:lod/gl46/quads.frag") .compile(); //TODO: Note the cull shader needs a different element array since its rastering cubes not quads private final Shader cullShader = Shader.make() - .add(ShaderType.VERTEX, "voxelmon:lod/gl46/cull/raster.vert") - .add(ShaderType.FRAGMENT, "voxelmon:lod/gl46/cull/raster.frag") + .add(ShaderType.VERTEX, "zenith:lod/gl46/cull/raster.vert") + .add(ShaderType.FRAGMENT, "zenith:lod/gl46/cull/raster.frag") .compile(); - private final GlBuffer glCommandBuffer = new GlBuffer(100_000*5*4, 0); - private final GlBuffer glVisibilityBuffer = new GlBuffer(100_000*4, 0); + private final GlBuffer glCommandBuffer = new GlBuffer(200_000*5*4, 0); + private final GlBuffer glVisibilityBuffer = new GlBuffer(200_000*4, 0); public Gl46FarWorldRenderer() { super(); @@ -108,6 +109,11 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { cullShader.bind(); glColorMask(false, false, false, false); glDepthMask(false); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + //glEnable(GL_REPRESENTATIVE_FRAGMENT_TEST_NV); + glDrawElementsInstanced(GL_TRIANGLES, 6 * 2 * 3, GL_UNSIGNED_BYTE, (1 << 16) * 6 * 2, this.geometry.getSectionCount()); glDepthMask(true); glColorMask(true, true, true, true); diff --git a/src/main/java/me/cortex/zenith/common/world/SaveLoadSystem.java b/src/main/java/me/cortex/zenith/common/world/SaveLoadSystem.java index 699e1375..3b4d8859 100644 --- a/src/main/java/me/cortex/zenith/common/world/SaveLoadSystem.java +++ b/src/main/java/me/cortex/zenith/common/world/SaveLoadSystem.java @@ -48,7 +48,7 @@ public class SaveLoadSystem { raw.limit(raw.position()); raw.rewind(); ByteBuffer compressedData = MemoryUtil.memAlloc((int)ZSTD_COMPRESSBOUND(raw.remaining())); - long compressedSize = ZSTD_compress(compressedData, raw, 15); + long compressedSize = ZSTD_compress(compressedData, raw, 7); compressedData.limit((int) compressedSize); compressedData.rewind(); MemoryUtil.memFree(raw); diff --git a/src/main/java/me/cortex/zenith/common/world/storage/SplicedStorageBackendAdaptor.java b/src/main/java/me/cortex/zenith/common/world/storage/SplicedStorageBackendAdaptor.java new file mode 100644 index 00000000..654856da --- /dev/null +++ b/src/main/java/me/cortex/zenith/common/world/storage/SplicedStorageBackendAdaptor.java @@ -0,0 +1,74 @@ +package me.cortex.zenith.common.world.storage; + +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import me.cortex.zenith.common.world.storage.lmdb.LMDBStorageBackend; +import net.minecraft.util.math.random.RandomSeed; + +import java.io.File; +import java.nio.ByteBuffer; + +//Segments the section data into multiple dbs +public class SplicedStorageBackendAdaptor extends StorageBackend { + private final StorageBackend[] backends = new StorageBackend[32]; + + public SplicedStorageBackendAdaptor() { + for (int i = 0; i < this.backends.length; i++) { + this.backends[i] = new LMDBStorageBackend(new File("db_store/storage-db-"+i+".db")); + } + } + + + //public static long getWorldSectionId(int lvl, int x, int y, int z) { + // return ((long)lvl<<60)|((long)(y&0xFF)<<52)|((long)(z&((1<<24)-1))<<28)|((long)(x&((1<<24)-1))<<4);//NOTE: 4 bits spare for whatever + // } + //private int getSegmentId(long key) { + // return (int) (((key>>4)&1)|((key>>27)&0b10)|((key>>50)&0b100)); + //} + + private int getSegmentId(long key) { + return (int) (RandomSeed.mixStafford13(RandomSeed.mixStafford13(key)^key)&0x1F); + } + + //TODO: reencode the key to be shifted one less OR + // use like a mix64 to shuffle the key in getSegmentId so that + // multiple layers of spliced storage backends can be stacked + + @Override + public ByteBuffer getSectionData(long key) { + return this.backends[this.getSegmentId(key)].getSectionData(key); + } + + @Override + public void setSectionData(long key, ByteBuffer data) { + this.backends[this.getSegmentId(key)].setSectionData(key, data); + } + + @Override + public void deleteSectionData(long key) { + this.backends[this.getSegmentId(key)].deleteSectionData(key); + } + + @Override + public void putIdMapping(int id, ByteBuffer data) { + this.backends[0].putIdMapping(id, data); + } + + @Override + public Int2ObjectOpenHashMap getIdMappingsData() { + return this.backends[0].getIdMappingsData(); + } + + @Override + public void flush() { + for (var db : this.backends) { + db.flush(); + } + } + + @Override + public void close() { + for (var db : this.backends) { + db.close(); + } + } +} diff --git a/src/main/resources/assets/zenith/shaders/lod/gl46/cull/raster.frag b/src/main/resources/assets/zenith/shaders/lod/gl46/cull/raster.frag index 6a7b9af5..8e4e7c3a 100644 --- a/src/main/resources/assets/zenith/shaders/lod/gl46/cull/raster.frag +++ b/src/main/resources/assets/zenith/shaders/lod/gl46/cull/raster.frag @@ -4,9 +4,9 @@ #import flat in uint id; flat in uint value; -//out vec4 colour; +out vec4 colour; void main() { visibilityData[id] = value; - //colour = vec4(float(id&7)/7, float((id>>3)&7)/7, float((id>>6)&7)/7, 1); + colour = vec4(float(id&7)/7, float((id>>3)&7)/7, float((id>>6)&7)/7, 1); } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 112eb137..d92c3ac1 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -15,6 +15,9 @@ "entrypoints": { "client": [ "me.cortex.zenith.client.Voxelmon" + ], + "modmenu": [ + "me.cortex.zenith.client.config.ZenithConfigScreenFactory" ] }, "mixins": [