lecodes-sdk 1.2.0 → 2.0.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 (260) hide show
  1. package/README.md +5 -2
  2. package/dist/editor.d.ts +12 -0
  3. package/dist/global.d.ts +4 -8
  4. package/dist/host.d.ts +2 -3
  5. package/dist/types/animate/tween/Animation.d.ts +0 -3
  6. package/dist/types/animate/tween/animateValue.d.ts +4 -2
  7. package/dist/types/animate/tween/easing.d.ts +8 -0
  8. package/dist/types/animate/tween/spec.d.ts +15 -7
  9. package/dist/types/audio/audio.d.ts +2 -1
  10. package/dist/types/canvas/Canvas.d.ts +40 -108
  11. package/dist/types/canvas/gen/cssColor.d.ts +17 -0
  12. package/dist/types/canvas/gen/recorder.d.ts +118 -0
  13. package/dist/types/canvas/gen/spec.d.ts +144 -0
  14. package/dist/types/core/color.d.ts +3 -1
  15. package/dist/types/core/pins.d.ts +18 -0
  16. package/dist/types/g2/Node2D.d.ts +5 -8
  17. package/dist/types/g2/Scene2D.d.ts +6 -2
  18. package/dist/types/gl/Foliage.d.ts +30 -7
  19. package/dist/types/gl/Light.d.ts +8 -0
  20. package/dist/types/gl/Lightmap.d.ts +13 -2
  21. package/dist/types/gl/Material.d.ts +17 -3
  22. package/dist/types/gl/Model.d.ts +6 -2
  23. package/dist/types/gl/Node.d.ts +3 -6
  24. package/dist/types/gl/Scene.d.ts +41 -13
  25. package/dist/types/gl/Texture.d.ts +1 -1
  26. package/dist/types/gl/animation/Locomotion.d.ts +8 -1
  27. package/dist/types/inject.d.ts +11 -11
  28. package/dist/types/inject.editor.d.ts +1 -0
  29. package/dist/types/net/core.d.ts +7 -0
  30. package/dist/types/plugin.d.ts +76 -0
  31. package/dist/types/plugins/gen/camera/sdk/camera.d.ts +24 -0
  32. package/dist/types/plugins/gen/camera/sdk/camera.gen.d.ts +25 -0
  33. package/dist/types/plugins/{geolocation.d.ts → gen/geolocation/sdk/geolocation.d.ts} +2 -20
  34. package/dist/types/plugins/gen/geolocation/sdk/geolocation.gen.d.ts +31 -0
  35. package/dist/types/plugins/{map.d.ts → gen/map/sdk/map.d.ts} +9 -50
  36. package/dist/types/plugins/gen/map/sdk/map.gen.d.ts +53 -0
  37. package/dist/types/plugins/gen/push/sdk/push.d.ts +23 -0
  38. package/dist/types/plugins/gen/push/sdk/push.gen.d.ts +35 -0
  39. package/dist/types/plugins/{qr.d.ts → gen/qr-scanner/sdk/qr-scanner.d.ts} +2 -3
  40. package/dist/types/plugins/gen/qr-scanner/sdk/qr-scanner.gen.d.ts +15 -0
  41. package/dist/types/runtime/app.d.ts +9 -2
  42. package/dist/types/runtime/fetch.d.ts +2 -0
  43. package/dist/types/runtime/input.d.ts +1 -1
  44. package/dist/types/runtime/media.d.ts +6 -10
  45. package/dist/types/runtime/misc.d.ts +4 -1
  46. package/dist/types/runtime/net.d.ts +3 -2
  47. package/dist/types/runtime/touch.d.ts +32 -0
  48. package/dist/types/scene/defineScene.d.ts +43 -2
  49. package/dist/types/scene/editor.d.ts +52 -0
  50. package/dist/types/scene/gizmos.d.ts +7 -4
  51. package/dist/types/ui/NativeView.d.ts +6 -4
  52. package/dist/types/ui/UI.d.ts +1 -1
  53. package/dist/types/ui/UIBottomSheet.d.ts +6 -12
  54. package/dist/types/ui/UIButton.d.ts +12 -14
  55. package/dist/types/ui/UIContainer.d.ts +0 -6
  56. package/dist/types/ui/UIImage.d.ts +1 -4
  57. package/dist/types/ui/UIInput.d.ts +8 -24
  58. package/dist/types/ui/UIModal.d.ts +0 -2
  59. package/dist/types/ui/UINode.d.ts +70 -56
  60. package/dist/types/ui/UIPager.d.ts +28 -27
  61. package/dist/types/ui/UIPopover.d.ts +0 -2
  62. package/dist/types/ui/UIScreen.d.ts +12 -17
  63. package/dist/types/ui/UIScrollable.d.ts +1 -4
  64. package/dist/types/ui/UIText.d.ts +0 -2
  65. package/dist/types/ui/UIVideo.d.ts +3 -5
  66. package/dist/types/ui/UIVirtualizedList.d.ts +14 -16
  67. package/dist/types/ui/UIWidget.d.ts +10 -9
  68. package/dist/types/ui/colorKeys.gen.d.ts +9 -0
  69. package/dist/types/ui/presentable.d.ts +46 -32
  70. package/dist/types/ui/router.d.ts +18 -7
  71. package/dist/types/ui/styleColor.d.ts +1 -0
  72. package/dist/types/ui/transitions.d.ts +18 -0
  73. package/dist/types/ui/tree.d.ts +75 -0
  74. package/dist/types/version.d.ts +10 -0
  75. package/dist/types.json +1 -1
  76. package/package.json +12 -3
  77. package/prompts/2d.md +2 -6
  78. package/prompts/3d.md +1 -5
  79. package/prompts/README.md +1 -1
  80. package/prompts/canvas.md +9 -8
  81. package/prompts/compose.ts +1 -1
  82. package/prompts/core.md +3 -3
  83. package/prompts/design.md +1 -1
  84. package/prompts/dist/2d-game.md +473 -239
  85. package/prompts/dist/3d-app.md +553 -205
  86. package/prompts/dist/ar-app.md +435 -202
  87. package/prompts/dist/design.md +113 -95
  88. package/prompts/dist/ui-app.md +386 -170
  89. package/prompts/ui-design.md +2 -3
  90. package/prompts/ui.md +45 -37
  91. package/src/animate/tween/Animation.ts +34 -150
  92. package/src/animate/tween/Timeline.ts +175 -175
  93. package/src/animate/tween/animateValue.ts +6 -3
  94. package/src/animate/tween/easing.ts +10 -3
  95. package/src/animate/tween/spec.ts +41 -15
  96. package/src/audio/Sound.ts +3 -3
  97. package/src/audio/audio.ts +2 -1
  98. package/src/bridges/2d.d.ts +317 -0
  99. package/src/bridges/app.d.ts +91 -0
  100. package/src/bridges/audio.d.ts +97 -0
  101. package/src/bridges/canvas.d.ts +79 -0
  102. package/src/bridges/device.d.ts +72 -0
  103. package/src/bridges/fetch.d.ts +80 -0
  104. package/src/bridges/files.d.ts +70 -0
  105. package/src/bridges/gl.d.ts +1133 -0
  106. package/src/bridges/input.d.ts +72 -0
  107. package/src/bridges/media.d.ts +55 -0
  108. package/src/bridges/nav.d.ts +71 -0
  109. package/src/bridges/net.d.ts +52 -0
  110. package/src/bridges/service.d.ts +52 -0
  111. package/src/bridges/socket.d.ts +31 -0
  112. package/src/bridges/storage.d.ts +33 -0
  113. package/src/bridges/tree.d.ts +301 -0
  114. package/src/bridges/types.d.ts +49 -0
  115. package/src/canvas/Canvas.ts +114 -159
  116. package/src/canvas/gen/cssColor.ts +224 -0
  117. package/src/canvas/gen/recorder.ts +212 -0
  118. package/src/canvas/gen/spec.ts +201 -0
  119. package/src/chisel.ts +193 -0
  120. package/src/compile/assetMacro.ts +1 -1
  121. package/src/compile/bundler.ts +11 -2
  122. package/src/compile/compileProject.ts +43 -4
  123. package/src/compile/fontMacro.ts +3 -4
  124. package/src/compile/header.ts +26 -5
  125. package/src/compile/index.ts +3 -1
  126. package/src/compile/liteMaterial.ts +1 -1
  127. package/src/compile/sceneEditor.ts +11 -26
  128. package/src/core/color.ts +73 -30
  129. package/src/core/pins.ts +51 -0
  130. package/src/core/signals.ts +8 -1
  131. package/src/g2/CharacterController2D.ts +3 -3
  132. package/src/g2/Node2D.ts +57 -39
  133. package/src/g2/Physics2D.ts +2 -2
  134. package/src/g2/Scene2D.ts +35 -23
  135. package/src/g2/Texture2D.ts +1 -1
  136. package/src/g2/loop.ts +4 -4
  137. package/src/gl/CameraPlace.ts +52 -52
  138. package/src/gl/Foliage.ts +72 -17
  139. package/src/gl/Geometry.ts +1 -2
  140. package/src/gl/Light.ts +10 -0
  141. package/src/gl/Lightmap.ts +45 -29
  142. package/src/gl/Material.ts +95 -51
  143. package/src/gl/Mesh.ts +120 -120
  144. package/src/gl/Model.ts +21 -16
  145. package/src/gl/Node.ts +91 -24
  146. package/src/gl/Particles.ts +1 -1
  147. package/src/gl/Scene.ts +100 -44
  148. package/src/gl/Texture.ts +8 -7
  149. package/src/gl/animation/AnimationClip.ts +1 -1
  150. package/src/gl/animation/DynamicBone.ts +482 -482
  151. package/src/gl/animation/Locomotion.ts +8 -3
  152. package/src/gl/nav/NavMesh.ts +3 -4
  153. package/src/gl/physics/Physics.ts +2 -2
  154. package/src/gl/physics/physicsEvents.ts +3 -3
  155. package/src/gl/scenarios.ts +291 -291
  156. package/src/gl/terrain/Terrain.ts +4 -5
  157. package/src/gl/touch.ts +14 -15
  158. package/src/host.d.ts +2 -3
  159. package/src/inject.editor.ts +7 -0
  160. package/src/inject.ts +13 -16
  161. package/src/net/core.ts +6 -5
  162. package/src/net/index.ts +1 -1
  163. package/src/net/replication.ts +1 -1
  164. package/src/plugin.ts +191 -0
  165. package/src/plugins/gen/camera/contract.d.ts +27 -0
  166. package/src/plugins/gen/camera/sdk/camera.gen.ts +46 -0
  167. package/src/plugins/gen/camera/sdk/camera.ts +57 -0
  168. package/src/plugins/gen/geolocation/contract.d.ts +50 -0
  169. package/src/plugins/gen/geolocation/sdk/geolocation.gen.ts +54 -0
  170. package/src/plugins/{geolocation.ts → gen/geolocation/sdk/geolocation.ts} +22 -43
  171. package/src/plugins/gen/map/contract.d.ts +144 -0
  172. package/src/plugins/gen/map/sdk/map.gen.ts +88 -0
  173. package/src/plugins/{map.ts → gen/map/sdk/map.ts} +68 -102
  174. package/src/plugins/gen/push/contract.d.ts +61 -0
  175. package/src/plugins/gen/push/sdk/push.gen.ts +60 -0
  176. package/src/plugins/gen/push/sdk/push.ts +105 -0
  177. package/src/plugins/gen/qr-scanner/contract.d.ts +16 -0
  178. package/src/plugins/gen/qr-scanner/sdk/qr-scanner.gen.ts +29 -0
  179. package/src/plugins/gen/qr-scanner/sdk/qr-scanner.ts +52 -0
  180. package/src/plugins/permission.ts +5 -4
  181. package/src/runtime/app.ts +20 -9
  182. package/src/runtime/appEvents.ts +5 -4
  183. package/src/runtime/channel.ts +18 -15
  184. package/src/runtime/clipboard.ts +4 -3
  185. package/src/runtime/datetime.ts +2 -1
  186. package/src/runtime/device.ts +17 -15
  187. package/src/runtime/fetch.ts +30 -20
  188. package/src/runtime/files.ts +16 -15
  189. package/src/runtime/input.ts +12 -10
  190. package/src/runtime/media.ts +50 -46
  191. package/src/runtime/misc.ts +7 -3
  192. package/src/runtime/net.ts +8 -7
  193. package/src/runtime/rpc.ts +1 -3
  194. package/src/runtime/service.ts +19 -14
  195. package/src/runtime/share.ts +4 -3
  196. package/src/runtime/storage.ts +6 -4
  197. package/src/runtime/touch.ts +32 -0
  198. package/src/scene/defineScene.ts +61 -365
  199. package/src/scene/editor.ts +408 -0
  200. package/src/scene/editorPlugins.ts +3 -3
  201. package/src/scene/gizmos.ts +15 -9
  202. package/src/server/db/marci/query.ts +1 -1
  203. package/src/server/host.ts +1 -1
  204. package/src/server/runtime.ts +1 -1
  205. package/src/ui/NativeView.ts +72 -25
  206. package/src/ui/UI.ts +3 -3
  207. package/src/ui/UIBottomSheet.ts +16 -17
  208. package/src/ui/UIButton.ts +54 -16
  209. package/src/ui/UIContainer.ts +0 -6
  210. package/src/ui/UIImage.ts +34 -30
  211. package/src/ui/UIInput.ts +29 -37
  212. package/src/ui/UIModal.ts +1 -3
  213. package/src/ui/UINode.ts +347 -297
  214. package/src/ui/UIPager.ts +93 -78
  215. package/src/ui/UIPopover.ts +0 -2
  216. package/src/ui/UIScreen.ts +41 -36
  217. package/src/ui/UIScrollable.ts +19 -13
  218. package/src/ui/UISpacer.ts +1 -1
  219. package/src/ui/UITabs.ts +8 -6
  220. package/src/ui/UIText.ts +7 -17
  221. package/src/ui/UIVideo.ts +30 -27
  222. package/src/ui/UIVirtualizedList.ts +58 -59
  223. package/src/ui/UIWidget.ts +38 -18
  224. package/src/ui/colorKeys.gen.ts +37 -0
  225. package/src/ui/fonts.ts +2 -2
  226. package/src/ui/presentable.ts +59 -42
  227. package/src/ui/router.ts +52 -35
  228. package/src/ui/styleColor.ts +56 -0
  229. package/src/ui/theme.ts +7 -6
  230. package/src/ui/transitions.ts +249 -0
  231. package/src/ui/tree.ts +346 -0
  232. package/src/version.ts +24 -0
  233. package/tests/helpers/engineWorld.ts +11 -0
  234. package/tests/helpers/fakeTree.ts +353 -0
  235. package/tests/helpers/hostStubs.ts +31 -0
  236. package/tests/helpers/index.ts +14 -0
  237. package/tests/helpers/memoryMarci.ts +124 -0
  238. package/tests/helpers/phases.ts +23 -0
  239. package/tests/helpers/preload.ts +18 -0
  240. package/tests/helpers/stubApp.ts +2 -0
  241. package/tests/helpers/stubDevice.ts +2 -0
  242. package/tests/helpers/stubFetch.ts +2 -0
  243. package/tests/helpers/stubInput.ts +2 -0
  244. package/dist/inject.js +0 -4629
  245. package/dist/types/core/registry.d.ts +0 -7
  246. package/dist/types/plugins/camera.d.ts +0 -25
  247. package/dist/types/plugins/push.d.ts +0 -46
  248. package/src/bridges.d.ts +0 -1769
  249. package/src/compile/__tests__/assetIconMacro.test.ts +0 -219
  250. package/src/compile/__tests__/assetMacro.test.ts +0 -100
  251. package/src/compile/__tests__/assetName.test.ts +0 -55
  252. package/src/compile/__tests__/compile.test.ts +0 -310
  253. package/src/compile/__tests__/detectEntry.test.ts +0 -151
  254. package/src/compile/__tests__/fontMacro.test.ts +0 -199
  255. package/src/compile/__tests__/serverSplit.test.ts +0 -27
  256. package/src/core/__tests__/stateMachine.test.ts +0 -132
  257. package/src/core/registry.ts +0 -23
  258. package/src/plugins/camera.ts +0 -81
  259. package/src/plugins/push.ts +0 -132
  260. package/src/plugins/qr.ts +0 -73
