Compare commits
3 Commits
dev
...
inverted_n
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8dd71defe | ||
|
|
e3329f210b | ||
|
|
5841b36469 |
@@ -2,6 +2,7 @@ package me.cortex.voxy.client.core;
|
||||
|
||||
public interface IGetVoxyRenderSystem {
|
||||
VoxyRenderSystem getVoxyRenderSystem();
|
||||
VoxyRenderSystem getVoxyOverworldRenderSystem();
|
||||
void shutdownRenderer();
|
||||
void createRenderer();
|
||||
}
|
||||
|
||||
@@ -61,12 +61,16 @@ public class VoxyRenderSystem {
|
||||
public final ChunkBoundRenderer chunkBoundRenderer;
|
||||
|
||||
public VoxyRenderSystem(WorldEngine world, ServiceThreadPool threadPool) {
|
||||
this(world, threadPool, 1L<<32);
|
||||
}
|
||||
|
||||
public VoxyRenderSystem(WorldEngine world, ServiceThreadPool threadPool, long maxGeometryCapacity) {
|
||||
//Trigger the shared index buffer loading
|
||||
SharedIndexBuffer.INSTANCE.id();
|
||||
Capabilities.init();//Ensure clinit is called
|
||||
|
||||
this.worldIn = world;
|
||||
this.renderer = new RenderService(world, threadPool);
|
||||
this.renderer = new RenderService(world, threadPool, maxGeometryCapacity);
|
||||
this.postProcessing = new PostProcessing();
|
||||
int minSec = MinecraftClient.getInstance().world.getBottomSectionCoord()>>5;
|
||||
int maxSec = (MinecraftClient.getInstance().world.getTopSectionCoord()-1)>>5;
|
||||
|
||||
@@ -62,11 +62,12 @@ public class RenderService<T extends AbstractSectionRenderer<J, Q>, J extends Vi
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public RenderService(WorldEngine world, ServiceThreadPool serviceThreadPool) {
|
||||
public RenderService(WorldEngine world, ServiceThreadPool serviceThreadPool, long maxGeometryCapacity) {
|
||||
this.world = world;
|
||||
this.modelService = new ModelBakerySubsystem(world.getMapper());
|
||||
|
||||
long geometryCapacity = getGeometryBufferSize();
|
||||
geometryCapacity = Math.min(maxGeometryCapacity, geometryCapacity);
|
||||
|
||||
this.geometryData = (Q) new BasicSectionGeometryData(1<<20, geometryCapacity);
|
||||
|
||||
|
||||
@@ -648,8 +648,12 @@ public class AsyncNodeManager {
|
||||
public void addTopLevel(long section) {//Only called from render thread
|
||||
if (!this.running) throw new IllegalStateException("Not running");
|
||||
long stamp = this.tlnLock.writeLock();
|
||||
int state = this.tlnAdd.add(section)?1:0;
|
||||
state -= this.tlnRem.remove(section)?1:0;
|
||||
int state = 0;
|
||||
if (!this.tlnRem.remove(section)) {
|
||||
state += this.tlnAdd.add(section)?1:0;
|
||||
} else {
|
||||
state -= 1;
|
||||
}
|
||||
if (state != 0) {
|
||||
if (this.workCounter.getAndAdd(state) == 0) {
|
||||
LockSupport.unpark(this.thread);
|
||||
@@ -661,8 +665,12 @@ public class AsyncNodeManager {
|
||||
public void removeTopLevel(long section) {//Only called from render thread
|
||||
if (!this.running) throw new IllegalStateException("Not running");
|
||||
long stamp = this.tlnLock.writeLock();
|
||||
int state = this.tlnRem.add(section)?1:0;
|
||||
state -= this.tlnAdd.remove(section)?1:0;
|
||||
int state = 0;
|
||||
if (!this.tlnAdd.remove(section)) {
|
||||
state += this.tlnRem.add(section)?1:0;
|
||||
} else {
|
||||
state -= 1;
|
||||
}
|
||||
if (state != 0) {
|
||||
if (this.workCounter.getAndAdd(state) == 0) {
|
||||
LockSupport.unpark(this.thread);
|
||||
|
||||
@@ -162,7 +162,7 @@ public class NodeManager {
|
||||
|
||||
public void removeTopLevelNode(long pos) {
|
||||
if (!this.topLevelNodes.remove(pos)) {
|
||||
throw new IllegalStateException("Position not in top level map");
|
||||
throw new IllegalStateException("Position not in top level map: " + WorldEngine.pprintPos(pos));
|
||||
}
|
||||
int nodeId = this.activeSectionMap.get(pos);
|
||||
if (nodeId == -1) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import me.cortex.voxy.commonImpl.WorldIdentifier;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.ObjectAllocator;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix4f;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -25,6 +26,8 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
|
||||
@Shadow private Frustum frustum;
|
||||
@Shadow private @Nullable ClientWorld world;
|
||||
@Unique private VoxyRenderSystem renderer;
|
||||
@Unique private VoxyRenderSystem overworldRenderer;
|
||||
@Unique private WorldIdentifier overworldIdentifier;
|
||||
|
||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;setupTerrain(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/Frustum;ZZ)V", shift = At.Shift.AFTER))
|
||||
private void injectSetup(ObjectAllocator allocator, RenderTickCounter tickCounter, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, Matrix4f positionMatrix, Matrix4f projectionMatrix, CallbackInfo ci) {
|
||||
@@ -38,6 +41,11 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
|
||||
return this.renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxyRenderSystem getVoxyOverworldRenderSystem() {
|
||||
return this.overworldRenderer;
|
||||
}
|
||||
|
||||
@Inject(method = "reload()V", at = @At("RETURN"), order = 900)//We want to inject before sodium
|
||||
private void reloadVoxyRenderer(CallbackInfo ci) {
|
||||
this.shutdownRenderer();
|
||||
@@ -51,6 +59,9 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
|
||||
if (this.world != world) {
|
||||
this.shutdownRenderer();
|
||||
}
|
||||
if (world!=null&&world.getRegistryKey()==World.OVERWORLD) {
|
||||
this.overworldIdentifier = WorldIdentifier.of(world);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "close", at = @At("HEAD"))
|
||||
@@ -64,6 +75,10 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
|
||||
this.renderer.shutdown();
|
||||
this.renderer = null;
|
||||
}
|
||||
if (this.overworldRenderer != null) {
|
||||
this.overworldRenderer.shutdown();
|
||||
this.overworldRenderer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,5 +103,11 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
|
||||
return;
|
||||
}
|
||||
this.renderer = new VoxyRenderSystem(world, instance.getThreadPool());
|
||||
if (this.world.getRegistryKey()== World.NETHER && this.overworldIdentifier != null) {
|
||||
var engine = this.overworldIdentifier.getOrCreateEngine();
|
||||
if (engine != null) {
|
||||
this.overworldRenderer = new VoxyRenderSystem(engine, instance.getThreadPool(), 1L<<31);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,13 @@ public class MixinDefaultChunkRenderer {
|
||||
if (renderer != null) {
|
||||
renderer.renderOpaque(matrices, camera.x, camera.y, camera.z);
|
||||
}
|
||||
|
||||
var overworldRenderer = ((IGetVoxyRenderSystem) MinecraftClient.getInstance().worldRenderer).getVoxyOverworldRenderSystem();
|
||||
if (overworldRenderer != null) {
|
||||
overworldRenderer.renderOpaque(new ChunkRenderMatrices(matrices.projection(),
|
||||
new Matrix4f(matrices.modelView()).scale(1/8f).scale(1,-1,1)),
|
||||
camera.x*8, (300-camera.y)*8, (camera.z)*8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user