Compare commits
3 Commits
performanc
...
de99d54ad6
| Author | SHA1 | Date | |
|---|---|---|---|
| de99d54ad6 | |||
| 2bcdeecb81 | |||
| 7b2845ee01 |
@@ -92,52 +92,57 @@ public class Level {
|
|||||||
public void WritePixel<T>(int x, int y, int size) {
|
public void WritePixel<T>(int x, int y, int size) {
|
||||||
int halfsize = size/2;
|
int halfsize = size/2;
|
||||||
|
|
||||||
|
int startPtX = x % chunkResX;
|
||||||
|
int startPtY = y % chunkResY;
|
||||||
|
|
||||||
for (int i = -halfsize; i <= halfsize; i++) {
|
for (int i = -halfsize; i <= halfsize; i++) {
|
||||||
for (int j = 0; j < 1; j++) {
|
for (int j = -halfsize; j <= halfsize; j++) {
|
||||||
// for (int j = -halfsize; j <= halfsize; j++) {
|
|
||||||
// calculate in-chunk coordinates
|
// calculate in-chunk coordinates
|
||||||
int inChunkX = x % chunkResX;
|
int iteratorX = i;
|
||||||
int inChunkY = y % chunkResY;
|
int iteratorY = j;
|
||||||
int brushX = i;
|
int ptX = startPtX;
|
||||||
int brushY = j;
|
int ptY = startPtY;
|
||||||
|
|
||||||
// calculate chunk to write to
|
// calculate chunk to write to
|
||||||
int chunkX = x/chunkResX;
|
int chunkX = x/chunkResX;
|
||||||
if (inChunkX + i < 0) {
|
|
||||||
chunkX--;
|
|
||||||
// 320 -22
|
|
||||||
brushX = chunkResX + inChunkX + i;
|
|
||||||
inChunkX = chunkResX - inChunkX;
|
|
||||||
} else if (inChunkX + i >= chunkResX) {
|
|
||||||
chunkX++;
|
|
||||||
inChunkX = 0;
|
|
||||||
brushX = i % chunkResX;
|
|
||||||
}
|
|
||||||
inChunkX += brushX;
|
|
||||||
|
|
||||||
if (chunkX < 0 || chunkX >= chunksPerX) {
|
// left of chunk
|
||||||
GD.PrintErr($"Trying to write out of bounds: {x}:{y}");
|
if (startPtX + iteratorX < 0) {
|
||||||
return;
|
chunkX--;
|
||||||
|
iteratorX = chunkResX + startPtX + iteratorX;
|
||||||
|
ptX = startPtX + iteratorX;
|
||||||
|
|
||||||
|
// right of chunk
|
||||||
|
} else if (startPtX + iteratorX >= chunkResX) {
|
||||||
|
chunkX++;
|
||||||
|
ptX = startPtX + iteratorX - chunkResX;
|
||||||
|
} else {
|
||||||
|
ptX = startPtX + iteratorX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int chunkY = y/chunkResY;
|
int chunkY = y/chunkResY;
|
||||||
if (inChunkY + j < 0) {
|
|
||||||
|
// above chunk
|
||||||
|
if (startPtY + iteratorY < 0) {
|
||||||
chunkY--;
|
chunkY--;
|
||||||
brushY = chunkResY - (inChunkY + j);
|
ptY = chunkResY + (startPtY + iteratorY);
|
||||||
inChunkY = chunkResY - inChunkY;
|
|
||||||
} else if (inChunkY + j >= chunkResY) {
|
// left of chunk
|
||||||
|
} else if (startPtY + iteratorY >= chunkResY) {
|
||||||
chunkY++;
|
chunkY++;
|
||||||
inChunkY = 0;
|
ptY = iteratorY % chunkResY;
|
||||||
brushY = j % chunkResY;
|
} else {
|
||||||
}
|
ptY = startPtY + iteratorY;
|
||||||
inChunkY += brushY;
|
|
||||||
|
|
||||||
if (chunkY < 0 || chunkY >= chunksPerY) {
|
|
||||||
GD.PrintErr($"Trying to write out of bounds: {x}:{y}");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chunks[chunkX, chunkY].WritePixel<T>(inChunkX, inChunkY);
|
// ignore everything outside
|
||||||
|
if (chunkX < 0) continue;
|
||||||
|
if (chunkX > chunksPerX) continue;
|
||||||
|
if (chunkY < 0) continue;
|
||||||
|
if (chunkY > chunksPerY) continue;
|
||||||
|
|
||||||
|
chunks[chunkX, chunkY].WritePixel<T>(ptX, ptY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user