Skip to content

Commit

Permalink
Prevent rendering chunks without neighbors present
Browse files Browse the repository at this point in the history
Also replace EnumFacing.values() calls with constant arrays
  • Loading branch information
embeddedt committed Oct 28, 2023
1 parent 9f1d00e commit fc2423d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.embeddedt.archaicfix.occlusion.util.IntStack;

public class OcclusionHelpers {
public static final EnumFacing[] FACING_VALUES = EnumFacing.values();

public static OcclusionWorker worker;
public static OcclusionRenderer renderer;
public static long chunkUpdateDeadline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ public OcclusionRenderer(RenderGlobal renderGlobal) {
public RenderGlobal getRenderGlobal() {
return rg;
}



/**
* If the update list is not queued for a full resort (e.g. when the player moves or renderers have their positions
* changed), uses binary search to add the renderer in the update queue at the appropriate place. Otherwise,
* the renderer is just added to the end of the list.
* @param wr renderer to add to the list
*/
private void addRendererToUpdateQueue(WorldRenderer wr) {
for(EnumFacing dir : OcclusionHelpers.FACING_VALUES) {
Chunk chunk = rg.theWorld.getChunkFromBlockCoords(wr.posX + dir.getFrontOffsetX() * 16, wr.posZ + dir.getFrontOffsetZ() * 16);
if(chunk != null && chunk instanceof EmptyChunk)
return; // do not allow rendering chunk without neighbors
}
if(!((IWorldRenderer)wr).arch$isInUpdateList()) {
((IWorldRenderer)wr).arch$setInUpdateList(true);
worldRenderersToUpdateList.add(wr);
Expand Down Expand Up @@ -291,7 +297,7 @@ public void updateRendererNeighbors() {
VisGraph oSides = isChunkEmpty(o) ? OcclusionWorker.DUMMY : ((ICulledChunk)o).getVisibility()[rend.posY >> 4];
ci.visGraph = oSides;
ci.vis = oSides.getVisibilityArray();
for(EnumFacing dir : EnumFacing.values()) {
for(EnumFacing dir : OcclusionHelpers.FACING_VALUES) {
WorldRenderer neighbor = getRenderer(
rend.posX + dir.getFrontOffsetX() * 16,
rend.posY + dir.getFrontOffsetY() * 16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private static StepDirection[][] generateAllowedSteps() {
public boolean isFrustumCheckPending;

public CullInfo() {
this.neighbors = new CullInfo[EnumFacing.values().length];
this.neighbors = new CullInfo[OcclusionHelpers.FACING_VALUES.length];
this.visGraph = DUMMY;
this.vis = visGraph.getVisibilityArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class SetVisibility {

private static final int COUNT_FACES = EnumFacing.values().length;
private static final int COUNT_FACES = OcclusionHelpers.FACING_VALUES.length;

public static long setManyVisible(long bitSet, Set<EnumFacing> faces) {
Iterator<EnumFacing> iterator = faces.iterator();
Expand Down Expand Up @@ -48,7 +48,7 @@ public static String toString(long bitSet) {

StringBuilder stringbuilder = new StringBuilder();
stringbuilder.append(' ');
EnumFacing[] aenumfacing = EnumFacing.values();
EnumFacing[] aenumfacing = OcclusionHelpers.FACING_VALUES;
int i = aenumfacing.length;
int j;
EnumFacing enumfacing;
Expand All @@ -59,13 +59,13 @@ public static String toString(long bitSet) {
}

stringbuilder.append('\n');
aenumfacing = EnumFacing.values();
aenumfacing = OcclusionHelpers.FACING_VALUES;
i = aenumfacing.length;

for (j = 0; j < i; ++j) {
enumfacing = aenumfacing[j];
stringbuilder.append(enumFacingToStringFixed(enumfacing).toUpperCase().charAt(0));
EnumFacing[] aenumfacing1 = EnumFacing.values();
EnumFacing[] aenumfacing1 = OcclusionHelpers.FACING_VALUES;
int k = aenumfacing1.length;

for (int l = 0; l < k; ++l) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private EnumSet computeVisibleFacingsFrom(int index, IntStack linkedlist) {
BitSet blocks = this.visibleBlocks;
blocks.set(index, true);

EnumFacing[] facings = EnumFacing.values();
EnumFacing[] facings = OcclusionHelpers.FACING_VALUES;
int k = facings.length;
while (!linkedlist.isEmpty()) {
int j = linkedlist.poll();
Expand Down

0 comments on commit fc2423d

Please sign in to comment.