@threenative/core 0.3.11 → 0.3.13

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 (236) hide show
  1. package/README.md +1 -1
  2. package/capabilities.json +1988 -204
  3. package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
  4. package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
  5. package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
  6. package/dist/chunk-4SRAQFTU.js +133 -0
  7. package/dist/chunk-CFGTPFUH.js +231 -0
  8. package/dist/chunk-DIPIJICH.js +8916 -0
  9. package/dist/chunk-EEABDLUC.js +2237 -0
  10. package/dist/chunk-EFWZWLPY.js +1895 -0
  11. package/dist/chunk-GXY7B3JG.js +46 -0
  12. package/dist/chunk-GYUZJQ7U.js +280 -0
  13. package/dist/chunk-H4J6IAJE.js +504 -0
  14. package/dist/chunk-KIRUKTBQ.js +187 -0
  15. package/dist/chunk-QWJEMUUT.js +94 -0
  16. package/dist/chunk-SV4QVUTQ.js +31 -0
  17. package/dist/chunk-U4YHUKKL.js +615 -0
  18. package/dist/chunk-VP43GIWW.js +18 -0
  19. package/dist/chunk-XDTZ4QMO.js +160 -0
  20. package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
  21. package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
  22. package/dist/hot.d.ts +5 -4
  23. package/dist/hot.js +5 -52
  24. package/dist/index.d.ts +633 -1351
  25. package/dist/index.js +12873 -23068
  26. package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
  27. package/dist/playtest.d.ts +5 -4
  28. package/dist/playtest.js +25 -75
  29. package/dist/quality-BYqKGAwo.d.ts +868 -0
  30. package/dist/react-css.js +1 -215
  31. package/dist/react.d.ts +3 -2
  32. package/dist/render-environment.d.ts +170 -0
  33. package/dist/render-environment.js +352 -0
  34. package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
  35. package/dist/spells/index.d.ts +643 -0
  36. package/dist/spells/index.js +1558 -0
  37. package/dist/spells/ultra/index.d.ts +1600 -0
  38. package/dist/spells/ultra/index.js +6804 -0
  39. package/dist/terrain-jobs-worker.js +1 -123
  40. package/dist/two-sided-foliage-W523J3UM.js +1 -0
  41. package/dist/ui-layer.js +6 -384
  42. package/dist/worker.js +13 -43
  43. package/dist/world.d.ts +988 -268
  44. package/dist/world.js +17464 -18290
  45. package/mcp/animation-server.mjs +1 -1
  46. package/mcp/animation.mjs +2 -3
  47. package/mcp/engine-server.mjs +245 -52
  48. package/mcp/servers.mjs +10 -3
  49. package/mcp/terrain.mjs +8 -0
  50. package/package.json +19 -7
  51. package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
  52. package/patches/three@0.187.0.patch +2004 -407
  53. package/src/animation-batch.ts +193 -0
  54. package/src/animation-layers.ts +7 -3
  55. package/src/animation.ts +209 -29
  56. package/src/asset-cache.ts +3 -3
  57. package/src/asset-memo.ts +202 -0
  58. package/src/assets.ts +437 -125
  59. package/src/auto-batch.ts +190 -44
  60. package/src/card-lod.ts +152 -0
  61. package/src/compressed-texture-preparation.ts +1008 -0
  62. package/src/compute-driven.ts +1 -1
  63. package/src/config.ts +8 -0
  64. package/src/debug.ts +103 -22
  65. package/src/dev-global.ts +54 -0
  66. package/src/engine-hooks.ts +37 -0
  67. package/src/frame-budget.ts +50 -23
  68. package/src/game-boot-phase.ts +269 -0
  69. package/src/game-dev-tools.ts +86 -0
  70. package/src/game-frame-loop.ts +958 -0
  71. package/src/game-renderer-metrics.ts +77 -0
  72. package/src/game-startup.ts +1076 -0
  73. package/src/game-ui.ts +84 -0
  74. package/src/game-validate.ts +70 -0
  75. package/src/game.ts +198 -2264
  76. package/src/gamepad-mappings.ts +269 -0
  77. package/src/generated/console-markers.ts +13 -0
  78. package/src/geometry-capture.ts +28 -4
  79. package/src/gpu-readings.ts +98 -0
  80. package/src/gpu-scene-bvh.ts +149 -36
  81. package/src/hot.ts +4 -7
  82. package/src/index.ts +141 -9
  83. package/src/input.ts +237 -25
  84. package/src/instanced-batch-lod.ts +3 -8
  85. package/src/interpolation.ts +171 -40
  86. package/src/launch-diagnostics.ts +22 -12
  87. package/src/look/ao-admission.ts +25 -0
  88. package/src/look/auto-exposure.ts +5 -16
  89. package/src/look/default-tone-mapping.ts +41 -5
  90. package/src/look/filmic-tone-mapping.ts +15 -13
  91. package/src/look/local-exposure.ts +2 -7
  92. package/src/look/look-diagnostics.ts +3 -3
  93. package/src/look/quad-pass.ts +21 -0
  94. package/src/look/quality.ts +14 -5
  95. package/src/look/unreal-bloom.ts +4 -13
  96. package/src/look/world-environment.ts +113 -103
  97. package/src/loop.ts +29 -0
  98. package/src/merge-parts.ts +20 -24
  99. package/src/model-lod.ts +139 -17
  100. package/src/particle-kinds.ts +515 -0
  101. package/src/particle-significance.ts +12 -0
  102. package/src/particles.ts +19 -10
  103. package/src/picking.ts +17 -3
  104. package/src/platform.ts +23 -4
  105. package/src/playtest.ts +27 -1
  106. package/src/profiling/FrameStages.ts +5 -6
  107. package/src/profiling/Spans.ts +3 -17
  108. package/src/profiling/debug-telemetry.ts +2 -6
  109. package/src/profiling/render-list-validate.ts +6 -15
  110. package/src/projection-apply.ts +4 -1
  111. package/src/projection-marker.ts +2 -1
  112. package/src/projection-plan.ts +9 -6
  113. package/src/quiet-markers.ts +3 -10
  114. package/src/render/cpu-bvh.ts +100 -0
  115. package/src/render/depth-pyramid.ts +6 -14
  116. package/src/render/environment/environmentContribution.ts +202 -0
  117. package/src/render/environment/environmentRadiance.ts +44 -0
  118. package/src/render/environment/environmentSampleCache.ts +56 -0
  119. package/src/render/environment/environmentSampling.ts +201 -0
  120. package/src/render/environment/environmentSnapshot.ts +71 -0
  121. package/src/render/environment/gate.ts +57 -0
  122. package/src/render/mesh-pool.ts +4 -20
  123. package/src/render/probe-trace.ts +872 -0
  124. package/src/render/probe-volume.ts +780 -34
  125. package/src/render/radiance-cache.ts +17 -0
  126. package/src/render/resolution-subrect.ts +2 -0
  127. package/src/render/rough-diffuse.ts +46 -12
  128. package/src/render/soft-shadow.ts +27 -12
  129. package/src/render/virtual-shadow-adaptive.ts +55 -0
  130. package/src/render/virtual-shadow-casters.ts +175 -0
  131. package/src/render/virtual-shadow-layers.ts +76 -0
  132. package/src/render/virtual-shadow-level.ts +224 -0
  133. package/src/render/virtual-shadow-markers.ts +193 -0
  134. package/src/render/virtual-shadow-options.ts +370 -0
  135. package/src/render/virtual-shadow-pages.ts +5 -0
  136. package/src/render/virtual-shadow-partial.ts +13 -0
  137. package/src/render/virtual-shadow.ts +231 -1008
  138. package/src/render/world-impostor-surface.ts +402 -40
  139. package/src/render/world-impostor.ts +5 -2
  140. package/src/render-camera-cull.ts +98 -3
  141. package/src/render-environment.ts +41 -0
  142. package/src/render-pass-budget.ts +34 -7
  143. package/src/renderProjection.ts +22 -0
  144. package/src/renderer-config.ts +36 -0
  145. package/src/renderer-facts.ts +37 -0
  146. package/src/renderer.ts +144 -65
  147. package/src/resolution-scaler.ts +3 -2
  148. package/src/scene-entry-inspectors.ts +61 -0
  149. package/src/snow-field.ts +2 -1
  150. package/src/spells/cast-pool.ts +361 -0
  151. package/src/spells/index.ts +177 -0
  152. package/src/spells/mechanisms.ts +295 -0
  153. package/src/spells/reaction-field.ts +415 -0
  154. package/src/spells/spell-lights.ts +139 -0
  155. package/src/spells/spell-world.ts +187 -0
  156. package/src/spells/spell.ts +397 -0
  157. package/src/spells/spells.ts +283 -0
  158. package/src/spells/ultra/engine/camera.ts +184 -0
  159. package/src/spells/ultra/engine/quality.ts +96 -0
  160. package/src/spells/ultra/index.ts +52 -0
  161. package/src/spells/ultra/main.ts +305 -0
  162. package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
  163. package/src/spells/ultra/spells/cast.ts +233 -0
  164. package/src/spells/ultra/spells/fire.ts +1267 -0
  165. package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
  166. package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
  167. package/src/spells/ultra/vfx/FxTarget.ts +61 -0
  168. package/src/spells/ultra/vfx/GroundField.ts +1399 -0
  169. package/src/spells/ultra/vfx/Particles.ts +1475 -0
  170. package/src/spells/ultra/vfx/Ribbons.ts +645 -0
  171. package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
  172. package/src/spells/ultra/vfx/Volumes.ts +489 -0
  173. package/src/spells/ultra/vfx/common.ts +1195 -0
  174. package/src/spells/ultra/vfx/noise.ts +441 -0
  175. package/src/startup-offscreen-bytes.ts +78 -0
  176. package/src/startup-readiness.ts +128 -34
  177. package/src/static-transform.ts +25 -19
  178. package/src/streamed-textures.ts +112 -0
  179. package/src/streaming.ts +68 -4
  180. package/src/texture-streaming.ts +331 -0
  181. package/src/version.ts +1 -1
  182. package/src/warmup.ts +56 -8
  183. package/src/water-surface.ts +9 -3
  184. package/src/worker.ts +12 -2
  185. package/src/world-bundle-safety.ts +446 -0
  186. package/src/world-cell-batches.ts +1178 -0
  187. package/src/world-cell-chunks.ts +1128 -0
  188. package/src/world-cell-data.ts +995 -0
  189. package/src/world-cell-impostors.ts +1461 -0
  190. package/src/world-cell-lod-bias.ts +151 -0
  191. package/src/world-cell-models.ts +1074 -0
  192. package/src/world-cell-options.ts +177 -0
  193. package/src/world-cell-placements.ts +798 -0
  194. package/src/world-cell-prewarm.ts +592 -0
  195. package/src/world-cell-readiness.ts +357 -0
  196. package/src/world-cell-records.ts +401 -0
  197. package/src/world-cell-render-bundles.ts +459 -0
  198. package/src/world-cell-render-gpu-dress.ts +710 -0
  199. package/src/world-cell-render-main-cull.ts +540 -0
  200. package/src/world-cell-render-shadow-claims.ts +198 -0
  201. package/src/world-cell-render-util.ts +259 -0
  202. package/src/world-cell-render.ts +1501 -0
  203. package/src/world-cell-residency.ts +754 -0
  204. package/src/world-cell-stale.ts +238 -0
  205. package/src/world-cells.ts +1335 -10418
  206. package/src/world-chunk-shadow.ts +308 -0
  207. package/src/world-collar.ts +315 -0
  208. package/src/world-gpu-flags.ts +131 -0
  209. package/src/world-gpu-readback.ts +881 -0
  210. package/src/world-gpu-reference.ts +524 -0
  211. package/src/world-gpu-scene.ts +256 -2286
  212. package/src/world-gpu-shadow.ts +203 -0
  213. package/src/world-gpu-types.ts +409 -0
  214. package/src/world-gpu-validation.ts +518 -0
  215. package/src/world-heightfield.ts +802 -0
  216. package/src/world-load-limiter.ts +111 -0
  217. package/src/world-model-sections.ts +80 -0
  218. package/src/world-noise.ts +241 -0
  219. package/src/world-package.ts +42 -0
  220. package/src/world-region.ts +1 -1
  221. package/src/world-river-ribbon.ts +282 -0
  222. package/src/world-root-frame.ts +39 -0
  223. package/src/world-shore-field.ts +91 -0
  224. package/src/world-static-pose.ts +163 -0
  225. package/src/world-surface-sampler.ts +48 -0
  226. package/src/world-terrain-splat.ts +361 -153
  227. package/src/world-tile-budget.ts +249 -0
  228. package/src/world-tile-geometry.ts +469 -0
  229. package/src/world-tile-lod.ts +408 -0
  230. package/src/world-tile-observation.ts +566 -0
  231. package/src/world-tile-stitch.ts +166 -0
  232. package/src/world-tiles.ts +247 -1755
  233. package/src/world-validate.ts +6 -14
  234. package/src/world-warm.ts +51 -0
  235. package/src/world-water-bodies.ts +359 -0
  236. package/src/world.ts +48 -741
