Fix biome

This commit is contained in:
mcrcortex
2024-08-05 16:42:12 +10:00
parent 0fdba1bf64
commit 593f222760
6 changed files with 48 additions and 4 deletions

View File

@@ -6,10 +6,14 @@ import me.cortex.voxy.client.core.gl.GlFramebuffer;
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
import me.cortex.voxy.client.core.rendering.util.RawDownloadStream;
import me.cortex.voxy.common.world.other.Mapper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import org.lwjgl.opengl.GL11;
import java.lang.invoke.VarHandle;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
import static org.lwjgl.opengl.ARBFramebufferObject.GL_COLOR_ATTACHMENT0;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
@@ -26,6 +30,7 @@ public class ModelBakerySubsystem {
private final ModelStore storage = new ModelStore();
public final ModelFactory factory;
private final IntLinkedOpenHashSet blockIdQueue = new IntLinkedOpenHashSet();
private final ConcurrentLinkedDeque<Mapper.BiomeEntry> biomeQueue = new ConcurrentLinkedDeque<>();
public ModelBakerySubsystem(Mapper mapper) {
this.factory = new ModelFactory(mapper, this.storage, this.textureDownStream);
@@ -50,6 +55,13 @@ public class ModelBakerySubsystem {
}
}
//Upload all biomes
while (!this.biomeQueue.isEmpty()) {
var biome = this.biomeQueue.poll();
var biomeReg = MinecraftClient.getInstance().world.getRegistryManager().get(RegistryKeys.BIOME);
this.factory.addBiome(biome.id, biomeReg.get(Identifier.of(biome.biome)));
}
//Submit is effectively free if nothing is submitted
this.textureDownStream.submit();
@@ -71,6 +83,10 @@ public class ModelBakerySubsystem {
}
}
public void addBiome(Mapper.BiomeEntry biomeEntry) {
this.biomeQueue.add(biomeEntry);
}
public void addDebugData(List<String> debug) {
debug.add("MQ/IF/MC: " + this.blockIdQueue.size() + "/" + this.factory.getInflightCount() + "/" + this.factory.getBakedCount());//Model bake queue/in flight/model baked count
}

View File

@@ -449,9 +449,16 @@ public class ModelFactory {
}
public void addBiome(int id, Biome biome) {
this.biomes.add(biome);
if (this.biomes.size()-1 != id) {
throw new IllegalStateException("Biome ordering not consistent with biome id for biome " + biome + " expected id: " + (this.biomes.size()-1) + " got id: " + id);
for (int i = this.biomes.size(); i <= id; i++) {
this.biomes.add(null);
}
var oldBiome = this.biomes.set(id, biome);
if (oldBiome != null && oldBiome != biome) {
throw new IllegalStateException("Biome was put in an id that was not null");
}
if (oldBiome == biome) {
System.err.println("Biome added was a duplicate");
}
int i = 0;
@@ -465,6 +472,9 @@ public class ModelFactory {
MemoryUtil.memPutInt(UploadStream.INSTANCE.upload(this.storage.modelBuffer, (entry.getLeft()* MODEL_SIZE)+ 4*6 + 4, 4), biomeIndex);
long clrUploadPtr = UploadStream.INSTANCE.upload(this.storage.modelColourBuffer, biomeIndex * 4L, 4L * this.biomes.size());
for (var biomeE : this.biomes) {
if (biomeE == null) {
continue;//If null, ignore
}
MemoryUtil.memPutInt(clrUploadPtr, captureColourConstant(colourProvider, entry.getRight(), biomeE)|0xFF000000); clrUploadPtr += 4;
}
}

View File

@@ -15,6 +15,7 @@ import me.cortex.voxy.client.core.rendering.util.UploadStream;
import me.cortex.voxy.common.world.WorldEngine;
import net.minecraft.client.render.Camera;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
@@ -54,6 +55,9 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
world.setDirtyCallback(this.nodeManager::sectionUpdate);
Arrays.stream(world.getMapper().getBiomeEntries()).forEach(this.modelService::addBiome);
world.getMapper().setBiomeCallback(this.modelService::addBiome);
for(int x = -1; x<=1;x++) {
for (int z = -1; z <= 1; z++) {

View File

@@ -3,6 +3,7 @@ package me.cortex.voxy.client.core.rendering.hierachical2;
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
import me.cortex.voxy.client.core.rendering.section.AbstractSectionGeometryManager;
import me.cortex.voxy.common.util.HierarchicalBitSet;
import me.cortex.voxy.common.world.WorldSection;
import me.jellysquid.mods.sodium.client.util.MathUtil;
import org.lwjgl.system.MemoryUtil;
@@ -13,6 +14,7 @@ public class HierarchicalNodeManager {
public final int maxNodeCount;
private final long[] localNodeData;
private final AbstractSectionGeometryManager geometryManager;
private final HierarchicalBitSet allocationSet;
public HierarchicalNodeManager(int maxNodeCount, AbstractSectionGeometryManager geometryManager) {
if (!MathUtil.isPowerOfTwo(maxNodeCount)) {
@@ -21,6 +23,7 @@ public class HierarchicalNodeManager {
if (maxNodeCount>(1<<24)) {
throw new IllegalArgumentException("Max node count cannot exceed 2^24");
}
this.allocationSet = new HierarchicalBitSet(maxNodeCount);
this.maxNodeCount = maxNodeCount;
this.localNodeData = new long[maxNodeCount*4];
this.geometryManager = geometryManager;

View File

@@ -0,0 +1,8 @@
package me.cortex.voxy.client.core.rendering.hierachical2;
//Request of the leaf node to expand
class LeafExpansionRequest {
//Child states contain micrometadata in the top bits
// such as isEmpty, and isEmptyButEventuallyHasNonEmptyChild
private final int[] childStates = new int[8];
}

View File

@@ -73,8 +73,11 @@ public class Mapper {
return (id&(~(0xFFL<<56)))|(Integer.toUnsignedLong(light)<<56);
}
public void setCallbacks(Consumer<StateEntry> stateCallback, Consumer<BiomeEntry> biomeCallback) {
public void setStateCallback(Consumer<StateEntry> stateCallback) {
this.newStateCallback = stateCallback;
}
public void setBiomeCallback(Consumer<BiomeEntry> biomeCallback) {
this.newBiomeCallback = biomeCallback;
}