Speed up dynamic light rays without changing falloff.
Skip Bresenham when a tile is outside light range, and walk LOS without allocating a tile array on the hot path.
@@ -62,6 +62,35 @@ test("dynamic lights use the same wall occlusion as baked light", () =>
62
62
assert.ok(dynamicLightAtTile(2, 0, sources, () => true) > 0);
63
63
});
64
64
65
test("dynamic lights skip rays beyond range before occlusion work", () =>
66
{
67
let occlusionCalls = 0;
68
const occlusion = () =>
69
{
70
occlusionCalls += 1;
71
return LightOcclusion.clear;
72
};
73
const sources = [{ tileX: 0, tileY: 0, range: 2, intensity: 1 }];
74
assert.equal(dynamicLightAtTile(5, 0, sources, occlusion), 0);
75
assert.equal(occlusionCalls, 0, "out-of-range tiles must not run LOS");
76
// Two steps away → one intermediate tile, so occlusion is consulted.
77
assert.ok(dynamicLightAtTile(2, 0, sources, occlusion) > 0);
78
assert.ok(occlusionCalls > 0);
79
});
80
81
test("evaluateLightRay matches Bresenham intermediates without allocating the path", () =>
82
{
83
const blocked = new Set(["1,0"]);
84
const occlusion = (x, y) => (blocked.has(`${x},${y}`)
85
? LightOcclusion.solid
86
: LightOcclusion.clear);
87
assert.equal(evaluateLightRay(0, 0, 2, 0, occlusion).reaches, false);
88
assert.equal(evaluateLightRay(0, 0, 3, 0, () => LightOcclusion.clear).reaches, true);
89
assert.equal(evaluateLightRay(0, 0, 3, 0, () => LightOcclusion.clear).extraDistance, 0);
90
const partial = (x, y) => (x === 1 && y === 0 ? LightOcclusion.partial : LightOcclusion.clear);
91
assert.equal(evaluateLightRay(0, 0, 2, 0, partial).extraDistance, 1);
92
});
93
65
94
test("tables and marketplace counters do not occlude light rays", () =>
66
95
{
67
96
const origin = createEmptyChunkData();
@@ -62,6 +62,35 @@ test("dynamic lights use the same wall occlusion as baked light", () =>62
assert.ok(dynamicLightAtTile(2, 0, sources, () => true) > 0);62
assert.ok(dynamicLightAtTile(2, 0, sources, () => true) > 0);63
});63
});64
64
65
test("dynamic lights skip rays beyond range before occlusion work", () =>66
{67
let occlusionCalls = 0;68
const occlusion = () =>69
{70
occlusionCalls += 1;71
return LightOcclusion.clear;72
};73
const sources = [{ tileX: 0, tileY: 0, range: 2, intensity: 1 }];74
assert.equal(dynamicLightAtTile(5, 0, sources, occlusion), 0);75
assert.equal(occlusionCalls, 0, "out-of-range tiles must not run LOS");76
// Two steps away → one intermediate tile, so occlusion is consulted.77
assert.ok(dynamicLightAtTile(2, 0, sources, occlusion) > 0);78
assert.ok(occlusionCalls > 0);79
});80
81
test("evaluateLightRay matches Bresenham intermediates without allocating the path", () =>82
{83
const blocked = new Set(["1,0"]);84
const occlusion = (x, y) => (blocked.has(`${x},${y}`)85
? LightOcclusion.solid86
: LightOcclusion.clear);87
assert.equal(evaluateLightRay(0, 0, 2, 0, occlusion).reaches, false);88
assert.equal(evaluateLightRay(0, 0, 3, 0, () => LightOcclusion.clear).reaches, true);89
assert.equal(evaluateLightRay(0, 0, 3, 0, () => LightOcclusion.clear).extraDistance, 0);90
const partial = (x, y) => (x === 1 && y === 0 ? LightOcclusion.partial : LightOcclusion.clear);91
assert.equal(evaluateLightRay(0, 0, 2, 0, partial).extraDistance, 1);92
});93
65
test("tables and marketplace counters do not occlude light rays", () =>94
test("tables and marketplace counters do not occlude light rays", () =>66
{95
{67
const origin = createEmptyChunkData();96
const origin = createEmptyChunkData();