Skip to content

Commit

Permalink
Fix lights popping in and out by checking all cells visibility within…
Browse files Browse the repository at this point in the history
… their range and turning light on if a lit cell is visible
  • Loading branch information
JosiahJack committed Oct 25, 2024
1 parent db0715a commit 47bb006
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion Assets/Scripts/DynamicCulling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,15 +1303,37 @@ public void ToggleLightsVisibility() {
int x,y;
for (int i=0;i<lights.Count;i++) {
if (lights[i] == null) continue;

x = lightCoords[i].x;
y = lightCoords[i].y;
if (gridCells[x,y].visible || !worldCellsOpen[x,y]) {
int range = (int)Mathf.Floor(lights[i].range / 2.56f);
int xMin = x - range;
int xMax = x + range;
int yMin = y - range;
int yMax = y + range;
for (int ix = xMin;ix <= xMax; ix++) {
for (int iy = yMin;iy <= yMax; iy++) {
if (!XYPairInBounds(ix,iy)) continue;

if (gridCells[ix,iy].visible) {
lights[i].enabled = true;
lightsInPVS.Add(lights[i]);
lightsInPVSCoords.Add(lightCoords[i]);
goto LightContinue;
}
}
}

if (gridCells[x,y].visible || !gridCells[x,y].open) {
lights[i].enabled = true;
lightsInPVS.Add(lights[i]);
lightsInPVSCoords.Add(lightCoords[i]);
} else {
lights[i].enabled = false;
}

LightContinue:
continue;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/LevelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void LoadLevel(int levnum, GameObject targetDestination, Vector3 targetPo
public void LoadLevelFromSave (int levnum) {
LoadLevelData(levnum); // Let this function check and load data if it isn't yet.
currentLevel = levnum; // Set current level to be the new level
DisableAllNonOccupiedLevelsExcept(currentLevel);
DisableAllNonOccupiedLevelsExcept(currentLevel); // Unload last level.
levels[currentLevel].SetActive(true); // Load new level
PostLoadLevelSetupSystems();
}
Expand Down

0 comments on commit 47bb006

Please sign in to comment.