mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-22 13:09:45 +00:00
Further improve code prose + remove some unnecessary writes
This commit is contained in:
1 parent
8e5f3c49b1
commit
177b37f63d
3 files changed
+42
-48
No files matched your search
@@ -116,19 +116,14 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
|
||||
*/
|
||||
private static void compileMobOverlayList(MobOverlayStyle style, long worldTicks) {
|
||||
MOB_OVERLAY_LIST.beginCompile(MOB_OVERLAY_SCAN, style, worldTicks);
|
||||
final int minX = MOB_OVERLAY_SCAN.getMinX();
|
||||
final int minZ = MOB_OVERLAY_SCAN.getMinZ();
|
||||
final int span = MOB_OVERLAY_SCAN.getSpan();
|
||||
final int toChunkX = (minX + span - 1) >> MobOverlayScan.CHUNK_SHIFT;
|
||||
final int toChunkZ = (minZ + span - 1) >> MobOverlayScan.CHUNK_SHIFT;
|
||||
for (int chunkX = minX >> MobOverlayScan.CHUNK_SHIFT; chunkX <= toChunkX; chunkX++) {
|
||||
for (int chunkZ = minZ >> MobOverlayScan.CHUNK_SHIFT; chunkZ <= toChunkZ; chunkZ++) {
|
||||
for (int chunkX = MOB_OVERLAY_SCAN.getMinChunkX(); chunkX <= MOB_OVERLAY_SCAN.getMaxChunkX(); chunkX++) {
|
||||
for (int chunkZ = MOB_OVERLAY_SCAN.getMinChunkZ(); chunkZ <= MOB_OVERLAY_SCAN.getMaxChunkZ(); chunkZ++) {
|
||||
if (!MOB_OVERLAY_LIST.beginChunk(MOB_OVERLAY_SCAN, chunkX, chunkZ)) continue;
|
||||
|
||||
MOB_OVERLAY_LIST.endChunk(compileChunkFaces(style, chunkX, chunkZ));
|
||||
}
|
||||
}
|
||||
MOB_OVERLAY_LIST.endCompile();
|
||||
MOB_OVERLAY_LIST.endCompile(MOB_OVERLAY_SCAN);
|
||||
}
|
||||
|
||||
private static boolean compileChunkFaces(MobOverlayStyle style, int chunkX, int chunkZ) {
|
||||
|
||||
@@ -16,15 +16,12 @@ public final class MobOverlayDisplayList {
|
||||
|
||||
private int firstListId = NO_LIST;
|
||||
private int parentListId = NO_LIST;
|
||||
private boolean hasParentList;
|
||||
private int anchorX;
|
||||
private int anchorY;
|
||||
private int anchorZ;
|
||||
private int chunkSpan;
|
||||
private boolean[] isCompiled = new boolean[0];
|
||||
private boolean[] hasFaces = new boolean[0];
|
||||
private int[] compiledChunkX = new int[0];
|
||||
private int[] compiledChunkZ = new int[0];
|
||||
private int[] compiledChunkVersion = new int[0];
|
||||
private int modesVersion;
|
||||
private MobOverlayStyle style;
|
||||
@@ -54,16 +51,6 @@ public final class MobOverlayDisplayList {
|
||||
anchorX = scan.getMinX();
|
||||
anchorY = scan.getMinY();
|
||||
anchorZ = scan.getMinZ();
|
||||
final int fromChunkX = scan.getMinX() >> MobOverlayScan.CHUNK_SHIFT;
|
||||
final int toChunkX = (scan.getMinX() + scan.getSpan() - 1) >> MobOverlayScan.CHUNK_SHIFT;
|
||||
final int fromChunkZ = scan.getMinZ() >> MobOverlayScan.CHUNK_SHIFT;
|
||||
final int toChunkZ = (scan.getMinZ() + scan.getSpan() - 1) >> MobOverlayScan.CHUNK_SHIFT;
|
||||
for (int chunk = 0; chunk < isCompiled.length; chunk++) {
|
||||
final boolean isInBox = compiledChunkX[chunk] >= fromChunkX && compiledChunkX[chunk] <= toChunkX
|
||||
&& compiledChunkZ[chunk] >= fromChunkZ
|
||||
&& compiledChunkZ[chunk] <= toChunkZ;
|
||||
isCompiled[chunk] &= isInBox;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,16 +60,11 @@ public final class MobOverlayDisplayList {
|
||||
* @return false, with no list started, when the chunk column's list is current
|
||||
*/
|
||||
public boolean beginChunk(MobOverlayScan scan, int chunkX, int chunkZ) {
|
||||
final int chunk = Math.floorMod(chunkX, chunkSpan) * chunkSpan + Math.floorMod(chunkZ, chunkSpan);
|
||||
final int chunk = scan.findChunk(chunkX, chunkZ);
|
||||
final int chunkVersion = scan.readChunkVersion(chunkX, chunkZ);
|
||||
final boolean isCurrent = isCompiled[chunk] && compiledChunkX[chunk] == chunkX
|
||||
&& compiledChunkZ[chunk] == chunkZ
|
||||
&& compiledChunkVersion[chunk] == chunkVersion;
|
||||
if (isCurrent) return false;
|
||||
if (isCompiled[chunk] && compiledChunkVersion[chunk] == chunkVersion) return false;
|
||||
|
||||
isCompiled[chunk] = true;
|
||||
compiledChunkX[chunk] = chunkX;
|
||||
compiledChunkZ[chunk] = chunkZ;
|
||||
compiledChunkVersion[chunk] = chunkVersion;
|
||||
compilingChunk = chunk;
|
||||
GL11.glNewList(firstListId + chunk, GL11.GL_COMPILE);
|
||||
@@ -94,27 +76,27 @@ public final class MobOverlayDisplayList {
|
||||
hasFaces[compilingChunk] = hasChunkFaces;
|
||||
}
|
||||
|
||||
public void endCompile() {
|
||||
public void endCompile(MobOverlayScan scan) {
|
||||
GL11.glNewList(parentListId, GL11.GL_COMPILE);
|
||||
for (int chunk = 0; chunk < isCompiled.length; chunk++) {
|
||||
if (!(isCompiled[chunk] && hasFaces[chunk])) continue;
|
||||
for (int chunkX = scan.getMinChunkX(); chunkX <= scan.getMaxChunkX(); chunkX++) {
|
||||
for (int chunkZ = scan.getMinChunkZ(); chunkZ <= scan.getMaxChunkZ(); chunkZ++) {
|
||||
final int chunk = scan.findChunk(chunkX, chunkZ);
|
||||
if (!hasFaces[chunk]) continue;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(
|
||||
(compiledChunkX[chunk] << MobOverlayScan.CHUNK_SHIFT) - anchorX,
|
||||
0,
|
||||
(compiledChunkZ[chunk] << MobOverlayScan.CHUNK_SHIFT) - anchorZ);
|
||||
GL11.glCallList(firstListId + chunk);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(
|
||||
(chunkX << MobOverlayScan.CHUNK_SHIFT) - anchorX,
|
||||
0,
|
||||
(chunkZ << MobOverlayScan.CHUNK_SHIFT) - anchorZ);
|
||||
GL11.glCallList(firstListId + chunk);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
GL11.glEndList();
|
||||
hasParentList = true;
|
||||
}
|
||||
|
||||
/** The model view matrix is relative to block ({@code cameraX}, {@code cameraY}, {@code cameraZ}). */
|
||||
public void draw(int cameraX, int cameraY, int cameraZ) {
|
||||
if (!hasParentList) return;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(anchorX - cameraX, anchorY - cameraY, anchorZ - cameraZ);
|
||||
GL11.glCallList(parentListId);
|
||||
@@ -127,7 +109,6 @@ public final class MobOverlayDisplayList {
|
||||
GLAllocation.deleteDisplayLists(firstListId);
|
||||
firstListId = NO_LIST;
|
||||
parentListId = NO_LIST;
|
||||
hasParentList = false;
|
||||
chunkSpan = 0;
|
||||
Arrays.fill(isCompiled, false);
|
||||
}
|
||||
@@ -140,8 +121,6 @@ public final class MobOverlayDisplayList {
|
||||
parentListId = firstListId + chunkCount;
|
||||
isCompiled = new boolean[chunkCount];
|
||||
hasFaces = new boolean[chunkCount];
|
||||
compiledChunkX = new int[chunkCount];
|
||||
compiledChunkZ = new int[chunkCount];
|
||||
compiledChunkVersion = new int[chunkCount];
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,22 @@ public final class MobOverlayScan {
|
||||
return minZ;
|
||||
}
|
||||
|
||||
public int getMinChunkX() {
|
||||
return minX >> CHUNK_SHIFT;
|
||||
}
|
||||
|
||||
public int getMaxChunkX() {
|
||||
return (minX + span - 1) >> CHUNK_SHIFT;
|
||||
}
|
||||
|
||||
public int getMinChunkZ() {
|
||||
return minZ >> CHUNK_SHIFT;
|
||||
}
|
||||
|
||||
public int getMaxChunkZ() {
|
||||
return (minZ + span - 1) >> CHUNK_SHIFT;
|
||||
}
|
||||
|
||||
/** The version changes when a cell in or beside the chunk column changes, and when the box moves. */
|
||||
public int readChunkVersion(int chunkX, int chunkZ) {
|
||||
return chunkVersions[findChunk(chunkX, chunkZ)];
|
||||
@@ -266,7 +282,7 @@ public final class MobOverlayScan {
|
||||
boolean isChanged = false;
|
||||
for (int x = minX; x < minX + span; x++) {
|
||||
for (int z = minZ; z < minZ + span; z++) {
|
||||
if (dirty[findColumn(x, z)]) isChanged |= scanColumn(x, z);
|
||||
if (dirty[findColumn(x, z)]) isChanged |= rescanColumn(x, z);
|
||||
}
|
||||
}
|
||||
return isChanged;
|
||||
@@ -279,7 +295,7 @@ public final class MobOverlayScan {
|
||||
for (; nextRescanColumn < sliceEnd; nextRescanColumn++) {
|
||||
final int x = minX + nextRescanColumn / span;
|
||||
final int z = minZ + nextRescanColumn % span;
|
||||
isChanged |= scanColumn(x, z);
|
||||
isChanged |= rescanColumn(x, z);
|
||||
}
|
||||
if (nextRescanColumn >= columnCount) nextRescanColumn = 0;
|
||||
return isChanged;
|
||||
@@ -289,7 +305,11 @@ public final class MobOverlayScan {
|
||||
private boolean scanColumn(int x, int z) {
|
||||
column.moveTo(x, z);
|
||||
dirty[findColumn(x, z)] = false;
|
||||
final boolean isChanged = column.scan(minY, minY + height);
|
||||
return column.scan(minY, minY + height);
|
||||
}
|
||||
|
||||
private boolean rescanColumn(int x, int z) {
|
||||
final boolean isChanged = scanColumn(x, z);
|
||||
// the connected outline of a cell depends on the spawn modes of the cells beside the cell
|
||||
if (isChanged) {
|
||||
for (int offsetX = -1; offsetX <= 1; offsetX++) {
|
||||
@@ -335,7 +355,7 @@ public final class MobOverlayScan {
|
||||
chunkVersions[findChunk(chunkX, chunkZ)] = ++chunkVersionCount;
|
||||
}
|
||||
|
||||
private int findChunk(int chunkX, int chunkZ) {
|
||||
public int findChunk(int chunkX, int chunkZ) {
|
||||
return Math.floorMod(chunkX, chunkSpan) * chunkSpan + Math.floorMod(chunkZ, chunkSpan);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user