@origingame/engine 0.0.0-stage → 0.1.1

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 (159) hide show
  1. package/bin/og.mjs +25 -0
  2. package/dist/web/origin-engine.d.ts +1233 -0
  3. package/dist/web/origin-engine.js +8628 -0
  4. package/dist/web/origin-engine_bg.wasm +0 -0
  5. package/dist/web/origin-engine_bg.wasm.d.ts +366 -0
  6. package/dist/web-publish/origin-engine-lanes.js +8509 -0
  7. package/dist/web-publish/origin-engine-lanes_bg.wasm +0 -0
  8. package/dist/web-publish/origin-engine.d.ts +1176 -0
  9. package/dist/web-publish/origin-engine.js +8313 -0
  10. package/dist/web-publish/origin-engine_bg.wasm +0 -0
  11. package/dist/web-publish/origin-engine_bg.wasm.d.ts +347 -0
  12. package/dist/web-publish/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  13. package/dist/web-publish-2d/origin-engine-lanes.js +8509 -0
  14. package/dist/web-publish-2d/origin-engine-lanes_bg.wasm +0 -0
  15. package/dist/web-publish-2d/origin-engine.d.ts +1176 -0
  16. package/dist/web-publish-2d/origin-engine.js +8313 -0
  17. package/dist/web-publish-2d/origin-engine_bg.wasm +0 -0
  18. package/dist/web-publish-2d/origin-engine_bg.wasm.d.ts +347 -0
  19. package/dist/web-publish-2d/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  20. package/knowledge/README.md +31 -0
  21. package/knowledge/knowledge.json +13 -0
  22. package/knowledge/looks/catalogue.json +1871 -0
  23. package/knowledge/package.json +33 -0
  24. package/knowledge/rules/platform.json +329 -0
  25. package/knowledge/scaffold/README.md +27 -0
  26. package/knowledge/scaffold/distribution.json +48 -0
  27. package/knowledge/scaffold/origin-engine.json +19 -0
  28. package/knowledge/scaffold/template/.origin/setup +14 -0
  29. package/knowledge/scaffold/template/LICENSES.md +23 -0
  30. package/knowledge/scaffold/template/README.md +37 -0
  31. package/knowledge/scaffold/template/assets/ai/guard.ogt +48 -0
  32. package/knowledge/scaffold/template/assets/audio/click.ogt +9 -0
  33. package/knowledge/scaffold/template/assets/fonts/NotoSansSC-Regular-subset.ttf.ogt +12 -0
  34. package/knowledge/scaffold/template/assets/fonts/OFL.txt +93 -0
  35. package/knowledge/scaffold/template/assets/looks/origin-game.ogt +12 -0
  36. package/knowledge/scaffold/template/assets/nav/yard.ogt +27 -0
  37. package/knowledge/scaffold/template/assets/scenes/main.ogt +34 -0
  38. package/knowledge/scaffold/template/assets/strings/en.ogt +14 -0
  39. package/knowledge/scaffold/template/assets/textures/stone_n.png.ogt +7 -0
  40. package/knowledge/scaffold/template/gitattributes +22 -0
  41. package/knowledge/scaffold/template/gitignore +8 -0
  42. package/knowledge/scaffold/template/package.json +18 -0
  43. package/knowledge/scaffold/template/project.ogt +25 -0
  44. package/knowledge/scaffold/template/src/main.ts +246 -0
  45. package/knowledge/scaffold/template/tests/guard.og.ts +67 -0
  46. package/knowledge/scaffold/template/tests/smoke.og.ts +43 -0
  47. package/knowledge/scaffold/template/tsconfig.json +17 -0
  48. package/knowledge/scripts/lib.ts +207 -0
  49. package/knowledge/scripts/mount.ts +210 -0
  50. package/knowledge/scripts/pack.ts +25 -0
  51. package/knowledge/scripts/scaffold.ts +72 -0
  52. package/knowledge/scripts/validate.ts +749 -0
  53. package/knowledge/skills/og-ai/SKILL.md +386 -0
  54. package/knowledge/skills/og-audio/SKILL.md +191 -0
  55. package/knowledge/skills/og-build/SKILL.md +330 -0
  56. package/knowledge/skills/og-core/SKILL.md +285 -0
  57. package/knowledge/skills/og-feel/SKILL.md +385 -0
  58. package/knowledge/skills/og-game/SKILL.md +1479 -0
  59. package/knowledge/skills/og-i18n/SKILL.md +220 -0
  60. package/knowledge/skills/og-platform-sdk/SKILL.md +199 -0
  61. package/knowledge/skills/og-taste/SKILL.md +537 -0
  62. package/knowledge/skills/og-ui/SKILL.md +444 -0
  63. package/knowledge/wiki/ai.md +627 -0
  64. package/knowledge/wiki/anim.md +1187 -0
  65. package/knowledge/wiki/atmosphere.md +636 -0
  66. package/knowledge/wiki/audio.md +732 -0
  67. package/knowledge/wiki/camera.md +711 -0
  68. package/knowledge/wiki/commands.md +357 -0
  69. package/knowledge/wiki/game.md +220 -0
  70. package/knowledge/wiki/i18n.md +213 -0
  71. package/knowledge/wiki/index.md +1027 -0
  72. package/knowledge/wiki/input.md +1714 -0
  73. package/knowledge/wiki/load.md +1280 -0
  74. package/knowledge/wiki/math.md +166 -0
  75. package/knowledge/wiki/nav.md +1154 -0
  76. package/knowledge/wiki/physics.md +3142 -0
  77. package/knowledge/wiki/platform.md +857 -0
  78. package/knowledge/wiki/probe.md +1692 -0
  79. package/knowledge/wiki/reflect.md +285 -0
  80. package/knowledge/wiki/render.md +3511 -0
  81. package/knowledge/wiki/rng.md +393 -0
  82. package/knowledge/wiki/stream.md +376 -0
  83. package/knowledge/wiki/system.md +197 -0
  84. package/knowledge/wiki/systems.md +43 -0
  85. package/knowledge/wiki/terrain.md +727 -0
  86. package/knowledge/wiki/tilemap.md +422 -0
  87. package/knowledge/wiki/time.md +150 -0
  88. package/knowledge/wiki/transform.md +230 -0
  89. package/knowledge/wiki/tween.md +580 -0
  90. package/knowledge/wiki/ui.md +8000 -0
  91. package/knowledge/wiki/world.md +909 -0
  92. package/package.json +68 -4
  93. package/schema/api.schema.json +29675 -0
  94. package/shell/README.md +22 -0
  95. package/shell/brand/README.md +23 -0
  96. package/shell/brand/icon-192.png +0 -0
  97. package/shell/brand/icon-512.png +0 -0
  98. package/shell/brand/mark-on-paper.svg +6 -0
  99. package/shell/brand/origin-mark.svg +5 -0
  100. package/shell/brand/origin-motion.css +251 -0
  101. package/shell/brand/tokens.css +20 -0
  102. package/shell/brand.ts +132 -0
  103. package/shell/page.ts +715 -0
  104. package/shell/platform.ts +203 -0
  105. package/shell/player.ts +238 -0
  106. package/shell/shell.css +185 -0
  107. package/shell/sw.ts +177 -0
  108. package/shell/transport.ts +515 -0
  109. package/shell/wire.ts +369 -0
  110. package/src/e6.ts +69 -0
  111. package/src/env.d.ts +100 -0
  112. package/src/generated/abi.ts +980 -0
  113. package/src/index.ts +193 -0
  114. package/src/node/audio.ts +86 -0
  115. package/src/node/build.ts +109 -0
  116. package/src/node/device.ts +981 -0
  117. package/src/node/doctor.ts +60 -0
  118. package/src/node/index.ts +102 -0
  119. package/src/node/platform.ts +24 -0
  120. package/src/node/playtest-run.ts +249 -0
  121. package/src/node/png.ts +130 -0
  122. package/src/node/polish.ts +976 -0
  123. package/src/node/run.ts +373 -0
  124. package/src/node/web-build.ts +808 -0
  125. package/src/p2.ts +35 -0
  126. package/src/platform-local.ts +211 -0
  127. package/src/playtest.ts +131 -0
  128. package/src/runtime.ts +1509 -0
  129. package/src/systems/cameras.ts +247 -0
  130. package/src/ui-kit/bind.ts +141 -0
  131. package/src/ui-kit/huds.ts +303 -0
  132. package/src/ui-kit/index.ts +36 -0
  133. package/src/ui-kit/menus.ts +187 -0
  134. package/src/ui-kit/settings.ts +131 -0
  135. package/src/ui-kit/store.ts +222 -0
  136. package/src/ui-kit/story.ts +89 -0
  137. package/src/ui-kit/util.ts +106 -0
  138. package/src/web/a11y.ts +429 -0
  139. package/src/web/audio-worklet.ts +193 -0
  140. package/src/web/audio.ts +307 -0
  141. package/src/web/basis.ts +239 -0
  142. package/src/web/gamepad.ts +123 -0
  143. package/src/web/host.ts +166 -0
  144. package/src/web/input.ts +237 -0
  145. package/src/web/lanes.ts +21 -0
  146. package/src/web/play.ts +20 -0
  147. package/src/web/rpc-ring.ts +110 -0
  148. package/src/web/settle.ts +122 -0
  149. package/src/web/shell.ts +643 -0
  150. package/src/web/text-input.ts +248 -0
  151. package/src/web/worker.ts +1002 -0
  152. package/types/bindings.json +13654 -0
  153. package/types/index.d.ts +20090 -0
  154. package/vendor/basis/LICENSE +201 -0
  155. package/vendor/basis/NOTICE +15 -0
  156. package/vendor/basis/README.md +18 -0
  157. package/vendor/basis/basis_transcoder.js +19 -0
  158. package/vendor/basis/basis_transcoder.wasm +0 -0
  159. package/README.md +0 -3
