BlueGit

timfa questward

Draw free-flight pigeons above all blocks.

Flight sprites use a dedicated y-sort bias so they never tuck under walls or trees while flying.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
1823a2b437dd22bea47b64f81c126980959d917c
Parent
3dcfc07b
3 files changed +28 −7
client/src/render/worldView.js +9 −6
@@ -8,7 +8,7 @@ import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb }
8 8 import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
9 9 import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
10 10 import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
11 import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
11 import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
12 12 import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
13 13 import { createChunkAtlasCache } from "./chunkAtlasCache.js";
14 14 import
@@ -2441,7 +2441,8 @@ export class WorldView
2441 2441
2442 2442 entity.object.transform.rotation = walkTilt;
2443 2443 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2444 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2444 const flight = !!entity.freeFlight;
2445 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1, flight);
2445 2446 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2446 2447 {
2447 2448 const overlay = entity.overlays[index];
@@ -2468,7 +2469,7 @@ export class WorldView
2468 2469 {
2469 2470 this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null, flashColor);
2470 2471 }
2471 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2472 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1, flight);
2472 2473 }
2473 2474 for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)
2474 2475 {
@@ -2488,7 +2489,7 @@ export class WorldView
2488 2489 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2489 2490 else
2490 2491 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
2491 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2492 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);
2492 2493 }
2493 2494 this.#placeHpBar(entity, pivotX, pivotY);
2494 2495 this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);
@@ -3549,7 +3550,7 @@ export class WorldView
3549 3550 return object;
3550 3551 }
3551 3552
3552 #placePivoted (object, pivotX, pivotY, sortY, subOrder, scale = 1)
3553 #placePivoted (object, pivotX, pivotY, sortY, subOrder, scale = 1, flight = false)
3553 3554 {
3554 3555 const sprite = object?.renderer?.sprite;
3555 3556 if (!sprite)
@@ -3561,7 +3562,9 @@ export class WorldView
3561 3562 object.transform.position.x = center.x;
3562 3563 object.transform.position.y = center.y;
3563 3564 object.transform.size = new vector(draw.w * factor, draw.h * factor);
3564 object.layer = ySortLayer(sortY, subOrder);
3565 object.layer = flight
3566 ? flightSortLayer(sortY, subOrder)
3567 : ySortLayer(sortY, subOrder);
3565 3568 this.#markSortDirty();
3566 3569 }
3567 3570
@@ -8,7 +8,7 @@ import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb }
8import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
8import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
9import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
9import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
10import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
10import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
11import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
11import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
12import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
12import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
13import { createChunkAtlasCache } from "./chunkAtlasCache.js";
13import { createChunkAtlasCache } from "./chunkAtlasCache.js";
14import
14import
@@ -2441,7 +2441,8 @@ export class WorldView
2441
2441
2442 entity.object.transform.rotation = walkTilt;
2442 entity.object.transform.rotation = walkTilt;
2443 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2443 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2444 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2444 const flight = !!entity.freeFlight;
2445 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1, flight);
2445 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2446 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2446 {
2447 {
2447 const overlay = entity.overlays[index];
2448 const overlay = entity.overlays[index];
@@ -2468,7 +2469,7 @@ export class WorldView
2468 {
2469 {
2469 this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null, flashColor);
2470 this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null, flashColor);
2470 }
2471 }
2471 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2472 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1, flight);
2472 }
2473 }
2473 for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)
2474 for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)
2474 {
2475 {
@@ -2488,7 +2489,7 @@ export class WorldView
2488 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2489 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2489 else
2490 else
2490 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
2491 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
2491 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2492 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);
2492 }
2493 }
2493 this.#placeHpBar(entity, pivotX, pivotY);
2494 this.#placeHpBar(entity, pivotX, pivotY);
2494 this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);
2495 this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);
@@ -3549,7 +3550,7 @@ export class WorldView
3549 return object;
3550 return object;
3550 }
3551 }
3551
3552
3552 #placePivoted (object, pivotX, pivotY, sortY, subOrder, scale = 1)
3553 #placePivoted (object, pivotX, pivotY, sortY, subOrder, scale = 1, flight = false)
3553 {
3554 {
3554 const sprite = object?.renderer?.sprite;
3555 const sprite = object?.renderer?.sprite;
3555 if (!sprite)
3556 if (!sprite)
@@ -3561,7 +3562,9 @@ export class WorldView
3561 object.transform.position.x = center.x;
3562 object.transform.position.x = center.x;
3562 object.transform.position.y = center.y;
3563 object.transform.position.y = center.y;
3563 object.transform.size = new vector(draw.w * factor, draw.h * factor);
3564 object.transform.size = new vector(draw.w * factor, draw.h * factor);
3564 object.layer = ySortLayer(sortY, subOrder);
3565 object.layer = flight
3566 ? flightSortLayer(sortY, subOrder)
3567 : ySortLayer(sortY, subOrder);
3565 this.#markSortDirty();
3568 this.#markSortDirty();
3566 }
3569 }
3567
3570
server/tests/pivot.test.js +8 −1
@@ -1,6 +1,6 @@
1 1 import test from "node:test";
2 2 import assert from "node:assert/strict";
3 import { spriteCenterFromPivot, tilePivot, ySortLayer } from "../../shared/render/pivot.js";
3 import { spriteCenterFromPivot, tilePivot, ySortLayer, flightSortLayer } from "../../shared/render/pivot.js";
4 4
5 5 test("a 16×16 sprite pivot sits on the tile centre", () =>
6 6 {
@@ -32,3 +32,10 @@ test("Y-sort puts a southern tile in front of a northern tile", () =>
32 32 {
33 33 assert.ok(ySortLayer(16, 1) > ySortLayer(0, 1));
34 34 });
35
36 test("flight sort stays above any ground y-sort in view", () =>
37 {
38 const farSouthBlock = ySortLayer(50_000, 3);
39 assert.ok(flightSortLayer(0, 0) > farSouthBlock);
40 assert.ok(flightSortLayer(16, 1) > flightSortLayer(0, 1));
41 });
@@ -1,6 +1,6 @@
1import test from "node:test";
1import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { spriteCenterFromPivot, tilePivot, ySortLayer } from "../../shared/render/pivot.js";
3import { spriteCenterFromPivot, tilePivot, ySortLayer, flightSortLayer } from "../../shared/render/pivot.js";
4
4
5test("a 16×16 sprite pivot sits on the tile centre", () =>
5test("a 16×16 sprite pivot sits on the tile centre", () =>
6{
6{
@@ -32,3 +32,10 @@ test("Y-sort puts a southern tile in front of a northern tile", () =>
32{
32{
33 assert.ok(ySortLayer(16, 1) > ySortLayer(0, 1));
33 assert.ok(ySortLayer(16, 1) > ySortLayer(0, 1));
34});
34});
35
36test("flight sort stays above any ground y-sort in view", () =>
37{
38 const farSouthBlock = ySortLayer(50_000, 3);
39 assert.ok(flightSortLayer(0, 0) > farSouthBlock);
40 assert.ok(flightSortLayer(16, 1) > flightSortLayer(0, 1));
41});
shared/render/pivot.js +11 −0
@@ -29,3 +29,14 @@ export function ySortLayer (sortY, subOrder)
29 29 {
30 30 return 10000 + Math.round(sortY) * 4 + subOrder;
31 31 }
32
33 /**
34 * Free-flight sprites (e.g. pigeons) must draw above all ground y-sorted
35 * blocks/entities. Bias sits well above {@link ySortLayer} for any in-view tile.
36 */
37 export const FLIGHT_SORT_BIAS = 2_000_000;
38
39 export function flightSortLayer (sortY, subOrder = 0)
40 {
41 return FLIGHT_SORT_BIAS + Math.round(sortY) * 4 + (subOrder | 0);
42 }
@@ -29,3 +29,14 @@ export function ySortLayer (sortY, subOrder)
29{
29{
30 return 10000 + Math.round(sortY) * 4 + subOrder;
30 return 10000 + Math.round(sortY) * 4 + subOrder;
31}
31}
32
33/**
34 * Free-flight sprites (e.g. pigeons) must draw above all ground y-sorted
35 * blocks/entities. Bias sits well above {@link ySortLayer} for any in-view tile.
36 */
37export const FLIGHT_SORT_BIAS = 2_000_000;
38
39export function flightSortLayer (sortY, subOrder = 0)
40{
41 return FLIGHT_SORT_BIAS + Math.round(sortY) * 4 + (subOrder | 0);
42}