package rename + storage backend abstraction

This commit is contained in:
mcrcortex
2024-01-19 12:07:47 +10:00
parent 2345c8d692
commit e3bd036385
98 changed files with 268 additions and 242 deletions

View File

@@ -1,7 +0,0 @@
package me.cortex.voxelmon.client;
import me.cortex.voxelmon.client.core.VoxelCore;
public interface IGetVoxelCore {
VoxelCore getVoxelCore();
}

View File

@@ -1,10 +0,0 @@
package me.cortex.voxelmon.client.core;
//Tracks the distance with respect to the entire world size
public class TreeDistanceTracker {
private final int scalingFactor;
public TreeDistanceTracker(int scalingFactor) {
this.scalingFactor = scalingFactor;
}
}

View File

@@ -1,9 +0,0 @@
package me.cortex.voxelmon.client.core.rendering.building;
//Class for generating holding and remapping colours and ids
// used during building and then remapping into the global colour array before insertion into the world
public class ColourMapping {
public void reset() {
}
}

View File

@@ -0,0 +1,7 @@
package me.cortex.zenith.client;
import me.cortex.zenith.client.core.VoxelCore;
public interface IGetVoxelCore {
VoxelCore getVoxelCore();
}

View File

@@ -1,8 +1,9 @@
package me.cortex.voxelmon.client;
package me.cortex.zenith.client;
import me.cortex.voxelmon.common.world.storage.LMDBInterface;
import me.cortex.voxelmon.common.world.storage.StorageBackend;
import me.cortex.voxelmon.client.importers.WorldImporter;
import me.cortex.zenith.common.world.storage.lmdb.LMDBInterface;
import me.cortex.zenith.common.world.storage.StorageBackend;
import me.cortex.zenith.client.importers.WorldImporter;
import me.cortex.zenith.common.world.storage.lmdb.LMDBStorageBackend;
import org.lwjgl.system.MemoryUtil;
import java.io.File;
@@ -33,7 +34,7 @@ public class Test {
}
public static void main2(String[] args) throws Exception {
var storage = new StorageBackend(new File("run/storagefile.db"));
var storage = new LMDBStorageBackend(new File("run/storagefile.db"));
for (int i = 0; i < 2; i++) {
new Thread(()->{
//storage.getSectionData(1143914312599863680L);
@@ -45,7 +46,7 @@ public class Test {
//storage.setSectionData(1143914312599863680L, ByteBuffer.allocateDirect(12345));
//storage.close();
System.out.println(storage.getIdMappings());
System.out.println(storage.getIdMappingsData());
storage.putIdMapping(1, ByteBuffer.allocateDirect(12));
Thread.sleep(1000);

View File

@@ -1,7 +1,7 @@
package me.cortex.voxelmon.client;
package me.cortex.zenith.client;
//import me.cortex.voxelmon.client.terrain.WorldImportCommand;
import me.cortex.voxelmon.client.terrain.WorldImportCommand;
import me.cortex.zenith.client.terrain.WorldImportCommand;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;

View File

@@ -1,11 +1,11 @@
package me.cortex.voxelmon.client.core;
package me.cortex.zenith.client.core;
//Contains the logic to determine what is loaded and at what LoD level, dispatches render changes
// also determines what faces are built etc
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import me.cortex.voxelmon.client.core.rendering.RenderTracker;
import me.cortex.voxelmon.client.core.util.RingUtil;
import me.cortex.zenith.client.core.rendering.RenderTracker;
import me.cortex.zenith.client.core.util.RingUtil;
import net.minecraft.client.MinecraftClient;
//Can use ring logic
@@ -17,21 +17,23 @@ public class DistanceTracker {
private final TransitionRing2D[] rings;
private final RenderTracker tracker;
private final int scale;
private final int minYSection;
private final int maxYSection;
public DistanceTracker(RenderTracker tracker, int rings, int scale) {
this.rings = new TransitionRing2D[rings];
this.tracker = tracker;
this.scale = scale;
this.minYSection = MinecraftClient.getInstance().world.getBottomSectionCoord()/2;
this.maxYSection = MinecraftClient.getInstance().world.getTopSectionCoord()/2;
this.rings[0] = new TransitionRing2D(5, MinecraftClient.getInstance().options.getClampedViewDistance()/2, (x, z)->{
if (false) {
return;
}
for (int y = -2; y < 10; y++) {
for (int y = this.minYSection; y <= this.maxYSection; y++) {
this.tracker.remLvl0(x, y, z);
}
}, (x, z) -> {
for (int y = -2; y < 10; y++) {
for (int y = this.minYSection; y <= this.maxYSection; y++) {
this.tracker.addLvl0(x, y, z);
}
});
@@ -46,13 +48,13 @@ public class DistanceTracker {
}
private void inc(int lvl, int x, int z) {
for (int y = -2>>lvl; y <= 10>>lvl; y++) {
for (int y = this.minYSection>>lvl; y <= this.maxYSection>>lvl; y++) {
this.tracker.inc(lvl, x, y, z);
}
}
private void dec(int lvl, int x, int z) {
for (int y = -2>>lvl; y <= 10>>lvl; y++) {
for (int y = this.minYSection>>lvl; y <= this.maxYSection>>lvl; y++) {
this.tracker.dec(lvl, x, y, z);
}
}

View File

@@ -1,14 +1,15 @@
package me.cortex.voxelmon.client.core;
package me.cortex.zenith.client.core;
import me.cortex.voxelmon.client.core.rendering.*;
import me.cortex.voxelmon.client.core.rendering.building.RenderGenerationService;
import me.cortex.voxelmon.client.core.util.DebugUtil;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.voxelmon.client.core.other.BiomeColour;
import me.cortex.voxelmon.client.core.other.BlockStateColour;
import me.cortex.voxelmon.client.core.other.ColourResolver;
import me.cortex.voxelmon.common.world.other.Mapper;
import me.cortex.voxelmon.client.importers.WorldImporter;
import me.cortex.zenith.client.core.rendering.*;
import me.cortex.zenith.client.core.rendering.building.RenderGenerationService;
import me.cortex.zenith.client.core.util.DebugUtil;
import me.cortex.zenith.common.world.WorldEngine;
import me.cortex.zenith.client.core.other.BiomeColour;
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.lmdb.LMDBStorageBackend;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.Camera;
@@ -64,7 +65,7 @@ public class VoxelCore {
SharedIndexBuffer.INSTANCE.id();
this.renderer = new Gl46FarWorldRenderer();
System.out.println("Renderer initialized");
this.world = new WorldEngine(new File("storagefile.db"), 2, 15, 5);//"storagefile.db"//"ethoslab.db"
this.world = new WorldEngine(new LMDBStorageBackend(new File("storagefile.db")), 2, 20, 5);//"storagefile.db"//"ethoslab.db"
System.out.println("World engine");
this.renderTracker = new RenderTracker(this.world, this.renderer);
@@ -196,7 +197,7 @@ public class VoxelCore {
public WorldImporter createWorldImporter(World mcWorld, File worldPath) {
var importer = new WorldImporter(this.world, mcWorld);
importer.importWorldAsyncStart(worldPath, 5, null, ()->{
importer.importWorldAsyncStart(worldPath, 15, null, ()->{
System.err.println("DONE IMPORT");
});
return importer;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.core.gl;
package me.cortex.zenith.client.core.gl;
import me.cortex.voxelmon.common.util.TrackedObject;
import me.cortex.zenith.common.util.TrackedObject;
import static org.lwjgl.opengl.GL15.glDeleteBuffers;
import static org.lwjgl.opengl.GL44C.glBufferStorage;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.core.gl;
package me.cortex.zenith.client.core.gl;
import me.cortex.voxelmon.common.util.TrackedObject;
import me.cortex.zenith.common.util.TrackedObject;
import static org.lwjgl.opengl.GL32.*;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.core.gl;
package me.cortex.zenith.client.core.gl;
import me.cortex.voxelmon.common.util.TrackedObject;
import me.cortex.zenith.common.util.TrackedObject;
import static org.lwjgl.opengl.GL45C.*;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.core.gl;
package me.cortex.zenith.client.core.gl;
import me.cortex.voxelmon.common.util.TrackedObject;
import me.cortex.zenith.common.util.TrackedObject;
import static org.lwjgl.opengl.ARBMapBufferRange.GL_MAP_WRITE_BIT;
import static org.lwjgl.opengl.GL15.glDeleteBuffers;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.core.gl;
package me.cortex.zenith.client.core.gl;
import me.cortex.voxelmon.common.util.TrackedObject;
import me.cortex.zenith.common.util.TrackedObject;
import static org.lwjgl.opengl.ARBFramebufferObject.glDeleteFramebuffers;
import static org.lwjgl.opengl.ARBFramebufferObject.glGenFramebuffers;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.gl.shader;
package me.cortex.zenith.client.core.gl.shader;
public interface IShaderProcessor {
String process(ShaderType type, String source);

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.core.gl.shader;
package me.cortex.zenith.client.core.gl.shader;
import me.cortex.voxelmon.common.util.TrackedObject;
import me.cortex.zenith.common.util.TrackedObject;
import org.lwjgl.opengl.GL20C;
import java.util.HashMap;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.gl.shader;
package me.cortex.zenith.client.core.gl.shader;
import me.jellysquid.mods.sodium.client.gl.shader.ShaderConstants;
import me.jellysquid.mods.sodium.client.gl.shader.ShaderParser;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.gl.shader;
package me.cortex.zenith.client.core.gl.shader;
import static org.lwjgl.opengl.GL20.GL_FRAGMENT_SHADER;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.other;
package me.cortex.zenith.client.core.other;
public record BiomeColour(int id, int foliageColour, int waterColour) {
}

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.other;
package me.cortex.zenith.client.core.other;
public record BlockStateColour(int id, int biomeTintMsk, int[] faceColours) {
}

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.other;
package me.cortex.zenith.client.core.other;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;

View File

@@ -1,13 +1,13 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
//NOTE: an idea on how to do it is so that any render section, we _keep_ aquired (yes this will be very memory intensive)
// could maybe tosomething else
import me.cortex.voxelmon.client.core.gl.GlBuffer;
import me.cortex.voxelmon.client.core.rendering.building.BuiltSectionGeometry;
import me.cortex.voxelmon.client.core.rendering.util.UploadStream;
import me.cortex.voxelmon.client.core.other.BiomeColour;
import me.cortex.voxelmon.client.core.other.BlockStateColour;
import me.cortex.zenith.client.core.gl.GlBuffer;
import me.cortex.zenith.client.core.rendering.building.BuiltSectionGeometry;
import me.cortex.zenith.client.core.rendering.util.UploadStream;
import me.cortex.zenith.client.core.other.BiomeColour;
import me.cortex.zenith.client.core.other.BlockStateColour;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.Frustum;

View File

@@ -1,12 +1,12 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import me.cortex.voxelmon.client.core.gl.GlBuffer;
import me.cortex.voxelmon.client.core.rendering.building.BuiltSectionGeometry;
import me.cortex.voxelmon.client.core.rendering.util.BufferArena;
import me.cortex.voxelmon.client.core.rendering.util.UploadStream;
import me.cortex.zenith.client.core.gl.GlBuffer;
import me.cortex.zenith.client.core.rendering.building.BuiltSectionGeometry;
import me.cortex.zenith.client.core.rendering.util.BufferArena;
import me.cortex.zenith.client.core.rendering.util.UploadStream;
import org.lwjgl.system.MemoryUtil;
import java.util.concurrent.ConcurrentLinkedDeque;

View File

@@ -1,11 +1,11 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
import com.mojang.blaze3d.systems.RenderSystem;
import me.cortex.voxelmon.client.core.gl.GlBuffer;
import me.cortex.voxelmon.client.core.gl.shader.Shader;
import me.cortex.voxelmon.client.core.gl.shader.ShaderType;
import me.cortex.voxelmon.client.core.rendering.util.UploadStream;
import me.cortex.voxelmon.client.mixin.joml.AccessFrustumIntersection;
import me.cortex.zenith.client.core.gl.GlBuffer;
import me.cortex.zenith.client.core.gl.shader.Shader;
import me.cortex.zenith.client.core.gl.shader.ShaderType;
import me.cortex.zenith.client.core.rendering.util.UploadStream;
import me.cortex.zenith.client.mixin.joml.AccessFrustumIntersection;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
//Manages the storage and updating of model states, textures and colours
public class ModelManager {

View File

@@ -1,8 +1,8 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
import me.cortex.voxelmon.client.core.gl.shader.Shader;
import me.cortex.voxelmon.client.core.gl.shader.ShaderType;
import me.cortex.voxelmon.client.core.rendering.util.UploadStream;
import me.cortex.zenith.client.core.gl.shader.Shader;
import me.cortex.zenith.client.core.gl.shader.ShaderType;
import me.cortex.zenith.client.core.rendering.util.UploadStream;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.util.math.MatrixStack;

View File

@@ -1,9 +1,9 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
import me.cortex.voxelmon.client.core.gl.GlFramebuffer;
import me.cortex.voxelmon.client.core.gl.GlTexture;
import me.cortex.voxelmon.client.core.gl.shader.Shader;
import me.cortex.voxelmon.client.core.gl.shader.ShaderType;
import me.cortex.zenith.client.core.gl.GlFramebuffer;
import me.cortex.zenith.client.core.gl.GlTexture;
import me.cortex.zenith.client.core.gl.shader.Shader;
import me.cortex.zenith.client.core.gl.shader.ShaderType;
import org.lwjgl.opengl.GL11C;
import static org.lwjgl.opengl.ARBFramebufferObject.*;

View File

@@ -1,9 +1,9 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
import me.cortex.voxelmon.client.core.rendering.building.BuiltSectionGeometry;
import me.cortex.voxelmon.client.core.rendering.building.RenderGenerationService;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.voxelmon.common.world.WorldSection;
import me.cortex.zenith.client.core.rendering.building.BuiltSectionGeometry;
import me.cortex.zenith.client.core.rendering.building.RenderGenerationService;
import me.cortex.zenith.common.world.WorldEngine;
import me.cortex.zenith.common.world.WorldSection;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.Direction;

View File

@@ -1,9 +1,9 @@
package me.cortex.voxelmon.client.core.rendering;
package me.cortex.zenith.client.core.rendering;
import me.cortex.voxelmon.client.core.gl.GlBuffer;
import me.cortex.voxelmon.client.core.rendering.util.UploadStream;
import me.cortex.voxelmon.client.core.util.IndexUtil;
import me.cortex.voxelmon.common.util.MemoryBuffer;
import me.cortex.zenith.client.core.gl.GlBuffer;
import me.cortex.zenith.client.core.rendering.util.UploadStream;
import me.cortex.zenith.client.core.util.IndexUtil;
import me.cortex.zenith.common.util.MemoryBuffer;
import org.lwjgl.system.MemoryUtil;

View File

@@ -1,7 +1,7 @@
package me.cortex.voxelmon.client.core.rendering.building;
package me.cortex.zenith.client.core.rendering.building;
import me.cortex.voxelmon.common.util.MemoryBuffer;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.zenith.common.util.MemoryBuffer;
import me.cortex.zenith.common.world.WorldEngine;
public class BuiltSectionGeometry {
public final long position;

View File

@@ -1,8 +1,8 @@
package me.cortex.voxelmon.client.core.rendering.building;
package me.cortex.zenith.client.core.rendering.building;
import me.cortex.voxelmon.client.core.util.Mesher2D;
import me.cortex.voxelmon.common.world.other.Mapper;
import me.cortex.zenith.client.core.util.Mesher2D;
import me.cortex.zenith.common.world.other.Mapper;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;

View File

@@ -1,11 +1,11 @@
package me.cortex.voxelmon.client.core.rendering.building;
package me.cortex.zenith.client.core.rendering.building;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import me.cortex.voxelmon.common.util.MemoryBuffer;
import me.cortex.voxelmon.client.core.util.Mesher2D;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.voxelmon.common.world.WorldSection;
import me.cortex.voxelmon.common.world.other.Mapper;
import me.cortex.zenith.common.util.MemoryBuffer;
import me.cortex.zenith.client.core.util.Mesher2D;
import me.cortex.zenith.common.world.WorldEngine;
import me.cortex.zenith.common.world.WorldSection;
import me.cortex.zenith.common.world.other.Mapper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.Direction;
import org.lwjgl.system.MemoryUtil;
@@ -17,7 +17,6 @@ public class RenderDataFactory {
private final WorldEngine world;
private final long[] sectionCache = new long[32*32*32];
private final long[] connectedSectionCache = new long[32*32*32];
private final ColourMapping colourCache = new ColourMapping();
private final QuadEncoder encoder;
public RenderDataFactory(WorldEngine world) {
this.world = world;
@@ -34,7 +33,6 @@ public class RenderDataFactory {
//buildMask in the lower 6 bits contains the faces to build, the next 6 bits are whether the edge face builds against
// its neigbor or not (0 if it does 1 if it doesnt (0 is default behavior))
public BuiltSectionGeometry generateMesh(WorldSection section, int buildMask) {
this.colourCache.reset();
//TODO: to speed it up more, check like section.isEmpty() and stuff like that, have masks for if a slice/layer is entirly air etc
//TODO: instead of having it check its neighbors with the same lod level, compare against 1 level lower, this will prevent cracks and seams from

View File

@@ -1,8 +1,8 @@
package me.cortex.voxelmon.client.core.rendering.building;
package me.cortex.zenith.client.core.rendering.building;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.voxelmon.common.world.WorldSection;
import me.cortex.zenith.common.world.WorldEngine;
import me.cortex.zenith.common.world.WorldSection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;

View File

@@ -1,8 +1,8 @@
package me.cortex.voxelmon.client.core.rendering.util;
package me.cortex.zenith.client.core.rendering.util;
import me.cortex.voxelmon.client.core.gl.GlBuffer;
import me.cortex.voxelmon.client.core.util.AllocationArena;
import me.cortex.voxelmon.common.util.MemoryBuffer;
import me.cortex.zenith.client.core.gl.GlBuffer;
import me.cortex.zenith.client.core.util.AllocationArena;
import me.cortex.zenith.common.util.MemoryBuffer;
import org.lwjgl.system.MemoryUtil;
public class BufferArena {

View File

@@ -1,15 +1,15 @@
package me.cortex.voxelmon.client.core.rendering.util;
package me.cortex.zenith.client.core.rendering.util;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import me.cortex.voxelmon.client.core.gl.GlBuffer;
import me.cortex.voxelmon.client.core.gl.GlFence;
import me.cortex.voxelmon.client.core.gl.GlPersistentMappedBuffer;
import me.cortex.voxelmon.client.core.util.AllocationArena;
import me.cortex.zenith.client.core.gl.GlBuffer;
import me.cortex.zenith.client.core.gl.GlFence;
import me.cortex.zenith.client.core.gl.GlPersistentMappedBuffer;
import me.cortex.zenith.client.core.util.AllocationArena;
import java.util.ArrayDeque;
import java.util.Deque;
import static me.cortex.voxelmon.client.core.util.AllocationArena.SIZE_LIMIT;
import static me.cortex.zenith.client.core.util.AllocationArena.SIZE_LIMIT;
import static org.lwjgl.opengl.ARBDirectStateAccess.glCopyNamedBufferSubData;
import static org.lwjgl.opengl.ARBDirectStateAccess.glFlushMappedNamedBufferRange;
import static org.lwjgl.opengl.ARBMapBufferRange.*;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.util;
package me.cortex.zenith.client.core.util;
import it.unimi.dsi.fastutil.longs.LongRBTreeSet;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.util;
package me.cortex.zenith.client.core.util;
import java.io.IOException;
import java.io.InputStream;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.util;
package me.cortex.zenith.client.core.util;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.render.*;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.core.util;
package me.cortex.zenith.client.core.util;
import me.cortex.voxelmon.common.util.MemoryBuffer;
import me.cortex.zenith.common.util.MemoryBuffer;
import org.lwjgl.system.MemoryUtil;
public class IndexUtil {

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.util;
package me.cortex.zenith.client.core.util;
import java.util.Arrays;
import java.util.BitSet;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.core.util;
package me.cortex.zenith.client.core.util;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;

View File

@@ -1,10 +1,10 @@
package me.cortex.voxelmon.client.importers;
package me.cortex.zenith.client.importers;
import com.mojang.serialization.Codec;
import me.cortex.voxelmon.client.core.util.ByteBufferBackedInputStream;
import me.cortex.voxelmon.common.voxelization.VoxelizedSection;
import me.cortex.voxelmon.common.voxelization.WorldConversionFactory;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.zenith.client.core.util.ByteBufferBackedInputStream;
import me.cortex.zenith.common.voxelization.VoxelizedSection;
import me.cortex.zenith.common.voxelization.WorldConversionFactory;
import me.cortex.zenith.common.world.WorldEngine;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@@ -29,6 +29,7 @@ import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
public class WorldImporter {
@@ -36,13 +37,18 @@ public class WorldImporter {
private final WorldEngine world;
private final World mcWorld;
private final RegistryEntry<Biome> defaultBiome;
private final Codec<ReadableContainer<RegistryEntry<Biome>>> biomeCodec;
private final AtomicInteger totalRegions = new AtomicInteger();
private final AtomicInteger regionsProcessed = new AtomicInteger();
private final AtomicInteger percentMarker = new AtomicInteger();
public WorldImporter(WorldEngine worldEngine, World mcWorld) {
this.world = worldEngine;
this.mcWorld = mcWorld;
var biomeRegistry = mcWorld.getRegistryManager().get(RegistryKeys.BIOME);
this.defaultBiome = biomeRegistry.entryOf(BiomeKeys.PLAINS);
this.biomeCodec = PalettedContainer.createReadableContainerCodec(biomeRegistry.getIndexedEntries(), biomeRegistry.createEntryCodec(), PalettedContainer.PaletteProvider.BIOME, biomeRegistry.entryOf(BiomeKeys.PLAINS));
}
@@ -50,7 +56,8 @@ public class WorldImporter {
public void importWorldAsyncStart(File directory, int threads, Function<ImportUpdate, Boolean> updateCallback, Runnable onCompletion) {
this.worker = new Thread(() -> {
var workers = new ForkJoinPool(threads);
for (var file : directory.listFiles()) {
var files = directory.listFiles();
for (var file : files) {
if (!file.isFile()) {
continue;
}
@@ -62,9 +69,19 @@ public class WorldImporter {
}
int rx = Integer.parseInt(sections[1]);
int rz = Integer.parseInt(sections[2]);
this.totalRegions.addAndGet(1);
workers.submit(() -> {
try {
this.importRegionFile(file.toPath(), rx, rz);
int regionsProcessedCount = this.regionsProcessed.addAndGet(1);
synchronized (this.world) {
int percentMark = this.percentMarker.get();
int percent = (regionsProcessedCount*100)/this.totalRegions.get();
if (percent > percentMark) {
System.out.println(regionsProcessedCount + "/" + this.totalRegions.get());
this.percentMarker.addAndGet(1);
}
}
} catch (
Exception e) {
e.printStackTrace();
@@ -173,8 +190,7 @@ public class WorldImporter {
}
var blockStates = BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, section.getCompound("block_states")).result().get();
var biomes = this.biomeCodec.parse(NbtOps.INSTANCE, section.getCompound("biomes")).result().get();
var biomes = this.biomeCodec.parse(NbtOps.INSTANCE, section.getCompound("biomes")).result().orElse(null);
VoxelizedSection csec = WorldConversionFactory.convert(
this.world.getMapper(),
blockStates,
@@ -182,11 +198,12 @@ public class WorldImporter {
(bx, by, bz, state) -> (byte) 0,
x,
y,
z
z,
this.defaultBiome
);
this.world.insertUpdate(csec);
while (this.world.savingService.getTaskCount() > 2000) {
while (this.world.savingService.getTaskCount() > 4000) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.mixin.joml;
package me.cortex.zenith.client.mixin.joml;
import org.joml.FrustumIntersection;
import org.joml.Vector4f;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.mixin.minecraft;
package me.cortex.zenith.client.mixin.minecraft;
import net.minecraft.client.render.BackgroundRenderer;
import org.spongepowered.asm.mixin.Mixin;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.mixin.minecraft;
package me.cortex.zenith.client.mixin.minecraft;
import me.cortex.voxelmon.client.IGetVoxelCore;
import me.cortex.zenith.client.IGetVoxelCore;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientChunkManager;
import net.minecraft.util.math.ChunkPos;

View File

@@ -1,6 +1,6 @@
package me.cortex.voxelmon.client.mixin.minecraft;
package me.cortex.zenith.client.mixin.minecraft;
import me.cortex.voxelmon.client.IGetVoxelCore;
import me.cortex.zenith.client.IGetVoxelCore;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
import org.spongepowered.asm.mixin.Mixin;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.mixin.minecraft;
package me.cortex.zenith.client.mixin.minecraft;
import net.minecraft.client.render.GameRenderer;
import org.spongepowered.asm.mixin.Mixin;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.mixin.minecraft;
package me.cortex.zenith.client.mixin.minecraft;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;

View File

@@ -1,7 +1,7 @@
package me.cortex.voxelmon.client.mixin.minecraft;
package me.cortex.zenith.client.mixin.minecraft;
import me.cortex.voxelmon.client.IGetVoxelCore;
import me.cortex.voxelmon.client.core.VoxelCore;
import me.cortex.zenith.client.IGetVoxelCore;
import me.cortex.zenith.client.core.VoxelCore;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
@@ -82,6 +82,6 @@ public abstract class MixinWorldRenderer implements IGetVoxelCore {
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;getViewDistance()F"), require = 0)
private float changeRD(GameRenderer instance) {
float viewDistance = instance.getViewDistance();
return 16*1512;
return 16*5120;
}
}

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.terrain;
package me.cortex.zenith.client.terrain;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.world.biome.Biome;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.client.terrain;
package me.cortex.zenith.client.terrain;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.client.MinecraftClient;

View File

@@ -1,10 +1,10 @@
package me.cortex.voxelmon.client.terrain;
package me.cortex.zenith.client.terrain;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import me.cortex.voxelmon.client.IGetVoxelCore;
import me.cortex.voxelmon.client.importers.WorldImporter;
import me.cortex.zenith.client.IGetVoxelCore;
import me.cortex.zenith.client.importers.WorldImporter;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.util;
package me.cortex.zenith.common.util;
import org.lwjgl.system.MemoryUtil;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.util;
package me.cortex.zenith.common.util;
import java.lang.ref.Cleaner;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.util;
package me.cortex.zenith.common.util;
public class VolatileHolder <T> {
public volatile T obj;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.voxelization;
package me.cortex.zenith.common.voxelization;
public interface I3dSupplier <T> {
T supply(int x, int y, int z);

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.voxelization;
package me.cortex.zenith.common.voxelization;
import net.minecraft.block.BlockState;

View File

@@ -1,7 +1,7 @@
package me.cortex.voxelmon.common.voxelization;
package me.cortex.zenith.common.voxelization;
import me.cortex.voxelmon.common.world.other.Mapper;
import me.cortex.zenith.common.world.other.Mapper;
//16x16x16 block section
public class VoxelizedSection {

View File

@@ -1,7 +1,7 @@
package me.cortex.voxelmon.common.voxelization;
package me.cortex.zenith.common.voxelization;
import me.cortex.voxelmon.common.world.other.Mipper;
import me.cortex.voxelmon.common.world.other.Mapper;
import me.cortex.zenith.common.world.other.Mipper;
import me.cortex.zenith.common.world.other.Mapper;
import net.minecraft.block.BlockState;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.world.biome.Biome;
@@ -25,7 +25,8 @@ public class WorldConversionFactory {
ILightingSupplier lightSupplier,
int sx,
int sy,
int sz) {
int sz,
RegistryEntry<Biome> defaultBiome) {
long[] section = new long[4*4*4+2*2*2+1];//Mipping
long[][] subSections = new long[4*4*4][];
long[] current = new long[4*4*4+2*2*2];
@@ -33,7 +34,10 @@ public class WorldConversionFactory {
for (int oy = 0; oy < 4; oy++) {
for (int oz = 0; oz < 4; oz++) {
for (int ox = 0; ox < 4; ox++) {
RegistryEntry<Biome> biome = biomeContainer.get(ox, oy, oz);
RegistryEntry<Biome> biome = defaultBiome;
if (biomeContainer != null) {
biome = biomeContainer.get(ox, oy, oz);
}
int nonAir = 0;
for (int iy = 0; iy < 4; iy++) {
for (int iz = 0; iz < 4; iz++) {

View File

@@ -1,7 +1,7 @@
package me.cortex.voxelmon.common.world;
package me.cortex.zenith.common.world;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import me.cortex.voxelmon.common.util.VolatileHolder;
import me.cortex.zenith.common.util.VolatileHolder;
public class ActiveSectionTracker {
//Deserialize into the supplied section, returns true on success, false on failure

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.world;
package me.cortex.zenith.common.world;
import it.unimi.dsi.fastutil.longs.Long2ShortOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongArrayList;
@@ -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, 10);
long compressedSize = ZSTD_compress(compressedData, raw, 15);
compressedData.limit((int) compressedSize);
compressedData.rewind();
MemoryUtil.memFree(raw);

View File

@@ -1,13 +1,12 @@
package me.cortex.voxelmon.common.world;
package me.cortex.zenith.common.world;
import me.cortex.voxelmon.common.voxelization.VoxelizedSection;
import me.cortex.voxelmon.common.world.other.Mapper;
import me.cortex.voxelmon.common.world.service.SectionSavingService;
import me.cortex.voxelmon.common.world.service.VoxelIngestService;
import me.cortex.voxelmon.common.world.storage.StorageBackend;
import me.cortex.zenith.common.voxelization.VoxelizedSection;
import me.cortex.zenith.common.world.other.Mapper;
import me.cortex.zenith.common.world.service.SectionSavingService;
import me.cortex.zenith.common.world.service.VoxelIngestService;
import me.cortex.zenith.common.world.storage.StorageBackend;
import org.lwjgl.system.MemoryUtil;
import java.io.File;
import java.util.Arrays;
import java.util.function.Consumer;
@@ -21,6 +20,8 @@ public class WorldEngine {
public final VoxelIngestService ingestService;
public final SectionSavingService savingService;
private Consumer<WorldSection> dirtyCallback;
private final int maxMipLevels;
public void setDirtyCallback(Consumer<WorldSection> tracker) {
this.dirtyCallback = dirtyCallback;
@@ -28,12 +29,9 @@ public class WorldEngine {
public Mapper getMapper() {return this.mapper;}
private final int maxMipLevels;
public WorldEngine(File storagePath, int ingestWorkers, int savingServiceWorkers, int maxMipLayers) {
public WorldEngine(StorageBackend storageBackend, int ingestWorkers, int savingServiceWorkers, int maxMipLayers) {
this.maxMipLevels = maxMipLayers;
this.storage = new StorageBackend(storagePath);
this.storage = storageBackend;
this.mapper = new Mapper(this.storage);
this.sectionTracker = new ActiveSectionTracker(maxMipLayers, this::unsafeLoadSection);

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.world;
package me.cortex.zenith.common.world;
import java.util.Arrays;

View File

@@ -1,7 +1,7 @@
package me.cortex.voxelmon.common.world.other;
package me.cortex.zenith.common.world.other;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import me.cortex.voxelmon.common.world.storage.StorageBackend;
import me.cortex.zenith.common.world.storage.StorageBackend;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@@ -44,8 +44,8 @@ public class Mapper {
this.storage = storage;
//Insert air since its a special entry (index 0)
var airEntry = new StateEntry(0, Blocks.AIR.getDefaultState());
block2stateEntry.put(airEntry.state, airEntry);
blockId2stateEntry.add(airEntry);
this.block2stateEntry.put(airEntry.state, airEntry);
this.blockId2stateEntry.add(airEntry);
this.loadFromStorage();
}
@@ -71,7 +71,7 @@ public class Mapper {
}
private void loadFromStorage() {
var mappings = this.storage.getIdMappings();
var mappings = this.storage.getIdMappingsData();
List<StateEntry> sentries = new ArrayList<>();
List<BiomeEntry> bentries = new ArrayList<>();
List<Pair<byte[], Integer>> sentryErrors = new ArrayList<>();

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.world.other;
package me.cortex.zenith.common.world.other;
//Mipper for data
public class Mipper {

View File

@@ -1,8 +1,8 @@
package me.cortex.voxelmon.common.world.service;
package me.cortex.zenith.common.world.service;
import me.cortex.voxelmon.common.world.SaveLoadSystem;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.voxelmon.common.world.WorldSection;
import me.cortex.zenith.common.world.SaveLoadSystem;
import me.cortex.zenith.common.world.WorldEngine;
import me.cortex.zenith.common.world.WorldSection;
import org.lwjgl.system.MemoryUtil;
import java.util.concurrent.ConcurrentLinkedDeque;

View File

@@ -1,9 +1,9 @@
package me.cortex.voxelmon.common.world.service;
package me.cortex.zenith.common.world.service;
import it.unimi.dsi.fastutil.Pair;
import me.cortex.voxelmon.common.voxelization.VoxelizedSection;
import me.cortex.voxelmon.common.voxelization.WorldConversionFactory;
import me.cortex.voxelmon.common.world.WorldEngine;
import me.cortex.zenith.common.voxelization.VoxelizedSection;
import me.cortex.zenith.common.voxelization.WorldConversionFactory;
import me.cortex.zenith.common.world.WorldEngine;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.world.LightType;
import net.minecraft.world.chunk.ChunkNibbleArray;
@@ -69,7 +69,8 @@ public class VoxelIngestService {
},
chunk.getPos().x,
i,
chunk.getPos().z
chunk.getPos().z,
null
);
this.world.insertUpdate(csec);

View File

@@ -0,0 +1,22 @@
package me.cortex.zenith.common.world.storage;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.nio.ByteBuffer;
public abstract class StorageBackend {
public abstract ByteBuffer getSectionData(long key);
public abstract void setSectionData(long key, ByteBuffer data);
public abstract void deleteSectionData(long key);
public abstract void putIdMapping(int id, ByteBuffer data);
public abstract Int2ObjectOpenHashMap<byte[]> getIdMappingsData();
public abstract void flush();
public abstract void close();
}

View File

@@ -1,8 +1,8 @@
package me.cortex.voxelmon.common.world.storage;
package me.cortex.zenith.common.world.storage.lmdb;
import org.lwjgl.util.lmdb.MDBVal;
import static me.cortex.voxelmon.common.world.storage.LMDBInterface.E;
import static me.cortex.zenith.common.world.storage.lmdb.LMDBInterface.E;
import static org.lwjgl.util.lmdb.LMDB.*;
public class Cursor implements AutoCloseable {

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.world.storage;
package me.cortex.zenith.common.world.storage.lmdb;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;

View File

@@ -1,6 +1,7 @@
package me.cortex.voxelmon.common.world.storage;
package me.cortex.zenith.common.world.storage.lmdb;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import me.cortex.zenith.common.world.storage.StorageBackend;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.util.lmdb.MDBVal;
@@ -12,8 +13,9 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
import static org.lwjgl.util.lmdb.LMDB.*;
import static org.lwjgl.util.lmdb.LMDB.MDB_NOTFOUND;
public class StorageBackend {
public class LMDBStorageBackend extends StorageBackend {
private static final long GROW_SIZE = 1<<25;//Grow by 33 mb each time
private final AtomicInteger accessingCounts = new AtomicInteger();
@@ -22,7 +24,7 @@ public class StorageBackend {
private final LMDBInterface dbi;
private final LMDBInterface.Database sectionDatabase;
private final LMDBInterface.Database idMappingDatabase;
public StorageBackend(File file) {
public LMDBStorageBackend(File file) {
this.dbi = new LMDBInterface.Builder()
.setMaxDbs(2)
.open(file.getAbsolutePath(), MDB_NOSUBDIR)//MDB_NOLOCK (IF I DO THIS, must sync the db manually)// TODO: THIS
@@ -123,7 +125,7 @@ public class StorageBackend {
}));
}
public Int2ObjectOpenHashMap<byte[]> getIdMappings() {
public Int2ObjectOpenHashMap<byte[]> getIdMappingsData() {
return this.synchronizedTransaction(() -> {
Int2ObjectOpenHashMap<byte[]> mapping = new Int2ObjectOpenHashMap<>();
this.idMappingDatabase.transaction(MDB_RDONLY, transaction -> {
@@ -154,5 +156,4 @@ public class StorageBackend {
this.idMappingDatabase.close();
this.dbi.close();
}
}

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.world.storage;
package me.cortex.zenith.common.world.storage.lmdb;
import org.lwjgl.system.MemoryStack;

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.world.storage;
package me.cortex.zenith.common.world.storage.lmdb;
public interface TransactionWrappedCallback<T> {
T exec(TransactionWrapper wrapper);

View File

@@ -1,4 +1,4 @@
package me.cortex.voxelmon.common.world.storage;
package me.cortex.zenith.common.world.storage.lmdb;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;
@@ -6,7 +6,7 @@ import org.lwjgl.util.lmdb.MDBVal;
import java.nio.ByteBuffer;
import static me.cortex.voxelmon.common.world.storage.LMDBInterface.E;
import static me.cortex.zenith.common.world.storage.lmdb.LMDBInterface.E;
import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.util.lmdb.LMDB.*;

View File

@@ -3,10 +3,10 @@
layout(local_size_x = 128, local_size_y = 1, local_size_x = 1) in;
#import <voxelmon:lod/gl46/quad_format.glsl>
#import <voxelmon:lod/gl46/bindings.glsl>
#import <voxelmon:lod/gl46/frustum.glsl>
#import <voxelmon:lod/gl46/section.glsl>
#import <zenith:lod/gl46/quad_format.glsl>
#import <zenith:lod/gl46/bindings.glsl>
#import <zenith:lod/gl46/frustum.glsl>
#import <zenith:lod/gl46/section.glsl>
//https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GL_EXT_shader_16bit_storage.txt
// adds support for uint8_t which can use for compact visibility buffer

View File

@@ -1,7 +1,7 @@
#version 460 core
#extension GL_ARB_gpu_shader_int64 : enable
#define VISIBILITY_ACCESS writeonly
#import <voxelmon:lod/gl46/bindings.glsl>
#import <zenith:lod/gl46/bindings.glsl>
flat in uint id;
flat in uint value;
//out vec4 colour;

View File

@@ -1,8 +1,8 @@
#version 460 core
#extension GL_ARB_gpu_shader_int64 : enable
#define VISIBILITY_ACCESS writeonly
#import <voxelmon:lod/gl46/bindings.glsl>
#import <voxelmon:lod/gl46/section.glsl>
#import <zenith:lod/gl46/bindings.glsl>
#import <zenith:lod/gl46/section.glsl>
flat out uint id;
flat out uint value;

View File

@@ -1,8 +1,8 @@
#version 460 core
#extension GL_ARB_gpu_shader_int64 : enable
#import <voxelmon:lod/gl46/quad_format.glsl>
#import <voxelmon:lod/gl46/bindings.glsl>
#import <zenith:lod/gl46/quad_format.glsl>
#import <zenith:lod/gl46/bindings.glsl>
layout(location = 0) out flat vec4 colour;

View File

@@ -14,14 +14,14 @@
"environment": "client",
"entrypoints": {
"client": [
"me.cortex.voxelmon.client.Voxelmon"
"me.cortex.zenith.client.Voxelmon"
]
},
"mixins": [
"voxelmon.mixins.json"
"zenith.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.22"
},
"accessWidener": "voxelmon.accesswidener"
"accessWidener": "zenith.accesswidener"
}

View File

@@ -1,6 +1,6 @@
{
"required": true,
"package": "me.cortex.voxelmon.client.mixin",
"package": "me.cortex.zenith.client.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"minecraft.MixinBackgroundRenderer",