aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/makamys/lodmod/ducks/IWorldRenderer.java1
-rw-r--r--src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java17
-rw-r--r--src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java27
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java45
4 files changed, 51 insertions, 39 deletions
diff --git a/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java b/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java
index 83857d6..56cfb7b 100644
--- a/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java
+++ b/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java
@@ -9,4 +9,5 @@ import net.minecraft.client.renderer.WorldRenderer;
public interface IWorldRenderer {
public List<ChunkMesh> getChunkMeshes();
+ public void myTick();
}
diff --git a/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java b/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java
index 0981974..196e809 100644
--- a/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java
+++ b/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java
@@ -1,6 +1,7 @@
package makamys.lodmod.mixin;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -14,6 +15,9 @@ import net.minecraft.client.renderer.WorldRenderer;
@Mixin(RenderGlobal.class)
abstract class MixinRenderGlobal {
+ @Shadow
+ private WorldRenderer[] sortedWorldRenderers;
+
@Redirect(method = "renderSortedRenderers", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderAllRenderLists(ID)V"))
private void redirectRenderAllRenderLists(RenderGlobal thiz, int p1, double p2) {
if(!LODMod.isActive() || (LODMod.isActive() && LODMod.renderer.renderWorld)) {
@@ -21,21 +25,10 @@ abstract class MixinRenderGlobal {
}
}
- @Redirect(method = "renderSortedRenderers", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/WorldRenderer;getGLCallListForPass(I)I"))
- public int redirectCallList(WorldRenderer thiz, int arg) {
- int numba = thiz.getGLCallListForPass(arg);
- if(LODMod.isActive()) {
- if(numba != -1) {
- LODMod.renderer.onWorldRendererRender(thiz);
- }
- }
- return numba;
- }
-
@Inject(method = "renderSortedRenderers", at = @At(value = "HEAD"))
public void preRenderSortedRenderers(int startRenderer, int numRenderers, int renderPass, double partialTickTime, CallbackInfoReturnable cir) {
if(LODMod.isActive()) {
- LODMod.renderer.preRenderSortedRenderers(renderPass, partialTickTime);
+ LODMod.renderer.preRenderSortedRenderers(renderPass, partialTickTime, sortedWorldRenderers);
}
}
}
diff --git a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
index a3a0e60..3dc2187 100644
--- a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
+++ b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
@@ -45,6 +45,11 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
@Shadow
private int glRenderList;
+ boolean lastDrawn;
+
+ @Shadow
+ public boolean needsUpdate;
+
public List<ChunkMesh> chunkMeshes = new ArrayList<>();
@Redirect(method = "setPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/Render;renderAABB(Lnet/minecraft/util/AxisAlignedBB;)V"))
@@ -66,15 +71,21 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
@Inject(method = "updateRenderer", at = @At(value = "HEAD"))
private void preUpdateRenderer(CallbackInfo ci) {
if(LODMod.isActive()) {
- chunkMeshes.clear();
+ if(needsUpdate) {
+ chunkMeshes.clear();
+ } else {
+ chunkMeshes = null;
+ }
}
}
@Inject(method = "updateRenderer", at = @At(value = "TAIL"))
private void postUpdateRenderer(CallbackInfo ci) {
if(LODMod.isActive()) {
- LODMod.renderer.onWorldRendererPost(WorldRenderer.class.cast(this));
- chunkMeshes.clear();
+ if(chunkMeshes != null) {
+ LODMod.renderer.onWorldRendererPost(WorldRenderer.class.cast(this));
+ chunkMeshes.clear();
+ }
}
}
@@ -124,7 +135,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
@Inject(method = "setDontDraw", at = @At(value = "HEAD"))
private void preSetDontDraw(CallbackInfo ci) {
if(LODMod.isActive()) {
- LODMod.renderer.onDontDraw(WorldRenderer.class.cast(this));
+ LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), false);
}
}
@@ -132,4 +143,12 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
public List<ChunkMesh> getChunkMeshes() {
return chunkMeshes;
}
+
+ public void myTick() {
+ boolean drawn = isInFrustum && (!skipRenderPass[0] || !skipRenderPass[1]);
+ if(drawn != lastDrawn) {
+ LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), drawn);
+ }
+ lastDrawn = drawn;
+ }
}
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index a821d73..28dd175 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -91,12 +91,18 @@ public class LODRenderer {
hasInited = init();
}
- public void preRenderSortedRenderers(int renderPass, double alpha) {
+ public void preRenderSortedRenderers(int renderPass, double alpha, WorldRenderer[] sortedWorldRenderers) {
if(renderPass != 0) return;
Minecraft.getMinecraft().entityRenderer.enableLightmap((double)alpha);
if(hasInited) {
+ for(WorldRenderer wr : sortedWorldRenderers) {
+ if(wr != null) {
+ ((IWorldRenderer)wr).myTick();
+ }
+ }
+
mainLoop();
handleKeyboard();
gcInterval = 10 * 1000;
@@ -416,35 +422,28 @@ public class LODRenderer {
ChunkMesh.usedRAM = 0;
}
- public void onWorldRendererPost(WorldRenderer wr) {
- LODChunk lodChunk = getLODChunk(Math.floorDiv(wr.posX, 16), Math.floorDiv(wr.posZ, 16));
- lodChunk.putChunkMeshes(Math.floorDiv(wr.posY, 16), ((IWorldRenderer)wr).getChunkMeshes());
- }
-
- public void onWorldRendererRender(WorldRenderer wr) {
+ public void onWorldRendererChanged(WorldRenderer wr, boolean visible) {
int x = Math.floorDiv(wr.posX, 16);
int y = Math.floorDiv(wr.posY, 16);
int z = Math.floorDiv(wr.posZ, 16);
-
LODChunk lodChunk = getLODChunk(x, z);
- setMeshVisible(lodChunk.chunkMeshes[y * 2 + 0], false);
- setMeshVisible(lodChunk.chunkMeshes[y * 2 + 1], false);
- setMeshVisible(lodChunk.simpleMeshes[0], false);
- setMeshVisible(lodChunk.simpleMeshes[1], false);
+ if(visible) {
+ setMeshVisible(lodChunk.chunkMeshes[y * 2 + 0], false);
+ setMeshVisible(lodChunk.chunkMeshes[y * 2 + 1], false);
+ setMeshVisible(lodChunk.simpleMeshes[0], false);
+ setMeshVisible(lodChunk.simpleMeshes[1], false);
+ } else {
+ setMeshVisible(lodChunk.chunkMeshes[y * 2 + 0], true);
+ setMeshVisible(lodChunk.chunkMeshes[y * 2 + 1], true);
+ }
}
- public void onDontDraw(WorldRenderer wr) {
- int chunkX = Math.floorDiv(wr.posX, 16);
- int chunkY = Math.floorDiv(wr.posY, 16);
- int chunkZ = Math.floorDiv(wr.posZ, 16);
-
- Entity player = (Entity)Minecraft.getMinecraft().getIntegratedServer().getConfigurationManager().playerEntityList.get(0);
- LODChunk lodChunk = getLODChunk(chunkX, chunkZ);
-
- int y = Math.floorDiv(wr.posY, 16);
- setMeshVisible(lodChunk.chunkMeshes[y * 2 + 0], true);
- setMeshVisible(lodChunk.chunkMeshes[y * 2 + 1], true);
+ public void onWorldRendererPost(WorldRenderer wr) {
+ if(Minecraft.getMinecraft().theWorld.getChunkFromChunkCoords(Math.floorDiv(wr.posX, 16), Math.floorDiv(wr.posZ, 16)).isChunkLoaded) {
+ LODChunk lodChunk = getLODChunk(Math.floorDiv(wr.posX, 16), Math.floorDiv(wr.posZ, 16));
+ lodChunk.putChunkMeshes(Math.floorDiv(wr.posY, 16), ((IWorldRenderer)wr).getChunkMeshes());
+ }
}
private double getLastSortDistanceSq(Entity player) {