@moku-labs/game 0.15.104 → 0.15.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10823,7 +10823,10 @@ function createViewRecord(entity, projection, key, item, rest, cause = "mount")
10823
10823
  dropWhenStill: false,
10824
10824
  loopOwed: false,
10825
10825
  exiting: false,
10826
- cause
10826
+ cause,
10827
+ seed: void 0,
10828
+ mask: 0,
10829
+ maskWarned: false
10827
10830
  };
10828
10831
  }
10829
10832
  //#endregion
@@ -11575,6 +11578,8 @@ function routeHint(hints, projection, key) {
11575
11578
  }
11576
11579
  //#endregion
11577
11580
  //#region src/plugins/world/projection/mutes.ts
11581
+ /** The most pairs with a `when` one spec may list: one bit each of a 32-bit mask. */
11582
+ const MOST_WHENS = 32;
11578
11583
  /**
11579
11584
  * Tells a table `mute()` made apart from a shared `initialOnly` seed, which is frozen.
11580
11585
  *
@@ -11614,17 +11619,15 @@ function ownFields(stored) {
11614
11619
  return isOwnFields(stored) ? stored : new Set(stored);
11615
11620
  }
11616
11621
  /**
11617
- * The `initialOnly` fields of one component of a view, from the spec of its projection.
11622
+ * The `initialOnly` fields of one component of a view, from the seed the view was born with.
11618
11623
  *
11619
11624
  * @param state - The projection branch of the plugin state.
11620
11625
  * @param entity - The entity of the view.
11621
11626
  * @param name - The component name.
11622
- * @returns The seed set, or `undefined` for an entity that is no view of such a projection.
11627
+ * @returns The seed set, or `undefined` for an entity that is no view, or one no pair covers.
11623
11628
  */
11624
11629
  function initialFieldsOf(state, entity, name) {
11625
- const projection = state.byEntity.get(entity)?.projection;
11626
- const spec = projection === void 0 ? void 0 : state.specs.get(projection);
11627
- return spec === void 0 ? void 0 : state.initialOnly.get(spec)?.get(name);
11630
+ return state.byEntity.get(entity)?.seed?.get(name);
11628
11631
  }
11629
11632
  /**
11630
11633
  * Deletes a released field set once it is empty, and the entity's table once no component is
@@ -11644,8 +11647,8 @@ function dropEmptyMute(mutes, entity, table, name, owned) {
11644
11647
  }
11645
11648
  /**
11646
11649
  * Hands fields of one component of one entity to another writer, until the remover runs. A view
11647
- * born with an `initialOnly` seed gets its own copy first. The remover keeps the seed fields, asked
11648
- * when it runs: a mute made inside the spawn came before the view was known.
11650
+ * born with an `initialOnly` seed gets its own copy first. The remover keeps the fields of the
11651
+ * view's seed, asked when it runs: a mute made inside the spawn came before the view was known.
11649
11652
  *
11650
11653
  * @param state - The projection branch of the plugin state.
11651
11654
  * @param entity - The entity.
@@ -11671,39 +11674,141 @@ function muteFields(state, entity, name, fields) {
11671
11674
  };
11672
11675
  }
11673
11676
  /**
11674
- * Builds the frozen seed of a projection's `initialOnly` list: component name to its fields, a
11675
- * component named twice with both lists joined.
11677
+ * Checks one pair of a spec's `initialOnly` list.
11676
11678
  *
11677
11679
  * @param spec - The projection spec.
11678
- * @param pairs - Its `initialOnly` list, not empty.
11679
- * @returns The seed.
11680
- * @throws {Error} For a pair with no field.
11680
+ * @param pair - The pair.
11681
+ * @throws {Error} For a pair with no field, and for a third element that is no function.
11681
11682
  */
