Keep gatherable blocks off chunk atlases so nodes disappear on delta.
Resource nodes and pickables render as per-tile sprites; block chunkDelta triggers an immediate rebuild so exhausted ore and picked plants do not linger in baked rows.
@@ -1,5 +1,5 @@
1
1
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
2
import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, normalizeGround, normalizeBlock } from "/shared/definitions/tiles.js";
2
import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, normalizeGround, normalizeBlock, isChunkAtlasBakedBlock } from "/shared/definitions/tiles.js";
3
3
import { bloomImageName, spriteImageName } from "/shared/definitions/tileSprites.js";
4
4
import { resolveSeasonalVisualState, SeasonId } from "/shared/world/season.js";
5
5
import {
@@ -139,7 +139,7 @@ export function collectChunkSpriteExtras ({
139
139
if (!blockName)
140
140
{ continue; }
141
141
const blockMeta = blockCatalogMeta(catalog, blockEntry);
142
if (!isBakeable(images[blockName], blockMeta))
142
if (!isBakeable(images[blockName], blockMeta) || !isChunkAtlasBakedBlock(blockEntry))
143
143
{
144
144
tallBlocks.push({
145
145
tileX,
@@ -154,6 +154,27 @@ export function collectChunkSpriteExtras ({
154
154
return { tallBlocks, animatedGrounds };
155
155
}
156
156
157
/**
158
* Per-tile block sprite when the block is not represented in the chunk atlas row.
159
* @returns {{ sprite: string, bloom: string | null } | null}
160
*/
161
export function tileBlockSpriteEntry (catalog, images, blockEntry, season = SeasonId.summer)
162
{
163
if (!blockEntry)
164
{ return null; }
165
const blockName = blockSpriteName(catalog, blockEntry, season);
166
if (!blockName)
167
{ return null; }
168
const blockMeta = blockCatalogMeta(catalog, blockEntry);
169
const bakeable = isBakeable(images[blockName], blockMeta);
170
if (bakeable && isChunkAtlasBakedBlock(blockEntry))
171
{ return null; }
172
return {
173
sprite: blockName,
174
bloom: blockBloomName(catalog, blockEntry, season)
175
};
176
}
177
157
178
function bakeGroundCanvas ({
158
179
snapshot,
159
180
catalog,
@@ -238,7 +259,7 @@ function bakeBlockRowCanvas ({
238
259
if (!blockName)
239
260
{ continue; }
240
261
const blockMeta = blockCatalogMeta(catalog, blockEntry);
241
if (!isBakeable(images[blockName], blockMeta))
262
if (!isBakeable(images[blockName], blockMeta) || !isChunkAtlasBakedBlock(blockEntry))
242
263
{ continue; }
243
264
blit(ctx, images[blockName], localX * SPRITE_SIZE_PX, 0);
244
265
}
@@ -281,7 +302,7 @@ function bakeBloomCanvas ({
281
302
if (!blockName)
282
303
{ continue; }
283
304
const blockMeta = blockCatalogMeta(catalog, blockEntry);
284
if (!isBakeable(images[blockName], blockMeta))
305
if (!isBakeable(images[blockName], blockMeta) || !isChunkAtlasBakedBlock(blockEntry))
285
306
{ continue; }
286
307
const blockBloom = blockBloomName(catalog, blockEntry, season);
287
308
if (blockBloom)
@@ -1,5 +1,5 @@1
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";1
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";2
import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, normalizeGround, normalizeBlock } from "/shared/definitions/tiles.js";2
import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, normalizeGround, normalizeBlock, isChunkAtlasBakedBlock } from "/shared/definitions/tiles.js";3
import { bloomImageName, spriteImageName } from "/shared/definitions/tileSprites.js";3
import { bloomImageName, spriteImageName } from "/shared/definitions/tileSprites.js";4
import { resolveSeasonalVisualState, SeasonId } from "/shared/world/season.js";4
import { resolveSeasonalVisualState, SeasonId } from "/shared/world/season.js";5
import {5
import {@@ -139,7 +139,7 @@ export function collectChunkSpriteExtras ({139
if (!blockName)139
if (!blockName)140
{ continue; }140
{ continue; }141
const blockMeta = blockCatalogMeta(catalog, blockEntry);141
const blockMeta = blockCatalogMeta(catalog, blockEntry);142
if (!isBakeable(images[blockName], blockMeta))142
if (!isBakeable(images[blockName], blockMeta) || !isChunkAtlasBakedBlock(blockEntry))143
{143
{144
tallBlocks.push({144
tallBlocks.push({145
tileX,145
tileX,@@ -154,6 +154,27 @@ export function collectChunkSpriteExtras ({154
return { tallBlocks, animatedGrounds };154
return { tallBlocks, animatedGrounds };155
}155
}156
156
157
/**158
* Per-tile block sprite when the block is not represented in the chunk atlas row.159
* @returns {{ sprite: string, bloom: string | null } | null}160
*/161
export function tileBlockSpriteEntry (catalog, images, blockEntry, season = SeasonId.summer)162
{163
if (!blockEntry)164
{ return null; }165
const blockName = blockSpriteName(catalog, blockEntry, season);166
if (!blockName)167
{ return null; }168
const blockMeta = blockCatalogMeta(catalog, blockEntry);169
const bakeable = isBakeable(images[blockName], blockMeta);170
if (bakeable && isChunkAtlasBakedBlock(blockEntry))171
{ return null; }172
return {173
sprite: blockName,174
bloom: blockBloomName(catalog, blockEntry, season)175
};176
}177
157
function bakeGroundCanvas ({178
function bakeGroundCanvas ({158
snapshot,179
snapshot,159
catalog,180
catalog,@@ -238,7 +259,7 @@ function bakeBlockRowCanvas ({238
if (!blockName)259
if (!blockName)239
{ continue; }260
{ continue; }240
const blockMeta = blockCatalogMeta(catalog, blockEntry);261
const blockMeta = blockCatalogMeta(catalog, blockEntry);241
if (!isBakeable(images[blockName], blockMeta))262
if (!isBakeable(images[blockName], blockMeta) || !isChunkAtlasBakedBlock(blockEntry))242
{ continue; }263
{ continue; }243
blit(ctx, images[blockName], localX * SPRITE_SIZE_PX, 0);264
blit(ctx, images[blockName], localX * SPRITE_SIZE_PX, 0);244
}265
}@@ -281,7 +302,7 @@ function bakeBloomCanvas ({281
if (!blockName)302
if (!blockName)282
{ continue; }303
{ continue; }283
const blockMeta = blockCatalogMeta(catalog, blockEntry);304
const blockMeta = blockCatalogMeta(catalog, blockEntry);284
if (!isBakeable(images[blockName], blockMeta))305
if (!isBakeable(images[blockName], blockMeta) || !isChunkAtlasBakedBlock(blockEntry))285
{ continue; }306
{ continue; }286
const blockBloom = blockBloomName(catalog, blockEntry, season);307
const blockBloom = blockBloomName(catalog, blockEntry, season);287
if (blockBloom)308
if (blockBloom)@@ -7,7 +7,7 @@ import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from
7
7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";
8
8
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
9
9
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
10
import { bakeChunkAtlases } from "./chunkBake.js";
10
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
11
11
import { createChunkAtlasCache } from "./chunkAtlasCache.js";
12
12
import
13
13
{
@@ -1564,7 +1564,17 @@ export class WorldView
1564
1564
{ snapshot.blocks[index] = block; }
1565
1565
if (light !== undefined)
1566
1566
{ snapshot.light[index] = light; }
1567
const tileX = chunkX * CHUNK_SIZE + localX;
1568
const tileY = chunkY * CHUNK_SIZE + localY;
1569
if (block !== undefined)
1570
{
1571
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: false });
1572
this.#drawTile(tileX, tileY);
1573
return;
1574
}
1567
1575
this.#scheduleChunkRebuild(snapshot);
1576
if (ground !== undefined)
1577
{ this.#drawTile(tileX, tileY); }
1568
1578
}
1569
1579
1570
1580
/**
@@ -2463,17 +2473,13 @@ export class WorldView
2463
2473
2464
2474
#relayoutChunkTiles (snapshot)
2465
2475
{
2466
const baked = this.bakedChunks.get(`${snapshot.chunkX},${snapshot.chunkY}`);
2467
const tall = new Set(
2468
(baked?.tallBlocks ?? []).map((entry) => `${entry.tileX},${entry.tileY}`)
2469
);
2470
2476
for (let localY = 0; localY < CHUNK_SIZE; localY++)
2471
2477
{
2472
2478
for (let localX = 0; localX < CHUNK_SIZE; localX++)
2473
2479
{
2474
2480
const tileX = snapshot.chunkX * CHUNK_SIZE + localX;
2475
2481
const tileY = snapshot.chunkY * CHUNK_SIZE + localY;
2476
this.#drawTile(tileX, tileY, tall.has(`${tileX},${tileY}`));
2482
this.#drawTile(tileX, tileY);
2477
2483
}
2478
2484
}
2479
2485
}
@@ -2965,7 +2971,7 @@ export class WorldView
2965
2971
}
2966
2972
}
2967
2973
2968
#drawTile (tileX, tileY, forceTall = null)
2974
#drawTile (tileX, tileY)
2969
2975
{
2970
2976
const chunkX = Math.floor(tileX / CHUNK_SIZE);
2971
2977
const chunkY = Math.floor(tileY / CHUNK_SIZE);
@@ -3022,18 +3028,22 @@ export class WorldView
3022
3028
objects.waterEdges = null;
3023
3029
}
3024
3030
3025
const tallEntry = (baked?.tallBlocks ?? []).find((entry) => entry.tileX === tileX && entry.tileY === tileY);
3026
const isTall = forceTall === true || !!tallEntry;
3027
if (isTall && tallEntry)
3031
const tileBlock = tileBlockSpriteEntry(
3032
this.catalog,
3033
this.game.images,
3034
snapshot.blocks[index],
3035
this.worldSeason
3036
);
3037
if (tileBlock)
3028
3038
{
3029
3039
const pivot = tilePivot(tileX, tileY, this.tileSize());
3030
objects.block = this.#ensureSprite(objects.block, tallEntry.sprite, SORT_ENTITY);
3040
objects.block = this.#ensureSprite(objects.block, tileBlock.sprite, SORT_ENTITY);
3031
3041
if (objects.block)
3032
3042
{
3033
3043
this.#placePivoted(objects.block, pivot.x, pivot.y, pivot.y, SORT_ENTITY);
3034
3044
this.#syncLitSprite(objects.block, objects.shadeAlpha ?? 0);
3035
3045
}
3036
objects.blockBloom = this.#placeBloomOverlay(objects.blockBloom, tallEntry.bloom, pivot, SORT_ENTITY);
3046
objects.blockBloom = this.#placeBloomOverlay(objects.blockBloom, tileBlock.bloom, pivot, SORT_ENTITY);
3037
3047
}
3038
3048
else
3039
3049
{
@@ -7,7 +7,7 @@ import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";8
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";8
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";9
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";9
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";10
import { bakeChunkAtlases } from "./chunkBake.js";10
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";11
import { createChunkAtlasCache } from "./chunkAtlasCache.js";11
import { createChunkAtlasCache } from "./chunkAtlasCache.js";12
import12
import13
{13
{@@ -1564,7 +1564,17 @@ export class WorldView1564
{ snapshot.blocks[index] = block; }1564
{ snapshot.blocks[index] = block; }1565
if (light !== undefined)1565
if (light !== undefined)1566
{ snapshot.light[index] = light; }1566
{ snapshot.light[index] = light; }1567
const tileX = chunkX * CHUNK_SIZE + localX;1568
const tileY = chunkY * CHUNK_SIZE + localY;1569
if (block !== undefined)1570
{1571
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: false });1572
this.#drawTile(tileX, tileY);1573
return;1574
}1567
this.#scheduleChunkRebuild(snapshot);1575
this.#scheduleChunkRebuild(snapshot);1576
if (ground !== undefined)1577
{ this.#drawTile(tileX, tileY); }1568
}1578
}1569
1579
1570
/**1580
/**@@ -2463,17 +2473,13 @@ export class WorldView2463
2473
2464
#relayoutChunkTiles (snapshot)2474
#relayoutChunkTiles (snapshot)2465
{2475
{2466
const baked = this.bakedChunks.get(`${snapshot.chunkX},${snapshot.chunkY}`);2467
const tall = new Set(2468
(baked?.tallBlocks ?? []).map((entry) => `${entry.tileX},${entry.tileY}`)2469
);2470
for (let localY = 0; localY < CHUNK_SIZE; localY++)2476
for (let localY = 0; localY < CHUNK_SIZE; localY++)2471
{2477
{2472
for (let localX = 0; localX < CHUNK_SIZE; localX++)2478
for (let localX = 0; localX < CHUNK_SIZE; localX++)2473
{2479
{2474
const tileX = snapshot.chunkX * CHUNK_SIZE + localX;2480
const tileX = snapshot.chunkX * CHUNK_SIZE + localX;2475
const tileY = snapshot.chunkY * CHUNK_SIZE + localY;2481
const tileY = snapshot.chunkY * CHUNK_SIZE + localY;2476
this.#drawTile(tileX, tileY, tall.has(`${tileX},${tileY}`));2482
this.#drawTile(tileX, tileY);2477
}2483
}2478
}2484
}2479
}2485
}@@ -2965,7 +2971,7 @@ export class WorldView2965
}2971
}2966
}2972
}2967
2973
2968
#drawTile (tileX, tileY, forceTall = null)2974
#drawTile (tileX, tileY)2969
{2975
{2970
const chunkX = Math.floor(tileX / CHUNK_SIZE);2976
const chunkX = Math.floor(tileX / CHUNK_SIZE);2971
const chunkY = Math.floor(tileY / CHUNK_SIZE);2977
const chunkY = Math.floor(tileY / CHUNK_SIZE);@@ -3022,18 +3028,22 @@ export class WorldView3022
objects.waterEdges = null;3028
objects.waterEdges = null;3023
}3029
}3024
3030
3025
const tallEntry = (baked?.tallBlocks ?? []).find((entry) => entry.tileX === tileX && entry.tileY === tileY);3031
const tileBlock = tileBlockSpriteEntry(3026
const isTall = forceTall === true || !!tallEntry;3032
this.catalog,3027
if (isTall && tallEntry)3033
this.game.images,3034
snapshot.blocks[index],3035
this.worldSeason3036
);3037
if (tileBlock)3028
{3038
{3029
const pivot = tilePivot(tileX, tileY, this.tileSize());3039
const pivot = tilePivot(tileX, tileY, this.tileSize());3030
objects.block = this.#ensureSprite(objects.block, tallEntry.sprite, SORT_ENTITY);3040
objects.block = this.#ensureSprite(objects.block, tileBlock.sprite, SORT_ENTITY);3031
if (objects.block)3041
if (objects.block)3032
{3042
{3033
this.#placePivoted(objects.block, pivot.x, pivot.y, pivot.y, SORT_ENTITY);3043
this.#placePivoted(objects.block, pivot.x, pivot.y, pivot.y, SORT_ENTITY);3034
this.#syncLitSprite(objects.block, objects.shadeAlpha ?? 0);3044
this.#syncLitSprite(objects.block, objects.shadeAlpha ?? 0);3035
}3045
}3036
objects.blockBloom = this.#placeBloomOverlay(objects.blockBloom, tallEntry.bloom, pivot, SORT_ENTITY);3046
objects.blockBloom = this.#placeBloomOverlay(objects.blockBloom, tileBlock.bloom, pivot, SORT_ENTITY);3037
}3047
}3038
else3048
else3039
{3049
{@@ -0,0 +1,36 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { BlockType } from "../../shared/definitions/tiles.js";
4
import { oreBoulderState } from "../../shared/definitions/materialTiers.js";
5
import
6
{
7
isChunkAtlasBakedBlock,
8
isPickablePlantBlock
9
} from "../../shared/definitions/tiles.js";
10
11
test("ore boulders are not chunk-atlas baked", () =>
12
{
13
assert.equal(isChunkAtlasBakedBlock({
14
typeId: BlockType.boulder,
15
state: oreBoulderState("copper")
16
}), false);
17
});
18
19
test("exhausted plain boulders may be chunk-atlas baked", () =>
20
{
21
assert.equal(isChunkAtlasBakedBlock({
22
typeId: BlockType.boulder,
23
state: "boulder"
24
}), true);
25
});
26
27
test("pickable plants are not chunk-atlas baked", () =>
28
{
29
assert.equal(isPickablePlantBlock({ typeId: BlockType.flower, state: "red" }), true);
30
assert.equal(isChunkAtlasBakedBlock({ typeId: BlockType.flower, state: "red" }), false);
31
});
32
33
test("stone walls remain chunk-atlas baked", () =>
34
{
35
assert.equal(isChunkAtlasBakedBlock({ typeId: BlockType.stoneWall }), true);
36
});
@@ -0,0 +1,36 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { BlockType } from "../../shared/definitions/tiles.js";4
import { oreBoulderState } from "../../shared/definitions/materialTiers.js";5
import6
{7
isChunkAtlasBakedBlock,8
isPickablePlantBlock9
} from "../../shared/definitions/tiles.js";10
11
test("ore boulders are not chunk-atlas baked", () =>12
{13
assert.equal(isChunkAtlasBakedBlock({14
typeId: BlockType.boulder,15
state: oreBoulderState("copper")16
}), false);17
});18
19
test("exhausted plain boulders may be chunk-atlas baked", () =>20
{21
assert.equal(isChunkAtlasBakedBlock({22
typeId: BlockType.boulder,23
state: "boulder"24
}), true);25
});26
27
test("pickable plants are not chunk-atlas baked", () =>28
{29
assert.equal(isPickablePlantBlock({ typeId: BlockType.flower, state: "red" }), true);30
assert.equal(isChunkAtlasBakedBlock({ typeId: BlockType.flower, state: "red" }), false);31
});32
33
test("stone walls remain chunk-atlas baked", () =>34
{35
assert.equal(isChunkAtlasBakedBlock({ typeId: BlockType.stoneWall }), true);36
});