Pre-bake chunk light occlusion and limit dynamic lighting to 3×3 chunks.
Store per-tile occlusion on editor save for fast raycasts; only run torch/entity lighting in the nine chunks around the player while distant chunks keep baked torch light and ambient darkness.
@@ -1,10 +1,11 @@
1
1
import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BOTTOM_PX, ENTITY_STACK_SPREAD_DIAMETER_PX } from "/shared/protocol/constants.js";
2
2
import { dynamicLightAtTile, lightIntensity } from "/shared/lighting/raycast.js";
3
3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4
import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";
4
5
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
5
6
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
6
7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";
7
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";
8
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
8
9
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
9
10
import { bakeChunkAtlases } from "./chunkBake.js";
10
11
import
@@ -536,6 +537,10 @@ export class WorldView
536
537
if (normalizeDimensionId(this.dimensionId) !== snapDim)
537
538
{ return; }
538
539
const key = `${snapshot.chunkX},${snapshot.chunkY}`;
540
if (!Array.isArray(snapshot.occlusion) || snapshot.occlusion.length < CHUNK_SIZE * CHUNK_SIZE)
541
{
542
snapshot.occlusion = bakeChunkOcclusion(snapshot);
543
}
539
544
this.chunks.set(key, snapshot);
540
545
this.#scheduleChunkRebuild(snapshot);
541
546
this.#redrawPreview();
@@ -3011,6 +3016,34 @@ export class WorldView
3011
3016
this.scene._sortDirty = true;
3012
3017
}
3013
3018
3019
/** Player chunk for dynamic lighting; null in editor / before spawn → no 3×3 limit. */
3020
#activeLightingCenterChunk ()
3021
{
3022
const local = this.entities.get(this.localEntityId);
3023
if (!local)
3024
{ return null; }
3025
return {
3026
chunkX: Math.floor(local.tileX / CHUNK_SIZE),
3027
chunkY: Math.floor(local.tileY / CHUNK_SIZE)
3028
};
3029
}
3030
3031
#isActiveLightingChunk (chunkX, chunkY)
3032
{
3033
const center = this.#activeLightingCenterChunk();
3034
if (!center)
3035
{ return true; }
3036
return Math.abs(chunkX - center.chunkX) <= 1 && Math.abs(chunkY - center.chunkY) <= 1;
3037
}
3038
3039
#isActiveLightingTile (tileX, tileY)
3040
{
3041
return this.#isActiveLightingChunk(
3042
Math.floor(tileX / CHUNK_SIZE),
3043
Math.floor(tileY / CHUNK_SIZE)
3044
);
3045
}
3046
3014
3047
#updateShade ()
3015
3048
{
3016
3049
const ambientDark = this.#ambientDarkness();
@@ -3057,7 +3090,8 @@ export class WorldView
3057
3090
{
3058
3091
if (objects._inViewport === false)
3059
3092
{ continue; }
3060
const intensity = this.#tileLightIntensity(objects, activeLights, lightOcclusion);
3093
const lights = this.#isActiveLightingTile(objects.tileX, objects.tileY) ? activeLights : [];
3094
const intensity = this.#tileLightIntensity(objects, lights, lightOcclusion);
3061
3095
objects.shadeAlpha = ambientDark * (1 - intensity);
3062
3096
}
3063
3097
@@ -3065,7 +3099,8 @@ export class WorldView
3065
3099
{
3066
3100
if (baked._inViewport === false)
3067
3101
{ continue; }
3068
this.#writeChunkLightmap(baked, activeLights, lightOcclusion);
3102
const lights = this.#isActiveLightingChunk(baked.chunkX, baked.chunkY) ? activeLights : [];
3103
this.#writeChunkLightmap(baked, lights, lightOcclusion);
3069
3104
if (baked.groundObject?.renderer?.shaderUniforms)
3070
3105
{ baked.groundObject.renderer.shaderUniforms.u_ambientDark = ambientDark; }
3071
3106
for (const object of baked.blockObjects ?? [])
@@ -3142,6 +3177,8 @@ export class WorldView
3142
3177
if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
3143
3178
{ return false; }
3144
3179
const index = localY * CHUNK_SIZE + localX;
3180
if (Array.isArray(snapshot.occlusion) && snapshot.occlusion.length > index)
3181
{ return (snapshot.occlusion[index] | 0) >= LightOcclusion.solid; }
3145
3182
const ground = normalizeGround(snapshot.grounds?.[index]);
3146
3183
if (!isGroundPassable(ground.typeId))
3147
3184
{ return true; }
@@ -1,10 +1,11 @@1
import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BOTTOM_PX, ENTITY_STACK_SPREAD_DIAMETER_PX } from "/shared/protocol/constants.js";1
import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BOTTOM_PX, ENTITY_STACK_SPREAD_DIAMETER_PX } from "/shared/protocol/constants.js";2
import { dynamicLightAtTile, lightIntensity } from "/shared/lighting/raycast.js";2
import { dynamicLightAtTile, lightIntensity } from "/shared/lighting/raycast.js";3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";4
import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";4
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";5
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";5
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";6
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";6
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";7
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";8
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";8
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";9
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";9
import { bakeChunkAtlases } from "./chunkBake.js";10
import { bakeChunkAtlases } from "./chunkBake.js";10
import11
import@@ -536,6 +537,10 @@ export class WorldView536
if (normalizeDimensionId(this.dimensionId) !== snapDim)537
if (normalizeDimensionId(this.dimensionId) !== snapDim)537
{ return; }538
{ return; }538
const key = `${snapshot.chunkX},${snapshot.chunkY}`;539
const key = `${snapshot.chunkX},${snapshot.chunkY}`;540
if (!Array.isArray(snapshot.occlusion) || snapshot.occlusion.length < CHUNK_SIZE * CHUNK_SIZE)541
{542
snapshot.occlusion = bakeChunkOcclusion(snapshot);543
}539
this.chunks.set(key, snapshot);544
this.chunks.set(key, snapshot);540
this.#scheduleChunkRebuild(snapshot);545
this.#scheduleChunkRebuild(snapshot);541
this.#redrawPreview();546
this.#redrawPreview();@@ -3011,6 +3016,34 @@ export class WorldView3011
this.scene._sortDirty = true;3016
this.scene._sortDirty = true;3012
}3017
}3013
3018
3019
/** Player chunk for dynamic lighting; null in editor / before spawn → no 3×3 limit. */3020
#activeLightingCenterChunk ()3021
{3022
const local = this.entities.get(this.localEntityId);3023
if (!local)3024
{ return null; }3025
return {3026
chunkX: Math.floor(local.tileX / CHUNK_SIZE),3027
chunkY: Math.floor(local.tileY / CHUNK_SIZE)3028
};3029
}3030
3031
#isActiveLightingChunk (chunkX, chunkY)3032
{3033
const center = this.#activeLightingCenterChunk();3034
if (!center)3035
{ return true; }3036
return Math.abs(chunkX - center.chunkX) <= 1 && Math.abs(chunkY - center.chunkY) <= 1;3037
}3038
3039
#isActiveLightingTile (tileX, tileY)3040
{3041
return this.#isActiveLightingChunk(3042
Math.floor(tileX / CHUNK_SIZE),3043
Math.floor(tileY / CHUNK_SIZE)3044
);3045
}3046
3014
#updateShade ()3047
#updateShade ()3015
{3048
{3016
const ambientDark = this.#ambientDarkness();3049
const ambientDark = this.#ambientDarkness();@@ -3057,7 +3090,8 @@ export class WorldView3057
{3090
{3058
if (objects._inViewport === false)3091
if (objects._inViewport === false)3059
{ continue; }3092
{ continue; }3060
const intensity = this.#tileLightIntensity(objects, activeLights, lightOcclusion);3093
const lights = this.#isActiveLightingTile(objects.tileX, objects.tileY) ? activeLights : [];3094
const intensity = this.#tileLightIntensity(objects, lights, lightOcclusion);3061
objects.shadeAlpha = ambientDark * (1 - intensity);3095
objects.shadeAlpha = ambientDark * (1 - intensity);3062
}3096
}3063
3097
@@ -3065,7 +3099,8 @@ export class WorldView3065
{3099
{3066
if (baked._inViewport === false)3100
if (baked._inViewport === false)3067
{ continue; }3101
{ continue; }3068
this.#writeChunkLightmap(baked, activeLights, lightOcclusion);3102
const lights = this.#isActiveLightingChunk(baked.chunkX, baked.chunkY) ? activeLights : [];3103
this.#writeChunkLightmap(baked, lights, lightOcclusion);3069
if (baked.groundObject?.renderer?.shaderUniforms)3104
if (baked.groundObject?.renderer?.shaderUniforms)3070
{ baked.groundObject.renderer.shaderUniforms.u_ambientDark = ambientDark; }3105
{ baked.groundObject.renderer.shaderUniforms.u_ambientDark = ambientDark; }3071
for (const object of baked.blockObjects ?? [])3106
for (const object of baked.blockObjects ?? [])@@ -3142,6 +3177,8 @@ export class WorldView3142
if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)3177
if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)3143
{ return false; }3178
{ return false; }3144
const index = localY * CHUNK_SIZE + localX;3179
const index = localY * CHUNK_SIZE + localX;3180
if (Array.isArray(snapshot.occlusion) && snapshot.occlusion.length > index)3181
{ return (snapshot.occlusion[index] | 0) >= LightOcclusion.solid; }3145
const ground = normalizeGround(snapshot.grounds?.[index]);3182
const ground = normalizeGround(snapshot.grounds?.[index]);3146
if (!isGroundPassable(ground.typeId))3183
if (!isGroundPassable(ground.typeId))3147
{ return true; }3184
{ return true; }@@ -1821,6 +1821,7 @@ export class WorkerWorld
1821
1821
grounds: data.grounds,
1822
1822
blocks: data.blocks,
1823
1823
light: data.light,
1824
occlusion: data.occlusion,
1824
1825
entities: [],
1825
1826
groundItems: []
1826
1827
};
@@ -1844,6 +1845,7 @@ export class WorkerWorld
1844
1845
grounds: data.grounds,
1845
1846
blocks: data.blocks,
1846
1847
light: data.light,
1848
occlusion: data.occlusion,
1847
1849
entities,
1848
1850
groundItems: groundItemsInChunk(this, chunkX, chunkY)
1849
1851
};
@@ -1821,6 +1821,7 @@ export class WorkerWorld1821
grounds: data.grounds,1821
grounds: data.grounds,1822
blocks: data.blocks,1822
blocks: data.blocks,1823
light: data.light,1823
light: data.light,1824
occlusion: data.occlusion,1824
entities: [],1825
entities: [],1825
groundItems: []1826
groundItems: []1826
};1827
};@@ -1844,6 +1845,7 @@ export class WorkerWorld1844
grounds: data.grounds,1845
grounds: data.grounds,1845
blocks: data.blocks,1846
blocks: data.blocks,1846
light: data.light,1847
light: data.light,1848
occlusion: data.occlusion,1847
entities,1849
entities,1848
groundItems: groundItemsInChunk(this, chunkX, chunkY)1850
groundItems: groundItemsInChunk(this, chunkX, chunkY)1849
};1851
};@@ -1,16 +1,17 @@
1
1
import { CHUNK_SIZE, DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
2
2
import {
3
GroundType,
4
3
BlockType,
4
GroundType,
5
5
isBlockPassable,
6
blockBlocksRangedAttacks,
7
6
blockLightOcclusionForBlock,
8
7
LightOcclusion,
9
8
isGroundPassable,
9
blockBlocksRangedAttacks,
10
10
blockLightRange,
11
11
normalizeGround,
12
12
normalizeBlock
13
13
} from "../../../shared/definitions/tiles.js";
14
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";
14
15
import {
15
16
flowerBlockState,
16
17
flowerColorIdFromBlockState,
@@ -41,19 +42,22 @@ export function cloneChunkData (data)
41
42
grounds: data.grounds.map((ground) => normalizeGround(ground)),
42
43
blocks: data.blocks.map((block) => structuredClone(normalizeBlock(block))),
43
44
light: data.light.slice(),
45
occlusion: ensureChunkOcclusion(data).slice(),
44
46
spawners: (data.spawners ?? []).map((entry) => normalizeSpawner(entry)).filter(Boolean)
45
47
};
46
48
}
47
49
48
50
export function encodeChunkBlob (data)
49
51
{
50
return JSON.stringify({
52
const normalized = {
51
53
open: !!data.open,
52
54
grounds: data.grounds.map((ground) => normalizeGround(ground)),
53
55
blocks: data.blocks.map((block) => normalizeBlock(block)),
54
56
light: data.light,
55
57
spawners: (data.spawners ?? []).map((entry) => normalizeSpawner(entry)).filter(Boolean)
56
});
58
};
59
normalized.occlusion = bakeChunkOcclusion(normalized);
60
return JSON.stringify(normalized);
57
61
}
58
62
59
63
export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.defaultGroundTypeId, chunkX = 0, chunkY = 0)
@@ -67,6 +71,7 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def
67
71
const grounds = Array.isArray(parsed.grounds) ? parsed.grounds.slice(0, tileCount) : fallback.grounds;
68
72
const blocks = Array.isArray(parsed.blocks) ? parsed.blocks.slice(0, tileCount) : fallback.blocks.slice();
69
73
const light = Array.isArray(parsed.light) ? parsed.light.slice(0, tileCount) : fallback.light;
74
const occlusionRaw = Array.isArray(parsed.occlusion) ? parsed.occlusion.slice(0, tileCount) : null;
70
75
71
76
while (grounds.length < tileCount)
72
77
{ grounds.push(normalizeGround(groundTypeId, groundTypeId)); }
@@ -79,7 +84,7 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def
79
84
const originX = (chunkX | 0) * CHUNK_SIZE;
80
85
const originY = (chunkY | 0) * CHUNK_SIZE;
81
86
82
return {
87
const decoded = {
83
88
open: !!parsed.open,
84
89
grounds: grounds.map((ground) => normalizeGround(ground, groundTypeId)),
85
90
blocks: blocks.map((block, index) =>
@@ -100,6 +105,10 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def
100
105
light,
101
106
spawners
102
107
};
108
decoded.occlusion = occlusionRaw?.length === tileCount
109
? occlusionRaw.map((value) => value | 0)
110
: bakeChunkOcclusion(decoded);
111
return decoded;
103
112
}
104
113
105
114
export function normalizeSpawner (value)
@@ -178,12 +187,7 @@ export function isChunkTilePassable (data, localX, localY)
178
187
/** Light occlusion level for a chunk tile (ground impassable → solid). */
179
188
export function chunkTileLightOcclusion (data, localX, localY)
180
189
{
181
const index = tileIndex(localX, localY);
182
const ground = normalizeGround(data.grounds[index]);
183
if (!isGroundPassable(ground.typeId))
184
{ return LightOcclusion.solid; }
185
const block = data.blocks[index];
186
return blockLightOcclusionForBlock(block);
190
return tileLightOcclusionAt(data.grounds, data.blocks, localX, localY);
187
191
}
188
192
189
193
/** True when light rays are not solid-stopped (partial canopy still clears). */
@@ -1,16 +1,17 @@1
import { CHUNK_SIZE, DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";1
import { CHUNK_SIZE, DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";2
import {2
import {3
GroundType,4
BlockType,3
BlockType,4
GroundType,5
isBlockPassable,5
isBlockPassable,6
blockBlocksRangedAttacks,7
blockLightOcclusionForBlock,6
blockLightOcclusionForBlock,8
LightOcclusion,7
LightOcclusion,9
isGroundPassable,8
isGroundPassable,9
blockBlocksRangedAttacks,10
blockLightRange,10
blockLightRange,11
normalizeGround,11
normalizeGround,12
normalizeBlock12
normalizeBlock13
} from "../../../shared/definitions/tiles.js";13
} from "../../../shared/definitions/tiles.js";14
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";14
import {15
import {15
flowerBlockState,16
flowerBlockState,16
flowerColorIdFromBlockState,17
flowerColorIdFromBlockState,@@ -41,19 +42,22 @@ export function cloneChunkData (data)41
grounds: data.grounds.map((ground) => normalizeGround(ground)),42
grounds: data.grounds.map((ground) => normalizeGround(ground)),42
blocks: data.blocks.map((block) => structuredClone(normalizeBlock(block))),43
blocks: data.blocks.map((block) => structuredClone(normalizeBlock(block))),43
light: data.light.slice(),44
light: data.light.slice(),45
occlusion: ensureChunkOcclusion(data).slice(),44
spawners: (data.spawners ?? []).map((entry) => normalizeSpawner(entry)).filter(Boolean)46
spawners: (data.spawners ?? []).map((entry) => normalizeSpawner(entry)).filter(Boolean)45
};47
};46
}48
}47
49
48
export function encodeChunkBlob (data)50
export function encodeChunkBlob (data)49
{51
{50
return JSON.stringify({52
const normalized = {51
open: !!data.open,53
open: !!data.open,52
grounds: data.grounds.map((ground) => normalizeGround(ground)),54
grounds: data.grounds.map((ground) => normalizeGround(ground)),53
blocks: data.blocks.map((block) => normalizeBlock(block)),55
blocks: data.blocks.map((block) => normalizeBlock(block)),54
light: data.light,56
light: data.light,55
spawners: (data.spawners ?? []).map((entry) => normalizeSpawner(entry)).filter(Boolean)57
spawners: (data.spawners ?? []).map((entry) => normalizeSpawner(entry)).filter(Boolean)56
});58
};59
normalized.occlusion = bakeChunkOcclusion(normalized);60
return JSON.stringify(normalized);57
}61
}58
62
59
export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.defaultGroundTypeId, chunkX = 0, chunkY = 0)63
export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.defaultGroundTypeId, chunkX = 0, chunkY = 0)@@ -67,6 +71,7 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def67
const grounds = Array.isArray(parsed.grounds) ? parsed.grounds.slice(0, tileCount) : fallback.grounds;71
const grounds = Array.isArray(parsed.grounds) ? parsed.grounds.slice(0, tileCount) : fallback.grounds;68
const blocks = Array.isArray(parsed.blocks) ? parsed.blocks.slice(0, tileCount) : fallback.blocks.slice();72
const blocks = Array.isArray(parsed.blocks) ? parsed.blocks.slice(0, tileCount) : fallback.blocks.slice();69
const light = Array.isArray(parsed.light) ? parsed.light.slice(0, tileCount) : fallback.light;73
const light = Array.isArray(parsed.light) ? parsed.light.slice(0, tileCount) : fallback.light;74
const occlusionRaw = Array.isArray(parsed.occlusion) ? parsed.occlusion.slice(0, tileCount) : null;70
75
71
while (grounds.length < tileCount)76
while (grounds.length < tileCount)72
{ grounds.push(normalizeGround(groundTypeId, groundTypeId)); }77
{ grounds.push(normalizeGround(groundTypeId, groundTypeId)); }@@ -79,7 +84,7 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def79
const originX = (chunkX | 0) * CHUNK_SIZE;84
const originX = (chunkX | 0) * CHUNK_SIZE;80
const originY = (chunkY | 0) * CHUNK_SIZE;85
const originY = (chunkY | 0) * CHUNK_SIZE;81
86
82
return {87
const decoded = {83
open: !!parsed.open,88
open: !!parsed.open,84
grounds: grounds.map((ground) => normalizeGround(ground, groundTypeId)),89
grounds: grounds.map((ground) => normalizeGround(ground, groundTypeId)),85
blocks: blocks.map((block, index) =>90
blocks: blocks.map((block, index) =>@@ -100,6 +105,10 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def100
light,105
light,101
spawners106
spawners102
};107
};108
decoded.occlusion = occlusionRaw?.length === tileCount109
? occlusionRaw.map((value) => value | 0)110
: bakeChunkOcclusion(decoded);111
return decoded;103
}112
}104
113
105
export function normalizeSpawner (value)114
export function normalizeSpawner (value)@@ -178,12 +187,7 @@ export function isChunkTilePassable (data, localX, localY)178
/** Light occlusion level for a chunk tile (ground impassable → solid). */187
/** Light occlusion level for a chunk tile (ground impassable → solid). */179
export function chunkTileLightOcclusion (data, localX, localY)188
export function chunkTileLightOcclusion (data, localX, localY)180
{189
{181
const index = tileIndex(localX, localY);190
return tileLightOcclusionAt(data.grounds, data.blocks, localX, localY);182
const ground = normalizeGround(data.grounds[index]);183
if (!isGroundPassable(ground.typeId))184
{ return LightOcclusion.solid; }185
const block = data.blocks[index];186
return blockLightOcclusionForBlock(block);187
}191
}188
192
189
/** True when light rays are not solid-stopped (partial canopy still clears). */193
/** True when light rays are not solid-stopped (partial canopy still clears). */@@ -167,3 +167,16 @@ test("tree stumps do not occlude light rays", () =>
167
167
const pastTree = dynamicLightAtTile(2, 0, sources, tree);
168
168
assert.ok(pastStump > pastTree, "stump clears canopy penalty vs standing tree");
169
169
});
170
171
test("encodeChunkBlob stores pre-baked occlusion aligned with chunkTileLightOcclusion", async () =>
172
{
173
const { encodeChunkBlob, decodeChunkBlob, chunkTileLightOcclusion } = await import("../src/world/chunkData.js");
174
const data = createEmptyChunkData();
175
data.open = true;
176
data.blocks[0] = { typeId: BlockType.stoneWall, config: null };
177
const blob = encodeChunkBlob(data);
178
const decoded = decodeChunkBlob(blob);
179
assert.equal(decoded.occlusion.length, CHUNK_SIZE * CHUNK_SIZE);
180
assert.equal(decoded.occlusion[0], chunkTileLightOcclusion(decoded, 0, 0));
181
assert.equal(decoded.occlusion[1], LightOcclusion.clear);
182
});
@@ -167,3 +167,16 @@ test("tree stumps do not occlude light rays", () =>167
const pastTree = dynamicLightAtTile(2, 0, sources, tree);167
const pastTree = dynamicLightAtTile(2, 0, sources, tree);168
assert.ok(pastStump > pastTree, "stump clears canopy penalty vs standing tree");168
assert.ok(pastStump > pastTree, "stump clears canopy penalty vs standing tree");169
});169
});170
171
test("encodeChunkBlob stores pre-baked occlusion aligned with chunkTileLightOcclusion", async () =>172
{173
const { encodeChunkBlob, decodeChunkBlob, chunkTileLightOcclusion } = await import("../src/world/chunkData.js");174
const data = createEmptyChunkData();175
data.open = true;176
data.blocks[0] = { typeId: BlockType.stoneWall, config: null };177
const blob = encodeChunkBlob(data);178
const decoded = decodeChunkBlob(blob);179
assert.equal(decoded.occlusion.length, CHUNK_SIZE * CHUNK_SIZE);180
assert.equal(decoded.occlusion[0], chunkTileLightOcclusion(decoded, 0, 0));181
assert.equal(decoded.occlusion[1], LightOcclusion.clear);182
});