11682
- function buildSeed(spec, pairs) {
11683
+ function checkPair(spec, pair) {
11684
+ const [component, fields, when] = pair;
11685
+ const name = component.componentName;
11686
+ if (fields.length === 0) throw new Error(`[game] Projection "${spec.name}" lists ${name} in initialOnly with no field.\n Name the fields only the birth of a view writes, or drop the pair.`);
11687
+ if (pair.length > 2 && typeof when !== "function") throw new Error(`[game] Projection "${spec.name}" lists ${name} in initialOnly with a "when" that is no function.\n Give a function of the item, or drop the third element.`);
11688
+ }
11689
+ /**
11690
+ * The indices of the pairs with a `when`, in order.
11691
+ *
11692
+ * @param spec - The projection spec.
11693
+ * @param pairs - Its checked `initialOnly` list.
11694
+ * @returns The indices.
11695
+ * @throws {Error} For more pairs with a `when` than a mask holds.
11696
+ */
11697
+ function asksOf(spec, pairs) {
11698
+ const asks = [];
11699
+ for (const [index, pair] of pairs.entries()) if (pair[2] !== void 0) asks.push(index);
11700
+ if (asks.length > MOST_WHENS) throw new Error(`[game] Projection "${spec.name}" lists ${asks.length} initialOnly pairs with a "when".\n Join pairs that ask the same, to ${MOST_WHENS} at most.`);
11701
+ return asks;
11702
+ }
11703
+ /**
11704
+ * Builds the frozen seed of one answer mask: component name to its fields, from the pairs without
11705
+ * a `when` and the pairs whose bit is set, a component named twice with both lists joined.
11706
+ *
11707
+ * @param book - The seed book of the spec.
11708
+ * @param mask - The answers, bit i for the i-th pair with a `when`.
11709
+ * @returns The seed, or `undefined` when the mask covers no pair.
11710
+ */
11711
+ function buildSeed(book, mask) {
11683
11712
  const seed = /* @__PURE__ */ new Map();
11684
- for (const [component, fields] of pairs) {
11713
+ let whenBit = 0;
11714
+ for (const [component, fields, when] of book.pairs) {
11715
+ if (when !== void 0) {
11716
+ const covered = (mask & 1 << whenBit) !== 0;
11717
+ whenBit += 1;
11718
+ if (!covered) continue;
11719
+ }
11685
11720
  const name = component.componentName;
11686
- if (fields.length === 0) throw new Error(`[game] Projection "${spec.name}" lists ${name} in initialOnly with no field.\n Name the fields only the birth of a view writes, or drop the pair.`);
11687
11721
  seed.set(name, Object.freeze(/* @__PURE__ */ new Set([...seed.get(name) ?? [], ...fields])));
11688
11722
  }
11689
- return Object.freeze(seed);
11723
+ return seed.size === 0 ? void 0 : Object.freeze(seed);
11690
11724
  }
11691
11725
  /**
11692
- * Checks the `initialOnly` list of a spec and keeps its seed: once per spec, since a name is
11693
- * registered once and `replace` brings a new spec. A spec without the option, or with an empty
11694
- * list, has none.
11726
+ * The seed of one answer mask, built the first time a view is born with it, then the same table.
11727
+ *
11728
+ * @param book - The seed book of the spec.
11729
+ * @param mask - The answers.
11730
+ * @returns The shared seed, or `undefined` for a mask that covers no pair.
11731
+ */
11732
+ function seedFor(book, mask) {
11733
+ if (book.seeds.has(mask)) return book.seeds.get(mask);
11734
+ const seed = buildSeed(book, mask);
11735
+ book.seeds.set(mask, seed);
11736
+ return seed;
11737
+ }
11738
+ /**
11739
+ * Creates the empty seed table of a book. It lives in its own non-exported function because lint
11740
+ * rule L5 refuses a collection built inside an exported declaration.
11741
+ *
11742
+ * @returns An empty table of mask to seed.
11743
+ */
11744
+ function emptySeeds() {
11745
+ return /* @__PURE__ */ new Map();
11746
+ }
11747
+ /**
11748
+ * Checks the `initialOnly` list of a spec and makes its seed book, keeping nothing. A spec whose
11749
+ * pairs have no `when` gets the one seed of mask 0 now, as before.
11695
11750
  *
11696
- * @param state - The projection branch of the plugin state.
11697
11751
  * @param spec - The spec `register` or `replace` stores.
11698
- * @returns The seed, or `undefined`.
11699
- * @throws {Error} For a pair with no field; nothing is kept then.
11752
+ * @returns The book, or `undefined` for a spec without the option or with an empty list.
11753
+ * @throws {Error} For a pair with no field, a `when` that is no function, or too many `when`s.
11700
11754
  */
11701
- function learnSeed(state, spec) {
11755
+ function checkBook(spec) {
11702
11756
  const pairs = spec.initialOnly;
11703
11757
  if (pairs === void 0 || pairs.length === 0) return void 0;
11704
- const seed = buildSeed(spec, pairs);
11705
- state.initialOnly.set(spec, seed);
11706
- return seed;
11758
+ for (const pair of pairs) checkPair(spec, pair);
11759
+ const book = {
11760
+ pairs,
11761
+ asks: asksOf(spec, pairs),
11762
+ seeds: emptySeeds()
11763
+ };
11764
+ if (book.asks.length === 0) seedFor(book, 0);
11765
+ return book;
11766
+ }
11767
+ /**
11768
+ * Checks the `initialOnly` list of a spec and keeps its seed book: once per spec, since a name is
11769
+ * registered once and `replace` brings a new spec.
11770
+ *
11771
+ * @param state - The projection branch of the plugin state.
11772
+ * @param spec - The spec `register` stores.
11773
+ * @throws {Error} For a pair with no field, a `when` that is no function, or too many `when`s;
11774
+ * nothing is kept then.
11775
+ */
11776
+ function learnSeed(state, spec) {
11777
+ const book = checkBook(spec);
11778
+ if (book !== void 0) state.initialOnly.set(spec, book);
11779
+ }
11780
+ /**
11781
+ * Asks the `when`s of a book on one item.
11782
+ *
11783
+ * @param book - The seed book of the spec, if it has one.
11784
+ * @param item - The item.
11785
+ * @returns The answers, bit i set when the i-th `when` answers true; 0 with no book or no `when`.
11786
+ * @throws {Error} What a `when` throws.
11787
+ */
11788
+ function maskOfBook(book, item) {
11789
+ if (book === void 0) return 0;
11790
+ const { asks, pairs } = book;
11791
+ const count = asks.length;
11792
+ let mask = 0;
11793
+ for (let bit = 0; bit < count; bit += 1) {
11794
+ const when = pairs[asks[bit] ?? 0]?.[2];
11795
+ if (when?.(item) === true) mask |= 1 << bit;
11796
+ }
11797
+ return mask;
11798
+ }
11799
+ /**
11800
+ * The answers a view is born with: the `when`s of its projection asked on the item it is born
11801
+ * with. Asked before the spawn, so a `when` that throws spawns nothing, as a `view` that throws.
11802
+ *
11803
+ * @param state - The projection branch of the plugin state.
11804
+ * @param spec - The projection spec.
11805
+ * @param item - The item of the birth: the model item, or the warm item for a warm build.
11806
+ * @returns The mask; 0 for a spec without a `when`.
11807
+ * @throws {Error} What a `when` throws.
11808
+ */
11809
+ function birthMask(state, spec, item) {
11810
+ if (spec.initialOnly === void 0) return 0;
11811
+ return maskOfBook(state.initialOnly.get(spec), item);
11707
11812
  }
11708
11813
  /**
11709
11814
  * Joins a seed into a table of the entity's own, in place, so the remover of every mute that wrote
@@ -11728,26 +11833,58 @@ function joinSeed(state, table, seed) {
11728
11833
  }
11729
11834
  }
11730
11835
  /**
11731
- * Gives a view that was just born the seed of its projection, so from now on nothing of the
11732
- * projection writes or compares those fields. The birth itself wrote them from `view`. A view a
11733
- * listener of its spawn muted already keeps its table, and the seed joins it.
11836
+ * Gives a view that was just born the seed of its answers (`view.mask`), so from now on nothing of
11837
+ * the projection writes or compares those fields. The birth itself wrote them from `view`. The
11838
+ * view keeps the seed. A view a listener of its spawn muted already keeps its table, and the seed
11839
+ * joins it.
11734
11840
  *
11735
11841
  * @param state - The projection branch of the plugin state.
11736
11842
  * @param spec - The projection spec.
11737
- * @param entity - The entity of the new view.
11843
+ * @param view - The new view, its mask set.
11738
11844
  */
11739
- function seedMutes(state, spec, entity) {
11845
+ function seedMutes(state, spec, view) {
11740
11846
  if (spec.initialOnly === void 0) return;
11741
- const seed = state.initialOnly.get(spec);
11847
+ const book = state.initialOnly.get(spec);
11848
+ const seed = book === void 0 ? void 0 : seedFor(book, view.mask);
11742
11849
  if (seed === void 0) return;
11743
- const stored = state.mutes.get(entity);
11850
+ view.seed = seed;
11851
+ const stored = state.mutes.get(view.entity);
11744
11852
  if (stored === void 0) {
11745
- state.mutes.set(entity, seed);
11853
+ state.mutes.set(view.entity, seed);
11746
11854
  return;
11747
11855
  }
11748
11856
  const table = ownTable(stored);
11749
11857
  joinSeed(state, table, seed);
11750
- state.mutes.set(entity, table);
11858
+ state.mutes.set(view.entity, table);
11859
+ }
11860
+ /**
11861
+ * The dev check after a view took a new item: when the `when`s of its projection answer otherwise
11862
+ * on it than at the birth, `world:initial-only-changed` is warned, once per view. Nothing changes
11863
+ * in the view. A release build asks nothing: the guard is inline, so a `define` of `false` folds
11864
+ * it. A `when` that throws here warns nothing: the reconcile of a dev build stops nowhere a release
11865
+ * build goes on.
11866
+ *
11867
+ * @param pctx - Domain context of the projection module.
11868
+ * @param spec - The projection spec.
11869
+ * @param view - The view, its item the new one.
11870
+ */
11871
+ function checkDrift(pctx, spec, view) {
11872
+ if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) return;
11873
+ if (view.maskWarned || spec.initialOnly === void 0) return;
11874
+ const book = pctx.ctx.state.projection.initialOnly.get(spec);
11875
+ if (book === void 0 || book.asks.length === 0) return;
11876
+ let mask;
11877
+ try {
11878
+ mask = maskOfBook(book, view.item);
11879
+ } catch {
11880
+ return;
11881
+ }
11882
+ if (mask === view.mask) return;
11883
+ view.maskWarned = true;
11884
+ pctx.ctx.log.warn("world:initial-only-changed", {
11885
+ projection: spec.name,
11886
+ key: view.key
11887
+ });
11751
11888
  }
11752
11889
  /**
11753
11890
  * Moves a view with a table of its own from one seed to the next: a set of the old seed goes, the
@@ -11757,7 +11894,7 @@ function seedMutes(state, spec, entity) {
11757
11894
  * @param state - The projection branch of the plugin state.
11758
11895
  * @param entity - The entity of the view.
11759
11896
  * @param stored - The table the view has now, if any.
11760
- * @param from - The seed of the old spec, if any.
11897
+ * @param from - The seed the view held, if any.
11761
11898
  * @param to - The seed of the new spec, if any.
11762
11899
  */
11763
11900
  function reseedOwn(state, entity, stored, from, to) {
@@ -11768,24 +11905,54 @@ function reseedOwn(state, entity, stored, from, to) {
11768
11905
  else state.mutes.set(entity, table);
11769
11906
  }
11770
11907
  /**
11771
- * Moves the views of a replaced projection from the seed of the old spec to the seed of the new
11772
- * one. A view that holds the old seed, or none when the old spec had none, takes the new seed. A
11773
- * view a `mute()` gave its own table keeps it: the sets of the old seed in it go, the new seed
11774
- * joins it.
11908
+ * Moves one view from the seed it holds to a new one. A view that holds its seed, or none, takes
11909
+ * the new seed. A view a `mute()` gave its own table keeps it: the sets of the old seed in it go,
11910
+ * the new seed joins it.
11775
11911
  *
11776
11912
  * @param state - The projection branch of the plugin state.
11777
- * @param name - The projection name.
11778
- * @param from - The seed of the old spec, if any.
11779
- * @param to - The seed of the new spec, if any.
11913
+ * @param view - The view.
11914
+ * @param to - The new seed, if any.
11780
11915
  */
11781
- function reseedViews(state, name, from, to) {
11916
+ function reseedView(state, view, to) {
11917
+ const from = view.seed;
11918
+ view.seed = to;
11782
11919
  if (from === to) return;
11783
- for (const view of state.byEntity.values()) {
11784
- if (view.projection !== name) continue;
11785
- const stored = state.mutes.get(view.entity);
11786
- if (stored !== from) reseedOwn(state, view.entity, stored, from, to);
11787
- else if (to === void 0) state.mutes.delete(view.entity);
11788
- else state.mutes.set(view.entity, to);
11920
+ const stored = state.mutes.get(view.entity);
11921
+ if (stored !== from) reseedOwn(state, view.entity, stored, from, to);
11922
+ else if (to === void 0) state.mutes.delete(view.entity);
11923
+ else state.mutes.set(view.entity, to);
11924
+ }
11925
+ /**
11926
+ * The views of one projection, in the order of `byEntity`.
11927
+ *
11928
+ * @param state - The projection branch of the plugin state.
11929
+ * @param name - The projection name.
11930
+ * @returns A new list.
11931
+ */
11932
+ function viewsOf(state, name) {
11933
+ const views = [];
11934
+ for (const view of state.byEntity.values()) if (view.projection === name) views.push(view);
11935
+ return views;
11936
+ }
11937
+ /**
11938
+ * Replaces the `initialOnly` of a registered projection: checks the new spec, asks its `when`s on
11939
+ * the item every view of the projection shows now, then keeps its seed book and moves each view
11940
+ * from the seed it holds to the seed of its new answers. Every mask is asked before anything
11941
+ * moves, so a `when` that throws leaves the state as it was.
11942
+ *
11943
+ * @param state - The projection branch of the plugin state.
11944
+ * @param spec - The new spec, not yet stored.
11945
+ * @throws {Error} For a spec `learnSeed` refuses, and what a `when` throws; nothing moves then.
11946
+ */
11947
+ function replaceSeed(state, spec) {
11948
+ const book = checkBook(spec);
11949
+ const views = viewsOf(state, spec.name);
11950
+ const masks = views.map((view) => maskOfBook(book, view.item));
11951
+ if (book !== void 0) state.initialOnly.set(spec, book);
11952
+ for (const [index, view] of views.entries()) {
11953
+ const mask = masks[index] ?? 0;
11954
+ view.mask = mask;
11955
+ reseedView(state, view, book === void 0 ? void 0 : seedFor(book, mask));
11789
11956
  }
11790
11957
  }
11791
11958
  //#endregion
@@ -12094,19 +12261,22 @@ function coolShown(state, name, view) {
12094
12261
  /**
12095
12262
  * Writes the difference between a view's rest pose and a new output of `view` straight onto its entity: added and
12096
12263
  * changed components are written, removed ones taken off, no hook runs and no motion plays. The direct write of a
12097
- * changed item, for a held view and for the one the open shows.
12264
+ * changed item, for a held view and for the one the open shows. The view takes the new item, so a dev build checks
12265
+ * the `initialOnly` answers of its birth against it (`checkDrift`).
12098
12266
  *
12099
12267
  * @param pctx - Domain context of the projection module.
12268
+ * @param spec - The projection spec.
12100
12269
  * @param view - The view.
12101
12270
  * @param next - The new output of `view(item)`, by component name.
12102
12271
  * @param item - The item it was made from.
12103
12272
  */
12104
- function writeDifference(pctx, view, next, item) {
12273
+ function writeDifference(pctx, spec, view, next, item) {
12105
12274
  const { changed } = diffComponents(view.rest, next, pctx.deps.components.Tree.componentName);
12106
12275
  for (const [name, value] of next) if (!view.rest.has(name)) writeValue(pctx, view.entity, value);
12107
12276
  for (const [name, value] of view.rest) if (!next.has(name)) pctx.deps.ecs.remove(view.entity, value.type);
12108
12277
  view.rest = next;
12109
12278
  view.item = item;
12279
+ checkDrift(pctx, spec, view);
12110
12280
  finishHandles(view);
12111
12281
  writeRestNow(pctx, view, changed);
12112
12282
  }
@@ -12204,6 +12374,22 @@ function viewOfItem(pctx, spec, item) {
12204
12374
  }
12205
12375
  }
12206
12376
  /**
12377
+ * Asks the `initialOnly` `when`s of a spec on a warm item. A throw is logged as a projection that failed.
12378
+ *
12379
+ * @param pctx - Domain context of the projection module.
12380
+ * @param spec - The projection spec.
12381
+ * @param item - The warm item.
12382
+ * @returns The answer mask, or `undefined` when a `when` threw.
12383
+ */
12384
+ function maskOfItem(pctx, spec, item) {
12385
+ try {
12386
+ return birthMask(pctx.ctx.state.projection, spec, item);
12387
+ } catch (error) {
12388
+ pctx.ctx.log.error("world:projection-failed", { projection: spec.name }, asError$2(error));
12389
+ return;
12390
+ }
12391
+ }
12392
+ /**
12207
12393
  * Starts the work of a record: it becomes the record in work, `left()` counts the warm budget from the frame rate
12208
12394
  * the loop runs at, and the loop is woken, so the building frames come at the full rate.
12209
12395
  *
@@ -12221,7 +12407,7 @@ function startWork(pctx, record) {
12221
12407
  * Spawns the held view of a warm item, as a scene build spawns a view: bare, flagged held, then its `Layer` and its
12222
12408
  * view components, so an `onAdded` hook already asks `isBuilding` true, and with `"change"` as its cause, so its
12223
12409
  * enter plays when it is shown. The record is in work from before the spawn: what ui marks in its hooks is the
12224
- * record's. Nothing is spawned when `view` throws.
12410
+ * record's. The `initialOnly` `when`s are asked on the warm item. Nothing is spawned when `view` or a `when` throws.
12225
12411
  *
12226
12412
  * @param pctx - Domain context of the projection module.
12227
12413
  * @param spec - The projection spec.
@@ -12233,12 +12419,15 @@ function startWork(pctx, record) {
12233
12419
  function spawnWarm(pctx, spec, record, warm) {
12234
12420
  const values = viewOfItem(pctx, spec, warm.item);
12235
12421
  if (values === void 0) return;
12422
+ const mask = maskOfItem(pctx, spec, warm.item);
12423
+ if (mask === void 0) return;
12236
12424
  const state = pctx.ctx.state.projection;
12237
12425
  startWork(pctx, record);
12238
12426
  const entity = spawnFlagged(pctx, spec, values, state.warmHeld);
12239
12427
  const view = createViewRecord(entity, spec.name, warm.key, warm.item, values, "change");
12240
12428
  record.entities.add(entity);
12241
- seedMutes(state, spec, entity);
12429
+ view.mask = mask;
12430
+ seedMutes(state, spec, view);
12242
12431
  state.byEntity.set(entity, view);
12243
12432
  record.view = view;
12244
12433
  record.key = warm.key;
@@ -12267,7 +12456,7 @@ function refreshWarm(pctx, spec, record, warm) {
12267
12456
  return true;
12268
12457
  }
12269
12458
  startWork(pctx, record);
12270
- writeDifference(pctx, view, next, warm.item);
12459
+ writeDifference(pctx, spec, view, next, warm.item);
12271
12460
  record.item = warm.item;
12272
12461
  return true;
12273
12462
  }
@@ -12456,6 +12645,7 @@ function playEnter$1(pctx, spec, view, entry) {
12456
12645
  function enterEntry(pctx, spec, mounted, entry) {
12457
12646
  const values = collectView(pctx, spec, entry.item);
12458
12647
  const state = pctx.ctx.state.projection;
12648
+ const mask = birthMask(state, spec, entry.item);
12459
12649
  const building = state.building;
12460
12650
  let entity;
12461
12651
  if (building?.mounted.get(spec.name) === mounted) entity = spawnFlagged(pctx, spec, values, building.entities);
@@ -12467,7 +12657,8 @@ function enterEntry(pctx, spec, mounted, entry) {
12467
12657
  }, [layer, ...values.values()]);
12468
12658
  }
12469
12659
  const view = createViewRecord(entity, spec.name, entry.key, entry.item, values, entry.direct ? "mount" : "change");
12470
- seedMutes(state, spec, entity);
12660
+ view.mask = mask;
12661
+ seedMutes(state, spec, view);
12471
12662
  mounted.live.set(entry.key, view);
12472
12663
  state.byEntity.set(entity, view);
12473
12664
  state.membershipVersion += 1;
@@ -12495,8 +12686,10 @@ function adoptEntry(pctx, spec, mounted, record, entry) {
12495
12686
  const view = record.view;
12496
12687
  const next = sameItem(record.item, entry.item) ? void 0 : collectView(pctx, spec, entry.item);
12497
12688
  showHeld$1(pctx, mounted, record, entry.direct ? "mount" : "change");
12498
- if (next === void 0) view.item = entry.item;
12499
- else writeDifference(pctx, view, next, entry.item);
12689
+ if (next === void 0) {
12690
+ view.item = entry.item;
12691
+ checkDrift(pctx, spec, view);
12692
+ } else writeDifference(pctx, spec, view, next, entry.item);
12500
12693
  playEnter$1(pctx, spec, view, entry);
12501
12694
  }
12502
12695
  /**
@@ -12529,12 +12722,14 @@ function changeEntry(pctx, spec, view, entry) {
12529
12722
  const previous = view.item;
12530
12723
  if (!entry.direct && !entry.force && added.length + changed.length + removed.length === 0) {
12531
12724
  view.item = entry.item;
12725
+ checkDrift(pctx, spec, view);
12532
12726
  return false;
12533
12727
  }
12534
12728
  for (const value of valuesOf(next, added)) writeValue(pctx, view.entity, value);
12535
12729
  for (const value of valuesOf(view.rest, removed)) pctx.deps.ecs.remove(view.entity, value.type);
12536
12730
  view.rest = next;
12537
12731
  view.item = entry.item;
12732
+ checkDrift(pctx, spec, view);
12538
12733
  if (entry.direct) {
12539
12734
  finishHandles(view);
12540
12735
  writeRestNow(pctx, view, [...next.keys()]);
@@ -12585,6 +12780,7 @@ function reviveEntry(pctx, spec, mounted, view, entry) {
12585
12780
  for (const value of valuesOf(view.rest, removed)) pctx.deps.ecs.remove(view.entity, value.type);
12586
12781
  view.rest = next;
12587
12782
  view.item = entry.item;
12783
+ checkDrift(pctx, spec, view);
12588
12784
  if (entry.direct) {
12589
12785
  writeRestNow(pctx, view, [...next.keys()]);
12590
12786
  entry.rewritten.push(view);
@@ -13552,14 +13748,11 @@ function createProjectionApi(ctx, deps) {
13552
13748
  state.specs.set(spec.name, spec);
13553
13749
  },
13554
13750
  replace: (spec) => {
13555
- const previous = state.specs.get(spec.name);
13556
- if (previous === void 0) throw new Error(`[game] Projection "${spec.name}" is not registered.\n Register it before replacing it.`);
13751
+ if (state.specs.get(spec.name) === void 0) throw new Error(`[game] Projection "${spec.name}" is not registered.\n Register it before replacing it.`);
13557
13752
  const mounted = state.mounted.has(spec.name);
13558
13753
  if (mounted) checkLayers(spec, state.layers);
13559
- const from = state.initialOnly.get(previous);
13560
- const seed = learnSeed(state, spec);
13754
+ replaceSeed(state, spec);
13561
13755
  state.specs.set(spec.name, spec);
13562
- reseedViews(state, spec.name, from, seed);
13563
13756
  if (!mounted) return;
13564
13757
  if (spec.warm === void 0 && !state.held.has(spec.name)) forgetWarm(pctx, spec.name);
13565
13758
  else ensureWarm(state, spec);
@@ -17757,19 +17950,17 @@ function endLoan(inputs) {
17757
17950
  inputs?.hold(void 0);
17758
17951
  }
17759
17952
  /**
17760
- * The first enabled slot of a stack, when it reads inputs: the one stage 2 keeps (OQ23-5).
17953
+ * The inputs of the first enabled slot of a stack, when it reads any: the seam stage 2 keeps (OQ23-5). The seam itself,
17954
+ * no object around it: a shaded frame of a view whose filter reads inputs asks twice.
17761
17955
  *
17762
17956
  * @param slots - The record's slots.
17763
- * @returns The slot and its inputs, or `undefined`.
17957
+ * @returns The seam, or `undefined`.
17764
17958
  */
17765
17959
  function firstInputs(slots) {
17766
17960
  for (let index = 0; index < slots.length; index += 1) {
17767
17961
  const slot = slots[index];
17768
17962
  if (slot === void 0 || !slot.filter.enabled) continue;
17769
- return slot.inputs === void 0 ? void 0 : {
17770
- slot,
17771
- inputs: slot.inputs
17772
- };
17963
+ return slot.inputs;
17773
17964
  }
17774
17965
  }
17775
17966
  /**
@@ -17922,7 +18113,7 @@ function sizeTargets(kctx, pixi, record, scales, padding) {
17922
18113
  * Stage 2, the pre-pass result of the first enabled filter with inputs (spec 24 B3.9): the keeper's stand-in is
17923
18114
  * rendered over the picture, its apply draws the chain into engine targets; the version is read after the draw, a
17924
18115
  * scale that changed inside it resizes the targets and draws once more; the filter then holds the results. An empty
17925
- * chain holds nothing.
18116
+ * chain holds nothing. Whatever it draws, no stage 3 drew over it yet (`heldPlaced`).
17926
18117
  *
17927
18118
  * @param kctx - The kept context.
17928
18119
  * @param pixi - The module that draws.
@@ -17936,6 +18127,7 @@ function sizeTargets(kctx, pixi, record, scales, padding) {
17936
18127
  function renderStage2(kctx, pixi, matrices, record, context) {
17937
18128
  const { inputs, resolution, padding } = context;
17938
18129
  const scales = scalesOf(inputs);
18130
+ record.heldPlaced = false;
17939
18131
  if (record.s2Of !== inputs) endLoan(record.s2Of);
17940
18132
  record.s2Of = inputs;
17941
18133
  if (scales === void 0) {
@@ -18000,7 +18192,8 @@ function readsPlace(record) {
18000
18192
  /**
18001
18193
  * Stage 3, the filter output: the stand-in, carrying the record's filters, is rendered at `M3 = translate(Ps, Ps)`
18002
18194
  * into the output texture. A placed filter's origin gets the picture's canvas origin first, `O + Δ`; a local one
18003
- * writes nothing.
18195
+ * writes nothing. A render over held results places them (`heldPlaced`): the filter's apply inside it wrote each
18196
+ * input's scale and clamp for them, which a mesh of the record reads as they stand. A render that failed placed nothing.
18004
18197
  *
18005
18198
  * @param kctx - The kept context.
18006
18199
  * @param pixi - The module that draws.
@@ -18020,7 +18213,9 @@ function renderStage3(kctx, pixi, matrices, record, now) {
18020
18213
  const Ps = key[KEY.Ps] ?? 0;
18021
18214
  if (readsPlace(record)) setOrigins(record.slots, (key[KEY.X0] ?? 0) - Ps + now.tx - (key[KEY.tx] ?? 0), (key[KEY.Y0] ?? 0) - Ps + now.ty - (key[KEY.ty] ?? 0));
18022
18215
  matrices.m3.set(1, 0, 0, 1, Ps, Ps);
18023
- if (!kctx.host.renderTo(standIn, output, matrices.m3, true)) return false;
18216
+ const rendered = kctx.host.renderTo(standIn, output, matrices.m3, true);
18217
+ record.heldPlaced = rendered && record.s2Of !== void 0;
18218
+ if (!rendered) return false;
18024
18219
  key[KEY.r] = now.r;
18025
18220
  key[KEY.P] = now.P;
18026
18221
  key[KEY.s3Tx] = now.tx;
@@ -18416,6 +18611,110 @@ function flushRanges(kctx) {
18416
18611
  state.drawnPictures += range.sprite === void 0 ? 0 : 1;
18417
18612
  }
18418
18613
  }
18614
+ /**
18615
+ * One vector of the group, over an array the caller keeps.
18616
+ *
18617
+ * @param value - The array.
18618
+ * @returns The uniform.
18619
+ */
18620
+ function vector(value) {
18621
+ return {
18622
+ value,
18623
+ type: "vec4<f32>"
18624
+ };
18625
+ }
18626
+ /**
18627
+ * The group of the numbers a filter pass hands a body, under the names Pixi's filter system fills, and the arrays it
18628
+ * reads, typed. Static: a group that is not is uploaded on every draw, and a shaded view changes these only when it
18629
+ * moves or its picture changes size.
18630
+ *
18631
+ * @param pixi - The module that draws.
18632
+ * @returns The group, zeros, and its vectors.
18633
+ */
18634
+ function filterGlobals(pixi) {
18635
+ const vectors = {
18636
+ uInputSize: /* @__PURE__ */ new Float32Array(4),
18637
+ uInputPixel: /* @__PURE__ */ new Float32Array(4),
18638
+ uInputClamp: /* @__PURE__ */ new Float32Array(4),
18639
+ uOutputFrame: /* @__PURE__ */ new Float32Array(4),
18640
+ uGlobalFrame: /* @__PURE__ */ new Float32Array(4),
18641
+ uOutputTexture: /* @__PURE__ */ new Float32Array(4)
18642
+ };
18643
+ return {
18644
+ group: new pixi.UniformGroup({
18645
+ uInputSize: vector(vectors.uInputSize),
18646
+ uInputPixel: vector(vectors.uInputPixel),
18647
+ uInputClamp: vector(vectors.uInputClamp),
18648
+ uOutputFrame: vector(vectors.uOutputFrame),
18649
+ uGlobalFrame: vector(vectors.uGlobalFrame),
18650
+ uOutputTexture: vector(vectors.uOutputTexture)
18651
+ }, { isStatic: true }),
18652
+ vectors
18653
+ };
18654
+ }
18655
+ /**
18656
+ * The unit square of a quad program, its uvs over the whole texture: the mesh's scale gives it its size.
18657
+ *
18658
+ * @param pixi - The module that draws.
18659
+ * @returns A new geometry.
18660
+ */
18661
+ function unitQuad(pixi) {
18662
+ return new pixi.MeshGeometry({
18663
+ positions: new Float32Array([
18664
+ 0,
18665
+ 0,
18666
+ 1,
18667
+ 0,
18668
+ 1,
18669
+ 1,
18670
+ 0,
18671
+ 1
18672
+ ]),
18673
+ uvs: new Float32Array([
18674
+ 0,
18675
+ 0,
18676
+ 1,
18677
+ 0,
18678
+ 1,
18679
+ 1,
18680
+ 0,
18681
+ 1
18682
+ ]),
18683
+ indices: new Uint32Array([
18684
+ 0,
18685
+ 1,
18686
+ 2,
18687
+ 0,
18688
+ 2,
18689
+ 3
18690
+ ])
18691
+ });
18692
+ }
18693
+ /**
18694
+ * The shader of a quad over a texture. `fu` is left out for a filter that binds none: Pixi throws on an undefined
18695
+ * resource. Each input the quad names gets that texture too, its sampler that texture's style, until the kept cache
18696
+ * binds the held result there (`shade.ts`): Pixi builds a group only of what is bound, and a draw over a hole throws.
18697
+ *
18698
+ * @param pixi - The module that draws.
18699
+ * @param quad - The slot's quad.
18700
+ * @param gfu - The global filter uniforms.
18701
+ * @param source - The texture it reads.
18702
+ * @returns The shader.
18703
+ */
18704
+ function quadShader(pixi, quad, gfu, source) {
18705
+ const { program, fu, inputNames = [] } = quad;
18706
+ const resources = {
18707
+ gfu,
18708
+ uTexture: source,
18709
+ uSampler: source.style
18710
+ };
18711
+ if (fu !== void 0) resources.fu = fu;
18712
+ for (const [index, name] of inputNames.entries()) resources[name] = index % 2 === 0 ? source : source.style;
18713
+ return new pixi.Shader({
18714
+ gpuProgram: program,
18715
+ resources
18716
+ });
18717
+ }
18419
18718
  //#endregion
18420
18719
  //#region src/plugins/renderer/kept/drawn-bounds.ts
18421
18720
  /** Every flag of a node's display status: visible, renderable, not culled (Pixi's `localDisplayStatus`). */
@@ -18533,110 +18832,6 @@ function drawnBounds(pixi, top) {
18533
18832
  addDrawn$1(pixi, top, into, 0, top);
18534
18833
  return into;
18535
18834
  }
18536
- /**
18537
- * One vector of the group, over an array the caller keeps.
18538
- *
18539
- * @param value - The array.
18540
- * @returns The uniform.
18541
- */
18542
- function vector(value) {
18543
- return {
18544
- value,
18545
- type: "vec4<f32>"
18546
- };
18547
- }
18548
- /**
18549
- * The group of the numbers a filter pass hands a body, under the names Pixi's filter system fills, and the arrays it
18550
- * reads, typed. Static: a group that is not is uploaded on every draw, and a shaded view changes these only when it
18551
- * moves or its picture changes size.
18552
- *
18553
- * @param pixi - The module that draws.
18554
- * @returns The group, zeros, and its vectors.
18555
- */
18556
- function filterGlobals(pixi) {
18557
- const vectors = {
18558
- uInputSize: /* @__PURE__ */ new Float32Array(4),
18559
- uInputPixel: /* @__PURE__ */ new Float32Array(4),
18560
- uInputClamp: /* @__PURE__ */ new Float32Array(4),
18561
- uOutputFrame: /* @__PURE__ */ new Float32Array(4),
18562
- uGlobalFrame: /* @__PURE__ */ new Float32Array(4),
18563
- uOutputTexture: /* @__PURE__ */ new Float32Array(4)
18564
- };
18565
- return {
18566
- group: new pixi.UniformGroup({
18567
- uInputSize: vector(vectors.uInputSize),
18568
- uInputPixel: vector(vectors.uInputPixel),
18569
- uInputClamp: vector(vectors.uInputClamp),
18570
- uOutputFrame: vector(vectors.uOutputFrame),
18571
- uGlobalFrame: vector(vectors.uGlobalFrame),
18572
- uOutputTexture: vector(vectors.uOutputTexture)
18573
- }, { isStatic: true }),
18574
- vectors
18575
- };
18576
- }
18577
- /**
18578
- * The unit square of a quad program, its uvs over the whole texture: the mesh's scale gives it its size.
18579
- *
18580
- * @param pixi - The module that draws.
18581
- * @returns A new geometry.
18582
- */
18583
- function unitQuad(pixi) {
18584
- return new pixi.MeshGeometry({
18585
- positions: new Float32Array([
18586
- 0,
18587
- 0,
18588
- 1,
18589
- 0,
18590
- 1,
18591
- 1,
18592
- 0,
18593
- 1
18594
- ]),
18595
- uvs: new Float32Array([
18596
- 0,
18597
- 0,
18598
- 1,
18599
- 0,
18600
- 1,
18601
- 1,
18602
- 0,
18603
- 1
18604
- ]),
18605
- indices: new Uint32Array([
18606
- 0,
18607
- 1,
18608
- 2,
18609
- 0,
18610
- 2,
18611
- 3
18612
- ])
18613
- });
18614
- }
18615
- /**
18616
- * The shader of a quad over a texture. `fu` is left out for a filter that binds none: Pixi throws on an undefined
18617
- * resource.
18618
- *
18619
- * @param pixi - The module that draws.
18620
- * @param quad - The slot's quad.
18621
- * @param gfu - The global filter uniforms.
18622
- * @param source - The texture it reads.
18623
- * @returns The shader.
18624
- */
18625
- function quadShader(pixi, quad, gfu, source) {
18626
- const { program, fu } = quad;
18627
- const texture = {
18628
- gfu,
18629
- uTexture: source,
18630
- uSampler: source.style
18631
- };
18632
- return new pixi.Shader({
18633
- gpuProgram: program,
18634
- resources: fu === void 0 ? texture : {
18635
- ...texture,
18636
- fu
18637
- }
18638
- });
18639
- }
18640
18835
  //#endregion
18641
18836
  //#region src/plugins/renderer/kept/shade.ts
18642
18837
  /**
@@ -18646,7 +18841,8 @@ function quadShader(pixi, quad, gfu, source) {
18646
18841
  * Ps)` with no filter, one pass only when the picture, the padding or the resolution changed; a new number is drawn by
18647
18842
  * the mesh with no pass at all. The renderer holds no shader text: `effects` hands a built program over the slot. The
18648
18843
  * policy of the mode, when it is entered and left, lives in `record.ts`; this file holds what is made, bound and freed.
18649
- * The filter's uniform group is the instance's own, read by the mesh as it stands.
18844
+ * The filter's uniform group is the instance's own, read by the mesh as it stands. A filter that reads inputs binds the
18845
+ * record's held stage 2 results under the names its quad gives (F126 stage 4).
18650
18846
  */
18651
18847
  /** The numbers `renderShade` wants in the group this frame, in the order of `writeGlobals`. One array: it allocates nothing. */
18652
18848
  const WANTED = /* @__PURE__ */ new Float32Array(24);
@@ -18810,6 +19006,27 @@ function rebuildShader(pixi, shade, quad, source) {
18810
19006
  old.destroy();
18811
19007
  }
18812
19008
  /**
19009
+ * Binds the record's held stage 2 results under the names of each input the quad gives, its texture then its sampler,
19010
+ * written only where they differ: a write Pixi takes as a change of the group, which it builds again. An input with no
19011
+ * result held binds the texture the shader reads (`shade.source`): the mesh never holds a released one, which is
19012
+ * destroyed. Indexed, allocates nothing.
19013
+ *
19014
+ * @param shade - The shade, its shader on the slot's quad and its source the output's.
19015
+ * @param record - The record.
19016
+ */
19017
+ function bindHeld(shade, record) {
19018
+ const names = shade.quad.inputNames;
19019
+ if (names === void 0) return;
19020
+ const { resources } = shade.shader;
19021
+ for (let input = 0; 2 * input + 1 < names.length; input += 1) {
19022
+ const texture = names[2 * input];
19023
+ const sampler = names[2 * input + 1];
19024
+ const source = record.s2[input]?.source ?? shade.source;
19025
+ if (texture !== void 0 && resources[texture] !== source) resources[texture] = source;
19026
+ if (sampler !== void 0 && resources[sampler] !== source.style) resources[sampler] = source.style;
19027
+ }
19028
+ }
19029
+ /**
18813
19030
  * Copies a vector of `WANTED` into the group where it differs. Both sides are 32-bit numbers: a double would differ from
18814
19031
  * its stored value in every frame, and the group would be uploaded in every frame.
18815
19032
  *
@@ -18908,10 +19125,10 @@ function copyPadded(kctx, pixi, matrices, record, output) {
18908
19125
  }
18909
19126
  /**
18910
19127
  * The frame of a shaded record: stage 3 for the mesh. The output at its size, the shader on the slot's quad and on that
18911
- * texture, the padded picture copied when `s1`, the padding or the resolution changed (one pass, counted), the global
18912
- * uniforms, then `keptOrigin` at 0: in the mode the place is in `uOutputFrame.xy`, so `canvasPixel` and a body that reads
18913
- * the frame answer the same. The keys stage 3 writes. A new number needs none of it: the mesh reads the instance's own
18914
- * uniform group. Allocates nothing while the size stands.
19128
+ * texture, the held results of its inputs bound, the padded picture copied when `s1`, the padding or the resolution
19129
+ * changed (one pass, counted), the global uniforms, then `keptOrigin` at 0: in the mode the place is in `uOutputFrame.xy`,
19130
+ * so `canvasPixel` and a body that reads the frame answer the same. The keys stage 3 writes. A new number needs none of
19131
+ * it: the mesh reads the instance's own uniform group. Allocates nothing while the size stands.
18915
19132
  *
18916
19133
  * @param kctx - The kept context.
18917
19134
  * @param pixi - The module that draws.
@@ -18938,6 +19155,7 @@ function renderShade(kctx, pixi, matrices, record, now) {
18938
19155
  shade.source = source;
18939
19156
  shade.copied = -1;
18940
19157
  }
19158
+ bindHeld(shade, record);
18941
19159
  const resized = source.pixelWidth !== shade.copiedWidth || source.pixelHeight !== shade.copiedHeight;
18942
19160
  if ((shade.copied !== record.s1Version || resized) && !copyPadded(kctx, pixi, matrices, record, output)) return false;
18943
19161
  writeGlobals(kctx, record, shade, source, now);
@@ -19327,10 +19545,10 @@ function drawsDirect(stack) {
19327
19545
  }
19328
19546
  /**
19329
19547
  * Tells whether the record being stepped may draw through its filter's own body (F126 stage 2): on WebGPU, one enabled
19330
- * filter with a quad, no inputs, on `"inherit"`, at the canvas resolution, and not drawn direct. An `Alpha` beside it does
19331
- * not fit: stage 3 draws `F(A·x)` in stack order, the mesh would draw `A·F(x)`, and for a body that is not alpha-linear
19332
- * the picture would pop at every entry. A top that blends otherwise never gets here: `pictureWhy` refuses it. A mesh
19333
- * destroyed with a parent around it has nothing left to draw on. Allocates nothing.
19548
+ * filter with a quad, on `"inherit"`, at the canvas resolution, not drawn direct, and inputs its mesh may bind
19549
+ * (`inputsFit`). An `Alpha` beside it does not fit: stage 3 draws `F(A·x)` in stack order, the mesh would draw `A·F(x)`,
19550
+ * and for a body that is not alpha-linear the picture would pop at every entry. A top that blends otherwise never gets
19551
+ * here: `pictureWhy` refuses it. A mesh destroyed with a parent around it has nothing left to draw on. Allocates nothing.
19334
19552
  *
19335
19553
  * @param kctx - The kept context.
19336
19554
  * @param record - The record.
@@ -19341,10 +19559,32 @@ function shadeFits(kctx, record, stack) {
19341
19559
  if (kctx.host.kind() !== "webgpu" || stack.enabled !== 1) return false;
19342
19560
  if (stack.rs !== NOW.r || drawsDirect(stack)) return false;
19343
19561
  const slot = enabledSlot(record.slots);
19344
- const bodyOnQuad = slot?.quad !== void 0 && slot.inputs === void 0;
19345
- const followsCanvas = slot?.filter.resolution === "inherit";
19562
+ const quad = slot?.quad;
19563
+ if (slot === void 0 || quad === void 0) return false;
19564
+ const followsCanvas = slot.filter.resolution === "inherit";
19346
19565
  const meshStands = !record.shaded || record.shade?.mesh.destroyed !== true;
19347
- return bodyOnQuad && followsCanvas && meshStands;
19566
+ return followsCanvas && meshStands && inputsFit(record, slot, quad);
19567
+ }
19568
+ /**
19569
+ * Tells whether the inputs of a record's one enabled filter let its mesh draw (F126 stage 4). A filter with none fits
19570
+ * while its quad names none: a game's own slot has no inputs, and names on its quad would bind results nobody drew. One
19571
+ * with inputs fits while its quad names two per input, the record holds a result of each, drawn by this seam over the
19572
+ * picture and the chain as they are (`chainOwed`, which refuses another seam too), and stage 3 drew over them last
19573
+ * (`heldPlaced`): the mesh reads the scale and clamp of each input as stage 3 left them. A body that reads the screen
19574
+ * does not fit with inputs: a change of its chain would leave the mesh for stage 3, which reads the picture's target.
19575
+ * Allocates nothing.
19576
+ *
19577
+ * @param record - The record.
19578
+ * @param slot - Its one enabled slot.
19579
+ * @param quad - The slot's quad.
19580
+ * @returns True when they fit.
19581
+ */
19582
+ function inputsFit(record, slot, quad) {
19583
+ const { inputs } = slot;
19584
+ const names = quad.inputNames?.length ?? 0;
19585
+ if (inputs === void 0) return names === 0;
19586
+ if (record.category === "screen" || names !== 2 * inputs.count) return false;
19587
+ return record.s2.length === inputs.count && record.heldPlaced && !chainOwed(record, inputs);
19348
19588
  }
19349
19589
  /**
19350
19590
  * Tells whether a take the budget refused still does not fit (P6.3); the pool's bytes are the take's to have (F119).
@@ -19642,6 +19882,7 @@ function createRecord$1(kctx, pixi, entity, view, slots, category) {
19642
19882
  s2InputsVersion: 0,
19643
19883
  s2PictureVersion: 0,
19644
19884
  s2Of: void 0,
19885
+ heldPlaced: false,
19645
19886
  dirtyS1: true,
19646
19887
  dirtyS2: false,
19647
19888
  dirtyS3: false,
@@ -19813,9 +20054,9 @@ function neededBytes(record, now, box) {
19813
20054
  const { w1, h1, Ps } = box;
19814
20055
  let bytes = textureBytes(w1, h1, now.rs);
19815
20056
  if (!drawsDirect(now)) bytes += textureBytes(w1 + 2 * Ps, h1 + 2 * Ps, now.r);
19816
- const first = firstInputs(record.slots);
19817
- if (first !== void 0) for (let index = 0; index < first.inputs.count; index += 1) {
19818
- const scale = first.inputs.scaleOf(index) ?? 0;
20057
+ const inputs = firstInputs(record.slots);
20058
+ if (inputs !== void 0) for (let index = 0; index < inputs.count; index += 1) {
20059
+ const scale = inputs.scaleOf(index) ?? 0;
19819
20060
  bytes += textureBytes(w1 + 2 * now.P, h1 + 2 * now.P, now.rs * scale);
19820
20061
  }
19821
20062
  return bytes;
@@ -19996,7 +20237,9 @@ function isEmptyBounds(bounds) {
19996
20237
  /**
19997
20238
  * Renders the stages of a take whose keys are written: the subtree picture, the pre-pass results of the first filter
19998
20239
  * with inputs, the filter output; the budget counts the textures after. A live view whose take failed draws live
19999
- * again: its filters go back on its top.
20240
+ * again: its filters go back on its top. A record on its mesh whose filter reads inputs leaves it after stage 2 and
20241
+ * draws stage 3 over the new results: the mesh would read their scale and clamp before any stage 3 wrote them. The
20242
+ * next frame's refresh puts one that may draw no other way back on the mesh.
20000
20243
  *
20001
20244
  * @param kctx - The kept context.
20002
20245
  * @param pixi - The module that draws.
@@ -20009,7 +20252,7 @@ function isEmptyBounds(bounds) {
20009
20252
  function renderStages(kctx, pixi, matrices, record, view, now) {
20010
20253
  const live = record.mode === "live";
20011
20254
  if (live) handFilters(kctx, pixi, record, view);
20012
- const first = firstInputs(record.slots);
20255
+ const inputs = firstInputs(record.slots);
20013
20256
  let ok = renderStage1(kctx, pixi, matrices, record);
20014
20257
  if (drawsDirect(now)) {
20015
20258
  goDirect(kctx, record);
@@ -20019,12 +20262,13 @@ function renderStages(kctx, pixi, matrices, record, view, now) {
20019
20262
  }
20020
20263
  record.direct = false;
20021
20264
  meshForTake(kctx, pixi, record, ok);
20022
- if (ok && first !== void 0) renderStage2(kctx, pixi, matrices, record, {
20023
- inputs: first.inputs,
20265
+ if (ok && inputs !== void 0) renderStage2(kctx, pixi, matrices, record, {
20266
+ inputs,
20024
20267
  resolution: now.r,
20025
20268
  padding: now.P
20026
20269
  });
20027
20270
  else if (record.s2Of !== void 0) releaseInputs(kctx, record);
20271
+ if (record.shaded && !shadeFits(kctx, record, now)) leaveShade(record);
20028
20272
  if (record.shaded) record.shadedAt = kctx.state.frame;
20029
20273
  ok = ok && (record.shaded ? renderShade : renderStage3)(kctx, pixi, matrices, record, now);
20030
20274
  account(kctx, record);
@@ -20087,7 +20331,8 @@ function goDirect(kctx, record) {
20087
20331
  record.direct = true;
20088
20332
  }
20089
20333
  /**
20090
- * Ends the loan of stage 2 when the first filter with inputs left the stack: the results are destroyed.
20334
+ * Ends the loan of stage 2 when the first filter with inputs left the stack: the results are destroyed, and nothing is
20335
+ * placed any more.
20091
20336
  *
20092
20337
  * @param kctx - The kept context.
20093
20338
  * @param record - The record.
@@ -20095,6 +20340,7 @@ function goDirect(kctx, record) {
20095
20340
  function releaseInputs(kctx, record) {
20096
20341
  endLoan(record.s2Of);
20097
20342
  record.s2Of = void 0;
20343
+ record.heldPlaced = false;
20098
20344
  for (const target of record.s2.splice(0)) dropTexture(kctx, target);
20099
20345
  }
20100
20346
  /**
@@ -20692,7 +20938,7 @@ function outputOwed(record, hold) {
20692
20938
  * @returns The `OWED`.
20693
20939
  */
20694
20940
  function stagesOwed(record, hold) {
20695
- const inputs = firstInputs(record.slots)?.inputs;
20941
+ const inputs = firstInputs(record.slots);
20696
20942
  if (inputs !== void 0 && chainOwed(record, inputs)) return OWED.chain;
20697
20943
  return inputs === void 0 && record.s2Of !== void 0 || outputOwed(record, hold) ? OWED.output : OWED.none;
20698
20944
  }
@@ -20718,7 +20964,9 @@ function refresh$1(kctx, pixi, matrices, record, view, hold) {
20718
20964
  }
20719
20965
  /**
20720
20966
  * Redoes what a record that does not draw direct owes, on its mesh when it is shaded or goes on it now: a stack that
20721
- * stopped fitting leaves and owes stage 3, one at rest may leave, and what is left is today's tail of stage 2 and 3.
20967
+ * stopped fitting leaves and owes stage 3, one at rest may leave, and what is left is today's tail of stage 2 and 3. A
20968
+ * shaded record whose filter's chain is owed no longer fits: it leaves and draws stages 2 and 3 on its sprite, and comes
20969
+ * back by the count of its outputs.
20722
20970
  *
20723
20971
  * @param kctx - The kept context.
20724
20972
  * @param pixi - The module that draws.
@@ -20741,7 +20989,7 @@ function refreshOutput(kctx, pixi, matrices, record, view, hold) {
20741
20989
  retakeOrGoLive(kctx, pixi, matrices, record, view, why);
20742
20990
  return true;
20743
20991
  }
20744
- const inputs = firstInputs(record.slots)?.inputs;
20992
+ const inputs = firstInputs(record.slots);
20745
20993
  if (inputs === void 0 && record.s2Of !== void 0) releaseInputs(kctx, record);
20746
20994
  record.direct = false;
20747
20995
  if (!unfit && enterShadeWhenDue(kctx, pixi, record, owed, fits)) {
@@ -48088,20 +48336,23 @@ function uniformStruct(uniforms, group = 1) {
48088
48336
  return `struct FilterUniforms {\n${uniforms.map((uniform) => ` ${uniform.name}: ${uniform.type},\n`).join("")}};\n\n@group(${group}) @binding(0) var<uniform> fu: FilterUniforms;\n`;
48089
48337
  }
48090
48338
  /**
48091
- * The engine's half of each input: the texture and the sampler in `@group(1)` after `fu`, and the function that
48092
- * reads the input at the body's uv, its scale and its clamp applied. Nothing without inputs.
48339
+ * The engine's half of each input: the texture and the sampler in the group of `fu`, after it (input `k` at bindings
48340
+ * `1 + 2k` and `2 + 2k`), and the function that reads the input at the body's uv, its scale and its clamp applied.
48341
+ * Nothing without inputs.
48093
48342
  *
48094
48343
  * @param inputs - The inputs in declaration order.
48344
+ * @param group - The bind group of `fu` and the inputs: 1 in a filter's source, 3 in a quad program's.
48095
48345
  * @returns The WGSL lines, or `""`.
48096
48346
  * @example
48097
48347
  * ```ts
48098
- * const soft = { name: "soft", from: "input", texture: "uSoft", sampler: "uSoftSampler", sample: "sampleSoft", scale: { name: "softScale", type: "f32", form: "number", size: 1 }, clamp: { name: "softClamp", type: "vec4<f32>", form: "vector", size: 4 }, stages: [], chain: () => [] } as const;
48348
+ * const soft = { name: "soft", from: "input", texture: "softTexture", sampler: "softSampler", sample: "sampleSoft", scale: { name: "softScale", type: "vec2<f32>", form: "vector", size: 2 }, clamp: { name: "softClamp", type: "vec4<f32>", form: "vector", size: 4 }, stages: [], chain: () => [] } as const;
48099
48349
  *
48100
48350
  * inputBindings([soft]).includes("fn sampleSoft(uv: vec2<f32>) -> vec4<f32>"); // true
48351
+ * inputBindings([soft], 3).startsWith("@group(3) @binding(1) var softTexture: texture_2d<f32>;"); // true
48101
48352
  * ```
48102
48353
  */
48103
- function inputBindings(inputs) {
48104
- return inputs.map((input, index) => `@group(1) @binding(${1 + 2 * index}) var ${input.texture}: texture_2d<f32>;\n@group(1) @binding(${2 + 2 * index}) var ${input.sampler}: sampler;\n\nfn ${input.sample}(uv: vec2<f32>) -> vec4<f32> {\n return textureSampleLevel(${input.texture}, ${input.sampler}, clamp(uv * gfu.uInputSize.xy * fu.${input.scale.name}, fu.${input.clamp.name}.xy, fu.${input.clamp.name}.zw), 0.0);\n}
48354
+ function inputBindings(inputs, group = 1) {
48355
+ return inputs.map((input, index) => `@group(${group}) @binding(${1 + 2 * index}) var ${input.texture}: texture_2d<f32>;\n@group(${group}) @binding(${2 + 2 * index}) var ${input.sampler}: sampler;\n\nfn ${input.sample}(uv: vec2<f32>) -> vec4<f32> {\n return textureSampleLevel(${input.texture}, ${input.sampler}, clamp(uv * gfu.uInputSize.xy * fu.${input.scale.name}, fu.${input.clamp.name}.xy, fu.${input.clamp.name}.zw), 0.0);\n}
48105
48356
 
48106
48357
  `).join("");
48107
48358
  }
@@ -48258,26 +48509,36 @@ function quadBody(wgsl) {
48258
48509
  return found === 1 && !QUAD_REFUSED.test(wgsl.replaceAll(COMMENT$1, "")) ? rewritten : void 0;
48259
48510
  }
48260
48511
  /**
48261
- * The quad program of a filter: the head of the mesh, the uniform struct at group 3 (the uniforms, then the engine's
48262
- * `keptOrigin` of a body that calls `canvasPixel`, as `assemble` lists them, so the struct matches the instance's group
48263
- * member for member: a shader that asks for more than the group holds fails only as an asynchronous GPU validation
48264
- * error, a blank view with nothing in the logs), the `canvasPixel` helper, the body as `filterBody`, the entry point.
48512
+ * The quad program of a filter: the head of the mesh, the uniform struct at group 3 (the uniforms, then the scale and
48513
+ * the clamp of each input, then the engine's `keptOrigin` of a body that calls `canvasPixel`, as `assemble` lists
48514
+ * them, so the struct matches the instance's group member for member: a shader that asks for more than the group holds
48515
+ * fails only as an asynchronous GPU validation error, a blank view with nothing in the logs), each input's texture and
48516
+ * sampler at group 3 after `fu` with its `sample<Name>` helper (the renderer binds the held chain results there), the
48517
+ * `canvasPixel` helper, the body as `filterBody`, the entry point. Without inputs the text is the one of a filter that
48518
+ * reads none.
48265
48519
  *
48266
48520
  * @param uniforms - The uniforms in declaration order.
48267
48521
  * @param body - The fragment body the game wrote.
48268
48522
  * @param origin - The `keptOrigin` uniform, for a body that calls `canvasPixel`.
48523
+ * @param inputs - The inputs in declaration order, each starting from the view's own input; none by default.
48269
48524
  * @returns The WGSL source of both stages, or `undefined` for a body the rewrite does not fit.
48270
48525
  * @example
48271
48526
  * ```ts
48272
48527
  * assembleQuad([], "@fragment fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> { return vec4<f32>(uv, 0.0, 1.0); }")?.includes("fn filterBody(uv: vec2<f32>) -> vec4<f32>"); // true
48273
48528
  * assembleQuad([], "@fragment fn mainFragment(@builtin(position) at: vec4<f32>) -> @location(0) vec4<f32> { return at; }"); // undefined
48529
+ * assembleQuad(Bloom.filter.uniforms, BLOOM_WGSL, undefined, Bloom.filter.inputs)?.includes("@group(3) @binding(2) var brightSampler: sampler;"); // true
48274
48530
  * ```
48275
48531
  */
48276
- function assembleQuad(uniforms, body, origin) {
48532
+ function assembleQuad(uniforms, body, origin, inputs = []) {
48277
48533
  const rewritten = quadBody(body);
48278
48534
  if (rewritten === void 0) return void 0;
48279
- const struct = uniformStruct(origin === void 0 ? uniforms : [...uniforms, origin], 3);
48280
- return `${QUAD_HEADER}${struct}${origin === void 0 ? "" : CANVAS_PIXEL}${rewritten}${QUAD_TAIL}`;
48535
+ const struct = uniformStruct([
48536
+ ...uniforms,
48537
+ ...inputs.flatMap((input) => [input.scale, input.clamp]),
48538
+ ...origin === void 0 ? [] : [origin]
48539
+ ], 3);
48540
+ const helper = origin === void 0 ? "" : CANVAS_PIXEL;
48541
+ return `${QUAD_HEADER}${struct}${inputBindings(inputs, 3)}${helper}${rewritten}${QUAD_TAIL}`;
48281
48542
  }
48282
48543
  //#endregion
48283
48544
  //#region src/plugins/effects/filters/glsl.ts
@@ -48980,7 +49241,7 @@ function defineFilter(id, spec) {
48980
49241
  id,
48981
49242
  source: assemble(uniforms, inputs, spec.wgsl, origin, backdrop),
48982
49243
  glsl: assembleGlsl(uniforms, inputs, spec.glsl, origin, backdrop),
48983
- quadSource: inputs.length === 0 && !backdrop ? assembleQuad(uniforms, spec.wgsl, origin) : void 0,
49244
+ quadSource: !backdrop && inputs.every((input) => input.from === "input") ? assembleQuad(uniforms, spec.wgsl, origin, inputs) : void 0,
48984
49245
  uniforms,
48985
49246
  passes,
48986
49247
  padding,
@@ -50638,21 +50899,34 @@ function createStandIn(ectx, pixi, kind, value) {
50638
50899
  *
50639
50900
  * @param pixi - The module the renderer loaded.
50640
50901
  * @param definition - A definition whose check answered ok.
50641
- * @param program - The quad program of a kind that hands one over, drawn with the probe's own uniform group.
50902
+ * @param program - The quad program of a kind that hands one over, drawn with the probe's own uniform group and the
50903
+ * names of its inputs.
50642
50904
  * @returns The probe's filter, its quad and its teardown.
50643
50905
  */
50644
50906
  function createWarmFilter(pixi, definition, program) {
50645
50907
  const body = createOurs(pixi, definition, PROBE_VALUE);
50908
+ const quad = program === void 0 ? void 0 : {
50909
+ program,
50910
+ fu: body.group,
50911
+ inputNames: quadInputNames(definition)
50912
+ };
50646
50913
  return {
50647
50914
  filter: body.filter,
50648
- quad: program === void 0 ? void 0 : {
50649
- program,
50650
- fu: body.group
50651
- },
50915
+ quad,
50652
50916
  destroy: () => destroyBody(body)
50653
50917
  };
50654
50918
  }
50655
50919
  /**
50920
+ * The resource names a quad binds the held result of each input under: its texture, then its sampler, in declaration
50921
+ * order. Made once with the quad object it goes on, never per frame.
50922
+ *
50923
+ * @param definition - The definition.
50924
+ * @returns The names; empty for a definition without inputs.
50925
+ */
50926
+ function quadInputNames(definition) {
50927
+ return definition.inputs.flatMap((input) => [input.texture, input.sampler]);
50928
+ }
50929
+ /**
50656
50930
  * Compares a vector uniform with a list of numbers element by element and writes the elements that
50657
50931
  * differ: the indices `set(vector.slice(0, size))` would write, without the slice.
50658
50932
  *
@@ -51848,7 +52122,7 @@ function quadProgramFor(ectx, pixi, instance) {
51848
52122
  }
51849
52123
  /**
51850
52124
  * What an instance's slot carries for the quad, one object for the instance's life: the renderer builds its shader
51851
- * again for another one.
52125
+ * again for another one. It names each input the mesh binds a held chain result under (none for a filter without).
51852
52126
  *
51853
52127
  * @param ectx - Domain context of the effects plugin.
51854
52128
  * @param pixi - The module the renderer loaded.
@@ -51861,7 +52135,8 @@ function quadOf(ectx, pixi, instance) {
51861
52135
  if (program === void 0) return void 0;
51862
52136
  instance.quad ??= {
51863
52137
  program,
51864
- fu: instance.group
52138
+ fu: instance.group,
52139
+ inputNames: quadInputNames(instance.definition)
51865
52140
  };
51866
52141
  return instance.quad;
51867
52142
  }
@@ -74901,7 +75176,8 @@ function scenesFor() {
74901
75176
  * Types a projection: keyed items of the model turned into entities. `Item` is inferred from the
74902
75177
  * return of `from` and reaches `key`, `view` and every motion hook; `layer` and `lift` stay
74903
75178
  * literal, so `defineScene` can check them against the layers of the scene. Each pair of
74904
- * `initialOnly` has its field names checked against its own component.
75179
+ * `initialOnly` has its field names checked against its own component, and its `when`, if any,
75180
+ * takes the item.
74905
75181
  *
74906
75182
  * @param spec - Name, layer, optional lift layer, `from`, `key`, `view`, the motion hooks and
74907
75183
  * the `initialOnly` fields.
@@ -75536,8 +75812,9 @@ const BloomBlur = /*#__PURE__*/ defineFilter("effects.bloomBlur", {
75536
75812
  /**
75537
75813
  * @file effects/set — `Bloom`: light around the bright parts of a view. The one member with a chain: its input `bright`
75538
75814
  * is the view's light above `threshold`, cut and boxed down to ¼ (⅛ for a wide radius) in one pass and blurred there in
75539
- * one more; the body adds it back by `strength`. 3 passes at any radius and resolution. A chain member never rides the
75540
- * quad: a value change runs the chain again and redraws the kept picture's filter (stage 3).
75815
+ * one more; the body adds it back by `strength`. 3 passes at any radius and resolution. A change of `strength` rides
75816
+ * the view's quad over the held chain result on WebGPU; one of `threshold` or `radius` runs the chain again and redraws
75817
+ * the kept picture's filter (stage 3).
75541
75818
  */
75542
75819
  /** The most texels the blur's sigma may reach: past it the rings stand too far apart on the boxed-down light. */
75543
75820
  const MAX_SIGMA = 8;
@@ -75629,9 +75906,10 @@ function bloomChain(value, context) {
75629
75906
  * (over the A26's screen its passes fill 1.9 Mpx a frame at 2.625). List it in a feature's `filters`, as a game's own
75630
75907
  * filter. It reads a second texture drawn by a chain of two stages, the light cut and boxed down to ¼ (⅛ when the
75631
75908
  * radius is over 8 texels at ¼: radius 16 at the phone's 2.625, 32 at 2) and blurred there: 3 passes at any radius.
75632
- * A still view is kept as a picture; a tween of any field runs the chain again and redraws the picture's filter, 3
75633
- * passes, in every frame it moves: it never draws on the view's quad. Past a sigma of 8 texels at ⅛ the bloom stops
75634
- * widening.
75909
+ * A still view is kept as a picture. A `strength` tween leaves the chain as it was: on WebGPU the view draws on its own
75910
+ * quad over the held chain result, no pass of its own, and on WebGL it redraws the picture's filter, 3 passes. A
75911
+ * `threshold` or `radius` tween runs the chain again too, in every frame it moves. Past a sigma of 8 texels at ⅛ the
75912
+ * bloom stops widening.
75635
75913
  *
75636
75914
  * @example
75637
75915
  * ```ts