Rearranged some stuff

This commit is contained in:
2023-08-15 05:13:39 +10:00
parent 33a9c2f0d1
commit 321a73d20b
7 changed files with 42 additions and 30 deletions

View File

@@ -69,7 +69,7 @@ fn shadowCastOctant(node: opaque, x: int, y: int, dirX: int, dirY: int, depth: i
//for each tile, cast its shadow, and see if its already obscured
for (var j: int = 0; abs(j) < depth; j += dirY) {
for (var i: int = 0; abs(i) < depth; i += dirX) {
for (var i: int = 0; abs(i) < abs(j); i += dirX) {
//make sure this tile can actually cast a shadow
var CACHE_ITERATION: int const = (y + j) * MAP_GRID_WIDTH * 2 + (x + i) * 2;
var ITERATION: int const = (y + j) * MAP_GRID_WIDTH * 3 + (x + i) * 3;
@@ -87,6 +87,10 @@ fn shadowCastOctant(node: opaque, x: int, y: int, dirX: int, dirY: int, depth: i
//cast the shadow
var shadow = shadowCastTile(i + x, j + y, dirX, dirY, depth);
if (shadow == null) {
continue;
}
//merge shadows if needed
var index: int = 0;
@@ -127,12 +131,17 @@ fn shadowCastOctant(node: opaque, x: int, y: int, dirX: int, dirY: int, depth: i
if (index > 0 && shadows.length() > index && shadows[index -1][1] > shadow[0]) {
print "second bracket";
overlapping = true;
shadows[index-1][1] = shadow[1]; //extend the prev shadow
print "MARK one";
shadows[index-1][1] = max(shadows[index-1][1], shadow[1]); //extend the prev shadow
print "MARK two";
//see if the newly extended prev overlaps the shadow at "index"
if (shadows[index-1][1] >= shadows[index][0]) {
//merge the two
shadows[index-1][1] = shadows[index][1];
shadows[index-1][1] = max(shadows[index-1][1], shadows[index][1]);
shadows = shadows.remove(index);
}
}
@@ -142,7 +151,7 @@ fn shadowCastOctant(node: opaque, x: int, y: int, dirX: int, dirY: int, depth: i
print "third bracket";
overlapping = true;
//extend the next shadow
shadows[index][1] = shadow[0];
shadows[index][0] = min(shadows[index][0], shadow[0]);
}
if (!overlapping) {
@@ -163,13 +172,22 @@ fn shadowCastTile(x: int, y: int, dirX: int, dirY: int, depth: int) {
var start = abs(shadowCastPoint(x, y, depth));
var end = abs(shadowCastPoint(x + sign(dirX), y + sign(dirY), depth));
return [start, end];
if (checkIsNaN(start) || checkIsNaN(end)) {
return null;
}
if (start < end) {
return [start, end];
}
else {
return [end, start];
}
}
fn shadowCastPoint(x: float, y: float, depth: int) {
// if (y == 0) {
// return sin(tan(INFINITY));
// }
if (y == 0) {
return NAN;
}
return sin(tan(x/y)) * depth;
}