@@ -0,0 +1,376 @@
1
+ <!-- Generated from crates/og-api/api.ogt by `og api gen`. Do not edit: `og api check` fails on any difference; change api.ogt and regenerate. -->
2
+
3
+ # The `stream` module
4
+
5
+ Asset streaming groups (phase 3): a scene's `stream "<name>" { asset ...; distance x y z r [unload d] | volume "<entity>"; priority n }` blocks name glTF models (without skins or morph targets), textures, texture arrays, flipbooks (an `array true` sheet brings its array), sounds, environment maps, palettes, looks and colour LUTs (`.cube`) that load and unload together, and what loads them: the camera within `r` of the anchor (kept until it is past `unload`, 1.25 r by default), the camera inside the named entity's box (its position ± half its scale, turned with it), or neither (og.stream.request only). `og cook` packs each group's files into `cooked/stream/<name>.ogb`; `og build --publish` ships the packs beside the boot bundle, which the shell and the service worker fetch first, and fetches a pack only when its group loads.
6
+
7
+ At every tick boundary the engine decides which groups are wanted, admits them by priority (then name) within the memory budget (256 MiB by default; GPU textures and meshes and decoded audio, as the cook measured them), evicting lower-priority resident groups to make room for a higher one, and reads and puts in place at most one group's assets per boundary. A group that cannot fit waits, queued; one larger than the whole budget fails. Until its group is resident, a model draws its proxy (its coarsest LOD, untextured), a texture is a 1x1 grey placeholder and a sound plays as silence of its own length; then the real ones take over the same handles. Physics always collides with the proxy's meshes and a sound's length never changes, so nothing a tick reads depends on what is resident: a run's world hash is the same streamed or not.
8
+
9
+ Texture arrays, flipbooks, environment maps, palettes, looks and colour LUTs have no stand-in: they load once their group is resident, and when it unloads the renderer lets them go and their handles wait (the sky lights the scene, Stylise.palette quantises to none, PostEffects.lut grades nothing, og.render.sprite of the array and applying the look are refused, an og.Sprite, a flipbook's sprite or a particle emitter of the array draws nothing) until the group is resident again, when they come back under the same handles. One the frame still uses when its group unloads (the map Environment lights it with, the palette Stylise quantises to, an array a sprite, a screen sprite or a particle emitter draws from, the look last applied, the LUT PostEffects grades with) is never freed under the frame: it is kept, with a warning naming it in the engine's log, until the frame stops using it. What is kept still takes its memory: its bytes count in the budget's `used` (and `kept`, and its group's StreamStatus.kept) until it is let go, so a group that would not fit beside it waits.
10
+
11
+ Every change of a group's state sends StreamEvent at the start of the next tick; og.stream.status and og.stream.budget answer at once, and the probe's `dump_stream` lists the budget, the memory used and its peak, every group (trigger, state, why, since which tick, what it keeps for the frame after unloading with each asset's bytes), the recent changes, the terrain streamer's tiles and the fetch queue.
12
+
13
+ What streams is read through one queue: first the chunks of the sounds cooked in chunks that a playhead needs soonest (the one it is playing, then by the seconds until it gets there at its pitch, a loop's start by the time to its wrap), then the loading groups' packs by priority (then name). At most four reads are in flight at once (on the web, fetches; natively a read completes at once, so only the order shows); the rest wait in that order. `dump_stream`'s `fetch` lists what is in flight and what waits, each with its path and what it is for (a sound's chunk and its seconds, a group's pack and its priority).
14
+
15
+ - **TypeScript**: functions are the namespace `og.stream`; components, resources and events are tokens on `og`.
16
+ - **Publish builds**: kept (members may override).
17
+ - **Skill**: `og-game`, which teaches the module (how much of it to use, and how to prove it).
18
+ - **Index**: [every module and name](index.md).
19
+
20
+ ```ogt
21
+ module stream {
22
+ # declarations follow, each quoted below
23
+ ```
24
+
25
+ <sub>`api.ogt` line 11257</sub>
26
+
27
+ ## Contents
28
+
29
+ | Name | Kind | Summary |
30
+ |---|---|---|
31
+ | [`StreamState`](#type-StreamState) | enum | Where a streaming group is. |
32
+ | [`STREAM_UNLOADED`](#const-STREAM_UNLOADED) | constant | `StreamEvent.state`: the group is unloaded (StreamState unloaded). |
33
+ | [`STREAM_QUEUED`](#const-STREAM_QUEUED) | constant | `StreamEvent.state`: the group waits for room in the budget (StreamState queued). |
34
+ | [`STREAM_LOADING`](#const-STREAM_LOADING) | constant | `StreamEvent.state`: the group's pack is being read (StreamState loading). |
35
+ | [`STREAM_RESIDENT`](#const-STREAM_RESIDENT) | constant | `StreamEvent.state`: the group's assets are in place (StreamState resident). |
36
+ | [`STREAM_FAILED`](#const-STREAM_FAILED) | constant | `StreamEvent.state`: the group failed (StreamState failed; og.stream.status says why). |
37
+ | [`og.StreamEvent`](#record-StreamEvent) | event | A group changed state: sent by og.stream at the start of the tick after the change. |
38
+ | [`StreamStatus`](#type-StreamStatus) | struct | One streaming group. |
39
+ | [`StreamBudget`](#type-StreamBudget) | struct | The streaming memory budget and every group. |
40
+ | [`og.stream.status`](#fn-status) | function | One streaming group's state. |
41
+ | [`og.stream.request`](#fn-request) | function | Ask for a group (any trigger) until og.stream.release: it loads from the next tick boundary, within the budget by its priority. |
42
+ | [`og.stream.release`](#fn-release) | function | Stop asking for a group; it unloads at the next tick boundary unless its trigger still wants it. |
43
+ | [`og.stream.budget`](#fn-budget) | function | The memory budget, what the groups take now, the peak and every group. |
44
+ | [`og.stream.setBudget`](#fn-setBudget) | function | Set the memory budget from the next tick boundary; a lower one evicts the lowest-priority groups until the rest fit. |
45
+
46
+ ## Functions
47
+
48
+ <a id="fn-status"></a>
49
+
50
+ ### `og.stream.status`
51
+
52
+ One streaming group's state.
53
+
54
+ ```ts
55
+ og.stream.status(world: World, group: string): Result<StreamStatus>
56
+ ```
57
+
58
+ | Parameter | Type | Optional | Doc |
59
+ |---|---|---|---|
60
+ | `world` | `World` | no | The world. |
61
+ | `group` | `string` | no | The group's name, as its scene declares it. |
62
+
63
+ **Returns** `Result<StreamStatus>`: Refused for a group no scene declares.
64
+
65
+ Binding symbol `og_stream_status` · publish builds: kept
66
+
67
+ ```ogt
68
+ fn status {
69
+ doc "One streaming group's state."
70
+ param world World "The world."
71
+ param group String "The group's name, as its scene declares it."
72
+ returns Result.StreamStatus "Refused for a group no scene declares."
73
+ }
74
+ ```
75
+
76
+ <sub>`api.ogt` line 11327</sub>
77
+
78
+ <a id="fn-request"></a>
79
+
80
+ ### `og.stream.request`
81
+
82
+ Ask for a group (any trigger) until og.stream.release: it loads from the next tick boundary, within the budget by its priority.
83
+
84
+ ```ts
85
+ og.stream.request(world: World, group: string): Result<void>
86
+ ```
87
+
88
+ | Parameter | Type | Optional | Doc |
89
+ |---|---|---|---|
90
+ | `world` | `World` | no | The world. |
91
+ | `group` | `string` | no | The group's name. |
92
+
93
+ **Returns** `Result<void>`: Refused for a group no scene declares.
94
+
95
+ Binding symbol `og_stream_request` · publish builds: kept
96
+
97
+ ```ogt
98
+ fn request {
99
+ doc "Ask for a group (any trigger) until og.stream.release: it loads from the next tick boundary, within the budget by its priority."
100
+ param world World "The world."
101
+ param group String "The group's name."
102
+ returns Result.Void "Refused for a group no scene declares."
103
+ }
104
+ ```
105
+
106
+ <sub>`api.ogt` line 11334</sub>
107
+
108
+ <a id="fn-release"></a>
109
+
110
+ ### `og.stream.release`
111
+
112
+ Stop asking for a group; it unloads at the next tick boundary unless its trigger still wants it.
113
+
114
+ ```ts
115
+ og.stream.release(world: World, group: string): Result<void>
116
+ ```
117
+
118
+ | Parameter | Type | Optional | Doc |
119
+ |---|---|---|---|
120
+ | `world` | `World` | no | The world. |
121
+ | `group` | `string` | no | The group's name. |
122
+
123
+ **Returns** `Result<void>`: Refused for a group no scene declares.
124
+
125
+ Binding symbol `og_stream_release` · publish builds: kept
126
+
127
+ ```ogt
128
+ fn release {
129
+ doc "Stop asking for a group; it unloads at the next tick boundary unless its trigger still wants it."
130
+ param world World "The world."
131
+ param group String "The group's name."
132
+ returns Result.Void "Refused for a group no scene declares."
133
+ }
134
+ ```
135
+
136
+ <sub>`api.ogt` line 11341</sub>
137
+
138
+ <a id="fn-budget"></a>
139
+
140
+ ### `og.stream.budget`
141
+
142
+ The memory budget, what the groups take now, the peak and every group.
143
+
144
+ ```ts
145
+ og.stream.budget(world: World): Result<StreamBudget>
146
+ ```
147
+
148
+ | Parameter | Type | Optional | Doc |
149
+ |---|---|---|---|
150
+ | `world` | `World` | no | The world. |
151
+
152
+ **Returns** `Result<StreamBudget>`: The budget and the groups; refused only for a world that does not exist.
153
+
154
+ Binding symbol `og_stream_budget` · publish builds: kept
155
+
156
+ ```ogt
157
+ fn budget {
158
+ doc "The memory budget, what the groups take now, the peak and every group."
159
+ param world World "The world."
160
+ returns Result.StreamBudget "The budget and the groups; refused only for a world that does not exist."
161
+ }
162
+ ```
163
+
164
+ <sub>`api.ogt` line 11348</sub>
165
+
166
+ <a id="fn-setBudget"></a>
167
+
168
+ ### `og.stream.setBudget`
169
+
170
+ Set the memory budget from the next tick boundary; a lower one evicts the lowest-priority groups until the rest fit.
171
+
172
+ ```ts
173
+ og.stream.setBudget(world: World, bytes: number): Result<void>
174
+ ```
175
+
176
+ | Parameter | Type | Optional | Doc |
177
+ |---|---|---|---|
178
+ | `world` | `World` | no | The world. |
179
+ | `bytes` | `number` | no | The bytes resident groups may take. |
180
+
181
+ **Returns** `Result<void>`: Refused for a negative or non-finite size.
182
+
183
+ Binding symbol `og_stream_set_budget` · publish builds: kept
184
+
185
+ ```ogt
186
+ fn setBudget {
187
+ doc "Set the memory budget from the next tick boundary; a lower one evicts the lowest-priority groups until the rest fit."
188
+ param world World "The world."
189
+ param bytes f64 "The bytes resident groups may take."
190
+ returns Result.Void "Refused for a negative or non-finite size."
191
+ }
192
+ ```
193
+
194
+ <sub>`api.ogt` line 11354</sub>
195
+
196
+ ## Components, resources and events
197
+
198
+ <a id="record-StreamEvent"></a>
199
+
200
+ ### `og.StreamEvent` (event)
201
+
202
+ A group changed state: sent by og.stream at the start of the tick after the change.
203
+
204
+ Token `og.StreamEvent`, registered under the schema name `og.StreamEvent`; its value type is `StreamEvent`.
205
+
206
+ | Field | Type | Default | Range | Unit | Notes | Doc |
207
+ |---|---|---|---|---|---|---|
208
+ | `group` | `string` | `""` | — | — | — | The group's name (at most 63 bytes). |
209
+ | `state` | `number` | `0` | — | — | — | Its new state: STREAM_UNLOADED, STREAM_QUEUED, STREAM_LOADING, STREAM_RESIDENT or STREAM_FAILED (StreamState's order). |
210
+
211
+ ```ogt
212
+ event StreamEvent {
213
+ doc "A group changed state: sent by og.stream at the start of the tick after the change."
214
+ field group String "The group's name (at most 63 bytes)."
215
+ field state u32 "Its new state: STREAM_UNLOADED, STREAM_QUEUED, STREAM_LOADING, STREAM_RESIDENT or STREAM_FAILED (StreamState's order)."
216
+ }
217
+ ```
218
+
219
+ <sub>`api.ogt` line 11280</sub>
220
+
221
+ ## Types
222
+
223
+ <a id="type-StreamState"></a>
224
+
225
+ ### `StreamState` (enum)
226
+
227
+ Where a streaming group is.
228
+
229
+ A string: one of the variants below. The zero value is `"unloaded"`.
230
+
231
+ | Variant | Doc |
232
+ |---|---|
233
+ | `"unloaded"` | Not wanted; its assets draw and play their stand-ins. |
234
+ | `"queued"` | Wanted, waiting for room in the memory budget. |
235
+ | `"loading"` | Admitted: its pack is being read (its memory already counts). |
236
+ | `"resident"` | Its assets are in place of their stand-ins. |
237
+ | `"failed"` | Its pack could not be read, or it alone needs more than the budget (StreamStatus.reason says which). |
238
+
239
+ ```ogt
240
+ enum StreamState {
241
+ doc "Where a streaming group is."
242
+ variant unloaded "Not wanted; its assets draw and play their stand-ins."
243
+ variant queued "Wanted, waiting for room in the memory budget."
244
+ variant loading "Admitted: its pack is being read (its memory already counts)."
245
+ variant resident "Its assets are in place of their stand-ins."
246
+ variant failed "Its pack could not be read, or it alone needs more than the budget (StreamStatus.reason says which)."
247
+ }
248
+ ```
249
+
250
+ <sub>`api.ogt` line 11265</sub>
251
+
252
+ <a id="type-StreamStatus"></a>
253
+
254
+ ### `StreamStatus` (struct)
255
+
256
+ One streaming group.
257
+
258
+ | Field | Type | Default | Range | Unit | Notes | Doc |
259
+ |---|---|---|---|---|---|---|
260
+ | `name` | `string` | `""` | — | — | — | Its name. |
261
+ | `scene` | `string` | `""` | — | — | — | The scene that declares it. |
262
+ | `state` | `StreamState` | `"unloaded"` | — | — | — | Where it is. |
263
+ | `wanted` | `boolean` | `false` | — | — | — | Whether its trigger or a request wants it now. |
264
+ | `requested` | `boolean` | `false` | — | — | — | Whether og.stream.request asked for it (until og.stream.release). |
265
+ | `priority` | `number` | `0` | — | — | — | Higher loads first and is evicted last. |
266
+ | `trigger` | `string` | `""` | — | — | — | manual, distance or volume. |
267
+ | `memory` | `number` | `0` | — | `bytes` | — | What its assets take once loaded, in bytes. |
268
+ | `bytes` | `number` | `0` | — | `bytes` | — | Its pack's size, in bytes. |
269
+ | `assets` | `readonly string[]` | `[]` | — | — | — | Its asset ids. |
270
+ | `reason` | `string` | `""` | — | — | — | Why it is queued or failed; empty otherwise. |
271
+ | `since` | `number` | `0` | — | — | — | The tick of its last change. |
272
+ | `loads` | `number` | `0` | — | — | — | How many times it became resident. |
273
+ | `kept` | `number` | `0` | — | `bytes` | — | The bytes of its assets kept for the frame after it unloaded (counted in StreamBudget.used until let go); 0 otherwise. |
274
+
275
+ ```ogt
276
+ struct StreamStatus {
277
+ doc "One streaming group."
278
+ field name String "Its name."
279
+ field scene String "The scene that declares it."
280
+ field state StreamState "Where it is."
281
+ field wanted bool "Whether its trigger or a request wants it now."
282
+ field requested bool "Whether og.stream.request asked for it (until og.stream.release)."
283
+ field priority i32 "Higher loads first and is evicted last."
284
+ field trigger String "manual, distance or volume."
285
+ field memory f64 "What its assets take once loaded, in bytes." {
286
+ unit bytes
287
+ }
288
+ field bytes f64 "Its pack's size, in bytes." {
289
+ unit bytes
290
+ }
291
+ field assets List.String "Its asset ids."
292
+ field reason String "Why it is queued or failed; empty otherwise."
293
+ field since f64 "The tick of its last change."
294
+ field loads u32 "How many times it became resident."
295
+ field kept f64 "The bytes of its assets kept for the frame after it unloaded (counted in StreamBudget.used until let go); 0 otherwise." {
296
+ unit bytes
297
+ }
298
+ }
299
+ ```
300
+
301
+ <sub>`api.ogt` line 11286</sub>
302
+
303
+ <a id="type-StreamBudget"></a>
304
+
305
+ ### `StreamBudget` (struct)
306
+
307
+ The streaming memory budget and every group.
308
+
309
+ | Field | Type | Default | Range | Unit | Notes | Doc |
310
+ |---|---|---|---|---|---|---|
311
+ | `budget` | `number` | `0` | — | `bytes` | — | The bytes resident and loading groups may take. |
312
+ | `used` | `number` | `0` | — | `bytes` | — | The bytes they take now, with what unloaded groups keep for the frame. |
313
+ | `kept` | `number` | `0` | — | `bytes` | — | Of `used`, the bytes of assets kept for the frame after their group unloaded (an array a sprite still draws, the map the frame is lit by, ...). |
314
+ | `peak` | `number` | `0` | — | `bytes` | — | The most they ever took (never above the budget at the time). |
315
+ | `groups` | `readonly StreamStatus[]` | `[]` | — | — | — | Every group, by name. |
316
+
317
+ ```ogt
318
+ struct StreamBudget {
319
+ doc "The streaming memory budget and every group."
320
+ field budget f64 "The bytes resident and loading groups may take." {
321
+ unit bytes
322
+ }
323
+ field used f64 "The bytes they take now, with what unloaded groups keep for the frame." {
324
+ unit bytes
325
+ }
326
+ field kept f64 "Of `used`, the bytes of assets kept for the frame after their group unloaded (an array a sprite still draws, the map the frame is lit by, ...)." {
327
+ unit bytes
328
+ }
329
+ field peak f64 "The most they ever took (never above the budget at the time)." {
330
+ unit bytes
331
+ }
332
+ field groups List.StreamStatus "Every group, by name."
333
+ }
334
+ ```
335
+
336
+ <sub>`api.ogt` line 11310</sub>
337
+
338
+ ## Constants
339
+
340
+ | Constant | Type | Value | Doc |
341
+ |---|---|---|---|
342
+ | <a id="const-STREAM_UNLOADED"></a>`STREAM_UNLOADED` | `number` | `0` | `StreamEvent.state`: the group is unloaded (StreamState unloaded). |
343
+ | <a id="const-STREAM_QUEUED"></a>`STREAM_QUEUED` | `number` | `1` | `StreamEvent.state`: the group waits for room in the budget (StreamState queued). |
344
+ | <a id="const-STREAM_LOADING"></a>`STREAM_LOADING` | `number` | `2` | `StreamEvent.state`: the group's pack is being read (StreamState loading). |
345
+ | <a id="const-STREAM_RESIDENT"></a>`STREAM_RESIDENT` | `number` | `3` | `StreamEvent.state`: the group's assets are in place (StreamState resident). |
346
+ | <a id="const-STREAM_FAILED"></a>`STREAM_FAILED` | `number` | `4` | `StreamEvent.state`: the group failed (StreamState failed; og.stream.status says why). |
347
+
348
+ ```ogt
349
+ const STREAM_UNLOADED u32 0 "`StreamEvent.state`: the group is unloaded (StreamState unloaded)."
350
+ ```
351
+
352
+ <sub>`api.ogt` line 11274</sub>
353
+
354
+ ```ogt
355
+ const STREAM_QUEUED u32 1 "`StreamEvent.state`: the group waits for room in the budget (StreamState queued)."
356
+ ```
357
+
358
+ <sub>`api.ogt` line 11275</sub>
359
+
360
+ ```ogt
361
+ const STREAM_LOADING u32 2 "`StreamEvent.state`: the group's pack is being read (StreamState loading)."
362
+ ```
363
+
364
+ <sub>`api.ogt` line 11276</sub>
365
+
366
+ ```ogt
367
+ const STREAM_RESIDENT u32 3 "`StreamEvent.state`: the group's assets are in place (StreamState resident)."
368
+ ```
369
+
370
+ <sub>`api.ogt` line 11277</sub>
371
+
372
+ ```ogt
373
+ const STREAM_FAILED u32 4 "`StreamEvent.state`: the group failed (StreamState failed; og.stream.status says why)."
374
+ ```
375
+
376
+ <sub>`api.ogt` line 11278</sub>
@@ -0,0 +1,197 @@
1
+ <!-- Generated from crates/og-api/api.ogt by `og api gen`. Do not edit: `og api check` fails on any difference; change api.ogt and regenerate. -->
2
+
3
+ # The `system` module
4
+
5
+ Systems: functions the engine calls once per tick with their matched archetypes.
6
+
7
+ A system declares what it reads and writes; a write to an undeclared component is refused at registration with the field name.
8
+
9
+ Its query is every component of its reads and writes together: an entity matches only when it has all of them (and none of `without`). A component declared to read one entity with world.get (the player's car) therefore narrows the loop to entities that have it too, often to none, silently. world.query is refused inside a system, by design (a system reaches only what it declared, so its access is known before it runs): loop over each archetype in a system of its own, declaring only that archetype's components, and carry what crosses between systems in a resource.
10
+
11
+ Resources and events it reaches through the world must be declared too: in a dev or release build (og run, og test) an undeclared read or write throws with the system's name and the record and fails the tick; a publish build refuses it and logs it once per system in the engine log, and the game keeps running. og.Rng among the reads may fork (a fork reads the seed only and leaves the stream as it is); a draw moves the stream, so it needs og.Rng among the writes.
12
+
13
+ - **TypeScript**: functions are named exports of the package: `import { … } from "@origingame/engine"`; components, resources and events are tokens on `og`.
14
+ - **Publish builds**: kept (members may override).
15
+ - **Skill**: `og-core`, which teaches the module (how much of it to use, and how to prove it).
16
+ - **Index**: [every module and name](index.md).
17
+
18
+ ```ogt
19
+ module system {
20
+ # declarations follow, each quoted below
21
+ ```
22
+
23
+ <sub>`api.ogt` line 417</sub>
24
+
25
+ ## Contents
26
+
27
+ | Name | Kind | Summary |
28
+ |---|---|---|
29
+ | [`SystemDesc`](#type-SystemDesc) | desc struct | A system's declared access and order. |
30
+ | [`SystemRun`](#type-SystemRun) | callback | A system's body. It is called once per tick; loop over `q.archetypes()`, then over rows. |
31
+ | [`System`](#type-System) | interface | A registered system. |
32
+ | [`defineSystem`](#fn-defineSystem) | function | Declare a system. |
33
+
34
+ ## Functions
35
+
36
+ <a id="fn-defineSystem"></a>
37
+
38
+ ### `defineSystem`
39
+
40
+ Declare a system.
41
+
42
+ ```ts
43
+ defineSystem(name: string, desc: SystemDesc, run: SystemRun): System
44
+ ```
45
+
46
+ | Parameter | Type | Optional | Doc |
47
+ |---|---|---|---|
48
+ | `name` | `string` | no | The system's unique name, PascalCase. |
49
+ | `desc` | `SystemDesc` | no | Reads, writes and order. |
50
+ | `run` | `SystemRun` | no | The body. |
51
+
52
+ **Returns** `System`.
53
+
54
+ Binding symbol `og_system_define_system` · publish builds: kept
55
+
56
+ ```ogt
57
+ fn defineSystem {
58
+ doc "Declare a system."
59
+ param name String "The system's unique name, PascalCase."
60
+ param desc SystemDesc "Reads, writes and order."
61
+ param run SystemRun "The body."
62
+ returns System
63
+ }
64
+ ```
65
+
66
+ <sub>`api.ogt` line 449</sub>
67
+
68
+ ## Interfaces
69
+
70
+ <a id="type-System"></a>
71
+
72
+ ### `System` (interface)
73
+
74
+ A registered system.
75
+
76
+ ```ogt
77
+ interface System {
78
+ doc "A registered system."
79
+ # members follow, each quoted below
80
+ ```
81
+
82
+ <sub>`api.ogt` line 442</sub>
83
+
84
+ <a id="member-System-name"></a>
85
+
86
+ #### `System.name` (property)
87
+
88
+ The system's unique name.
89
+
90
+ ```ts
91
+ readonly name: string
92
+ ```
93
+
94
+ Binding symbol `og_system_get_name` · publish builds: kept
95
+
96
+ ```ogt
97
+ prop name String "The system's unique name."
98
+ ```
99
+
100
+ <sub>`api.ogt` line 444</sub>
101
+
102
+ <a id="member-System-reads"></a>
103
+
104
+ #### `System.reads` (property)
105
+
106
+ What it reads.
107
+
108
+ ```ts
109
+ readonly reads: readonly AnyReflected[]
110
+ ```
111
+
112
+ Binding symbol `og_system_get_reads` · publish builds: kept
113
+
114
+ ```ogt
115
+ prop reads List.AnyReflected "What it reads."
116
+ ```
117
+
118
+ <sub>`api.ogt` line 445</sub>
119
+
120
+ <a id="member-System-writes"></a>
121
+
122
+ #### `System.writes` (property)
123
+
124
+ What it writes.
125
+
126
+ ```ts
127
+ readonly writes: readonly AnyReflected[]
128
+ ```
129
+
130
+ Binding symbol `og_system_get_writes` · publish builds: kept
131
+
132
+ ```ogt
133
+ prop writes List.AnyReflected "What it writes."
134
+ ```
135
+
136
+ <sub>`api.ogt` line 446</sub>
137
+
138
+ ## Types
139
+
140
+ <a id="type-SystemDesc"></a>
141
+
142
+ ### `SystemDesc` (desc struct)
143
+
144
+ A system's declared access and order.
145
+
146
+ A desc: every field may be omitted and takes its default; `{}` is valid.
147
+
148
+ | Field | Type | Default | Range | Unit | Notes | Doc |
149
+ |---|---|---|---|---|---|---|
150
+ | `reads` | `readonly (AnyReflected \| AnyEvent)[]` | `[]` | — | — | — | Components, resources and events the system reads (world.events). Every component here is also required by its query: a matched entity has all of the reads' and writes' components. |
151
+ | `writes` | `readonly (AnyReflected \| AnyEvent)[]` | `[]` | — | — | — | Components, resources and events the system writes (world.emit). Every component here is also required by its query, with the reads'. |
152
+ | `without` | `readonly AnyComponent[]` | `[]` | — | — | — | Components a matched entity must not have. |
153
+ | `after` | `readonly string[]` | `[]` | — | — | — | Names of systems that must run before this one. |
154
+ | `before` | `readonly string[]` | `[]` | — | — | — | Names of systems that must run after this one. |
155
+
156
+ ```ogt
157
+ struct SystemDesc {
158
+ doc "A system's declared access and order."
159
+ desc true
160
+ field reads List.OneOf.AnyReflected.AnyEvent "Components, resources and events the system reads (world.events). Every component here is also required by its query: a matched entity has all of the reads' and writes' components."
161
+ field writes List.OneOf.AnyReflected.AnyEvent "Components, resources and events the system writes (world.emit). Every component here is also required by its query, with the reads'."
162
+ field without List.AnyComponent "Components a matched entity must not have."
163
+ field after List.String "Names of systems that must run before this one."
164
+ field before List.String "Names of systems that must run after this one."
165
+ }
166
+ ```
167
+
168
+ <sub>`api.ogt` line 425</sub>
169
+
170
+ <a id="type-SystemRun"></a>
171
+
172
+ ### `SystemRun` (callback)
173
+
174
+ A system's body. It is called once per tick; loop over `q.archetypes()`, then over rows.
175
+
176
+ Game code supplies this function.
177
+
178
+ ```ts
179
+ type SystemRun = (q: Query, time: Time, world: World) => void
180
+ ```
181
+
182
+ | Parameter | Type | Optional | Doc |
183
+ |---|---|---|---|
184
+ | `q` | `Query` | no | The archetypes matching the declared components. |
185
+ | `time` | `Time` | no | The Time resource for this tick. |
186
+ | `world` | `World` | no | The world, for resources, events and structural changes. |
187
+
188
+ ```ogt
189
+ callback SystemRun {
190
+ doc "A system's body. It is called once per tick; loop over `q.archetypes()`, then over rows."
191
+ param q Query "The archetypes matching the declared components."
192
+ param time Time "The Time resource for this tick."
193
+ param world World "The world, for resources, events and structural changes."
194
+ }
195
+ ```
196
+
197
+ <sub>`api.ogt` line 435</sub>
@@ -0,0 +1,43 @@
1
+ <!-- Generated from crates/og-api/api.ogt by `og api gen`. Do not edit: `og api check` fails on any difference; change api.ogt and regenerate. -->
2
+
3
+ # The `systems` module
4
+
5
+ Systems the engine ships as TypeScript: game-level code, listed explicitly in GameDesc.systems like the game's own, so the schedule (and dump_world) shows them and nothing runs that the game did not ask for.
6
+
7
+ - **TypeScript**: functions are none at module level (its members live on the types below); components, resources and events are tokens on `og`.
8
+ - **Publish builds**: kept (members may override).
9
+ - **Skill**: `og-feel`, which teaches the module (how much of it to use, and how to prove it).
10
+ - **Index**: [every module and name](index.md).
11
+
12
+ ```ogt
13
+ module systems {
14
+ # declarations follow, each quoted below
15
+ ```
16
+
17
+ <sub>`api.ogt` line 10346</sub>
18
+
19
+ ## Contents
20
+
21
+ | Name | Kind | Summary |
22
+ |---|---|---|
23
+ | [`og.systems.cameras`](#value-cameras) | value | The camera controllers, in this order: og.orbitCamera (og.OrbitCamera), og.followCamera (og.FollowCamera) and og.follow2D (og.Follow2D). Each moves og.Camera only while an entity carries its component. List them before the game's systems that read og.Camera: `systems: [...og.systems.cameras, ...yours]`. |
24
+
25
+ ## Values
26
+
27
+ Provided by the TypeScript runtime: no binding symbol.
28
+
29
+ <a id="value-cameras"></a>
30
+
31
+ ### `og.systems.cameras`
32
+
33
+ The camera controllers, in this order: og.orbitCamera (og.OrbitCamera), og.followCamera (og.FollowCamera) and og.follow2D (og.Follow2D). Each moves og.Camera only while an entity carries its component. List them before the game's systems that read og.Camera: `systems: [...og.systems.cameras, ...yours]`.
34
+
35
+ ```ts
36
+ const cameras: readonly System[]
37
+ ```
38
+
39
+ ```ogt
40
+ value cameras List.System "The camera controllers, in this order: og.orbitCamera (og.OrbitCamera), og.followCamera (og.FollowCamera) and og.follow2D (og.Follow2D). Each moves og.Camera only while an entity carries its component. List them before the game's systems that read og.Camera: `systems: [...og.systems.cameras, ...yours]`."
41
+ ```
42
+
43
+ <sub>`api.ogt` line 10350</sub>