Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(game): the ledger gets its first entry, and it is honest about what it knows

esenginec1e238bed4a6
diff --git a/examples/celestial-heights/engine-gaps.mjs b/examples/celestial-heights/engine-gaps.mjs
index 2afd07e36..a9bac6d91 100644
--- a/examples/celestial-heights/engine-gaps.mjs
+++ b/examples/celestial-heights/engine-gaps.mjs
@@ -31,4 +31,26 @@
*/
/** @type {Array<{id: string, hurts: string, workaround: string, fix: string, issue?: string, allows?: string[]}>} */
-export const GAPS = [];
+export const GAPS = [
+ {
+ id: 'ui-visual-written-at-runtime',
+ hurts:
+ 'A UIVisual written by a system renders in the wrong colour; the same component '
+ + 'left alone is pixel-exact. Measured on the packaged HUD meter: authored '
+ + '(231,90,105) stays exact while nothing writes it, and turns (51,28,43) under a '
+ + 'Mut write-back or (44,26,38) under an insert — the bar\'s LENGTH stays correct '
+ + 'either way, so it is the composite, not the value. The JS side reads the right '
+ + 'colour every frame. A probe project ruled out the node shape, the flex parent, '
+ + 'the Text sibling, the parent\'s alpha and the project\'s y-sort setting: standalone '
+ + 'and nested UIVisuals are all exact there — and nothing writes them.',
+ workaround:
+ 'Write through world.insert and only when the value actually changed (what the '
+ + 'engine\'s own createProgress.setValue does). That keeps the untouched full-health '
+ + 'bar exact and leaves only a changed bar dim, rather than every frame of it.',
+ fix:
+ 'Reproduce it in the probe by adding a system that writes a UIVisual — that isolates '
+ + 'it from the game — then root-cause it. Both write paths are suspect against UI '
+ + 'draw order, which C++ recomputes in uiRenderOrder_update during PostUpdate, the '
+ + 'same phase a gameplay system writes in.',
+ },
+];
diff --git a/examples/celestial-heights/src/systems/feedback.ts b/examples/celestial-heights/src/systems/feedback.ts
index c91d04fed..56f64b01d 100644
--- a/examples/celestial-heights/src/systems/feedback.ts
+++ b/examples/celestial-heights/src/systems/feedback.ts
@@ -28,11 +28,16 @@ export const healthBarSystem = defineSystem(
* the amount is the whole state — no geometry to keep in step with a layout.
*/
export const vitalityMeterSystem = defineSystem(
- [Query(Mut(UIVisual), VitalityMeter), Query(Health, Player)],
- (meters, players) => {
- for (const [, visual] of meters) {
+ [Query(UIVisual, VitalityMeter), Query(Health, Player), GetWorld()],
+ (meters, players, world) => {
+ for (const [entity, visual] of meters) {
for (const [, health] of players) {
- visual.fillAmount = health.max > 0 ? Math.max(0, health.current / health.max) : 0;
+ const amount = health.max > 0 ? Math.max(0, health.current / health.max) : 0;
+ // ENGINE-GAP(ui-visual-written-at-runtime): writing this every frame
+ // dims the bar, so it is written through insert, only on a change.
+ if (visual.fillAmount !== amount) {
+ world.insert(entity, UIVisual, { ...visual, fillAmount: amount });
+ }
break;
}
}