@@ -0,0 +1,317 @@
1
+ // The 2D engine bridge (`_creator2d`): engines/2d (sokol + Box2D).
2
+ // Part of the host contract: every runtime implements this global (runtime/native in C++, the web
3
+ // runtimes in TS). Types are the PRECISE ones the native side reads (see ./types.d.ts); the SDK
4
+ // only sees numbers. The ABI checker (scripts/check-pkg-bridges.mjs) reads this folder.
5
+ import type { bytes, f32, f64, i32, u32 } from "./types"
6
+
7
+ declare global {
8
+ // ---- 2D engine (sokol / creator-2d) ----------------------------------------------------------
9
+ // A 2D-only project loads ONLY creator2d.wasm — never Filament.
10
+ /** @engine 2d */
11
+ var _creator2d: {
12
+ backend: string
13
+ /** @c creator2dVersion */
14
+ version(): i32
15
+ /** @c c2dRender */
16
+ render(nowMs: f32): void
17
+ /** @custom */
18
+ onUpdate(cb: (dt: number) => void): void
19
+ /** @custom */
20
+ offUpdate(cb: (dt: number) => void): void
21
+ // Render-synced aspect update(dt) dispatch, called from inside c2dRender. Early = before the
22
+ // physics step; late = after animations, just before draw. Single-slot per phase (the SDK's
23
+ // Aspect dispatcher registers one callback that iterates its ordered updater list).
24
+ /** @custom */
25
+ setEarlyUpdate(cb: (dt: number) => void): void
26
+ /** @custom */
27
+ setLateUpdate(cb: (dt: number) => void): void
28
+ /** Clock multiplier for the 2D physics step + sprite animations (see `_creator.setTimeScale`). @c c2dSetTimeScale */
29
+ setTimeScale?(scale: f64): void
30
+ /** @custom */
31
+ setOnAnimEvent(cb: (ev: { entityId: number, clipId: number, type: number }) => void): void
32
+ // Raw scene pointer events from the host (canvas / iOS view). phase: 0 down, 1 move, 2 up, 3 cancel;
33
+ // x,y in logical (CSS px / iOS point) coords relative to the surface. The SDK hit-tests + tracks.
34
+ /** @custom */
35
+ setOnPointer(cb: (phase: number, pointerId: number, x: number, y: number) => void): void
36
+ /** @c c2dSetClearColor */
37
+ setClearColor(r: f32, g: f32, b: f32, a: f32): void
38
+
39
+ /** @c c2dCreateScene @custom web */
40
+ createScene(): i32
41
+ /** @c c2dDestroyScene @custom web */
42
+ destroyScene(sceneId: i32): void
43
+ /** @c c2dOpenScene @custom */
44
+ openScene(sceneId: i32): void
45
+ /** @c c2dCloseScene @custom */
46
+ closeScene(): void
47
+ /** @c c2dSceneSetClearColor */
48
+ sceneSetClearColor(sceneId: i32, r: f32, g: f32, b: f32, a: f32): void
49
+ /** @c c2dAddEntityToScene */
50
+ addEntityToScene(sceneId: i32, entityId: i32): void
51
+ /** @c c2dRemoveEntityFromScene */
52
+ removeEntityFromScene(sceneId: i32, entityId: i32): void
53
+ /** @c c2dSetLayerYSort */
54
+ setLayerYSort(sceneId: i32, layer: i32, enabled: boolean): void
55
+
56
+ /** @c c2dCameraSetPosition */
57
+ cameraSetPosition(sceneId: i32, x: f32, y: f32): void
58
+ /** @c c2dCameraSetZoom @custom web */
59
+ cameraSetZoom(sceneId: i32, zoom: f32): void
60
+ /** @c c2dCameraSetRotation */
61
+ cameraSetRotation(sceneId: i32, deg: f32): void
62
+ /** @c c2dCameraScreenToWorld @out 2 @custom web */
63
+ cameraScreenToWorld(sceneId: i32, sx: f32, sy: f32): Float32Array
64
+ /** @c c2dCameraWorldToScreen @out 2 @custom web */
65
+ cameraWorldToScreen(sceneId: i32, wx: f32, wy: f32): Float32Array
66
+
67
+ /** An OWNED root (owned.h): loose and dropped → its whole subtree goes. @c c2dCreateEntity @owned Entity2d */
68
+ createEntity(): Handle
69
+ /** The subtree, its records, and the SDK hears the ids (the freed channel). @custom */
70
+ destroyEntity(entityId: i32): void
71
+ /** True while the engine holds the entity (a parent, a scene). @c c2dEntityIsOwned */
72
+ entityIsOwned(entityId: i32): boolean
73
+ /** @c c2dSetPosition */
74
+ setPosition(entityId: i32, x: f32, y: f32): void
75
+ /** @c c2dSetRotation */
76
+ setRotation(entityId: i32, deg: f32): void
77
+ /** @c c2dSetScale */
78
+ setScale(entityId: i32, sx: f32, sy: f32): void
79
+ /** @c c2dSetLayer */
80
+ setLayer(entityId: i32, layer: i32): void
81
+ /** @c c2dSetZ */
82
+ setZ(entityId: i32, z: f32): void
83
+ /** @c c2dSetVisible */
84
+ setVisible(entityId: i32, visible: boolean): void
85
+ /** @c c2dGetPosition @out 2 */
86
+ getPosition(entityId: i32): Float32Array
87
+
88
+ /** @c c2dSetParent */
89
+ setParent(childId: i32, parentId: i32, keepWorld: boolean): void
90
+ /** @c c2dGetParent */
91
+ getParent(entityId: i32): i32
92
+ /** @c c2dGetChildCount */
93
+ getChildCount(entityId: i32): i32
94
+ /** @c c2dGetChild */
95
+ getChild(entityId: i32, index: i32): i32
96
+ /** @c c2dGetWorldPosition @out 2 */
97
+ getWorldPosition(entityId: i32): Float32Array
98
+ /** @c c2dGetWorldMatrix @out 6 */
99
+ getWorldMatrix(entityId: i32): Float32Array
100
+ /** @c c2dWorldToLocal @out 2 */
101
+ worldToLocal(entityId: i32, wx: f32, wy: f32): Float32Array
102
+ /** @c c2dLocalToWorld @out 2 */
103
+ localToWorld(entityId: i32, lx: f32, ly: f32): Float32Array
104
+ /** @c c2dGetLocalTransform @out 5 */
105
+ getLocalTransform(entityId: i32): Float32Array
106
+
107
+ /** @c c2dSetSprite */
108
+ setSprite(entityId: i32, textureId: i32): void
109
+ /** @c c2dSetSpriteFrame */
110
+ setSpriteFrame(entityId: i32, u0: f32, v0: f32, u1: f32, v1: f32): void
111
+ /** @c c2dSetSpriteFramePx */
112
+ setSpriteFramePx(entityId: i32, px: f32, py: f32, pw: f32, ph: f32): void
113
+ /** @c c2dSetSpriteSize */
114
+ setSpriteSize(entityId: i32, w: f32, h: f32): void
115
+ /** @c c2dSetSpriteAnchor */
116
+ setSpriteAnchor(entityId: i32, ax: f32, ay: f32): void
117
+ /** @c c2dSetSpriteColor */
118
+ setSpriteColor(entityId: i32, r: f32, g: f32, b: f32): void
119
+ /** @c c2dSetSpriteOpacity */
120
+ setSpriteOpacity(entityId: i32, a: f32): void
121
+ /** @c c2dSetSpriteFlip */
122
+ setSpriteFlip(entityId: i32, flipX: boolean, flipY: boolean): void
123
+
124
+ /** @custom */
125
+ createTexture(systemId: bytes, onComplete: (texId: number, w: number, h: number) => void, onReject: (e: any) => void): void
126
+ /** @c c2dGetTextureWidth */
127
+ getTextureWidth(texId: i32): i32
128
+ /** @c c2dGetTextureHeight */
129
+ getTextureHeight(texId: i32): i32
130
+ /** @c c2dDestroyTexture */
131
+ destroyTexture(texId: i32): void
132
+ /** @c c2dSetDefaultFilter */
133
+ setDefaultFilter(linear: boolean): void
134
+
135
+ // Textures from a _creatorCanvas surface (RGBA8, already rasterized — no decode, so synchronous).
136
+ // See ./canvas.d.ts.
137
+ /** @custom */
138
+ createTextureFromCanvas(surfaceId: i32): i32
139
+ /** @custom */
140
+ updateTextureFromCanvas(texId: i32, surfaceId: i32): void
141
+
142
+ /** @c c2dDefineAnimation @count frameCount=frames/4 */
143
+ defineAnimation(entityId: i32, frames: Float32Array, fps: f32, loop: boolean): i32
144
+ /** @c c2dPlayAnimation */
145
+ playAnimation(entityId: i32, clipId: i32): void
146
+ /** @c c2dStopAnimation */
147
+ stopAnimation(entityId: i32): void
148
+ /** @c c2dSetAnimationSpeed */
149
+ setAnimationSpeed(entityId: i32, speed: f32): void
150
+ /** @c c2dGetAnimationFrame */
151
+ getAnimationFrame(entityId: i32): i32
152
+
153
+ /** @c c2dCreateTilemap */
154
+ createTilemap(textureId: i32, cols: i32, rows: i32, tileW: f32, tileH: f32, atlasCols: i32, atlasRows: i32, data: Int32Array): i32
155
+ /** @c c2dSetTile */
156
+ setTile(tilemapId: i32, x: i32, y: i32, index: i32): void
157
+
158
+ /** @c c2dBulkSetPositions */
159
+ bulkSetPositions(ids: Uint32Array, xy: Float32Array, count: i32): void
160
+
161
+ // physics (Box2D v3; present only in CREATOR_2D_PHYSICS builds — physicsHasSupport() reports it).
162
+ // See docs/2d-physics-plan.md. physicsHasSupport() reports the BUILD, not the world: the world is
163
+ // created lazily by the first physicsCreateBody, so configure() is optional.
164
+ /** @c c2dPhysicsHasSupport */
165
+ physicsHasSupport(): boolean
166
+ /** Live and non-destructive: an existing world keeps its bodies and takes the new gravity.
167
+ * pixelsPerMeter only applies to a world that doesn't exist yet (global Box2D tolerance). @c c2dPhysicsConfigure */
168
+ physicsConfigure(gx: f32, gy: f32, pixelsPerMeter: f32, subStepCount: i32): void
169
+ /** @c c2dSetInterpolation */
170
+ setInterpolation(enabled: boolean): void
171
+ /** type 0 contactBegin / 1 contactEnd / 2 sensorBegin / 3 sensorEnd. A contact BEGIN carries the
172
+ * manifold — world point, normal pointing A→B, and the approach speed at impact; the other three
173
+ * carry zeros. (The begin manifold is pre-solve, so its impulses are all zero — `speed` is the
174
+ * pre-solve relative normal velocity, which is the number an impact actually wants.) @custom */
175
+ setOnPhysicsEvent(cb: (entityA: number, entityB: number, type: number, px: number, py: number, nx: number, ny: number, speed: number) => void): void
176
+ /** @c c2dPhysicsCreateBody */
177
+ physicsCreateBody(entityId: i32, motionType: i32): i32
178
+ /** @c c2dPhysicsRemoveBody */
179
+ physicsRemoveBody(bodyHandle: i32): void
180
+ // Shapes carry no `density` (built at density 1, so mass == area — physicsSetMass overrides) and
181
+ // do carry the collision filter. category/mask are 32-bit; 0 means "everything".
182
+ /** @c c2dPhysicsAddBox */
183
+ physicsAddBox(bodyHandle: i32, hw: f32, hh: f32, ox: f32, oy: f32, friction: f32, bounce: f32, isSensor: boolean, category: u32, mask: u32): void
184
+ /** @c c2dPhysicsAddCircle */
185
+ physicsAddCircle(bodyHandle: i32, radius: f32, ox: f32, oy: f32, friction: f32, bounce: f32, isSensor: boolean, category: u32, mask: u32): void
186
+ /** @c c2dPhysicsAddCapsule */
187
+ physicsAddCapsule(bodyHandle: i32, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32, friction: f32, bounce: f32, isSensor: boolean, category: u32, mask: u32): void
188
+ /** @c c2dPhysicsAddSegment */
189
+ physicsAddSegment(bodyHandle: i32, x1: f32, y1: f32, x2: f32, y2: f32, friction: f32, bounce: f32, category: u32, mask: u32): void
190
+ /** @c c2dPhysicsAddPolygon */
191
+ physicsAddPolygon(bodyHandle: i32, pts: Float32Array, count: i32, friction: f32, bounce: f32, isSensor: boolean, category: u32, mask: u32): void
192
+ /** A polyline of connected segments — long CONCAVE surfaces in one seam-free piece. STATIC bodies
193
+ * only, >= 4 points; the SDK synthesises the tangent points an open chain needs, because Box2D's
194
+ * first and last edges do not collide. One-sided: solid on the right of the point order. @c c2dPhysicsAddChain */
195
+ physicsAddChain(bodyHandle: i32, pts: Float32Array, count: i32, isLoop: boolean, friction: f32, bounce: f32, category: u32, mask: u32): void
196
+ /** Destroy every shape on a body, keeping the body (id, transform, velocity) — the first half of a
197
+ * live collider rebuild. @c c2dPhysicsClearShapes */
198
+ physicsClearShapes(bodyHandle: i32): void
199
+ /** Contact events are OFF per body until this turns them on — otherwise every crate-on-crate pair
200
+ * crosses the bridge every frame. The SDK enables it on the first 'enter'/'exit' listener. @c c2dPhysicsSetContactEvents */
201
+ physicsSetContactEvents(bodyHandle: i32, enabled: boolean): void
202
+ /** @c c2dPhysicsSetLinearVelocity */
203
+ physicsSetLinearVelocity(bodyHandle: i32, x: f32, y: f32): void
204
+ /** @c c2dPhysicsGetLinearVelocity @out 2 */
205
+ physicsGetLinearVelocity(bodyHandle: i32): Float32Array
206
+ /** @c c2dPhysicsSetAngularVelocity */
207
+ physicsSetAngularVelocity(bodyHandle: i32, degPerSec: f32): void
208
+ /** @c c2dPhysicsGetAngularVelocity */
209
+ physicsGetAngularVelocity(bodyHandle: i32): f64
210
+ /** @c c2dPhysicsApplyLinearImpulse */
211
+ physicsApplyLinearImpulse(bodyHandle: i32, x: f32, y: f32): void
212
+ /** Impulse at a WORLD point — the lever arm becomes angular impulse (a central impulse never
213
+ * spins a body). Mirrors 3D physicsApplyImpulseAt. @c c2dPhysicsApplyImpulseAt */
214
+ physicsApplyImpulseAt(bodyHandle: i32, x: f32, y: f32, px: f32, py: f32): void
215
+ /** @c c2dPhysicsApplyForce */
216
+ physicsApplyForce(bodyHandle: i32, x: f32, y: f32): void
217
+ /** Teleport the body to its ENTITY's current world transform — how node.position / .rotation reach
218
+ * it. The parent-chain math stays native instead of being re-derived in TS. Snaps prev/cur so the
219
+ * renderer doesn't interpolate across the jump; the body KEEPS its velocity. @c c2dPhysicsSetFromEntity */
220
+ physicsSetFromEntity(bodyHandle: i32): void
221
+ /** @c c2dPhysicsSetFixedRotation */
222
+ physicsSetFixedRotation(bodyHandle: i32, enabled: boolean): void
223
+ /** @c c2dPhysicsSetGravityScale */
224
+ physicsSetGravityScale(bodyHandle: i32, scale: f32): void
225
+ /** @c c2dPhysicsSetLinearDamping */
226
+ physicsSetLinearDamping(bodyHandle: i32, damping: f32): void
227
+ /** @c c2dPhysicsSetAngularDamping */
228
+ physicsSetAngularDamping(bodyHandle: i32, damping: f32): void
229
+ /** @c c2dPhysicsSetBullet */
230
+ physicsSetBullet(bodyHandle: i32, enabled: boolean): void
231
+ /** @c c2dPhysicsSetEnabled */
232
+ physicsSetEnabled(bodyHandle: i32, enabled: boolean): void
233
+ /** @c c2dPhysicsSetAwake */
234
+ physicsSetAwake(bodyHandle: i32, awake: boolean): void
235
+ /** Scales the shape-derived mass data, so the rotational inertia keeps its ratio. <= 0 restores
236
+ * the area-derived default. @c c2dPhysicsSetMass */
237
+ physicsSetMass(bodyHandle: i32, mass: f32): void
238
+ /** @c c2dPhysicsGetMass */
239
+ physicsGetMass(bodyHandle: i32): f64
240
+ /** @c c2dPhysicsSetMotionType */
241
+ physicsSetMotionType(bodyHandle: i32, motionType: i32): void
242
+ /** @c c2dPhysicsSetFriction */
243
+ physicsSetFriction(bodyHandle: i32, friction: f32): void
244
+ /** @c c2dPhysicsSetBounce */
245
+ physicsSetBounce(bodyHandle: i32, bounce: f32): void
246
+ /** @c c2dPhysicsSetFilter */
247
+ physicsSetFilter(bodyHandle: i32, category: u32, mask: u32): void
248
+ // Queries. `mask` = the union of group categories the query may hit (0 = everything); `ignore` is
249
+ // a list of ENTITY ids to skip, passed as floats because ids are small ints and that reuses the
250
+ // one buffer helper. Box2D's closest-ray API has no exclusion, hence the explicit list.
251
+ /** @c c2dPhysicsRaycastClosest @out 7 */
252
+ physicsRaycastClosest(x0: f32, y0: f32, x1: f32, y1: f32, mask: u32, ignore: Float32Array, ignoreCount: i32): Float32Array
253
+ /** All hits along the segment, nearest first: maxHits records of [entityId, px, py, nx, ny, fraction]. @c c2dPhysicsRaycastAll @out maxHits*6 */
254
+ physicsRaycastAll(x0: f32, y0: f32, x1: f32, y1: f32, mask: u32, ignore: Float32Array, ignoreCount: i32, maxHits: i32): Float32Array
255
+ /** Overlap an arbitrary convex shape given as a point cloud + radius (Box2D's b2ShapeProxy form),
256
+ * so one call covers circle / capsule / box / polygon — and the swept test for a moving circle.
257
+ * Returns up to maxHits entity ids. @c c2dPhysicsOverlap @out maxHits*1 */
258
+ physicsOverlap(pts: Float32Array, count: i32, radius: f32, mask: u32, ignore: Float32Array, ignoreCount: i32, maxHits: i32): Float32Array
259
+ /** Topmost by DRAW order (layer, then z) — not whatever the broadphase hands back first. @c c2dPhysicsOverlapPoint */
260
+ physicsOverlapPoint(x: f32, y: f32, mask: u32, ignore: Float32Array, ignoreCount: i32): i32
261
+ // CharacterController2D (Box2D's kinematic mover). The character steps on the engine's FIXED clock
262
+ // inside the same loop as the bodies, so the SDK does no per-frame work. Capsule ends are in the
263
+ // character's own frame. It also owns a hidden kinematic "shadow" body so raycasts, overlaps and
264
+ // sensors see it — solid shapes strip the reserved character bit from their mask, sensors add it.
265
+ /** @c c2dCharacterCreate */
266
+ characterCreate(entityId: i32, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32, maxSlopeDeg: f32, category: u32, mask: u32): i32
267
+ /** @c c2dCharacterDestroy */
268
+ characterDestroy(charId: i32): void
269
+ /** The HORIZONTAL command, world units/s — a per-frame command that EXPIRES once a step consumes it. @c c2dCharacterMove */
270
+ characterMove(charId: i32, x: f32): void
271
+ /** Free mode (gravityScale 0): both axes as one expiring command. @c c2dCharacterMoveFree */
272
+ characterMoveFree(charId: i32, x: f32, y: f32): void
273
+ /** @c c2dCharacterSetVerticalVelocity */
274
+ characterSetVerticalVelocity(charId: i32, vy: f32): void
275
+ /** LATCH the whole velocity — it persists until a characterMove takes the axis back. @c c2dCharacterSetVelocity */
276
+ characterSetVelocity(charId: i32, x: f32, y: f32): void
277
+ /** @c c2dCharacterSetGravityScale */
278
+ characterSetGravityScale(charId: i32, scale: f32): void
279
+ /** @c c2dCharacterSetMaxSlope */
280
+ characterSetMaxSlope(charId: i32, maxSlopeDeg: f32): void
281
+ /** @c c2dCharacterSetFilter */
282
+ characterSetFilter(charId: i32, category: u32, mask: u32): void
283
+ /** Ignore this entity's one-way surfaces (0 = none) — dropping through a semisolid platform. @c c2dCharacterSetDropThrough */
284
+ characterSetDropThrough(charId: i32, entityId: i32): void
285
+ /** Resize keeping the FEET planted; false = it didn't fit and NOTHING changed, so the caller
286
+ * retries later and that retry is an exact headroom test. @c c2dCharacterSetCapsule */
287
+ characterSetCapsule(charId: i32, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32): boolean
288
+ /** Teleport to the entity's world transform (how node.position reaches a character). Drops fall speed. @c c2dCharacterSetFromEntity */
289
+ characterSetFromEntity(charId: i32): void
290
+ /** out8 = [velX, velY, groundState (0 ground / 1 slope / 2 air), normalX, normalY, groundEntity,
291
+ * collisionCount, 0]. The velocity is MEASURED, not commanded. @c c2dCharacterGetState */
292
+ characterGetState(charId: i32, out: Float32Array): void
293
+ /** maxN records of [entityId, normalX, normalY] — what the mover pushed out of this step. @c c2dCharacterGetCollisions @out maxN*3 */
294
+ characterGetCollisions(charId: i32, maxN: i32): Float32Array
295
+ /** Mark a body's surfaces one-way: solid only from the side (nx, ny) points to, within arcDeg.
296
+ * Honoured by the mover and, via a native pre-solve callback, by ordinary rigid bodies. @c c2dPhysicsSetOneWay */
297
+ physicsSetOneWay(bodyHandle: i32, nx: f32, ny: f32, arcDeg: f32, enabled: boolean): void
298
+ /** @c c2dPickSprite */
299
+ pickSprite(sceneId: i32, wx: f32, wy: f32): i32
300
+ }
301
+ }
302
+
303
+ /** The 2D HOST's side of the contract (`HostScene2d` of creator-pkg/host.gen.h): the engine renders
304
+ * through a GL context / device the HOST owns and composites, so the host learns when a 2D scene
305
+ * opens and closes (bring up / tear down its render target, start / stop compositing) and may take
306
+ * over the engine's GPU setup. OPTIONAL as a whole; every slot optional.
307
+ * @host scene2d HostScene2d @optional */
308
+ export interface HostScene2d {
309
+ /** scene.open(): create the 2D render target lazily, start compositing. */
310
+ open2DScene?(sceneId: i32): void
311
+ close2DScene?(): void
312
+ /** The engine's GPU setup (sg_setup) instead of the default c2dInit(): a host with device handles to
313
+ * pass (the desktop Vulkan host, c2dInitVulkan) does it here and leaves the engine initialised. */
314
+ init2D?(): void
315
+ }
316
+
317
+ export {}
@@ -0,0 +1,91 @@
1
+ // The app bridge (`_creatorApp`): the app's own world (run / restart / quit) and its lifecycle.
2
+ // Part of the host contract: every runtime implements this global (runtime/native in C++, the web
3
+ // runtimes in TS). Types are the PRECISE ones the native side reads (see ./types.d.ts); the SDK
4
+ // only sees numbers. The ABI checker (scripts/check-pkg-bridges.mjs) reads this folder.
5
+ //
6
+ // A HOST bridge (`@host`): unlike an engine bridge, whose C functions live in an engine header, the
7
+ // native side of these methods is a table of functions the HOST fills in — `HostApp` in
8
+ // runtime/native/include/creator-pkg/host.gen.h, generated from this file by scripts/gen-bridges.ts.
9
+ // A method without a tag is a slot of that table (the JS wrapper is generated); `@custom` methods are
10
+ // the runtime's own (world control, the listener slot) and live in runtime/native/src/host/app.cpp.
11
+ // `?` on a method = an optional slot: a host that leaves it null gets no such JS method, so the SDK's
12
+ // `typeof` feature-detects stay honest. The `HostApp` interface below adds the slots the runtime
13
+ // calls that JS never sees (notifications to the host).
14
+ import type { bytes } from "./types"
15
+
16
+ declare global {
17
+ // ---- World control (run/restart/quit — the platform's `location` analog) ----------------------
18
+ // Worlds carry two host-tracked bits: an IDENTITY (project uuid) and a TRUST flag. The host's
19
+ // own boot world (the bundled launcher) is trusted; a world created by `run` is trusted only
20
+ // when its declared uuid is on the host's trusted-launcher allowlist AND the caller was
21
+ // trusted itself. Push registration attribution reads the identity (docs/push-plan.md).
22
+ /** @host app */
23
+ var _creatorApp: {
24
+ /** Swap in a new project world. `projectUuid` declares the new world's identity — honored
25
+ * ONLY when the calling world is trusted (launchers); silently dropped otherwise. `url`
26
+ * (any caller — the caller already controls the code it runs) is the new world's
27
+ * launchUrl: a string sets it, null clears it, omitted leaves it unchanged. @custom */
28
+ run(systemId: bytes, onReject: (err: string) => void, projectUuid?: string, url?: string | null): void
29
+ /** Re-run the CURRENT world's bundle in a fresh world — `location.reload()`. Identity and
30
+ * trust are inherited (the host re-evaluates bytes it already holds, so nothing is
31
+ * spoofable). `url`: string sets the new launchUrl, null clears it, omitted keeps the
32
+ * current one (a plain reload). If the re-run throws, the current world stays live. @custom */
33
+ restart?(url?: string | null): void
34
+ /** Leave the current app. A world launched by `run` returns to the caller's boot bundle
35
+ * (launch URL cleared, boot identity/trust restored). The boot world itself has no caller —
36
+ * the host's `exit` slot fires instead (Android backgrounds the task; hosts that can't
37
+ * exit programmatically, iOS/desktop, leave it null and the call is a no-op). @custom */
38
+ quit?(): void
39
+ /** The URL the app was (most recently) opened with, or null — the cold-start deep link. A warm
40
+ * link updates this value first, then fires the "url" event. Surfaced as app.launchUrl.
41
+ * Runtime-owned: the host seeds it with `setLaunchUrl` and run/restart carry it. @custom */
42
+ launchUrl?(): string | null
43
+
44
+ // ---- App lifecycle & environment (docs/app-lifecycle-plan.md) --------------------------------
45
+ // One push channel + synchronous pulls. All optional — typeof feature-detect; the SDK wrappers
46
+ // fall back cleanly (state "active", launchUrl null, online true) on hosts that lack them.
47
+ /** Register THE app-event listener (single slot per JS world — the SDK fans out; the runtime
48
+ * scopes the stored callback to the world and frees it on teardown). Events: "pause" / "resume"
49
+ * (app left / returned to the foreground), "url" (a link arrived while running; data = the URL),
50
+ * "online" / "offline" (connectivity changed). "pause" is delivered BEFORE the host halts the
51
+ * frame loop (the dispatch queue must still drain). The host pushes with `emitAppEvent`. @custom */
52
+ registerEvent?(callback: (event: string, data?: string) => void): void
53
+ /** The freed channel (owned handles, docs/plans/hosts-unification-plan.md phase 10): ONE function per
54
+ * world that hears `(kind, ids)` — OWNED_KIND_* of ui/tree.ts — when a subtree free took
55
+ * resources under other wrappers (a 3D / 2D root destroyed or dropped: its descendants). The
56
+ * SDK's core/pins.ts unpins them and marks the wrappers dead. @custom */
57
+ setFreedEmitter(callback: (kind: number, ids: number[]) => void): void
58
+ /** Collect garbage, drain the release queue and report the live owned records per kind
59
+ * (`{"live":{"tree":n,…},"pending":n}`) — the read behind checks/owned. @custom */
60
+ ownedStats(): string
61
+ /** Current lifecycle state: "active" | "background". Surfaced as app.state. */
62
+ state?(): string
63
+ /** Current connectivity (navigator.onLine semantics — best-effort: false only when the platform
64
+ * is sure there is no network). Surfaced as device.online. */
65
+ isOnline?(): boolean
66
+ /** Open a URL in the system browser / external handler (fire-and-forget). Backs openURL(). */
67
+ openUrl?(url: string): void
68
+ /** Lock the interface orientation: "landscape" (either landscape direction — sensor
69
+ * landscape, what a horizontal game wants), "portrait" (upright only) or "auto" (release —
70
+ * the device's rotation rules apply again). Fire-and-forget; the rotation itself is
71
+ * animated by the platform and lands as an ordinary resize. PER WORLD: the host resets the
72
+ * lock to "auto" on every world swap BEFORE the new bundle evaluates, so a game may lock at
73
+ * synchronous top level and the launcher always comes back unlocked. Optional — hosts
74
+ * without a rotatable screen (desktop, headless, macOS) omit it. Backs app.setOrientation. */
75
+ setOrientation?(mode: string): void
76
+ }
77
+ }
78
+
79
+ /** The slots of `HostApp` the runtime calls and JS never sees. */
80
+ export interface HostApp {
81
+ /** Fired whenever the current world's (identity, trust) changes: BEFORE the new bundle evaluates,
82
+ * and again with the restored values if the evaluation throws — so a host cache consulted from a
83
+ * synchronous host call (a push registration during the world's top-level code) is always
84
+ * current. `projectUuid` is null for an unattributed world. JS thread. */
85
+ worldChange?(projectUuid: string | null, trusted: boolean): void
86
+ /** `quit()` called from the boot world — no caller world to return to, so the host decides what
87
+ * "leave the app" means (the Android SDK backgrounds the task). JS thread. */
88
+ exit?(): void
89
+ }
90
+
91
+ export {}
@@ -0,0 +1,97 @@
1
+ // The audio bridge (`_creatorAudio`): engines/audio (miniaudio).
2
+ // Part of the host contract: every runtime implements this global (runtime/native in C++, the web
3
+ // runtimes in TS). Types are the PRECISE ones the native side reads (see ./types.d.ts); the SDK
4
+ // only sees numbers. The ABI checker (scripts/check-pkg-bridges.mjs) reads this folder.
5
+ import type { bytes, f32, f64, i32, u32 } from "./types"
6
+
7
+ declare global {
8
+ // ---- Game audio (creator-audio) ----------------------------------------------------------------
9
+ // docs/audio-plan.md. Whole clips decoded up front, a fixed voice pool (play allocates nothing),
10
+ // 3D sources the engine follows per frame, mixer buses with insert effects, reverb zones,
11
+ // occlusion. OPTIONAL as a block: the SDK gates on `typeof _creatorAudio !== 'undefined' &&
12
+ // hasSupport()` and stays inert (silent Sound, inert Voice) without it. Present on hosts built with
13
+ // CREATOR_PKG_AUDIO (desktop first; Android / Apple pending — parity `audio-game`). The headless
14
+ // renderer provides a RECORDER (plays are logged, nothing is mixed). Every parameter block is a
15
+ // fixed-order Float32Array (creator-audio.h CAUD_SRC_* / the effect param orders).
16
+ /** @engine audio */
17
+ var _creatorAudio: {
18
+ /** @guard audioEnsureEngine @c caudHasSupport */
19
+ hasSupport(): boolean
20
+ /** Decode the bytes behind a fetch system id (WAV / MP3 / OGG Vorbis) on the engine's
21
+ * loader thread; mono unless `stereo`. onDone(clipId, durationSeconds, channels). @custom */
22
+ loadClip(systemId: bytes, stereo: boolean, onDone: (clipId: number, duration: number, channels: number) => void, onReject: (message: string) => void): void
23
+ /** @c caudClipRelease */
24
+ releaseClip(clipId: u32): void
25
+ /** Bus id by name (-1 unknown); 0 master, 1 sfx, 2 music, 3 ui, 4 voice. @c caudBusId */
26
+ busId(name: string): i32
27
+ /** Creates (or finds) an app-defined bus under master. -1 when the 16 slots are full. @c caudBusCreate */
28
+ createBus(name: string): i32
29
+ /** @c caudBusSetVolume */
30
+ setBusVolume(bus: i32, volume: f32): void
31
+ /** @c caudBusSetMuted */
32
+ setBusMuted(bus: i32, muted: boolean): void
33
+ /** kind 1 reverb [roomSize, damping, width, mix, preDelay] · 2 echo [delay, decay, mix] ·
34
+ * 3 lowpass [cutoffHz]; an empty array turns the effect off. Changes are smoothed. @c caudBusSetEffect */
35
+ setBusEffect(bus: i32, kind: i32, params: Float32Array): void
36
+ /** @c caudBusStopAll */
37
+ stopBus(bus: i32, fade: f32): void
38
+ /** A 3D emitter. `attachSource` binds it to an entity the engine follows every frame;
39
+ * `setSourcePosition` places an unbound one (playAt). @guard audioEnsureEngine @c caudSourceCreate */
40
+ createSource(): u32
41
+ /** @c gl:audioAttachSource */
42
+ attachSource(sourceId: u32, entityId: u32): void
43
+ /** [minDistance, maxDistance, rolloff (0 none 1 inverse 2 linear 3 exp), coneInnerDeg,
44
+ * coneOuterDeg, coneOuterGain, doppler, spread, occlusion (0/1), bus]. @c caudSourceSetParams */
45
+ setSourceParams(sourceId: u32, params: Float32Array): void
46
+ /** @c caudSourceSetPose @pack x 3 @rest nullptr */
47
+ setSourcePosition(sourceId: u32, x: f32, y: f32, z: f32): void
48
+ /** @c caudSourceStopAll */
49
+ stopSource(sourceId: u32, fade: f32): void
50
+ /** @c caudSourceVoices */
51
+ sourceVoices(sourceId: u32): i32
52
+ /** @c gl:audioDetachSource, caudSourceDestroy */
53
+ destroySource(sourceId: u32): void
54
+ /** The listener entity; 0 = the active scene camera (the default). @c gl:audioSetListener */
55
+ setListener(entityId: u32): void
56
+ /** @c caudListenerSetDoppler */
57
+ setListenerOptions(dopplerFactor: f32): void
58
+ /** HRTF binaural rendering for the `maxVoices` nearest spatial voices (headphones); the rest keep panning. @guard audioEnsureEngine @c caudSetHrtf */
59
+ setHrtf(enabled: boolean, maxVoices: i32): void
60
+ /** Whether the engine's time scale (Time.scale) also pitches the sfx bus. Default false (pause = mute only). @guard audioEnsureEngine @c caudSetTimeScalePitch */
61
+ setTimeScalePitch(enabled: boolean): void
62
+ /** → a voice token (0 = nothing played: the pool refused, the clip is not ready). bus -1 = the
63
+ * source's bus (sfx for 2D). pan is 2D only. @c caudPlay @pack bus CaudPlay */
64
+ play(clipId: u32, sourceId: u32, bus: i32, volume: f32, pitch: f32, loop: boolean, priority: i32, fadeIn: f32, startAt: f32, pan: f32): u32
65
+ /** @c caudVoiceSetVolume */
66
+ setVoiceVolume(token: u32, volume: f32): void
67
+ /** @c caudVoiceSetPitch */
68
+ setVoicePitch(token: u32, pitch: f32): void
69
+ /** @c caudVoiceSetPan */
70
+ setVoicePan(token: u32, pan: f32): void
71
+ /** @c caudVoiceStop */
72
+ stopVoice(token: u32, fade: f32): void
73
+ /** @c caudVoicePlaying */
74
+ voicePlaying(token: u32): boolean
75
+ /** @c caudVoiceTime */
76
+ voiceTime(token: u32): f64
77
+ /** THE ended listener (single slot per JS world): called once per tick with the tokens of the
78
+ * voices that ended since the previous tick — natural end, stop, steal. @custom */
79
+ setOnEnded(callback: ((tokens: Float32Array) => void) | null): void
80
+ /** @c caudStopAll */
81
+ stopAll(fade: f32): void
82
+ /** A reverb volume: shape 0 box (dims = full size) / 1 sphere (dims[0] = diameter), in the
83
+ * entity's local units; `blend` metres of crossfade inside the border; reverb params as for
84
+ * setBusEffect kind 1. The listener inside blends the zone's reverb onto `bus`. @guard audioEnsureEngine @c caudZoneCreate */
85
+ createZone(): u32
86
+ /** @c gl:audioAttachZone */
87
+ attachZone(zoneId: u32, entityId: u32): void
88
+ /** @c caudZoneSet */
89
+ setZone(zoneId: u32, shape: i32, dims: Float32Array, blend: f32, bus: i32, reverb: Float32Array): void
90
+ /** @c gl:audioDetachZone, caudZoneDestroy */
91
+ destroyZone(zoneId: u32): void
92
+ /** [voicesPlaying, voicesMono, voicesStereo, stolen, clips, clipBytes, peak, sampleRate, listenerZone, zoneBlend, hrtfVoices]. @custom */
93
+ stats(): Float32Array
94
+ }
95
+ }
96
+
97
+ export {}
@@ -0,0 +1,79 @@
1
+ // The canvas bridge (`_creatorCanvas`): the 2D canvas surfaces a host paints.
2
+ // Part of the host contract: every runtime implements this global (runtime/native in C++, the web
3
+ // runtimes in TS). Types are the PRECISE ones the native side reads (see ./types.d.ts). A surface is an
4
+ // OWNED resource (docs/owned.md, OwnedKind::Canvas): the creators hand the SDK a Handle, a surface id on
5
+ // the wire is `_h.id`, and the runtime frees the surface once the app dropped the wrapper AND no UI image
6
+ // shows it. The ABI checker (scripts/check-pkg-bridges.mjs) reads this folder.
7
+ //
8
+ // Since phase 12 (docs/canvas.md) the runtime does NOT interpret the opcode stream
9
+ // itself: it links the AnyCanvas core (engines/canvas), which turns the SDK Canvas' opcode stream
10
+ // (spec/ops.h of the pinned submodule — the SDK's consts are generated from it) and SVG markup into
11
+ // ONE resolved draw list (spec/draw.h), and a host PAINTS that list (HostCanvas below). The runtime
12
+ // keeps the surface registry (ids, sizes); the host keeps the pixels.
13
+ import type { bytes, f32, i32, i32out, f32out } from "./types"
14
+
15
+ declare global {
16
+ // ---- 2D canvas (core; the AnyCanvas core + a painter per platform) --------------------------
17
+ // Immediate-mode 2D drawing that bakes to a texture, shared by 2D/3D/UI. The SDK Canvas records a
18
+ // command buffer (the AnyCanvas opcode stream) and flushes it here once per bake.
19
+ var _creatorCanvas: {
20
+ /** Rasterize `cmd` (cmdLen floats) into surface `surfaceId` (0 = create), sized w×h logical @
21
+ * `scale` device px. Clears then replays the whole buffer. A Handle when the surface is made now
22
+ * (0 in, or an id the registry no longer knows); the same id as a number for a re-bake.
23
+ * @owned Canvas */
24
+ rasterize(surfaceId: i32, w: f32, h: f32, scale: f32,
25
+ cmd: Float32Array, cmdLen: i32, refs: string[]): Handle | i32
26
+ // [width, ascent, descent] in logical px for `text` in the CSS `font`, measured on this platform.
27
+ measureText(text: string, font: string): Float32Array
28
+ /** Copy surface `surfaceId`'s pixels into a NEW standalone surface; its Handle, or null without a
29
+ * painter (or for an unknown source). Backs Canvas.toBitmap() — an immutable snapshot the source
30
+ * canvas can no longer touch. @owned Canvas */
31
+ snapshot(surfaceId: i32): Handle | null
32
+ /** Decode an image source into a NEW standalone surface (device px) — backs Canvas.loadImage() for
33
+ * Canvas.drawImage(). `bufferId < 0` → rasterize the SVG markup in `svg` (the core draws it, the
34
+ * host paints it); otherwise decode the encoded image bytes in host buffer `bufferId` (an SVG file
35
+ * is detected and drawn the same way). Delivers (surface, width, height) in device px to
36
+ * onComplete, or calls onReject on failure. @owned Canvas (the surface) */
37
+ loadImage(svg: string, bufferId: bytes,
38
+ onComplete: (surface: Handle, width: number, height: number) => void, onReject: () => void): void
39
+ // Encode surface `surfaceId` to an image ('image/png' | 'image/jpeg'), register the bytes as a host
40
+ // buffer, and return (bufferId, size) — the SDK wraps it in a File. Backs Canvas/Bitmap.toFile().
41
+ toFile(surfaceId: i32, type: string, onComplete: (bufferId: number, size: number) => void, onReject: () => void): void
42
+ // Free a surface NOW (Canvas / Bitmap destroy(): the explicit early free), even while an image shows it.
43
+ destroySurface(surfaceId: i32): void
44
+ // The deterministic JSON of the draw list a surface was last painted with (the AnyCanvas dump:
45
+ // checks/canvas hashes it, debugging reads it); "" for an unknown surface.
46
+ debugDrawList(surfaceId: i32): string
47
+ }
48
+ }
49
+
50
+ /** The PAINTER's side of the contract — the table the runtime's `_creatorCanvas` bridge calls after the
51
+ * AnyCanvas core produced a draw list (`HostCanvas` of creator-pkg/host.gen.h). Every call is synchronous
52
+ * on the JS thread. OPTIONAL as a whole: a host without a backend (the windowless server, a UI-only
53
+ * build) leaves the pointer null — every op is then a no-op and a baked texture is 0. Desktop / Quest:
54
+ * the tgfx painter (engines/canvas/painters/tgfx); Android: the Kotlin painter (painters/android);
55
+ * web / headless: painters/web. Surface ids come from the runtime's registry; a host creates the
56
+ * pixels on the first `paint` / `decodeImage` of an id and frees them on `releaseSurface`.
57
+ * @host canvas HostCanvas @optional */
58
+ export interface HostCanvas {
59
+ /** Paint the draw list `words` + `strings` (engines/canvas/spec/draw.h; already in device px) into
60
+ * surface `surfaceId`, which is pw×ph device px at `scale` device px per logical unit: create or
61
+ * resize the surface as needed, clear it, replay the list. */
62
+ paint(surfaceId: i32, pw: i32, ph: i32, scale: f32, words: Float32Array, strings: string[]): void
63
+ /** Metrics of `text` in the resolved font (family, px size, weight 100..900, italic) on THIS platform
64
+ * → out[3] = width, ascent, descent (logical px, both positive). The same font resolution the
65
+ * painter uses for a text command. @outSize out 3 */
66
+ measureText(text: string, family: string, size: f32, weight: i32, italic: boolean, out: f32out): void
67
+ /** Decode the encoded image bytes of host buffer `bufferId` into the NEW surface `surfaceId` (an id
68
+ * the runtime reserved); its pixel size to size[2] = w, h. False when the bytes do not decode.
69
+ * @outSize size 2 */
70
+ decodeImage(bufferId: i32, surfaceId: i32, size: i32out): boolean
71
+ /** A surface's straight-RGBA8 pixels, top row first, w×h device px in size[2] — malloc'd, the
72
+ * runtime frees them (the engines' createTextureFromCanvas, `toFile`, `snapshot`). Null for an
73
+ * unknown surface. @outSize size 2 */
74
+ readPixels(surfaceId: i32, size: i32out): Uint8Array | null
75
+ /** Free a surface's pixels (the runtime dropped the id). */
76
+ releaseSurface(surfaceId: i32): void
77
+ }
78
+
79
+ export {}