@@ -0,0 +1,238 @@
1
+ /**
2
+ * The refilter's stale scan over packed rows, run by one engine call a pass.
3
+ *
4
+ * `CellPlacements.refilter` asks which resident cell-assets the follow point or the LOD eye moved
5
+ * across a gate of. That scan visited every batch entry of every resident cell in JS: 0.9 ms a frame
6
+ * on the forest walk, where every cell carries a `placementReach`. The entries' state now lives in a
7
+ * slab of rows, kept per cell and rebuilt only when a cell's batches change, and the scan runs on the
8
+ * slab in the owned engine: `Object3D.__tnStaleRows(blocks, plan)` keeps it there, sent only when it
9
+ * changes and then only the blocks that changed ({@link patchRows}), and `__tnStaleEntries(gates,
10
+ * query)` scans it (`bindings_scene.cpp`). Upstream three runs {@link staleRows}, its twin.
11
+ *
12
+ * Slab: one block per resident cell, a header of {@link STALE_HEADER} numbers, then
13
+ * {@link STALE_ENTRY} numbers per batch entry.
14
+ * - header: cell left x, near z, size, filterNear, filterFar, has reach (0 or 1), entries, 0.
15
+ * - entry: asset index, lastFilter x y z, lastLod x y z, threshold (NaN: none), reach min, max,
16
+ * minY, maxY (NaN: no reach).
17
+ *
18
+ * Gates: the asset count, then `[at, count]` per asset index into the values that follow (`at` -1:
19
+ * the asset is gone), then the values.
20
+ *
21
+ * Query: follow x, follow y, follow z, eye x y z, GPU scene on (0 or 1), the world gate count, then
22
+ * the world's gates ascending.
23
+ *
24
+ * Answer: `[cell block ordinal, asset index, eye distance]` per stale cell-asset, in scan order.
25
+ */
26
+ export const STALE_HEADER = 8;
27
+ export const STALE_ENTRY = 12;
28
+ /** The query's fixed numbers, before the world's gates. */
29
+ export const STALE_QUERY = 8;
30
+
31
+ /** sqrt of the sum of squares, as the engine's twin computes it; `Math.hypot` costs more. */
32
+ function length(x: number, y: number, z = 0): number {
33
+ return Math.sqrt(x * x + y * y + z * z);
34
+ }
35
+
36
+ function span(
37
+ left: number,
38
+ near: number,
39
+ size: number,
40
+ x: number,
41
+ z: number,
42
+ ): readonly [number, number] {
43
+ const right = left + size;
44
+ const far = near + size;
45
+ return [
46
+ length(Math.max(left - x, x - right, 0), Math.max(near - z, z - far, 0)),
47
+ length(
48
+ Math.max(Math.abs(x - left), Math.abs(x - right)),
49
+ Math.max(Math.abs(z - near), Math.abs(z - far)),
50
+ ),
51
+ ];
52
+ }
53
+
54
+ /** The binary search of `crossesGate`, over the query's own gates. */
55
+ function crossesWorldGate(query: Float64Array, low: number, high: number): boolean {
56
+ const count = query[7] as number;
57
+ let start = 0;
58
+ let end = count;
59
+ while (start < end) {
60
+ const middle = (start + end) >> 1;
61
+ if ((query[STALE_QUERY + middle] as number) < low) start = middle + 1;
62
+ else end = middle;
63
+ }
64
+ return start < count && (query[STALE_QUERY + start] as number) <= high;
65
+ }
66
+
67
+ function vertical(y: number, minY: number, maxY: number): readonly [number, number] {
68
+ return [Math.max(minY - y, y - maxY, 0), Math.max(Math.abs(y - minY), Math.abs(y - maxY))];
69
+ }
70
+
71
+ /** Whether the follow point crossed the entry's `placementReach` range since its batch was built. */
72
+ function reachCrossed(
73
+ slab: Float64Array,
74
+ at: number,
75
+ cell: number,
76
+ followY: number,
77
+ brackets: readonly [number, number, number, number],
78
+ ): boolean {
79
+ const minY = slab[at + 10] as number;
80
+ const maxY = slab[at + 11] as number;
81
+ const filterY = slab[at + 2] as number;
82
+ const [reachBuiltNear, reachBuiltFar] = span(
83
+ slab[cell] as number,
84
+ slab[cell + 1] as number,
85
+ slab[cell + 2] as number,
86
+ slab[at + 1] as number,
87
+ slab[at + 3] as number,
88
+ );
89
+ const current = vertical(followY, minY, maxY);
90
+ const previous = vertical(filterY, minY, maxY);
91
+ const reachLow = Math.min(length(brackets[2], current[0]), length(reachBuiltNear, previous[0]));
92
+ const reachHigh = Math.max(length(brackets[3], current[1]), length(reachBuiltFar, previous[1]));
93
+ return (slab[at + 8] as number) <= reachHigh && (slab[at + 9] as number) >= reachLow;
94
+ }
95
+
96
+ /** The scan of one entry at `at`; true when its asset is stale. */
97
+ function entryStale(
98
+ slab: Float64Array,
99
+ at: number,
100
+ cell: number,
101
+ gates: Float64Array,
102
+ query: Float64Array,
103
+ brackets: readonly [number, number, number, number],
104
+ ): boolean {
105
+ const x = query[0] as number;
106
+ const followY = query[1] as number;
107
+ const z = query[2] as number;
108
+ const eyeX = query[3] as number;
109
+ const eyeY = query[4] as number;
110
+ const eyeZ = query[5] as number;
111
+ const gpuOn = query[6] as number;
112
+ const left = slab[cell] as number;
113
+ const nearZ = slab[cell + 1] as number;
114
+ const size = slab[cell + 2] as number;
115
+ const [eyeNear, eyeFar] = brackets;
116
+ const threshold = slab[at + 7] as number;
117
+ const reachMin = slab[at + 8] as number;
118
+ const reach = !Number.isNaN(reachMin);
119
+ if (!reach && (gpuOn === 1 || Number.isNaN(threshold))) return false;
120
+ const step = (Number.isNaN(threshold) ? 6 : threshold) / 8;
121
+ const filterX = slab[at + 1] as number;
122
+ const filterY = slab[at + 2] as number;
123
+ const filterZ = slab[at + 3] as number;
124
+ const lodX = slab[at + 4] as number;
125
+ const lodY = slab[at + 5] as number;
126
+ const lodZ = slab[at + 6] as number;
127
+ if (
128
+ length(x - filterX, followY - filterY, z - filterZ) <= step &&
129
+ length(eyeX - lodX, eyeY - lodY, eyeZ - lodZ) <= step
130
+ )
131
+ return false;
132
+ const asset = slab[at] as number;
133
+ const gateAt = gates[1 + asset * 2] as number;
134
+ if (gateAt < 0) return false;
135
+ const gateCount = gpuOn === 1 ? 0 : (gates[2 + asset * 2] as number);
136
+ const [builtNear, builtFar] = span(left, nearZ, size, lodX, lodZ);
137
+ let low = Math.min(eyeNear, builtNear);
138
+ let high = Math.max(eyeFar, builtFar);
139
+ if (reach) {
140
+ const minY = slab[at + 10] as number;
141
+ const maxY = slab[at + 11] as number;
142
+ const eyeNow = vertical(eyeY, minY, maxY);
143
+ const eyeBefore = vertical(lodY, minY, maxY);
144
+ low = Math.min(length(eyeNear, eyeNow[0]), length(builtNear, eyeBefore[0]));
145
+ high = Math.max(length(eyeFar, eyeNow[1]), length(builtFar, eyeBefore[1]));
146
+ if (reachCrossed(slab, at, cell, followY, brackets)) return true;
147
+ }
148
+ for (let gate = 0; gate < gateCount; gate += 1) {
149
+ const value = gates[gateAt + gate] as number;
150
+ if (value >= low && value <= high) return true;
151
+ }
152
+ return false;
153
+ }
154
+
155
+ /**
156
+ * The upstream-three twin of the engine's `__tnStaleEntries`: every cell-asset whose follow point or
157
+ * LOD eye crossed a gate or a `placementReach` boundary since its batch was built.
158
+ */
159
+ export function staleRows(slab: Float64Array, gates: Float64Array, query: Float64Array): number[] {
160
+ const out: number[] = [];
161
+ const seen = new Set<number>();
162
+ const x = query[0] as number;
163
+ const z = query[2] as number;
164
+ const eyeX = query[3] as number;
165
+ const eyeZ = query[5] as number;
166
+ const gpuOn = query[6] as number;
167
+ let ordinal = 0;
168
+ for (let cell = 0; cell < slab.length; ordinal += 1) {
169
+ const entries = slab[cell + 6] as number;
170
+ const next = cell + STALE_HEADER + entries * STALE_ENTRY;
171
+ const left = slab[cell] as number;
172
+ const nearZ = slab[cell + 1] as number;
173
+ const size = slab[cell + 2] as number;
174
+ const hasReach = slab[cell + 5] === 1;
175
+ const [eyeNear, eyeFar] = span(left, nearZ, size, eyeX, eyeZ);
176
+ const low = Math.min(eyeNear, slab[cell + 3] as number);
177
+ const high = Math.max(eyeFar, slab[cell + 4] as number);
178
+ if ((gpuOn === 1 && !hasReach) || (!hasReach && !crossesWorldGate(query, low, high))) {
179
+ cell = next;
180
+ continue;
181
+ }
182
+ const [near, far] = span(left, nearZ, size, x, z);
183
+ seen.clear();
184
+ for (let at = cell + STALE_HEADER; at < next; at += STALE_ENTRY) {
185
+ const asset = slab[at] as number;
186
+ if (seen.has(asset)) continue;
187
+ if (!entryStale(slab, at, cell, gates, query, [eyeNear, eyeFar, near, far])) continue;
188
+ seen.add(asset);
189
+ out.push(ordinal, asset, eyeNear);
190
+ }
191
+ cell = next;
192
+ }
193
+ return out;
194
+ }
195
+
196
+ /**
197
+ * The upstream-three twin of the engine's `__tnStaleRows(blocks, plan)`: the next slab, built from the
198
+ * one held and the blocks that changed. A refilter rebuilds one cell's block, so re-sending the whole
199
+ * slab cost 0.30 ms a swap frame on the forest walk for numbers the engine already held.
200
+ *
201
+ * `plan` is `[source, count]` pairs in slab order: `source` 0 or more keeps `count` numbers of the
202
+ * held slab from `source`, and -1 takes the next `count` numbers of `blocks`.
203
+ */
204
+ export function patchRows(
205
+ held: Float64Array,
206
+ blocks: Float64Array,
207
+ plan: ArrayLike<number>,
208
+ ): Float64Array<ArrayBuffer> {
209
+ let length = 0;
210
+ for (let at = 1; at < plan.length; at += 2) length += plan[at] as number;
211
+ const next = new Float64Array(length);
212
+ let written = 0;
213
+ let taken = 0;
214
+ for (let at = 0; at + 1 < plan.length; at += 2) {
215
+ const source = plan[at] as number;
216
+ const count = plan[at + 1] as number;
217
+ const from = source === -1 ? blocks : held;
218
+ const start = source === -1 ? taken : source;
219
+ if (
220
+ !(
221
+ Number.isInteger(start) &&
222
+ Number.isInteger(count) &&
223
+ start >= 0 &&
224
+ count >= 0 &&
225
+ start + count <= from.length
226
+ )
227
+ )
228
+ throw new RangeError(
229
+ `TN_WORLD_STALE: a plan run [${String(source)}, ${String(count)}] is outside its rows`,
230
+ );
231
+ next.set(from.subarray(start, start + count), written);
232
+ written += count;
233
+ if (source === -1) taken += count;
234
+ }
235
+ if (taken !== blocks.length)
236
+ throw new RangeError("TN_WORLD_STALE: the plan leaves changed blocks unread");
237
+ return next;
238
+ }