Half-fix Lorax culler

This commit is contained in:
Jens Pitkänen 2020-04-20 21:22:14 +03:00
parent 91708afb68
commit 3cc381f6e1

View File

@ -23,23 +23,37 @@ public class LoraxCuller : MonoBehaviour {
}
private void Update() {
for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) {
for (int ChunkIndex = 0; ChunkIndex < ChunkKeepAliveTransforms.Count; ChunkIndex++) {
GameObject OldChunk = EnabledChunks[LoraxIndex][ChunkIndex];
if (OldChunk != null) {
OldChunk.SetActive(false);
}
}
}
Hashtable Refs = new Hashtable();
for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) {
Lorax Lorax = Loraces[LoraxIndex];
for (int ChunkIndex = 0; ChunkIndex < ChunkKeepAliveTransforms.Count; ChunkIndex++) {
Vector3 KeepAlivePosition = ChunkKeepAliveTransforms[ChunkIndex].position;
GameObject NewChunk = Lorax.GetChunkAt(KeepAlivePosition.x, KeepAlivePosition.z);
GameObject OldChunk = EnabledChunks[LoraxIndex][ChunkIndex];
NewChunk.SetActive(true);
if (Refs.ContainsKey(NewChunk)) {
Refs[NewChunk] = (int)Refs[NewChunk] + 1;
} else {
Refs[NewChunk] = 1;
}
if (NewChunk != OldChunk && OldChunk != null) {
// No longer pointing to OldChunk, remove ref
if (Refs.ContainsKey(OldChunk)) {
Refs[OldChunk] = (int)Refs[OldChunk] - 1;
} else {
Refs[OldChunk] = -1;
}
}
EnabledChunks[LoraxIndex][ChunkIndex] = NewChunk;
}
}
foreach (GameObject Key in Refs.Keys) {
if ((int)Refs[Key] < 0) {
Key.SetActive(false);
}
}
}
}