diff --git a/src/main/java/codechicken/nei/MobSpawnMarkedFace.java b/src/main/java/codechicken/nei/MobSpawnMarkedFace.java index 0ee2316f..e611c9da 100644 --- a/src/main/java/codechicken/nei/MobSpawnMarkedFace.java +++ b/src/main/java/codechicken/nei/MobSpawnMarkedFace.java @@ -50,7 +50,10 @@ public final class MobSpawnMarkedFace { addVertex(1, 0); } - /** Add one cell of a 3 x 3 grid over the face. Edge cells are {@code width} wide, and the middle cell fills the rest. */ + /** + * Add one cell of a 3 x 3 grid over the face. Edge cells are {@code width} wide, and the middle cell fills the + * rest. + */ public void addCell(int offsetX, int offsetZ, double width) { final double west = computeCellStart(offsetX, width); final double east = 1 - computeCellStart(-offsetX, width); diff --git a/src/main/java/codechicken/nei/MobSpawnOverlayStyle.java b/src/main/java/codechicken/nei/MobSpawnOverlayStyle.java index 21ddc5a0..beed99c4 100644 --- a/src/main/java/codechicken/nei/MobSpawnOverlayStyle.java +++ b/src/main/java/codechicken/nei/MobSpawnOverlayStyle.java @@ -23,7 +23,9 @@ public enum MobSpawnOverlayStyle { } }, - /** A light tint, with a stronger band along the outline of each area of one spawn mode, like a connected texture. */ + /** + * A light tint, with a stronger band along the outline of each area of one spawn mode, like a connected texture. + */ CONNECTED(GL11.GL_QUADS) { @Override diff --git a/src/main/java/codechicken/nei/MobSpawnScan.java b/src/main/java/codechicken/nei/MobSpawnScan.java index dc61115a..07c402aa 100644 --- a/src/main/java/codechicken/nei/MobSpawnScan.java +++ b/src/main/java/codechicken/nei/MobSpawnScan.java @@ -38,6 +38,7 @@ public final class MobSpawnScan { private int nextMinY; private int nextMinZ; private int nextColumn; + private int passCount; private boolean hasModes; private long scannedTick; // world of the front buffer @@ -83,6 +84,11 @@ public final class MobSpawnScan { } } + /** Changes each time the front buffer changes. */ + public int getPassCount() { + return passCount; + } + public int getSpan() { return span; } @@ -174,5 +180,6 @@ public final class MobSpawnScan { minX = nextMinX; minY = nextMinY; minZ = nextMinZ; + passCount++; } } diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 262c8993..36bbd54c 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -443,8 +443,9 @@ public class NEIClientConfig { tag.getTag("world.overlays.lock").getBooleanValue(true); API.addOption(new OptionToggleButton("world.overlays.lock", true)); - tag.getTag("world.overlays.mobSpawnStyle").setComment( - "Mark on each block of the mob spawn overlay: x, connected, square, gtnh_logo or pufferfish") + tag.getTag("world.overlays.mobSpawnStyle") + .setComment( + "Mark on each block of the mob spawn overlay: x, connected, square, gtnh_logo or pufferfish") .getValue(MobSpawnOverlayStyle.DEFAULT.formatName()); API.addOption(new OptionCycled("world.overlays.mobSpawnStyle", MobSpawnOverlayStyle.values().length, true) { diff --git a/src/main/java/codechicken/nei/WorldOverlayRenderer.java b/src/main/java/codechicken/nei/WorldOverlayRenderer.java index 0d4c2e97..f39ac1c3 100644 --- a/src/main/java/codechicken/nei/WorldOverlayRenderer.java +++ b/src/main/java/codechicken/nei/WorldOverlayRenderer.java @@ -7,6 +7,7 @@ import java.util.concurrent.Callable; import net.minecraft.block.Block; import net.minecraft.block.BlockSnow; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; import net.minecraft.entity.EnumCreatureType; @@ -33,6 +34,10 @@ public class WorldOverlayRenderer implements IKeyStateTracker { public static int mobOverlay = 0; private static final MobSpawnScan mobSpawnScan = new MobSpawnScan(); private static final MobSpawnMarkedFace markedFace = new MobSpawnMarkedFace(); + // display list of the overlay quads, compiled when the scan or the style changes + private static int mobSpawnList = -1; + private static int mobSpawnListPass; + private static MobSpawnOverlayStyle mobSpawnListStyle; public static void reset() { mobOverlay = 0; @@ -93,18 +98,41 @@ public class WorldOverlayRenderer implements IKeyStateTracker { private static void renderMobSpawnOverlay(Entity entity, int intOffsetX, int intOffsetY, int intOffsetZ) { if (mobOverlay == 0) { mobSpawnScan.clear(); + deleteMobSpawnList(); return; } mobSpawnScan.update(entity, NEIClientConfig.getIntSetting("world.overlays.mobSpawnRadius")); final MobSpawnOverlayStyle style = MobSpawnOverlayStyle .parseStyle(NEIClientConfig.getSetting("world.overlays.mobSpawnStyle").getValue()); + if (!(mobSpawnList >= 0 && mobSpawnListPass == mobSpawnScan.getPassCount() && mobSpawnListStyle == style)) { + compileMobSpawnList(entity.worldObj, style); + } + beginMobSpawnDraw(style); + GL11.glPushMatrix(); + GL11.glTranslated( + mobSpawnScan.getMinX() - intOffsetX, + mobSpawnScan.getMinY() - intOffsetY, + mobSpawnScan.getMinZ() - intOffsetZ); + GL11.glCallList(mobSpawnList); + GL11.glPopMatrix(); + endMobSpawnDraw(style); + } + + /** + * Quad positions are relative to ({@link MobSpawnScan#getMinX}, {@link MobSpawnScan#getMinY}, + * {@link MobSpawnScan#getMinZ}). + */ + private static void compileMobSpawnList(World world, MobSpawnOverlayStyle style) { + if (mobSpawnList < 0) mobSpawnList = GLAllocation.generateDisplayLists(1); + mobSpawnListPass = mobSpawnScan.getPassCount(); + mobSpawnListStyle = style; + + GL11.glNewList(mobSpawnList, GL11.GL_COMPILE); final float alpha = style.computeAlpha(); - final World world = entity.worldObj; final Tessellator tess = Tessellator.instance; tess.startDrawing(style.glMode); - final int span = mobSpawnScan.getSpan(); for (int i = 0; i < span; i++) { for (int j = 0; j < span; j++) { @@ -113,20 +141,27 @@ public class WorldOverlayRenderer implements IKeyStateTracker { for (int k = 0; k < mobSpawnScan.getColumnEnd(column); k++) { if (mobSpawnScan.readSpawnMode(column, k) == 0) continue; - final int x = mobSpawnScan.getMinX() + i; - final int y = mobSpawnScan.getMinY() + k; - final int z = mobSpawnScan.getMinZ() + j; - final double yOffset = getOverlayYOffset(world, x, y, z); - markedFace.moveTo(x - intOffsetX, y - intOffsetY + yOffset, z - intOffsetZ); + final double yOffset = getOverlayYOffset( + world, + mobSpawnScan.getMinX() + i, + mobSpawnScan.getMinY() + k, + mobSpawnScan.getMinZ() + j); + markedFace.moveTo(i, k + yOffset, j); loadNeighbourModes(column, k); markedFace.applyColor(style.colouring, alpha); style.addVertices(markedFace); } } } - tess.draw(); - endMobSpawnDraw(style); + GL11.glEndList(); + } + + private static void deleteMobSpawnList() { + if (mobSpawnList < 0) return; + + GLAllocation.deleteDisplayLists(mobSpawnList); + mobSpawnList = -1; } /** {@link #endMobSpawnDraw} undoes every change here except the texture binding. */