@swf2es/render 0.1.33 → 0.1.35

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.
Files changed (61) hide show
  1. package/dist/commands.d.ts +11 -2
  2. package/dist/commands.d.ts.map +1 -1
  3. package/dist/commands.js +36 -6
  4. package/dist/commands.js.map +1 -1
  5. package/dist/geometry.d.ts +62 -5
  6. package/dist/geometry.d.ts.map +1 -1
  7. package/dist/geometry.js +100 -17
  8. package/dist/geometry.js.map +1 -1
  9. package/dist/index.d.ts +2 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +2 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/measure.d.ts.map +1 -1
  14. package/dist/measure.js +118 -61
  15. package/dist/measure.js.map +1 -1
  16. package/dist/plan.js +4 -4
  17. package/dist/plan.js.map +1 -1
  18. package/dist/registry.d.ts +4 -0
  19. package/dist/registry.d.ts.map +1 -1
  20. package/dist/registry.js +8 -0
  21. package/dist/registry.js.map +1 -1
  22. package/dist/rows.d.ts +8 -0
  23. package/dist/rows.d.ts.map +1 -1
  24. package/dist/rows.js +78 -9
  25. package/dist/rows.js.map +1 -1
  26. package/dist/scene.d.ts +13 -0
  27. package/dist/scene.d.ts.map +1 -1
  28. package/dist/scene.js +73 -0
  29. package/dist/scene.js.map +1 -1
  30. package/dist/spans.d.ts +27 -0
  31. package/dist/spans.d.ts.map +1 -0
  32. package/dist/spans.js +146 -0
  33. package/dist/spans.js.map +1 -0
  34. package/dist/webgl/atlas.d.ts +83 -18
  35. package/dist/webgl/atlas.d.ts.map +1 -1
  36. package/dist/webgl/atlas.js +271 -110
  37. package/dist/webgl/atlas.js.map +1 -1
  38. package/dist/webgl/backend.d.ts +5 -3
  39. package/dist/webgl/backend.d.ts.map +1 -1
  40. package/dist/webgl/backend.js +9 -9
  41. package/dist/webgl/backend.js.map +1 -1
  42. package/dist/webgl/batches.d.ts +36 -11
  43. package/dist/webgl/batches.d.ts.map +1 -1
  44. package/dist/webgl/batches.js +94 -51
  45. package/dist/webgl/batches.js.map +1 -1
  46. package/dist/webgl/draws.js +2 -2
  47. package/dist/webgl/draws.js.map +1 -1
  48. package/package.json +2 -2
  49. package/src/commands.ts +48 -6
  50. package/src/geometry.ts +109 -19
  51. package/src/index.ts +2 -0
  52. package/src/measure.ts +132 -68
  53. package/src/plan.ts +4 -4
  54. package/src/registry.ts +10 -0
  55. package/src/rows.ts +85 -18
  56. package/src/scene.ts +82 -0
  57. package/src/spans.ts +223 -0
  58. package/src/webgl/atlas.ts +321 -120
  59. package/src/webgl/backend.ts +9 -9
  60. package/src/webgl/batches.ts +108 -57
  61. package/src/webgl/draws.ts +2 -2
package/src/geometry.ts CHANGED
@@ -6,6 +6,16 @@ import { type Handle, Registry } from "./registry.js";
6
6
  */
7
7
  export const IDLE_FRAMES = 300;
8
8
 
9
+ /**
10
+ * Frames of the registry (Geometries.frame) a geometry stands copied to the GPU before its
11
+ * arrays are let go of (release): one drawn anew each frame, as a script's drawing redrawn every
12
+ * frame is, goes whole before then, and costs the backend no copy of its indices; copying a
13
+ * thousand such geometries' indices a frame took about a millisecond. An owner that reads a
14
+ * geometry's arrays after adding it does so within these frames, or asks for them again
15
+ * (rebuild).
16
+ */
17
+ export const RELEASE_FRAMES = 3;
18
+
9
19
  /** Floats a vertex of advanced text's glyph quads (GeometryData.glyphs). */
10
20
  export const GLYPH_FLOATS = 18;
11
21
 
