Merge remote-tracking branch 'origin/master'

This commit is contained in:
mcrcortex
2024-03-28 20:44:07 +10:00
6 changed files with 91 additions and 68 deletions

View File

@@ -62,6 +62,8 @@ dependencies {
modCompileOnly("maven.modrinth:starlight:1.1.3+1.20.4") modCompileOnly("maven.modrinth:starlight:1.1.3+1.20.4")
//modCompileOnly("maven.modrinth:immersiveportals:v5.1.7-mc1.20.4") //modCompileOnly("maven.modrinth:immersiveportals:v5.1.7-mc1.20.4")
modCompileOnly("maven.modrinth:vivecraft:1.20.4-1.1.6-fabric") modCompileOnly("maven.modrinth:vivecraft:1.20.4-1.1.6-fabric")
modCompileOnly("maven.modrinth:chunky:1.3.138")
modRuntimeOnly("maven.modrinth:chunky:1.3.138")
} }

View File

@@ -204,9 +204,12 @@ public class VoxelCore {
debug.add(""); debug.add("");
debug.add(""); debug.add("");
debug.add("Voxy Core: " + Voxy.VERSION); debug.add("Voxy Core: " + Voxy.VERSION);
/*
debug.add("Ingest service tasks: " + this.world.ingestService.getTaskCount()); debug.add("Ingest service tasks: " + this.world.ingestService.getTaskCount());
debug.add("Saving service tasks: " + this.world.savingService.getTaskCount()); debug.add("Saving service tasks: " + this.world.savingService.getTaskCount());
debug.add("Render service tasks: " + this.renderGen.getTaskCount()); debug.add("Render service tasks: " + this.renderGen.getTaskCount());
*/
debug.add("I/S/R tasks: " + this.world.ingestService.getTaskCount() + "/"+this.world.savingService.getTaskCount()+"/"+this.renderGen.getTaskCount());
debug.add("Loaded cache sizes: " + Arrays.toString(this.world.getLoadedSectionCacheSizes())); debug.add("Loaded cache sizes: " + Arrays.toString(this.world.getLoadedSectionCacheSizes()));
debug.add("Mesh cache count: " + this.renderGen.getMeshCacheCount()); debug.add("Mesh cache count: " + this.renderGen.getMeshCacheCount());
this.renderer.addDebugData(debug); this.renderer.addDebugData(debug);

View File

@@ -5,6 +5,8 @@ import me.cortex.voxy.client.core.model.IdNotYetComputedException;
import me.cortex.voxy.client.core.model.ModelManager; import me.cortex.voxy.client.core.model.ModelManager;
import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.common.world.WorldEngine;
import me.cortex.voxy.common.world.WorldSection; import me.cortex.voxy.common.world.WorldSection;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
@@ -49,36 +51,42 @@ public class RenderGenerationService {
while (this.running) { while (this.running) {
this.taskCounter.acquireUninterruptibly(); this.taskCounter.acquireUninterruptibly();
if (!this.running) break; if (!this.running) break;
BuildTask task;
synchronized (this.taskQueue) {
task = this.taskQueue.removeFirst();
}
var section = task.sectionSupplier.get();
if (section == null) {
continue;
}
section.assertNotFree();
BuiltSection mesh = null;
try { try {
mesh = factory.generateMesh(section); BuildTask task;
} catch (IdNotYetComputedException e) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
//We need to reinsert the build task into the queue
//System.err.println("Render task failed to complete due to un-computed client id");
synchronized (this.taskQueue) { synchronized (this.taskQueue) {
this.taskQueue.computeIfAbsent(section.key, key->{this.taskCounter.release(); return task;}); task = this.taskQueue.removeFirst();
} }
} var section = task.sectionSupplier.get();
section.release(); if (section == null) {
if (mesh != null) { continue;
this.resultConsumer.accept(mesh.clone());
if (!this.meshCache.putMesh(mesh)) {
mesh.free();
} }
section.assertNotFree();
BuiltSection mesh = null;
try {
mesh = factory.generateMesh(section);
} catch (IdNotYetComputedException e) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
//We need to reinsert the build task into the queue
//System.err.println("Render task failed to complete due to un-computed client id");
synchronized (this.taskQueue) {
this.taskQueue.computeIfAbsent(section.key, key->{this.taskCounter.release(); return task;});
}
}
section.release();
if (mesh != null) {
//TODO: if the mesh is null, need to clear the cache at that point
this.resultConsumer.accept(mesh.clone());
if (!this.meshCache.putMesh(mesh)) {
mesh.free();
}
}
} catch (Exception e) {
System.err.println(e);
MinecraftClient.getInstance().executeSync(()->MinecraftClient.getInstance().player.sendMessage(Text.literal("Voxy render service had an exception while executing please check logs and report error")));
} }
} }
} }

View File

