WiP: chunk overdraw fix

This commit is contained in:
2025-04-18 01:11:10 +02:00
parent 882a12862e
commit 7f31c8c3d5
7 changed files with 103 additions and 48 deletions

View File

@@ -67,29 +67,23 @@ public class Chunk {
else RemoveFromChunk(e);
}
public void WritePixel<T>(int x, int y, int size) {
int halfsize = size/2;
public void WritePixel<T>(int x, int y) {
if (x < 0 || x >= sizeX || y < 0 || y >= sizeY) {
GD.PrintErr($"Out of bounds for chunk: {x}:{y}");
return;
}
Type type = typeof(T);
object o = Activator.CreateInstance(type, x, y, this);
for (int i = -halfsize; i <= halfsize; i++) {
for (int j = -halfsize; j <= halfsize; j++) {
int X = Mathf.Clamp(x + i, 0, sizeX-1);
int Y = Mathf.Clamp(y + j, 0, sizeY-1);
object o = Activator.CreateInstance(type, X, Y, this);
// check if not empty:
if (Elements[X,Y].GetType() != typeof(Element)) {
return;
}
// if (Elements[X,Y].GetType() != type) {
Elements[X, Y].Chunk.RemoveFromChunk(Elements[X, Y]);
Elements[X, Y] = o as Element;
Elements[X, Y].Active = true;
// }
}
// check if not empty:
if (Elements[x,y].GetType() != typeof(Element)) {
return;
}
Elements[x, y].Chunk.RemoveFromChunk(Elements[x, y]);
Elements[x, y] = o as Element;
Elements[x, y].Active = true;
}
public int ActiveElementsCount() {