Merge branch 'fix/y-sort-viewport-drift'
@@ -1555,7 +1555,7 @@ export class WorldView
1555
1555
{
1556
1556
this.#centerCamera();
1557
1557
this.#syncYSortOrigin();
1558
this.#refreshBakedDepthLayers();
1558
this.#refreshDepthLayers();
1559
1559
this.#cullOffscreenDrawables();
1560
1560
}
1561
1561
@@ -1651,15 +1651,21 @@ export class WorldView
1651
1651
this.#updateStackOffset(entity, now);
1652
1652
this.#updateShove(entity, now, size);
1653
1653
this.#expireGatherToolOverlay(entity, now);
1654
this.#placeEntity(entity, now);
1655
1654
}
1656
1655
1656
// The y-sort origin must settle before any layer is computed this frame,
1657
// otherwise entities and blocks end up sorted against different origins.
1658
this.#centerCamera();
1659
this.#syncYSortOrigin();
1660
1661
for (const entity of this.entities.values())
1662
{ this.#placeEntity(entity, now); }
1663
1657
1664
this.#updateSwipes(now);
1658
1665
this.#updateDamageNumbers(now);
1659
1666
this.#updateSkillLevelFloats(now);
1660
1667
this.#relayoutSpellTargetHighlight();
1661
this.#centerCamera();
1662
this.#refreshBakedDepthLayers();
1668
this.#refreshDepthLayers();
1663
1669
this.#cullOffscreenDrawables();
1664
1670
this.#updateShade(deltaTime);
1665
1671
}
@@ -1800,6 +1806,7 @@ export class WorldView
1800
1806
until: started + MELEE_SWIPE_MS,
1801
1807
started,
1802
1808
durationMs: MELEE_SWIPE_MS,
1809
sortY,
1803
1810
fadeOpacity: true,
1804
1811
fromTileX: payload.fromTileX,
1805
1812
fromTileY: payload.fromTileY,
@@ -2425,7 +2432,6 @@ export class WorldView
2425
2432
const y = local.visualY + (local.stackOffsetY ?? 0);
2426
2433
this.scene.cameraPosition.x = this.scene.real_size.x / 2 - x;
2427
2434
this.scene.cameraPosition.y = this.scene.real_size.y / 2 - y;
2428
this.#syncYSortOrigin();
2429
2435
}
2430
2436
2431
2437
/**
@@ -2446,8 +2452,12 @@ export class WorldView
2446
2452
return flight ? flightSortLayer(relative, subOrder) : ySortLayer(relative, subOrder);
2447
2453
}
2448
2454
2449
/** Re-apply baked chunk row depth after the y-sort origin moves with the camera. */
2450
#refreshBakedDepthLayers ()
2455
/**
2456
* Re-apply depth for every world sprite that is not repositioned each frame.
2457
* Their layer is relative to the y-sort origin, which moves with the camera,
2458
* so a layer assigned once at draw time drifts as the player walks.
2459
*/
2460
#refreshDepthLayers ()
2451
2461
{
2452
2462
const size = this.tileSize();
2453
2463
for (const baked of this.bakedChunks.values())
@@ -2465,6 +2475,44 @@ export class WorldView
2465
2475
if (baked.bloomObject)
2466
2476
{ baked.bloomObject.layer = this.#depthLayer(top + chunkPx, SORT_BLOCK); }
2467
2477
}
2478
// Unbaked tile sprites: tall blocks, doors and animated grounds.
2479
for (const objects of this.tiles.values())
2480
{
2481
if (!objects.block && !objects.blockBloom && !objects.groundBloom)
2482
{ continue; }
2483
const pivotY = objects.tileY * size + size / 2;
2484
if (objects.block)
2485
{ objects.block.layer = this.#depthLayer(pivotY, objects.blockSort ?? SORT_ENTITY); }
2486
if (objects.blockBloom)
2487
{ objects.blockBloom.layer = this.#depthLayer(pivotY, SORT_ENTITY); }
2488
if (objects.groundBloom)
2489
{ objects.groundBloom.layer = this.#depthLayer(pivotY, LAYER_GROUND); }
2490
}
2491
for (const item of this.groundItems.values())
2492
{
2493
if (!item.object)
2494
{ continue; }
2495
item.object.layer = this.#depthLayer(item.tileY * size + size / 2 - 0.01, SORT_BLOCK);
2496
}
2497
// Lerping FX are re-placed in #updateSwipes; static ones need the refresh.
2498
for (const swipe of this.swipes)
2499
{
2500
if (swipe.lerp || swipe.sortY == null || !swipe.object)
2501
{ continue; }
2502
swipe.object.layer = this.#depthLayer(swipe.sortY, SORT_FX);
2503
}
2504
for (const entry of this.editorSpawners.values())
2505
{
2506
const pivotY = entry.tileY * size + size / 2;
2507
if (entry.object)
2508
{ entry.object.layer = this.#depthLayer(pivotY + 0.05, SORT_ENTITY); }
2509
const overlays = entry.overlays ?? [];
2510
for (let i = 0; i < overlays.length; i++)
2511
{
2512
if (overlays[i])
2513
{ overlays[i].layer = this.#depthLayer(pivotY + 0.05 + 0.001 * (i + 1), SORT_ENTITY); }
2514
}
2515
}
2468
2516
this.#markSortDirty();
2469
2517
}
2470
2518
@@ -4018,6 +4066,7 @@ export class WorldView
4018
4066
? doorSortSubOrder(blockEntry?.state, SORT_ENTITY)
4019
4067
: SORT_ENTITY;
4020
4068
objects.block = this.#ensureSprite(objects.block, tileBlock.sprite, blockSort);
4069
objects.blockSort = blockSort;
4021
4070
objects.cliffGroundTop = !!blockDef?.cliffGroundTop;
4022
4071
if (objects.block)
4023
4072
{
@@ -4043,6 +4092,7 @@ export class WorldView
4043
4092
{
4044
4093
objects.block?.destroy();
4045
4094
objects.block = null;
4095
objects.blockSort = null;
4046
4096
objects.blockBloom?.destroy();
4047
4097
objects.blockBloom = null;
4048
4098
objects.cliffGroundTop = false;
@@ -1555,7 +1555,7 @@ export class WorldView1555
{1555
{1556
this.#centerCamera();1556
this.#centerCamera();1557
this.#syncYSortOrigin();1557
this.#syncYSortOrigin();1558
this.#refreshBakedDepthLayers();1558
this.#refreshDepthLayers();1559
this.#cullOffscreenDrawables();1559
this.#cullOffscreenDrawables();1560
}1560
}1561
1561
@@ -1651,15 +1651,21 @@ export class WorldView1651
this.#updateStackOffset(entity, now);1651
this.#updateStackOffset(entity, now);1652
this.#updateShove(entity, now, size);1652
this.#updateShove(entity, now, size);1653
this.#expireGatherToolOverlay(entity, now);1653
this.#expireGatherToolOverlay(entity, now);1654
this.#placeEntity(entity, now);1655
}1654
}1656
1655
1656
// The y-sort origin must settle before any layer is computed this frame,1657
// otherwise entities and blocks end up sorted against different origins.1658
this.#centerCamera();1659
this.#syncYSortOrigin();1660
1661
for (const entity of this.entities.values())1662
{ this.#placeEntity(entity, now); }1663
1657
this.#updateSwipes(now);1664
this.#updateSwipes(now);1658
this.#updateDamageNumbers(now);1665
this.#updateDamageNumbers(now);1659
this.#updateSkillLevelFloats(now);1666
this.#updateSkillLevelFloats(now);1660
this.#relayoutSpellTargetHighlight();1667
this.#relayoutSpellTargetHighlight();1661
this.#centerCamera();1668
this.#refreshDepthLayers();1662
this.#refreshBakedDepthLayers();1663
this.#cullOffscreenDrawables();1669
this.#cullOffscreenDrawables();1664
this.#updateShade(deltaTime);1670
this.#updateShade(deltaTime);1665
}1671
}@@ -1800,6 +1806,7 @@ export class WorldView1800
until: started + MELEE_SWIPE_MS,1806
until: started + MELEE_SWIPE_MS,1801
started,1807
started,1802
durationMs: MELEE_SWIPE_MS,1808
durationMs: MELEE_SWIPE_MS,1809
sortY,1803
fadeOpacity: true,1810
fadeOpacity: true,1804
fromTileX: payload.fromTileX,1811
fromTileX: payload.fromTileX,1805
fromTileY: payload.fromTileY,1812
fromTileY: payload.fromTileY,@@ -2425,7 +2432,6 @@ export class WorldView2425
const y = local.visualY + (local.stackOffsetY ?? 0);2432
const y = local.visualY + (local.stackOffsetY ?? 0);2426
this.scene.cameraPosition.x = this.scene.real_size.x / 2 - x;2433
this.scene.cameraPosition.x = this.scene.real_size.x / 2 - x;2427
this.scene.cameraPosition.y = this.scene.real_size.y / 2 - y;2434
this.scene.cameraPosition.y = this.scene.real_size.y / 2 - y;2428
this.#syncYSortOrigin();2429
}2435
}2430
2436
2431
/**2437
/**@@ -2446,8 +2452,12 @@ export class WorldView2446
return flight ? flightSortLayer(relative, subOrder) : ySortLayer(relative, subOrder);2452
return flight ? flightSortLayer(relative, subOrder) : ySortLayer(relative, subOrder);2447
}2453
}2448
2454
2449
/** Re-apply baked chunk row depth after the y-sort origin moves with the camera. */2455
/**2450
#refreshBakedDepthLayers ()2456
* Re-apply depth for every world sprite that is not repositioned each frame.2457
* Their layer is relative to the y-sort origin, which moves with the camera,2458
* so a layer assigned once at draw time drifts as the player walks.2459
*/2460
#refreshDepthLayers ()2451
{2461
{2452
const size = this.tileSize();2462
const size = this.tileSize();2453
for (const baked of this.bakedChunks.values())2463
for (const baked of this.bakedChunks.values())@@ -2465,6 +2475,44 @@ export class WorldView2465
if (baked.bloomObject)2475
if (baked.bloomObject)2466
{ baked.bloomObject.layer = this.#depthLayer(top + chunkPx, SORT_BLOCK); }2476
{ baked.bloomObject.layer = this.#depthLayer(top + chunkPx, SORT_BLOCK); }2467
}2477
}2478
// Unbaked tile sprites: tall blocks, doors and animated grounds.2479
for (const objects of this.tiles.values())2480
{2481
if (!objects.block && !objects.blockBloom && !objects.groundBloom)2482
{ continue; }2483
const pivotY = objects.tileY * size + size / 2;2484
if (objects.block)2485
{ objects.block.layer = this.#depthLayer(pivotY, objects.blockSort ?? SORT_ENTITY); }2486
if (objects.blockBloom)2487
{ objects.blockBloom.layer = this.#depthLayer(pivotY, SORT_ENTITY); }2488
if (objects.groundBloom)2489
{ objects.groundBloom.layer = this.#depthLayer(pivotY, LAYER_GROUND); }2490
}2491
for (const item of this.groundItems.values())2492
{2493
if (!item.object)2494
{ continue; }2495
item.object.layer = this.#depthLayer(item.tileY * size + size / 2 - 0.01, SORT_BLOCK);2496
}2497
// Lerping FX are re-placed in #updateSwipes; static ones need the refresh.2498
for (const swipe of this.swipes)2499
{2500
if (swipe.lerp || swipe.sortY == null || !swipe.object)2501
{ continue; }2502
swipe.object.layer = this.#depthLayer(swipe.sortY, SORT_FX);2503
}2504
for (const entry of this.editorSpawners.values())2505
{2506
const pivotY = entry.tileY * size + size / 2;2507
if (entry.object)2508
{ entry.object.layer = this.#depthLayer(pivotY + 0.05, SORT_ENTITY); }2509
const overlays = entry.overlays ?? [];2510
for (let i = 0; i < overlays.length; i++)2511
{2512
if (overlays[i])2513
{ overlays[i].layer = this.#depthLayer(pivotY + 0.05 + 0.001 * (i + 1), SORT_ENTITY); }2514
}2515
}2468
this.#markSortDirty();2516
this.#markSortDirty();2469
}2517
}2470
2518
@@ -4018,6 +4066,7 @@ export class WorldView4018
? doorSortSubOrder(blockEntry?.state, SORT_ENTITY)4066
? doorSortSubOrder(blockEntry?.state, SORT_ENTITY)4019
: SORT_ENTITY;4067
: SORT_ENTITY;4020
objects.block = this.#ensureSprite(objects.block, tileBlock.sprite, blockSort);4068
objects.block = this.#ensureSprite(objects.block, tileBlock.sprite, blockSort);4069
objects.blockSort = blockSort;4021
objects.cliffGroundTop = !!blockDef?.cliffGroundTop;4070
objects.cliffGroundTop = !!blockDef?.cliffGroundTop;4022
if (objects.block)4071
if (objects.block)4023
{4072
{@@ -4043,6 +4092,7 @@ export class WorldView4043
{4092
{4044
objects.block?.destroy();4093
objects.block?.destroy();4045
objects.block = null;4094
objects.block = null;4095
objects.blockSort = null;4046
objects.blockBloom?.destroy();4096
objects.blockBloom?.destroy();4047
objects.blockBloom = null;4097
objects.blockBloom = null;4048
objects.cliffGroundTop = false;4098
objects.cliffGroundTop = false;