@@ -83,12 +93,23 @@ export interface GeometryData {
83
93
  * Every geometry a scene list may name, by id. What goes undrawn for
84
94
  * IDLE_FRAMES is let go of; its owner finds it gone by its handle and adds
85
95
  * it again. The backend takes what was added and removed since it last
86
- * looked (taken), and keeps its own copies.
96
+ * looked (taken), and keeps its own copies: once it has copied a geometry's
97
+ * arrays into a context not known to be lost, the registry lets go of them (release),
98
+ * unless their owner changes them in place (add's `keep`). Nothing else
99
+ * releases them, so a view with no GPU backend, as in node, keeps every
100
+ * geometry's arrays. A reader that needs arrays let go of, a lost context
101
+ * or a CPU rasterizer alike, asks for them again through one entry point,
102
+ * rebuild: the geometry is removed, and its owner adds it again with its
103
+ * arrays as it next draws it, as it does an expired one.
87
104
  */
88
105
  export class Geometries extends Registry {
89
106
  /** Changes only when a handle can have become stale, including expiry and context loss. */
90
107
  removalVersion = 0;
91
108
  private readonly data: (GeometryData | null)[] = [];
109
+ /** Whether each geometry's arrays stay held once copied, as their owner changes them in place (update). */
110
+ private readonly kept: boolean[] = [];
111
+ /** Whether each geometry is flat (GeometryData.flat), its arrays held or not. */
112
+ private readonly flats: boolean[] = [];
92
113
  /** Each geometry's box: its positions' least x and y, then their greatest. */
93
114
  private boxes = new Float32Array(1024);
94
115
  /** Added since the backend last took them. */
@@ -98,10 +119,17 @@ export class Geometries extends Registry {
98
119
  /** Found flat since the backend last took them (markFlat). */
99
120
  flattened: number[] = [];
100
121
 
101
- add(data: GeometryData): GeometryHandle {
122
+ /**
123
+ * `data` added, for the backend to copy. Its arrays are let go of once
124
+ * copied (release) unless `keep`, for an owner that changes them in place
125
+ * (update).
126
+ */
127
+ add(data: GeometryData, keep = false): GeometryHandle {
102
128
  const handle = this.hold(IDLE_FRAMES);
103
129
  const id = handle.id;
104
130
  this.data[id] = data;
131
+ this.kept[id] = keep;
132
+ this.flats[id] = data.flat === true;
105
133
  this.added.push(id);
106
134
  this.measure(id);
107
135
  return handle;
@@ -109,27 +137,98 @@ export class Geometries extends Registry {
109
137
 
110
138
  /**
111
139
  * Geometry `id`'s arrays changed in place, their lengths as they were: its
112
- * box measured again, and its vertices copied again where they lie.
140
+ * box measured again, and its vertices copied again where they lie. Only
141
+ * for a geometry added to be kept, and only its vertices: the backend
142
+ * keeps the indices it was added with (the atlas's Place.local).
113
143
  */
114
144
  update(id: number): void {
115
- if (this.data[id]) {
145
+ if (this.data[id] && this.kept[id]) {
116
146
  this.measure(id);
117
147
  this.updated.push(id);
118
148
  }
119
149
  }
120
150
 
151
+ /**
152
+ * Geometry `id`'s arrays copied by the backend into a context not known to be lost,
153
+ * which keeps what it needs of them: let go of, unless they were added to
154
+ * be kept. Its box and flatness stay. Only the GPU backend calls it, once
155
+ * the copy is made (webgl/atlas.ts).
156
+ */
157
+ release(id: number): void {
158
+ if (!this.kept[id]) {
159
+ this.data[id] = null;
160
+ }
161
+ }
162
+
163
+ /** Whether geometry `id` is held but its arrays were let go of (release). */
164
+ released(id: number): boolean {
165
+ return this.holds(id) && !this.data[id];
166
+ }
167
+
168
+ /**
169
+ * Geometry `id`'s arrays wanted again, by any reader of them: where they
170
+ * were let go of (release), the geometry is removed, for its owner to add
171
+ * it again with its arrays as it next draws it (tessellated and stroked
172
+ * again, or from a slow layer's kept triangles), as an expired one is;
173
+ * its handle then reads dead. True where it was removed so; false where
174
+ * its arrays are held (get), or it is not held at all. Called outside a
175
+ * frame's walk, or with the view's spans dropped after: a frame walked
176
+ * or kept as spans (scene/spans.ts) before the call names the removed id
177
+ * in its scene list, which then draws nothing for it. An owner remaking
178
+ * its own geometry as it is next asked for it, before it is drawn, may
179
+ * call it mid-walk (Parts.partsOf).
180
+ */
181
+ rebuild(id: number): boolean {
182
+ if (!this.released(id)) {
183
+ return false;
184
+ }
185
+
186
+ this.remove(id);
187
+ return true;
188
+ }
189
+
121
190
  /**
122
191
  * Geometry `id` found flat (GeometryData.flat) after it was added, for
123
192
  * the backend to draw it so: its flag alone taken again, not its vertices.
124
193
  */
125
194
  markFlat(id: number): void {
126
- const data = this.data[id];
127
- if (data && !data.flat) {
128
- data.flat = true;
195
+ if (this.holds(id) && !this.flats[id]) {
196
+ this.flats[id] = true;
197
+ const data = this.data[id];
198
+ if (data) {
199
+ data.flat = true;
200
+ }
201
+
129
202
  this.flattened.push(id);
130
203
  }
131
204
  }
132
205
 
206
+ /** Whether geometry `id` is flat (GeometryData.flat, markFlat). */
207
+ flat(id: number): boolean {
208
+ return this.flats[id] === true;
209
+ }
210
+
211
+ /**
212
+ * The context was lost, and the backend's copies with it: the geometries
213
+ * whose arrays were let go of rebuilt (rebuild), and those whose arrays
214
+ * are held added again as they are.
215
+ */
216
+ override lost(): void {
217
+ for (let id = 0; id < this.size; id++) {
218
+ this.rebuild(id);
219
+ }
220
+
221
+ this.added.length = 0;
222
+ this.removed.length = 0;
223
+ this.updated.length = 0;
224
+ this.flattened.length = 0;
225
+ for (let id = 0; id < this.size; id++) {
226
+ if (this.holds(id)) {
227
+ this.added.push(id);
228
+ }
229
+ }
230
+ }
231
+
133
232
  private measure(id: number): void {
134
233
  const data = this.data[id] as GeometryData;
135
234
  if (id * 4 >= this.boxes.length) {
@@ -166,24 +265,15 @@ export class Geometries extends Registry {
166
265
  return this.boxes;
167
266
  }
168
267
 
268
+ /** Geometry `id`'s arrays, null once let go of (release) or for one not held. */
169
269
  get(id: number): GeometryData | null {
170
270
  return this.data[id] ?? null;
171
271
  }
172
272
 
173
- /** The ids of every geometry held, in order. */
174
- live(): number[] {
175
- const ids: number[] = [];
176
- for (let id = 0; id < this.data.length; id++) {
177
- if (this.data[id]) {
178
- ids.push(id);
179
- }
180
- }
181
-
182
- return ids;
183
- }
184
-
185
273
  protected override dropped(id: number): void {
186
274
  this.removalVersion++;
187
275
  this.data[id] = null;
276
+ this.kept[id] = false;
277
+ this.flats[id] = false;
188
278
  }
189
279
  }
package/src/index.ts CHANGED
@@ -35,6 +35,7 @@ export {
35
35
  type GeometryHandle,
36
36
  GLYPH_FLOATS,
37
37
  IDLE_FRAMES,
38
+ RELEASE_FRAMES,
38
39
  TARGET_TEXEL,
39
40
  } from "./geometry.js";
40
41
  export { KEEP_IDLE_FRAMES, type KeepHandle, Keeps } from "./keeps.js";
@@ -86,4 +87,5 @@ export {
86
87
  WHOLE_ALIASED,
87
88
  WHOLE_SMOOTH,
88
89
  } from "./scene.js";
90
+ export { firstDifference, type Span, spanDifference } from "./spans.js";
89
91
  export { KEEP_FRAMES, type TextureData, type TextureHandle, Textures } from "./textures.js";
package/src/measure.ts CHANGED
@@ -29,12 +29,71 @@ export interface MeasureTarget {
29
29
  /** A hair, which keeps a padded edge on the pixel it lies on at any resolution. */
30
30
  const TEXEL_SNAP = 1e-6;
31
31
 
32
- // Scratch stacks, four numbers an open area: least x and y, greatest x and y, in target pixels.
33
- const areas: number[] = [];
34
- const clips: number[] = [];
35
- const open: number[] = [];
36
- // Each open layer's cut, four numbers as an area's: an alpha mask's rectangle in it (ALPHA_MASK).
37
- const cuts: number[] = [];
32
+ /**
33
+ * A scratch stack of areas, four numbers each: least x and y, greatest x
34
+ * and y, in target pixels. Typed and grown by doubling, never shortened,
35
+ * so that a frame neither boxes its numbers nor makes its store again.
36
+ */
37
+ class Areas {
38
+ data = new Float64Array(64);
39
+ /** Numbers in use, four an area. */
40
+ top = 0;
41
+
42
+ /** Room for one more area. */
43
+ room(): Float64Array {
44
+ if (this.top + 4 > this.data.length) {
45
+ const grown = new Float64Array(this.data.length * 2);
46
+ grown.set(this.data);
47
+ this.data = grown;
48
+ }
49
+
50
+ return this.data;
51
+ }
52
+
53
+ /** An area of nothing, its least past its greatest. */
54
+ pushEmpty(): void {
55
+ this.push(
56
+ Number.POSITIVE_INFINITY,
57
+ Number.POSITIVE_INFINITY,
58
+ Number.NEGATIVE_INFINITY,
59
+ Number.NEGATIVE_INFINITY,
60
+ );
61
+ }
62
+
63
+ push(left: number, top: number, right: number, bottom: number): void {
64
+ const data = this.room();
65
+ const n = this.top;
66
+ data[n] = left;
67
+ data[n + 1] = top;
68
+ data[n + 2] = right;
69
+ data[n + 3] = bottom;
70
+ this.top = n + 4;
71
+ }
72
+
73
+ /** The top area moved onto `to`. */
74
+ moveTop(to: Areas): void {
75
+ const data = to.room();
76
+ const from = this.data;
77
+ const n = this.top - 4;
78
+ const t = to.top;
79
+ data[t] = from[n];
80
+ data[t + 1] = from[n + 1];
81
+ data[t + 2] = from[n + 2];
82
+ data[t + 3] = from[n + 3];
83
+ to.top = t + 4;
84
+ this.top = n;
85
+ }
86
+ }
87
+
88
+ const areas = new Areas();
89
+ const clips = new Areas();
90
+ // Each open layer's cut, as an area: an alpha mask's rectangle in it (ALPHA_MASK).
91
+ const cuts = new Areas();
92
+ // The open layers by number, innermost last, `openTop` of them.
93
+ let open = new Int32Array(16);
94
+ let openTop = 0;
95
+ // drawnArea's area as it is measured.
96
+ const drawn = new Float64Array(4);
38
97
 
39
98
  /**
40
99
  * Each layer's rectangle of the target (SceneList.layerRect), from what is
@@ -60,11 +119,11 @@ export function measureLayers(
60
119
  return;
61
120
  }
62
121
 
63
- areas.length = 0;
64
- clips.length = 0;
65
- open.length = 0;
66
- cuts.length = 0;
67
- pushEmpty(areas);
122
+ areas.top = 0;
123
+ clips.top = 0;
124
+ cuts.top = 0;
125
+ openTop = 0;
126
+ areas.pushEmpty();
68
127
  const k = target.scale;
69
128
  const box = geometries.box;
70
129
  const m = rows.data;
@@ -72,16 +131,22 @@ export function measureLayers(
72
131
  for (let i = 0; i < scene.length; i++) {
73
132
  switch (scene.kind[i]) {
74
133
  case DRAW:
75
- placeDraw(scene, i, box, m, k, areas);
134
+ placeDraw(scene, i, box, m, k, areas.data, areas.top);
76
135
  break;
77
136
 
78
137
  case MASK_BEGIN:
79
138
  // The mask's own draws, measured apart.
80
- pushEmpty(areas);
139
+ areas.pushEmpty();
81
140
  break;
82
141
  case LAYER_BEGIN:
83
- open.push(scene.geometry[i]);
84
- pushEmpty(areas);
142
+ if (openTop === open.length) {
143
+ const grown = new Int32Array(open.length * 2);
144
+ grown.set(open);
145
+ open = grown;
146
+ }
147
+
148
+ open[openTop++] = scene.geometry[i];
149
+ areas.pushEmpty();
85
150
  cuts.push(
86
151
  Number.NEGATIVE_INFINITY,
87
152
  Number.NEGATIVE_INFINITY,
@@ -91,18 +156,20 @@ export function measureLayers(
91
156
  break;
92
157
  case MASK_USE:
93
158
  // The mask's draws clip what follows, measured apart till it pops.
94
- moveTop(areas, clips);
95
- pushEmpty(areas);
159
+ areas.moveTop(clips);
160
+ areas.pushEmpty();
96
161
  break;
97
162
  case MASK_POP: {
98
- const n = areas.length;
99
- const c = clips.length;
100
- const left = Math.max(areas[n - 4], clips[c - 4]);
101
- const top = Math.max(areas[n - 3], clips[c - 3]);
102
- const right = Math.min(areas[n - 2], clips[c - 2]);
103
- const bottom = Math.min(areas[n - 1], clips[c - 1]);
104
- areas.length = n - 4;
105
- clips.length = c - 4;
163
+ const a = areas.data;
164
+ const n = areas.top;
165
+ const cl = clips.data;
166
+ const c = clips.top;
167
+ const left = Math.max(a[n - 4], cl[c - 4]);
168
+ const top = Math.max(a[n - 3], cl[c - 3]);
169
+ const right = Math.min(a[n - 2], cl[c - 2]);
170
+ const bottom = Math.min(a[n - 1], cl[c - 1]);
171
+ areas.top = n - 4;
172
+ clips.top = c - 4;
106
173
  if (right > left && bottom > top) {
107
174
  unionTop(left, top, right, bottom);
108
175
  }
@@ -111,17 +178,19 @@ export function measureLayers(
111
178
  }
112
179
 
113
180
  case LAYER_END: {
114
- const n = areas.length;
115
- const layer = open.pop() as number;
181
+ const a = areas.data;
182
+ const n = areas.top;
183
+ const layer = open[--openTop];
116
184
  const pad = scene.pads[layer];
117
- const c = cuts.length - 4;
185
+ const cut = cuts.data;
186
+ const c = cuts.top - 4;
118
187
  if (pad < 0) {
119
- const left = Math.max(0, Math.floor(areas[n - 4]) - 1, cuts[c]);
120
- const top = Math.max(0, Math.floor(areas[n - 3]) - 1, cuts[c + 1]);
121
- const right = Math.min(target.width, Math.ceil(areas[n - 2]) + 1, cuts[c + 2]);
122
- const bottom = Math.min(target.height, Math.ceil(areas[n - 1]) + 1, cuts[c + 3]);
123
- areas.length = n - 4;
124
- cuts.length = c;
188
+ const left = Math.max(0, Math.floor(a[n - 4]) - 1, cut[c]);
189
+ const top = Math.max(0, Math.floor(a[n - 3]) - 1, cut[c + 1]);
190
+ const right = Math.min(target.width, Math.ceil(a[n - 2]) + 1, cut[c + 2]);
191
+ const bottom = Math.min(target.height, Math.ceil(a[n - 1]) + 1, cut[c + 3]);
192
+ areas.top = n - 4;
193
+ cuts.top = c;
125
194
  if (scene.geometry[i] === ALPHA_MASK) {
126
195
  // Not taken into the layer it ends, which it cuts to its rectangle: to nothing, where it
127
196
  // has none.
@@ -131,10 +200,10 @@ export function measureLayers(
131
200
 
132
201
  const p = c - 4;
133
202
  if (p >= 0) {
134
- cuts[p] = Math.max(cuts[p], left);
135
- cuts[p + 1] = Math.max(cuts[p + 1], top);
136
- cuts[p + 2] = Math.min(cuts[p + 2], right);
137
- cuts[p + 3] = Math.min(cuts[p + 3], bottom);
203
+ cut[p] = Math.max(cut[p], left);
204
+ cut[p + 1] = Math.max(cut[p + 1], top);
205
+ cut[p + 2] = Math.min(cut[p + 2], right);
206
+ cut[p + 3] = Math.min(cut[p + 3], bottom);
138
207
  }
139
208
 
140
209
  break;
@@ -150,10 +219,10 @@ export function measureLayers(
150
219
 
151
220
  // The view puts no alpha mask straight in a filtered layer, which would run its filters on
152
221
  // what the mask left (cuts).
153
- cuts.length = c;
222
+ cuts.top = c;
154
223
  const kept = scene.areas;
155
224
  for (let k = 0; k < 4; k++) {
156
- kept[layer * 4 + k] = areas[n - 4 + k];
225
+ kept[layer * 4 + k] = a[n - 4 + k];
157
226
  }
158
227
 
159
228
  filteredRect(
@@ -166,7 +235,7 @@ export function measureLayers(
166
235
  scene.wholes[layer],
167
236
  scene.objects,
168
237
  );
169
- areas.length = n - 4;
238
+ areas.top = n - 4;
170
239
  const r = scene.layers;
171
240
  const at = layer * 4;
172
241
  if (r[at + 2] > 0) {
@@ -320,14 +389,16 @@ export function drawnArea(
320
389
  scale: number,
321
390
  out: number[],
322
391
  ): void {
323
- out.length = 0;
324
- pushEmpty(out);
392
+ drawn[0] = Number.POSITIVE_INFINITY;
393
+ drawn[1] = Number.POSITIVE_INFINITY;
394
+ drawn[2] = Number.NEGATIVE_INFINITY;
395
+ drawn[3] = Number.NEGATIVE_INFINITY;
325
396
  let defining = 0;
326
397
  for (let i = from; i < scene.length; i++) {
327
398
  switch (scene.kind[i]) {
328
399
  case DRAW:
329
400
  if (defining === 0) {
330
- placeDraw(scene, i, geometries.box, rows.data, scale, out);
401
+ placeDraw(scene, i, geometries.box, rows.data, scale, drawn, 4);
331
402
  }
332
403
 
333
404
  break;
@@ -339,16 +410,25 @@ export function drawnArea(
339
410
  break;
340
411
  }
341
412
  }
413
+
414
+ out[0] = drawn[0];
415
+ out[1] = drawn[1];
416
+ out[2] = drawn[2];
417
+ out[3] = drawn[3];
342
418
  }
343
419
 
344
- /** Entry `i`'s geometry box placed by its row at `k` target pixels a stage pixel, taken into the area atop `stack`. */
420
+ /**
421
+ * Entry `i`'s geometry box placed by its row at `k` target pixels a stage
422
+ * pixel, taken into the area that ends before `stack[n]`.
423
+ */
345
424
  function placeDraw(
346
425
  scene: SceneList,
347
426
  i: number,
348
427
  box: Float32Array,
349
428
  m: Float32Array,
350
429
  k: number,
351
- stack: number[],
430
+ stack: Float64Array,
431
+ n: number,
352
432
  ): void {
353
433
  const g = scene.geometry[i] * 4;
354
434
  const x0 = box[g];
@@ -367,34 +447,18 @@ function placeDraw(
367
447
  const tx = m[r + 4] * k;
368
448
  const ty = m[r + 5] * k;
369
449
  // The box's corners placed: each of the least and greatest a coordinate takes, by sign.
370
- const n = stack.length;
371
450
  stack[n - 4] = Math.min(stack[n - 4], tx + Math.min(a * x0, a * x1) + Math.min(c * y0, c * y1));
372
451
  stack[n - 3] = Math.min(stack[n - 3], ty + Math.min(b * x0, b * x1) + Math.min(d * y0, d * y1));
373
452
  stack[n - 2] = Math.max(stack[n - 2], tx + Math.max(a * x0, a * x1) + Math.max(c * y0, c * y1));
374
453
  stack[n - 1] = Math.max(stack[n - 1], ty + Math.max(b * x0, b * x1) + Math.max(d * y0, d * y1));
375
454
  }
376
455
 
377
- function pushEmpty(stack: number[]): void {
378
- stack.push(
379
- Number.POSITIVE_INFINITY,
380
- Number.POSITIVE_INFINITY,
381
- Number.NEGATIVE_INFINITY,
382
- Number.NEGATIVE_INFINITY,
383
- );
384
- }
385
-
386
- /** The top area of `from` moved onto `to`. */
387
- function moveTop(from: number[], to: number[]): void {
388
- const n = from.length;
389
- to.push(from[n - 4], from[n - 3], from[n - 2], from[n - 1]);
390
- from.length = n - 4;
391
- }
392
-
393
456
  /** The open area on top grown to take in the rectangle. */
394
457
  function unionTop(left: number, top: number, right: number, bottom: number): void {
395
- const n = areas.length;
396
- areas[n - 4] = Math.min(areas[n - 4], left);
397
- areas[n - 3] = Math.min(areas[n - 3], top);
398
- areas[n - 2] = Math.max(areas[n - 2], right);
399
- areas[n - 1] = Math.max(areas[n - 1], bottom);
458
+ const a = areas.data;
459
+ const n = areas.top;
460
+ a[n - 4] = Math.min(a[n - 4], left);
461
+ a[n - 3] = Math.min(a[n - 3], top);
462
+ a[n - 2] = Math.max(a[n - 2], right);
463
+ a[n - 1] = Math.max(a[n - 1], bottom);
400
464
  }
package/src/plan.ts CHANGED
@@ -78,7 +78,7 @@ export function plan(scene: SceneList, background: number, out: Commands): void
78
78
  const alpha = (background >>> 24) / 255;
79
79
  out.push(
80
80
  CLEAR,
81
- out.param(
81
+ out.param4(
82
82
  (((background >> 16) & 0xff) / 255) * alpha,
83
83
  (((background >> 8) & 0xff) / 255) * alpha,
84
84
  ((background & 0xff) / 255) * alpha,
@@ -176,7 +176,7 @@ function emit(scene: SceneList, from: number, to: number, out: Commands, stage:
176
176
  if (r[at + 2] > 0 && r[at + 3] > 0) {
177
177
  out.push(
178
178
  COMPOSITE,
179
- out.param(r[at], r[at + 1], r[at + 2], r[at + 3], scene.texture[i]),
179
+ out.param5(r[at], r[at + 1], r[at + 2], r[at + 3], scene.texture[i]),
180
180
  scene.blend[i],
181
181
  scene.row[i],
182
182
  );
@@ -280,8 +280,8 @@ function layerParams(out: Commands, scene: SceneList, layer: number): number {
280
280
  const o = scene.objects;
281
281
  const at = layer * 4;
282
282
  return scene.wholes[layer] === NO_WHOLE
283
- ? out.param(r[at], r[at + 1], r[at + 2], r[at + 3], 0, 0, -1, -1)
284
- : out.param(
283
+ ? out.param8(r[at], r[at + 1], r[at + 2], r[at + 3], 0, 0, -1, -1)
284
+ : out.param8(
285
285
  r[at],
286
286
  r[at + 1],
287
287
  r[at + 2],
package/src/registry.ts CHANGED
@@ -40,6 +40,11 @@ export class Registry {
40
40
  return this.held[id] === true;
41
41
  }
42
42
 
43
+ /** The generation `id` has, or had when it was last let go of; 0 for one never handed out. */
44
+ generation(id: number): number {
45
+ return this.generations[id] ?? 0;
46
+ }
47
+
43
48
  /** How many ids there have been, the free ones among them. */
44
49
  get size(): number {
45
50
  return this.held.length;
@@ -68,6 +73,11 @@ export class Registry {
68
73
  }
69
74
  }
70
75
 
76
+ /** The frame `id` was last used in. */
77
+ usedIn(id: number): number {
78
+ return this.usedAt[id] ?? -1;
79
+ }
80
+
71
81
  /** `id` used this frame. */
72
82
  use(id: number): void {
73
83
  this.usedAt[id] = this.frame;