@@ -4,6 +4,8 @@ import me.cortex.voxy.common.storage.StorageCompressor;
import me.cortex.voxy.common.world.SaveLoadSystem; import me.cortex.voxy.common.world.SaveLoadSystem;
import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.common.world.WorldEngine;
import me.cortex.voxy.common.world.WorldSection; import me.cortex.voxy.common.world.WorldSection;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
@@ -40,12 +42,15 @@ public class SectionSavingService {
if (!this.running) break; if (!this.running) break;
var section = this.saveQueue.pop(); var section = this.saveQueue.pop();
section.assertNotFree(); section.assertNotFree();
section.inSaveQueue.set(false); try {
section.inSaveQueue.set(false);
var saveData = SaveLoadSystem.serialize(section); var saveData = SaveLoadSystem.serialize(section);
this.world.storage.setSectionData(section.key, saveData); this.world.storage.setSectionData(section.key, saveData);
MemoryUtil.memFree(saveData); MemoryUtil.memFree(saveData);
} catch (Exception e) {
System.err.println(e);
MinecraftClient.getInstance().executeSync(()->MinecraftClient.getInstance().player.sendMessage(Text.literal("Voxy saver had an exception while executing please check logs and report error")));
}
section.release(); section.release();
} }
} }

View File

@@ -4,6 +4,8 @@ import it.unimi.dsi.fastutil.Pair;
import me.cortex.voxy.common.voxelization.VoxelizedSection; import me.cortex.voxy.common.voxelization.VoxelizedSection;
import me.cortex.voxy.common.voxelization.WorldConversionFactory; import me.cortex.voxy.common.voxelization.WorldConversionFactory;
import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.common.world.WorldEngine;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.util.math.ChunkSectionPos; import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.world.LightType; import net.minecraft.world.LightType;
import net.minecraft.world.chunk.ChunkNibbleArray; import net.minecraft.world.chunk.ChunkNibbleArray;
@@ -42,39 +44,44 @@ public class VoxelIngestService {
while (this.running) { while (this.running) {
this.ingestCounter.acquireUninterruptibly(); this.ingestCounter.acquireUninterruptibly();
if (!this.running) break; if (!this.running) break;
var chunk = this.ingestQueue.pop(); try {
int i = chunk.getBottomSectionCoord() - 1; var chunk = this.ingestQueue.pop();
for (var section : chunk.getSectionArray()) { int i = chunk.getBottomSectionCoord() - 1;
i++; for (var section : chunk.getSectionArray()) {
var lighting = this.captureLightMap.remove(ChunkSectionPos.from(chunk.getPos(), i).asLong()); i++;
if (section.isEmpty()) { var lighting = this.captureLightMap.remove(ChunkSectionPos.from(chunk.getPos(), i).asLong());
this.world.insertUpdate(VoxelizedSection.createEmpty(chunk.getPos().x, i, chunk.getPos().z)); if (section.isEmpty()) {
} else { this.world.insertUpdate(VoxelizedSection.createEmpty(chunk.getPos().x, i, chunk.getPos().z));
VoxelizedSection csec = WorldConversionFactory.convert( } else {
this.world.getMapper(), VoxelizedSection csec = WorldConversionFactory.convert(
section.getBlockStateContainer(), this.world.getMapper(),
section.getBiomeContainer(), section.getBlockStateContainer(),
(x, y, z, state) -> { section.getBiomeContainer(),
if (lighting == null || ((lighting.first() != null && lighting.first().isUninitialized())&&(lighting.second()!=null&&lighting.second().isUninitialized()))) { (x, y, z, state) -> {
return (byte) 0x0f; if (lighting == null || ((lighting.first() != null && lighting.first().isUninitialized())&&(lighting.second()!=null&&lighting.second().isUninitialized()))) {
} else { return (byte) 0x0f;
//Lighting is a piece of shit cause its done per face } else {
int block = lighting.first()!=null?Math.min(15,lighting.first().get(x, y, z)):0; //Lighting is a piece of shit cause its done per face
int sky = lighting.second()!=null?Math.min(15,lighting.second().get(x, y, z)):0; int block = lighting.first()!=null?Math.min(15,lighting.first().get(x, y, z)):0;
if (block<state.getLuminance()) { int sky = lighting.second()!=null?Math.min(15,lighting.second().get(x, y, z)):0;
block = state.getLuminance(); if (block<state.getLuminance()) {
block = state.getLuminance();
}
sky = 15-sky;//This is cause sky light is inverted which saves memory when saving empty sections
return (byte) (sky|(block<<4));
} }
sky = 15-sky;//This is cause sky light is inverted which saves memory when saving empty sections },
return (byte) (sky|(block<<4)); chunk.getPos().x,
} i,
}, chunk.getPos().z
chunk.getPos().x, );
i, WorldConversionFactory.mipSection(csec, this.world.getMapper());
chunk.getPos().z this.world.insertUpdate(csec);
); }
WorldConversionFactory.mipSection(csec, this.world.getMapper());
this.world.insertUpdate(csec);
} }
} catch (Exception e) {
System.err.println(e);
MinecraftClient.getInstance().executeSync(()->MinecraftClient.getInstance().player.sendMessage(Text.literal("Voxy ingester had an exception while executing please check logs and report error")));
} }
} }
} }

View File

@@ -8,14 +8,12 @@
"minecraft.MixinDebugHud", "minecraft.MixinDebugHud",
"minecraft.MixinMinecraftClient", "minecraft.MixinMinecraftClient",
"minecraft.MixinWorldRenderer", "minecraft.MixinWorldRenderer",
"sodium.MixinSodiumWorldRender", "nvidium.MixinRenderPipeline",
"sodium.MixinDefaultChunkRenderer", "sodium.MixinDefaultChunkRenderer",
"sodium.MixinRenderSectionManager", "sodium.MixinRenderSectionManager",
"nvidium.MixinRenderPipeline" "sodium.MixinSodiumWorldRender"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1
}, }
"mixins": [
]
} }