Merge branch 'feature/water-coast-cross-chunk'
@@ -425,6 +425,7 @@ function saveSelectedChunk ()
425
425
$("apply-status").className = "hint";
426
426
const neighborSaves = [...dirtyNeighborChunks.entries()];
427
427
clearNeighborEditState();
428
const savedChunks = [{ chunkX, chunkY }];
428
429
socket.send({
429
430
type: MessageType.editorSaveChunk,
430
431
chunkX,
@@ -440,6 +441,7 @@ function saveSelectedChunk ()
440
441
for (const [key, data] of neighborSaves)
441
442
{
442
443
const [cx, cy] = key.split(",").map(Number);
444
savedChunks.push({ chunkX: cx, chunkY: cy });
443
445
socket.send({
444
446
type: MessageType.editorSaveChunk,
445
447
chunkX: cx,
@@ -453,6 +455,7 @@ function saveSelectedChunk ()
453
455
}
454
456
});
455
457
}
458
view?.bakeNatureTintForChunks?.(savedChunks);
456
459
requestNeighbors();
457
460
return true;
458
461
}
@@ -1049,6 +1052,7 @@ async function main ()
1049
1052
game.loadScene(scene);
1050
1053
view = new WorldView(game, scene, catalog);
1051
1054
view.followPlayer = false;
1055
view.natureTintEnabled = false;
1052
1056
view.setGraphicsPrefs(loadGraphicsSettings());
1053
1057
syncSeasonControls(view.worldSeason ?? seasonIdAt());
1054
1058
layoutScene();
@@ -425,6 +425,7 @@ function saveSelectedChunk ()425
$("apply-status").className = "hint";425
$("apply-status").className = "hint";426
const neighborSaves = [...dirtyNeighborChunks.entries()];426
const neighborSaves = [...dirtyNeighborChunks.entries()];427
clearNeighborEditState();427
clearNeighborEditState();428
const savedChunks = [{ chunkX, chunkY }];428
socket.send({429
socket.send({429
type: MessageType.editorSaveChunk,430
type: MessageType.editorSaveChunk,430
chunkX,431
chunkX,@@ -440,6 +441,7 @@ function saveSelectedChunk ()440
for (const [key, data] of neighborSaves)441
for (const [key, data] of neighborSaves)441
{442
{442
const [cx, cy] = key.split(",").map(Number);443
const [cx, cy] = key.split(",").map(Number);444
savedChunks.push({ chunkX: cx, chunkY: cy });443
socket.send({445
socket.send({444
type: MessageType.editorSaveChunk,446
type: MessageType.editorSaveChunk,445
chunkX: cx,447
chunkX: cx,@@ -453,6 +455,7 @@ function saveSelectedChunk ()453
}455
}454
});456
});455
}457
}458
view?.bakeNatureTintForChunks?.(savedChunks);456
requestNeighbors();459
requestNeighbors();457
return true;460
return true;458
}461
}@@ -1049,6 +1052,7 @@ async function main ()1049
game.loadScene(scene);1052
game.loadScene(scene);1050
view = new WorldView(game, scene, catalog);1053
view = new WorldView(game, scene, catalog);1051
view.followPlayer = false;1054
view.followPlayer = false;1055
view.natureTintEnabled = false;1052
view.setGraphicsPrefs(loadGraphicsSettings());1056
view.setGraphicsPrefs(loadGraphicsSettings());1053
syncSeasonControls(view.worldSeason ?? seasonIdAt());1057
syncSeasonControls(view.worldSeason ?? seasonIdAt());1054
layoutScene();1058
layoutScene();@@ -16,7 +16,7 @@ import
16
16
} from "/shared/render/tint.js";
17
17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
18
18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";
19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";
20
20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
21
21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
22
22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -1082,6 +1082,11 @@ export class WorldView
1082
1082
this.bloomEnabled = true;
1083
1083
/** Soft edge blend for blendable grounds (grass, dirt, …). */
1084
1084
this.softTerrain = false;
1085
/**
1086
* Per-chunk nature Perlin tint. Off in the world editor while painting
1087
* (rebakes are frequent); editor enables a one-shot bake on chunk save.
1088
*/
1089
this.natureTintEnabled = true;
1085
1090
this.settings = { ...DEFAULT_WORLD_SETTINGS };
1086
1091
this.worldHour = 12;
1087
1092
/** Calendar season for seasonal ground/block visuals (`spring` / `summer` / `fall` / `winter`). */
@@ -3758,15 +3763,18 @@ export class WorldView
3758
3763
#waterCoastEdges (tileX, tileY)
3759
3764
{
3760
3765
const season = this.worldSeason;
3761
const liquid = (x, y) => isLiquidWaterGround(this.#groundTypeAt(x, y), season);
3762
const n = liquid(tileX, tileY - 1);
3763
const e = liquid(tileX + 1, tileY);
3764
const s = liquid(tileX, tileY + 1);
3765
const w = liquid(tileX - 1, tileY);
3766
const ne = liquid(tileX + 1, tileY - 1);
3767
const nw = liquid(tileX - 1, tileY - 1);
3768
const se = liquid(tileX + 1, tileY + 1);
3769
const sw = liquid(tileX - 1, tileY + 1);
3766
const continues = (x, y) => fluidCoastContinues(
3767
this.#groundTypeAt(x, y),
3768
(typeId) => isLiquidWaterGround(typeId, season)
3769
);
3770
const n = continues(tileX, tileY - 1);
3771
const e = continues(tileX + 1, tileY);
3772
const s = continues(tileX, tileY + 1);
3773
const w = continues(tileX - 1, tileY);
3774
const ne = continues(tileX + 1, tileY - 1);
3775
const nw = continues(tileX - 1, tileY - 1);
3776
const se = continues(tileX + 1, tileY + 1);
3777
const sw = continues(tileX - 1, tileY + 1);
3770
3778
return {
3771
3779
n: n ? 0 : 1,
3772
3780
e: e ? 0 : 1,
@@ -3849,7 +3857,7 @@ export class WorldView
3849
3857
{ continue; }
3850
3858
const entry = normalizeGround(ground);
3851
3859
const def = GROUND_DEFINITIONS[entry.typeId];
3852
if (!def || def.proceduralWaves)
3860
if (!def || def.proceduralWaves || !def.blendable)
3853
3861
{ continue; }
3854
3862
let spriteName = null;
3855
3863
if (preferWet && def.wetShore)
@@ -4036,15 +4044,18 @@ export class WorldView
4036
4044
4037
4045
#lavaCoastEdges (tileX, tileY)
4038
4046
{
4039
const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));
4040
const n = lava(tileX, tileY - 1);
4041
const e = lava(tileX + 1, tileY);
4042
const s = lava(tileX, tileY + 1);
4043
const w = lava(tileX - 1, tileY);
4044
const ne = lava(tileX + 1, tileY - 1);
4045
const nw = lava(tileX - 1, tileY - 1);
4046
const se = lava(tileX + 1, tileY + 1);
4047
const sw = lava(tileX - 1, tileY + 1);
4047
const continues = (x, y) => fluidCoastContinues(
4048
this.#groundTypeAt(x, y),
4049
(typeId) => isLavaGround(typeId)
4050
);
4051
const n = continues(tileX, tileY - 1);
4052
const e = continues(tileX + 1, tileY);
4053
const s = continues(tileX, tileY + 1);
4054
const w = continues(tileX - 1, tileY);
4055
const ne = continues(tileX + 1, tileY - 1);
4056
const nw = continues(tileX - 1, tileY - 1);
4057
const se = continues(tileX + 1, tileY + 1);
4058
const sw = continues(tileX - 1, tileY + 1);
4048
4059
return {
4049
4060
n: n ? 0 : 1,
4050
4061
e: e ? 0 : 1,
@@ -4381,10 +4392,18 @@ export class WorldView
4381
4392
this.#bakeAndPlaceChunk(snapshot);
4382
4393
this.#relayoutChunkTiles(snapshot);
4383
4394
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.
4384
if (refreshSoftNeighbors)
4395
if (refreshSoftNeighbors && this.#needsSoftTerrainNeighborRefresh())
4385
4396
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }
4386
4397
}
4387
4398
4399
/** Soft blend / wet-sand atlas borders need a rebake when an adjacent chunk arrives. */
4400
#needsSoftTerrainNeighborRefresh ()
4401
{
4402
if (this.softTerrain)
4403
{ return true; }
4404
return Math.max(0, Number(this.settings?.wetSandBand) || 0) > 0;
4405
}
4406
4388
4407
#relayoutChunk (snapshot)
4389
4408
{
4390
4409
this.#layoutBakedChunk(snapshot);
@@ -4608,7 +4627,7 @@ export class WorldView
4608
4627
this.#scheduleIdleChunkPrefetch();
4609
4628
return;
4610
4629
}
4611
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: false });
4630
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: true });
4612
4631
if (this.#hasUnbakedChunks())
4613
4632
{ this.#scheduleIdleChunkPrefetch(); }
4614
4633
}
@@ -4626,7 +4645,7 @@ export class WorldView
4626
4645
{
4627
4646
const snap = this.chunks.get(key);
4628
4647
if (snap)
4629
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: false }); }
4648
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: true }); }
4630
4649
}
4631
4650
if (this.#chunkRebuildKeys.size)
4632
4651
{
@@ -4729,7 +4748,12 @@ export class WorldView
4729
4748
chunkY: snapshot.chunkY
4730
4749
};
4731
4750
baked.groundObject = new GameObject(0, 0, baked.groundImage, LAYER_GROUND);
4732
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage);
4751
this.#applyAtlasLighting(
4752
baked.groundObject,
4753
baked.lightmapImage,
4754
-1,
4755
this.#groundNatureImage(baked)
4756
);
4733
4757
this.scene.addObject(baked.groundObject);
4734
4758
for (let row = 0; row < CHUNK_SIZE; row++)
4735
4759
{
@@ -4759,7 +4783,12 @@ export class WorldView
4759
4783
baked.groundImage = groundImage;
4760
4784
baked.groundObject.renderer.sprite = groundImage;
4761
4785
}
4762
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage);
4786
this.#applyAtlasLighting(
4787
baked.groundObject,
4788
baked.lightmapImage,
4789
-1,
4790
this.#groundNatureImage(baked)
4791
);
4763
4792
for (let row = 0; row < CHUNK_SIZE; row++)
4764
4793
{
4765
4794
if (baked.blockCanvases[row] !== atlases.blockRows[row])
@@ -4787,13 +4816,23 @@ export class WorldView
4787
4816
}
4788
4817
baked.chunkX = snapshot.chunkX;
4789
4818
baked.chunkY = snapshot.chunkY;
4790
this.#refreshNatureNoiseAround(snapshot.chunkX, snapshot.chunkY);
4819
if (this.natureTintEnabled)
4820
{ this.#refreshNatureNoiseAround(snapshot.chunkX, snapshot.chunkY); }
4791
4821
baked.lightmapCacheKey = null;
4792
4822
this.#invalidateNeighborLightmapCaches(snapshot.chunkX, snapshot.chunkY);
4793
4823
this.#layoutBakedChunk(snapshot);
4794
4824
this.#queueBakedChunkTextures(baked, snapshot.chunkX, snapshot.chunkY);
4795
4825
}
4796
4826
4827
#groundNatureImage (baked)
4828
{
4829
if (!baked?.natureImage)
4830
{ return null; }
4831
if (this.natureTintEnabled || baked.natureTintReady)
4832
{ return baked.natureImage; }
4833
return null;
4834
}
4835
4797
4836
#releaseBakedAtlasRefs (baked)
4798
4837
{
4799
4838
if (!baked?.atlasCacheRefs)
@@ -4892,9 +4931,53 @@ export class WorldView
4892
4931
};
4893
4932
}
4894
4933
4934
/**
4935
* One-shot nature tint bake (editor chunk-save). Fills noise for each chunk
4936
* and its halo neighbors, and enables tint on the ground atlas.
4937
* @param {Iterable<{ chunkX: number, chunkY: number }>} chunks
4938
*/
4939
bakeNatureTintForChunks (chunks)
4940
{
4941
const seen = new Set();
4942
for (const entry of chunks ?? [])
4943
{
4944
const chunkX = entry?.chunkX;
4945
const chunkY = entry?.chunkY;
4946
if (!Number.isFinite(chunkX) || !Number.isFinite(chunkY))
4947
{ continue; }
4948
for (let dy = -1; dy <= 1; dy++)
4949
{
4950
for (let dx = -1; dx <= 1; dx++)
4951
{
4952
const key = `${chunkX + dx},${chunkY + dy}`;
4953
if (seen.has(key))
4954
{ continue; }
4955
seen.add(key);
4956
const baked = this.bakedChunks.get(key);
4957
const snapshot = this.chunks.get(key);
4958
if (!baked?.natureCanvas || !snapshot)
4959
{ continue; }
4960
this.#fillNatureNoise(baked, snapshot);
4961
baked.natureTintReady = true;
4962
if (baked.groundObject)
4963
{
4964
this.#applyAtlasLighting(
4965
baked.groundObject,
4966
baked.lightmapImage,
4967
-1,
4968
baked.natureImage
4969
);
4970
}
4971
}
4972
}
4973
}
4974
}
4975
4895
4976
/** Rebuild nature noise for a chunk and neighbors (halo needs adjacent grounds). */
4896
4977
#refreshNatureNoiseAround (chunkX, chunkY)
4897
4978
{
4979
if (!this.natureTintEnabled)
4980
{ return; }
4898
4981
for (let dy = -1; dy <= 1; dy++)
4899
4982
{
4900
4983
for (let dx = -1; dx <= 1; dx++)
@@ -4906,6 +4989,7 @@ export class WorldView
4906
4989
if (!baked?.natureCanvas || !snapshot)
4907
4990
{ continue; }
4908
4991
this.#fillNatureNoise(baked, snapshot);
4992
baked.natureTintReady = true;
4909
4993
if (baked.groundObject)
4910
4994
{ this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage); }
4911
4995
}
@@ -5518,9 +5602,10 @@ export class WorldView
5518
5602
// Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.
5519
5603
if (baked.groundObject?.renderer?.shaderUniforms)
5520
5604
{
5605
const natureOn = this.#groundNatureImage(baked) != null;
5521
5606
Object.assign(baked.groundObject.renderer.shaderUniforms, {
5522
5607
u_ambientDark: 1,
5523
...natureTintUniforms()
5608
...(natureOn ? natureTintUniforms() : { u_useNature: 0 })
5524
5609
});
5525
5610
}
5526
5611
for (const object of baked.blockObjects ?? [])
@@ -16,7 +16,7 @@ import16
} from "/shared/render/tint.js";16
} from "/shared/render/tint.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";@@ -1082,6 +1082,11 @@ export class WorldView1082
this.bloomEnabled = true;1082
this.bloomEnabled = true;1083
/** Soft edge blend for blendable grounds (grass, dirt, …). */1083
/** Soft edge blend for blendable grounds (grass, dirt, …). */1084
this.softTerrain = false;1084
this.softTerrain = false;1085
/**1086
* Per-chunk nature Perlin tint. Off in the world editor while painting1087
* (rebakes are frequent); editor enables a one-shot bake on chunk save.1088
*/1089
this.natureTintEnabled = true;1085
this.settings = { ...DEFAULT_WORLD_SETTINGS };1090
this.settings = { ...DEFAULT_WORLD_SETTINGS };1086
this.worldHour = 12;1091
this.worldHour = 12;1087
/** Calendar season for seasonal ground/block visuals (`spring` / `summer` / `fall` / `winter`). */1092
/** Calendar season for seasonal ground/block visuals (`spring` / `summer` / `fall` / `winter`). */@@ -3758,15 +3763,18 @@ export class WorldView3758
#waterCoastEdges (tileX, tileY)3763
#waterCoastEdges (tileX, tileY)3759
{3764
{3760
const season = this.worldSeason;3765
const season = this.worldSeason;3761
const liquid = (x, y) => isLiquidWaterGround(this.#groundTypeAt(x, y), season);3766
const continues = (x, y) => fluidCoastContinues(3762
const n = liquid(tileX, tileY - 1);3767
this.#groundTypeAt(x, y),3763
const e = liquid(tileX + 1, tileY);3768
(typeId) => isLiquidWaterGround(typeId, season)3764
const s = liquid(tileX, tileY + 1);3769
);3765
const w = liquid(tileX - 1, tileY);3770
const n = continues(tileX, tileY - 1);3766
const ne = liquid(tileX + 1, tileY - 1);3771
const e = continues(tileX + 1, tileY);3767
const nw = liquid(tileX - 1, tileY - 1);3772
const s = continues(tileX, tileY + 1);3768
const se = liquid(tileX + 1, tileY + 1);3773
const w = continues(tileX - 1, tileY);3769
const sw = liquid(tileX - 1, tileY + 1);3774
const ne = continues(tileX + 1, tileY - 1);3775
const nw = continues(tileX - 1, tileY - 1);3776
const se = continues(tileX + 1, tileY + 1);3777
const sw = continues(tileX - 1, tileY + 1);3770
return {3778
return {3771
n: n ? 0 : 1,3779
n: n ? 0 : 1,3772
e: e ? 0 : 1,3780
e: e ? 0 : 1,@@ -3849,7 +3857,7 @@ export class WorldView3849
{ continue; }3857
{ continue; }3850
const entry = normalizeGround(ground);3858
const entry = normalizeGround(ground);3851
const def = GROUND_DEFINITIONS[entry.typeId];3859
const def = GROUND_DEFINITIONS[entry.typeId];3852
if (!def || def.proceduralWaves)3860
if (!def || def.proceduralWaves || !def.blendable)3853
{ continue; }3861
{ continue; }3854
let spriteName = null;3862
let spriteName = null;3855
if (preferWet && def.wetShore)3863
if (preferWet && def.wetShore)@@ -4036,15 +4044,18 @@ export class WorldView4036
4044
4037
#lavaCoastEdges (tileX, tileY)4045
#lavaCoastEdges (tileX, tileY)4038
{4046
{4039
const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));4047
const continues = (x, y) => fluidCoastContinues(4040
const n = lava(tileX, tileY - 1);4048
this.#groundTypeAt(x, y),4041
const e = lava(tileX + 1, tileY);4049
(typeId) => isLavaGround(typeId)4042
const s = lava(tileX, tileY + 1);4050
);4043
const w = lava(tileX - 1, tileY);4051
const n = continues(tileX, tileY - 1);4044
const ne = lava(tileX + 1, tileY - 1);4052
const e = continues(tileX + 1, tileY);4045
const nw = lava(tileX - 1, tileY - 1);4053
const s = continues(tileX, tileY + 1);4046
const se = lava(tileX + 1, tileY + 1);4054
const w = continues(tileX - 1, tileY);4047
const sw = lava(tileX - 1, tileY + 1);4055
const ne = continues(tileX + 1, tileY - 1);4056
const nw = continues(tileX - 1, tileY - 1);4057
const se = continues(tileX + 1, tileY + 1);4058
const sw = continues(tileX - 1, tileY + 1);4048
return {4059
return {4049
n: n ? 0 : 1,4060
n: n ? 0 : 1,4050
e: e ? 0 : 1,4061
e: e ? 0 : 1,@@ -4381,10 +4392,18 @@ export class WorldView4381
this.#bakeAndPlaceChunk(snapshot);4392
this.#bakeAndPlaceChunk(snapshot);4382
this.#relayoutChunkTiles(snapshot);4393
this.#relayoutChunkTiles(snapshot);4383
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.4394
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.4384
if (refreshSoftNeighbors)4395
if (refreshSoftNeighbors && this.#needsSoftTerrainNeighborRefresh())4385
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }4396
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }4386
}4397
}4387
4398
4399
/** Soft blend / wet-sand atlas borders need a rebake when an adjacent chunk arrives. */4400
#needsSoftTerrainNeighborRefresh ()4401
{4402
if (this.softTerrain)4403
{ return true; }4404
return Math.max(0, Number(this.settings?.wetSandBand) || 0) > 0;4405
}4406
4388
#relayoutChunk (snapshot)4407
#relayoutChunk (snapshot)4389
{4408
{4390
this.#layoutBakedChunk(snapshot);4409
this.#layoutBakedChunk(snapshot);@@ -4608,7 +4627,7 @@ export class WorldView4608
this.#scheduleIdleChunkPrefetch();4627
this.#scheduleIdleChunkPrefetch();4609
return;4628
return;4610
}4629
}4611
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: false });4630
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: true });4612
if (this.#hasUnbakedChunks())4631
if (this.#hasUnbakedChunks())4613
{ this.#scheduleIdleChunkPrefetch(); }4632
{ this.#scheduleIdleChunkPrefetch(); }4614
}4633
}@@ -4626,7 +4645,7 @@ export class WorldView4626
{4645
{4627
const snap = this.chunks.get(key);4646
const snap = this.chunks.get(key);4628
if (snap)4647
if (snap)4629
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: false }); }4648
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: true }); }4630
}4649
}4631
if (this.#chunkRebuildKeys.size)4650
if (this.#chunkRebuildKeys.size)4632
{4651
{@@ -4729,7 +4748,12 @@ export class WorldView4729
chunkY: snapshot.chunkY4748
chunkY: snapshot.chunkY4730
};4749
};4731
baked.groundObject = new GameObject(0, 0, baked.groundImage, LAYER_GROUND);4750
baked.groundObject = new GameObject(0, 0, baked.groundImage, LAYER_GROUND);4732
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage);4751
this.#applyAtlasLighting(4752
baked.groundObject,4753
baked.lightmapImage,4754
-1,4755
this.#groundNatureImage(baked)4756
);4733
this.scene.addObject(baked.groundObject);4757
this.scene.addObject(baked.groundObject);4734
for (let row = 0; row < CHUNK_SIZE; row++)4758
for (let row = 0; row < CHUNK_SIZE; row++)4735
{4759
{@@ -4759,7 +4783,12 @@ export class WorldView4759
baked.groundImage = groundImage;4783
baked.groundImage = groundImage;4760
baked.groundObject.renderer.sprite = groundImage;4784
baked.groundObject.renderer.sprite = groundImage;4761
}4785
}4762
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage);4786
this.#applyAtlasLighting(4787
baked.groundObject,4788
baked.lightmapImage,4789
-1,4790
this.#groundNatureImage(baked)4791
);4763
for (let row = 0; row < CHUNK_SIZE; row++)4792
for (let row = 0; row < CHUNK_SIZE; row++)4764
{4793
{4765
if (baked.blockCanvases[row] !== atlases.blockRows[row])4794
if (baked.blockCanvases[row] !== atlases.blockRows[row])@@ -4787,13 +4816,23 @@ export class WorldView4787
}4816
}4788
baked.chunkX = snapshot.chunkX;4817
baked.chunkX = snapshot.chunkX;4789
baked.chunkY = snapshot.chunkY;4818
baked.chunkY = snapshot.chunkY;4790
this.#refreshNatureNoiseAround(snapshot.chunkX, snapshot.chunkY);4819
if (this.natureTintEnabled)4820
{ this.#refreshNatureNoiseAround(snapshot.chunkX, snapshot.chunkY); }4791
baked.lightmapCacheKey = null;4821
baked.lightmapCacheKey = null;4792
this.#invalidateNeighborLightmapCaches(snapshot.chunkX, snapshot.chunkY);4822
this.#invalidateNeighborLightmapCaches(snapshot.chunkX, snapshot.chunkY);4793
this.#layoutBakedChunk(snapshot);4823
this.#layoutBakedChunk(snapshot);4794
this.#queueBakedChunkTextures(baked, snapshot.chunkX, snapshot.chunkY);4824
this.#queueBakedChunkTextures(baked, snapshot.chunkX, snapshot.chunkY);4795
}4825
}4796
4826
4827
#groundNatureImage (baked)4828
{4829
if (!baked?.natureImage)4830
{ return null; }4831
if (this.natureTintEnabled || baked.natureTintReady)4832
{ return baked.natureImage; }4833
return null;4834
}4835
4797
#releaseBakedAtlasRefs (baked)4836
#releaseBakedAtlasRefs (baked)4798
{4837
{4799
if (!baked?.atlasCacheRefs)4838
if (!baked?.atlasCacheRefs)@@ -4892,9 +4931,53 @@ export class WorldView4892
};4931
};4893
}4932
}4894
4933
4934
/**4935
* One-shot nature tint bake (editor chunk-save). Fills noise for each chunk4936
* and its halo neighbors, and enables tint on the ground atlas.4937
* @param {Iterable<{ chunkX: number, chunkY: number }>} chunks4938
*/4939
bakeNatureTintForChunks (chunks)4940
{4941
const seen = new Set();4942
for (const entry of chunks ?? [])4943
{4944
const chunkX = entry?.chunkX;4945
const chunkY = entry?.chunkY;4946
if (!Number.isFinite(chunkX) || !Number.isFinite(chunkY))4947
{ continue; }4948
for (let dy = -1; dy <= 1; dy++)4949
{4950
for (let dx = -1; dx <= 1; dx++)4951
{4952
const key = `${chunkX + dx},${chunkY + dy}`;4953
if (seen.has(key))4954
{ continue; }4955
seen.add(key);4956
const baked = this.bakedChunks.get(key);4957
const snapshot = this.chunks.get(key);4958
if (!baked?.natureCanvas || !snapshot)4959
{ continue; }4960
this.#fillNatureNoise(baked, snapshot);4961
baked.natureTintReady = true;4962
if (baked.groundObject)4963
{4964
this.#applyAtlasLighting(4965
baked.groundObject,4966
baked.lightmapImage,4967
-1,4968
baked.natureImage4969
);4970
}4971
}4972
}4973
}4974
}4975
4895
/** Rebuild nature noise for a chunk and neighbors (halo needs adjacent grounds). */4976
/** Rebuild nature noise for a chunk and neighbors (halo needs adjacent grounds). */4896
#refreshNatureNoiseAround (chunkX, chunkY)4977
#refreshNatureNoiseAround (chunkX, chunkY)4897
{4978
{4979
if (!this.natureTintEnabled)4980
{ return; }4898
for (let dy = -1; dy <= 1; dy++)4981
for (let dy = -1; dy <= 1; dy++)4899
{4982
{4900
for (let dx = -1; dx <= 1; dx++)4983
for (let dx = -1; dx <= 1; dx++)@@ -4906,6 +4989,7 @@ export class WorldView4906
if (!baked?.natureCanvas || !snapshot)4989
if (!baked?.natureCanvas || !snapshot)4907
{ continue; }4990
{ continue; }4908
this.#fillNatureNoise(baked, snapshot);4991
this.#fillNatureNoise(baked, snapshot);4992
baked.natureTintReady = true;4909
if (baked.groundObject)4993
if (baked.groundObject)4910
{ this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage); }4994
{ this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage); }4911
}4995
}@@ -5518,9 +5602,10 @@ export class WorldView5518
// Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.5602
// Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.5519
if (baked.groundObject?.renderer?.shaderUniforms)5603
if (baked.groundObject?.renderer?.shaderUniforms)5520
{5604
{5605
const natureOn = this.#groundNatureImage(baked) != null;5521
Object.assign(baked.groundObject.renderer.shaderUniforms, {5606
Object.assign(baked.groundObject.renderer.shaderUniforms, {5522
u_ambientDark: 1,5607
u_ambientDark: 1,5523
...natureTintUniforms()5608
...(natureOn ? natureTintUniforms() : { u_useNature: 0 })5524
});5609
});5525
}5610
}5526
for (const object of baked.blockObjects ?? [])5611
for (const object of baked.blockObjects ?? [])@@ -1,6 +1,6 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";
3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion, fluidCoastContinues, isLavaGround } from "../../shared/definitions/tiles.js";
4
4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";
5
5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";
6
6
@@ -60,3 +60,25 @@ test("shallow water freezes in winter: no wade, not liquid for coast foam", () =
60
60
"water"
61
61
);
62
62
});
63
64
test("fluid coast continues under non-blendable floors and missing neighbors", () =>
65
{
66
const sameWater = (typeId) => isLiquidWaterGround(typeId, SeasonId.summer);
67
assert.equal(fluidCoastContinues(null, sameWater), true);
68
assert.equal(fluidCoastContinues(GroundType.water, sameWater), true);
69
assert.equal(fluidCoastContinues(GroundType.deepWater, sameWater), true);
70
assert.equal(fluidCoastContinues(GroundType.wood, sameWater), true);
71
assert.equal(fluidCoastContinues(GroundType.grass, sameWater), false);
72
assert.equal(fluidCoastContinues(GroundType.sand, sameWater), false);
73
// Winter ice and lava still count as coast (distinct from liquid water).
74
assert.equal(fluidCoastContinues(GroundType.water, (typeId) => isLiquidWaterGround(typeId, SeasonId.winter)), false);
75
assert.equal(fluidCoastContinues(GroundType.lava, sameWater), false);
76
});
77
78
test("lava coast continues under wood but not blendable land", () =>
79
{
80
const sameLava = (typeId) => isLavaGround(typeId);
81
assert.equal(fluidCoastContinues(GroundType.lava, sameLava), true);
82
assert.equal(fluidCoastContinues(GroundType.wood, sameLava), true);
83
assert.equal(fluidCoastContinues(GroundType.dirt, sameLava), false);
84
});
@@ -1,6 +1,6 @@1
import test from "node:test";1
import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion, fluidCoastContinues, isLavaGround } from "../../shared/definitions/tiles.js";4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";6
6
@@ -60,3 +60,25 @@ test("shallow water freezes in winter: no wade, not liquid for coast foam", () =60
"water"60
"water"61
);61
);62
});62
});63
64
test("fluid coast continues under non-blendable floors and missing neighbors", () =>65
{66
const sameWater = (typeId) => isLiquidWaterGround(typeId, SeasonId.summer);67
assert.equal(fluidCoastContinues(null, sameWater), true);68
assert.equal(fluidCoastContinues(GroundType.water, sameWater), true);69
assert.equal(fluidCoastContinues(GroundType.deepWater, sameWater), true);70
assert.equal(fluidCoastContinues(GroundType.wood, sameWater), true);71
assert.equal(fluidCoastContinues(GroundType.grass, sameWater), false);72
assert.equal(fluidCoastContinues(GroundType.sand, sameWater), false);73
// Winter ice and lava still count as coast (distinct from liquid water).74
assert.equal(fluidCoastContinues(GroundType.water, (typeId) => isLiquidWaterGround(typeId, SeasonId.winter)), false);75
assert.equal(fluidCoastContinues(GroundType.lava, sameWater), false);76
});77
78
test("lava coast continues under wood but not blendable land", () =>79
{80
const sameLava = (typeId) => isLavaGround(typeId);81
assert.equal(fluidCoastContinues(GroundType.lava, sameLava), true);82
assert.equal(fluidCoastContinues(GroundType.wood, sameLava), true);83
assert.equal(fluidCoastContinues(GroundType.dirt, sameLava), false);84
});