@nayan-ui/engine 0.0.0-stage → 1.0.0-beta.4

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 (198) hide show
  1. package/LICENSE +21 -0
  2. package/NayanEngine.podspec +28 -0
  3. package/README.md +308 -2
  4. package/lib/module/assets/AssetBytesCache.js +76 -0
  5. package/lib/module/assets/AssetCache.js +19 -0
  6. package/lib/module/assets/AssetLoader.js +52 -0
  7. package/lib/module/assets/CacheGeneration.js +7 -0
  8. package/lib/module/assets/IndexedDbCache.web.js +149 -0
  9. package/lib/module/assets/ProceduralCache.js +249 -0
  10. package/lib/module/assets/font.js +139 -0
  11. package/lib/module/assets/loft.js +142 -0
  12. package/lib/module/assets/model.js +96 -0
  13. package/lib/module/assets/modelling.js +254 -0
  14. package/lib/module/assets/shape.js +926 -0
  15. package/lib/module/assets/source.js +58 -0
  16. package/lib/module/assets/source.web.js +22 -0
  17. package/lib/module/assets/storage.js +4 -0
  18. package/lib/module/assets/storage.shared.js +38 -0
  19. package/lib/module/assets/storage.web.js +38 -0
  20. package/lib/module/assets/surface.js +47 -0
  21. package/lib/module/assets/texture.js +69 -0
  22. package/lib/module/drawing/DrawingCanvas.js +38 -0
  23. package/lib/module/drawing/DrawingCanvas.web.js +206 -0
  24. package/lib/module/drawing/DrawingDocument.js +256 -0
  25. package/lib/module/drawing/types.js +4 -0
  26. package/lib/module/globals.d.ts +12 -0
  27. package/lib/module/index.js +39 -0
  28. package/lib/module/input/Joystick.js +84 -0
  29. package/lib/module/input/Joystick.web.js +93 -0
  30. package/lib/module/input/keyboard.js +250 -0
  31. package/lib/module/media/audio-worklet.js +34 -0
  32. package/lib/module/media/audio.js +97 -0
  33. package/lib/module/media/haptics.js +82 -0
  34. package/lib/module/media/output.web.js +66 -0
  35. package/lib/module/native/BrowserEngine.js +568 -0
  36. package/lib/module/native/EngineBridge.js +4 -0
  37. package/lib/module/native/NativeNayanEngine.js +7 -0
  38. package/lib/module/native/NativeNayanEngine.web.js +62 -0
  39. package/lib/module/native/prepare.js +7 -0
  40. package/lib/module/native/prepare.web.js +17 -0
  41. package/lib/module/native/spec/NativeNayanEngine.js +17 -0
  42. package/lib/module/package.json +1 -0
  43. package/lib/module/render/GameView.js +317 -0
  44. package/lib/module/render/camera.js +34 -0
  45. package/lib/module/render/host.js +39 -0
  46. package/lib/module/render/host.web.js +104 -0
  47. package/lib/module/render/light.js +24 -0
  48. package/lib/module/render/meshes.js +159 -0
  49. package/lib/module/render/quality.js +119 -0
  50. package/lib/module/render/responder.js +4 -0
  51. package/lib/module/render/responder.web.js +97 -0
  52. package/lib/module/render/touch.js +185 -0
  53. package/lib/module/render/useWorld.js +72 -0
  54. package/lib/module/types.js +30 -0
  55. package/lib/module/world/Scoreboard.js +161 -0
  56. package/lib/module/world/TransformBatch.js +128 -0
  57. package/lib/module/world/World.js +704 -0
  58. package/lib/module/world/color.js +80 -0
  59. package/lib/module/world/desc.js +187 -0
  60. package/lib/module/world/effects.js +463 -0
  61. package/lib/module/world/quat.js +86 -0
  62. package/lib/module/world/types.js +4 -0
  63. package/lib/typescript/package.json +1 -0
  64. package/lib/typescript/src/assets/AssetBytesCache.d.ts +7 -0
  65. package/lib/typescript/src/assets/AssetCache.d.ts +9 -0
  66. package/lib/typescript/src/assets/AssetLoader.d.ts +11 -0
  67. package/lib/typescript/src/assets/CacheGeneration.d.ts +3 -0
  68. package/lib/typescript/src/assets/IndexedDbCache.web.d.ts +20 -0
  69. package/lib/typescript/src/assets/ProceduralCache.d.ts +45 -0
  70. package/lib/typescript/src/assets/font.d.ts +53 -0
  71. package/lib/typescript/src/assets/loft.d.ts +31 -0
  72. package/lib/typescript/src/assets/model.d.ts +58 -0
  73. package/lib/typescript/src/assets/modelling.d.ts +157 -0
  74. package/lib/typescript/src/assets/shape.d.ts +203 -0
  75. package/lib/typescript/src/assets/source.d.ts +10 -0
  76. package/lib/typescript/src/assets/source.web.d.ts +8 -0
  77. package/lib/typescript/src/assets/storage.d.ts +2 -0
  78. package/lib/typescript/src/assets/storage.shared.d.ts +7 -0
  79. package/lib/typescript/src/assets/storage.web.d.ts +7 -0
  80. package/lib/typescript/src/assets/surface.d.ts +17 -0
  81. package/lib/typescript/src/assets/texture.d.ts +30 -0
  82. package/lib/typescript/src/drawing/DrawingCanvas.d.ts +5 -0
  83. package/lib/typescript/src/drawing/DrawingCanvas.web.d.ts +4 -0
  84. package/lib/typescript/src/drawing/DrawingDocument.d.ts +210 -0
  85. package/lib/typescript/src/drawing/types.d.ts +12 -0
  86. package/lib/typescript/src/index.d.ts +45 -0
  87. package/lib/typescript/src/input/Joystick.d.ts +20 -0
  88. package/lib/typescript/src/input/Joystick.web.d.ts +13 -0
  89. package/lib/typescript/src/input/keyboard.d.ts +17 -0
  90. package/lib/typescript/src/media/audio.d.ts +46 -0
  91. package/lib/typescript/src/media/haptics.d.ts +22 -0
  92. package/lib/typescript/src/media/output.web.d.ts +4 -0
  93. package/lib/typescript/src/native/BrowserEngine.d.ts +8 -0
  94. package/lib/typescript/src/native/EngineBridge.d.ts +26 -0
  95. package/lib/typescript/src/native/NativeNayanEngine.d.ts +5 -0
  96. package/lib/typescript/src/native/NativeNayanEngine.web.d.ts +10 -0
  97. package/lib/typescript/src/native/prepare.d.ts +3 -0
  98. package/lib/typescript/src/native/prepare.web.d.ts +2 -0
  99. package/lib/typescript/src/native/spec/NativeNayanEngine.d.ts +211 -0
  100. package/lib/typescript/src/render/GameView.d.ts +107 -0
  101. package/lib/typescript/src/render/camera.d.ts +6 -0
  102. package/lib/typescript/src/render/host.d.ts +29 -0
  103. package/lib/typescript/src/render/host.web.d.ts +16 -0
  104. package/lib/typescript/src/render/light.d.ts +12 -0
  105. package/lib/typescript/src/render/meshes.d.ts +45 -0
  106. package/lib/typescript/src/render/quality.d.ts +48 -0
  107. package/lib/typescript/src/render/responder.d.ts +2 -0
  108. package/lib/typescript/src/render/responder.web.d.ts +40 -0
  109. package/lib/typescript/src/render/touch.d.ts +26 -0
  110. package/lib/typescript/src/render/useWorld.d.ts +20 -0
  111. package/lib/typescript/src/types.d.ts +81 -0
  112. package/lib/typescript/src/world/Scoreboard.d.ts +75 -0
  113. package/lib/typescript/src/world/TransformBatch.d.ts +39 -0
  114. package/lib/typescript/src/world/World.d.ts +207 -0
  115. package/lib/typescript/src/world/color.d.ts +18 -0
  116. package/lib/typescript/src/world/desc.d.ts +17 -0
  117. package/lib/typescript/src/world/effects.d.ts +157 -0
  118. package/lib/typescript/src/world/quat.d.ts +31 -0
  119. package/lib/typescript/src/world/types.d.ts +238 -0
  120. package/lib/web/audio-worklet.js +29 -0
  121. package/lib/web/engine_core_bg.wasm +0 -0
  122. package/lib/web/index.js +8240 -0
  123. package/lib/web/types/src/assets/AssetBytesCache.d.ts +6 -0
  124. package/lib/web/types/src/assets/AssetCache.d.ts +8 -0
  125. package/lib/web/types/src/assets/AssetLoader.d.ts +10 -0
  126. package/lib/web/types/src/assets/CacheGeneration.d.ts +2 -0
  127. package/lib/web/types/src/assets/IndexedDbCache.d.ts +19 -0
  128. package/lib/web/types/src/assets/ProceduralCache.d.ts +44 -0
  129. package/lib/web/types/src/assets/font.d.ts +52 -0
  130. package/lib/web/types/src/assets/loft.d.ts +30 -0
  131. package/lib/web/types/src/assets/model.d.ts +57 -0
  132. package/lib/web/types/src/assets/modelling.d.ts +156 -0
  133. package/lib/web/types/src/assets/shape.d.ts +202 -0
  134. package/lib/web/types/src/assets/source.d.ts +7 -0
  135. package/lib/web/types/src/assets/storage.d.ts +6 -0
  136. package/lib/web/types/src/assets/storage.shared.d.ts +6 -0
  137. package/lib/web/types/src/assets/surface.d.ts +16 -0
  138. package/lib/web/types/src/assets/texture.d.ts +29 -0
  139. package/lib/web/types/src/drawing/DrawingCanvas.d.ts +3 -0
  140. package/lib/web/types/src/drawing/DrawingDocument.d.ts +209 -0
  141. package/lib/web/types/src/drawing/types.d.ts +11 -0
  142. package/lib/web/types/src/index.d.ts +44 -0
  143. package/lib/web/types/src/input/Joystick.d.ts +12 -0
  144. package/lib/web/types/src/input/keyboard.d.ts +16 -0
  145. package/lib/web/types/src/media/audio.d.ts +45 -0
  146. package/lib/web/types/src/media/haptics.d.ts +21 -0
  147. package/lib/web/types/src/media/output.d.ts +3 -0
  148. package/lib/web/types/src/native/BrowserEngine.d.ts +7 -0
  149. package/lib/web/types/src/native/EngineBridge.d.ts +25 -0
  150. package/lib/web/types/src/native/NativeNayanEngine.d.ts +9 -0
  151. package/lib/web/types/src/native/prepare.d.ts +1 -0
  152. package/lib/web/types/src/native/spec/NativeNayanEngine.d.ts +210 -0
  153. package/lib/web/types/src/render/GameView.d.ts +106 -0
  154. package/lib/web/types/src/render/camera.d.ts +5 -0
  155. package/lib/web/types/src/render/host.d.ts +15 -0
  156. package/lib/web/types/src/render/light.d.ts +11 -0
  157. package/lib/web/types/src/render/meshes.d.ts +44 -0
  158. package/lib/web/types/src/render/quality.d.ts +47 -0
  159. package/lib/web/types/src/render/responder.d.ts +39 -0
  160. package/lib/web/types/src/render/touch.d.ts +25 -0
  161. package/lib/web/types/src/render/useWorld.d.ts +19 -0
  162. package/lib/web/types/src/types.d.ts +80 -0
  163. package/lib/web/types/src/world/Scoreboard.d.ts +74 -0
  164. package/lib/web/types/src/world/TransformBatch.d.ts +38 -0
  165. package/lib/web/types/src/world/World.d.ts +206 -0
  166. package/lib/web/types/src/world/color.d.ts +17 -0
  167. package/lib/web/types/src/world/desc.d.ts +16 -0
  168. package/lib/web/types/src/world/effects.d.ts +156 -0
  169. package/lib/web/types/src/world/quat.d.ts +30 -0
  170. package/lib/web/types/src/world/types.d.ts +237 -0
  171. package/native/android/CMakeLists.txt +34 -0
  172. package/native/android/NayanEngineSpec.h +15 -0
  173. package/native/android/build.gradle +26 -0
  174. package/native/android/codegen/CMakeLists.txt +3 -0
  175. package/native/android/proguard-rules.pro +2 -0
  176. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceView.java +295 -0
  177. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceViewManager.java +45 -0
  178. package/native/android/src/main/java/com/nayanui/engine/NayanEnginePackage.java +24 -0
  179. package/native/core/build/EngineCore.xcframework/Info.plist +43 -0
  180. package/native/core/build/EngineCore.xcframework/ios-arm64/libengine_core.a +0 -0
  181. package/native/core/build/EngineCore.xcframework/ios-arm64-simulator/libengine_core.a +0 -0
  182. package/native/core/build/android/arm64-v8a/libengine_core.a +0 -0
  183. package/native/core/build/android/armeabi-v7a/libengine_core.a +0 -0
  184. package/native/core/build/android/x86/libengine_core.a +0 -0
  185. package/native/core/build/android/x86_64/libengine_core.a +0 -0
  186. package/native/core/include/drawing-licenses.txt +58 -0
  187. package/native/core/include/engine_core.h +331 -0
  188. package/native/cpp/NayanEngineModule.cpp +998 -0
  189. package/native/cpp/NayanEngineModule.h +174 -0
  190. package/native/cpp/generated/NayanEngineSpecJSI.cpp +2 -0
  191. package/native/cpp/generated/NayanEngineSpecJSI.h +1026 -0
  192. package/native/ios/NayanEngineProvider.h +5 -0
  193. package/native/ios/NayanEngineProvider.mm +21 -0
  194. package/native/ios/NayanEngineSurface.mm +252 -0
  195. package/native/scripts/check-package.mjs +39 -0
  196. package/package.json +162 -4
  197. package/react-native.config.js +18 -0
  198. package/src/native/spec/NativeNayanEngine.ts +265 -0
@@ -0,0 +1,24 @@
1
+ package com.nayanui.engine;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.facebook.react.ReactPackage;
5
+ import com.facebook.react.bridge.NativeModule;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.uimanager.ViewManager;
8
+ import java.util.Collections;
9
+ import java.util.List;
10
+
11
+ /** Registers the EngineSurface view (the native module is a C++ TurboModule, registered separately). */
12
+ public class NayanEnginePackage implements ReactPackage {
13
+ @NonNull
14
+ @Override
15
+ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext context) {
16
+ return Collections.emptyList();
17
+ }
18
+
19
+ @NonNull
20
+ @Override
21
+ public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext context) {
22
+ return Collections.singletonList(new EngineSurfaceViewManager());
23
+ }
24
+ }
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>libengine_core.a</string>
10
+ <key>LibraryIdentifier</key>
11
+ <string>ios-arm64</string>
12
+ <key>LibraryPath</key>
13
+ <string>libengine_core.a</string>
14
+ <key>SupportedArchitectures</key>
15
+ <array>
16
+ <string>arm64</string>
17
+ </array>
18
+ <key>SupportedPlatform</key>
19
+ <string>ios</string>
20
+ </dict>
21
+ <dict>
22
+ <key>BinaryPath</key>
23
+ <string>libengine_core.a</string>
24
+ <key>LibraryIdentifier</key>
25
+ <string>ios-arm64-simulator</string>
26
+ <key>LibraryPath</key>
27
+ <string>libengine_core.a</string>
28
+ <key>SupportedArchitectures</key>
29
+ <array>
30
+ <string>arm64</string>
31
+ </array>
32
+ <key>SupportedPlatform</key>
33
+ <string>ios</string>
34
+ <key>SupportedPlatformVariant</key>
35
+ <string>simulator</string>
36
+ </dict>
37
+ </array>
38
+ <key>CFBundlePackageType</key>
39
+ <string>XFWK</string>
40
+ <key>XCFrameworkFormatVersion</key>
41
+ <string>1.0</string>
42
+ </dict>
43
+ </plist>
@@ -0,0 +1,58 @@
1
+ Drawing renderer dependencies
2
+ =============================
3
+
4
+ raqote 0.8.5
5
+ https://github.com/jrmuizel/raqote
6
+
7
+ Copyright (c) 2019 Jeff Muizelaar
8
+ All rights reserved.
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+
13
+ * Redistributions of source code must retain the above copyright notice, this
14
+ list of conditions and the following disclaimer.
15
+
16
+ * Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ * Neither the name of the copyright holder nor the names of its
21
+ contributors may be used to endorse or promote products derived from
22
+ this software without specific prior written permission.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+
35
+
36
+ svgtypes 0.16.1 (MIT option)
37
+ https://github.com/linebender/svgtypes
38
+
39
+ Copyright (c) 2018 Yevhenii Reizner
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining a copy
42
+ of this software and associated documentation files (the "Software"), to deal
43
+ in the Software without restriction, including without limitation the rights
44
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45
+ copies of the Software, and to permit persons to whom the Software is
46
+ furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in
49
+ all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57
+ THE SOFTWARE.
58
+
@@ -0,0 +1,331 @@
1
+ // C interface to the engine core. Keep in sync with src/ffi/ and src/world/{desc,animation,particles}.rs.
2
+ #pragma once
3
+ #include <stddef.h>
4
+ #include <stdint.h>
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ typedef struct World World;
11
+
12
+ #define ENGINE_NO_ENTITY UINT32_MAX
13
+ #define ENGINE_MAX_MESHES 4096 // 0..15 built-in shapes (15 = not drawn), 16.. models, glyphs, aliases
14
+ #define ENGINE_MAX_EVENTS 4096
15
+ #define ENGINE_EVENT_STRIDE 4 // u32s per event: entity_a, entity_b, flags, impact speed (f32 bits)
16
+ #define ENGINE_EVENT_STARTED 1u // flag: started touching (otherwise stopped)
17
+ #define ENGINE_EVENT_SENSOR 2u // flag: a sensor was involved
18
+ #define ENGINE_FIXED_DT (1.0f / 60.0f)
19
+
20
+ // ── Entity descriptions ──────────────────────────────────────────────────
21
+ // Entities are created and changed with one call, from ENGINE_DESC_LEN doubles. Slot 0 holds
22
+ // flags saying which fields are present; the rest live at the offsets below.
23
+ #define ENGINE_DESC_LEN 64
24
+
25
+ #define ENGINE_DESC_MESH (1u << 0)
26
+ #define ENGINE_DESC_POSITION (1u << 1)
27
+ #define ENGINE_DESC_ROTATION (1u << 2)
28
+ #define ENGINE_DESC_SCALE (1u << 3)
29
+ #define ENGINE_DESC_COLOR (1u << 4)
30
+ #define ENGINE_DESC_VELOCITY (1u << 5)
31
+ #define ENGINE_DESC_GROUND_VELOCITY (1u << 6)
32
+ #define ENGINE_DESC_SPIN (1u << 7)
33
+ #define ENGINE_DESC_BOB (1u << 8)
34
+ #define ENGINE_DESC_FOLLOW (1u << 9)
35
+ #define ENGINE_DESC_LIFETIME (1u << 10)
36
+ #define ENGINE_DESC_PARENT (1u << 11)
37
+ #define ENGINE_DESC_PHYSICS (1u << 12)
38
+ #define ENGINE_DESC_IMPACT (1u << 13)
39
+ #define ENGINE_DESC_ACCELERATION (1u << 14)
40
+ #define ENGINE_DESC_PICKABLE (1u << 15)
41
+ #define ENGINE_DESC_REGION (1u << 16)
42
+
43
+ #define ENGINE_SLOT_FLAGS 0
44
+ #define ENGINE_SLOT_MESH 1 // mesh id
45
+ #define ENGINE_SLOT_POSITION 2 // x y z
46
+ #define ENGINE_SLOT_ROTATION 5 // quaternion x y z w
47
+ #define ENGINE_SLOT_SCALE 9 // x y z
48
+ #define ENGINE_SLOT_COLOR 12 // r g b a
49
+ #define ENGINE_SLOT_VELOCITY 16 // x y z
50
+ #define ENGINE_SLOT_GROUND_VELOCITY 19 // x z (keeps vertical speed)
51
+ #define ENGINE_SLOT_SPIN 21 // x y z, radians/second
52
+ #define ENGINE_SLOT_BOB 24 // amplitude x y z, speed, phase
53
+ #define ENGINE_SLOT_FOLLOW 29 // target (-1 = stop), speed
54
+ #define ENGINE_SLOT_LIFETIME 31 // seconds (<= 0 clears)
55
+ #define ENGINE_SLOT_PARENT 32 // entity (-1 = detach)
56
+ // kind (0 remove, 1 dynamic, 2 kinematic, 3 fixed), shape (0 ball, 1 box, 2 from the mesh, 3 cylinder,
57
+ // 4 capsule, 5 cone), size x y z (ball: radius in x; box: half extents; cylinder/capsule/cone: radius in x,
58
+ // half the total height in y; <= 0 = sized from the entity's mesh and scale), layer, mask, sensor,
59
+ // friction, bounce, density, drag, angular drag, gravity scale, upright, ccd, planar (stays in its XY plane).
60
+ // Pairs interact if (a.mask & b.layer) || (b.mask & a.layer).
61
+ #define ENGINE_SLOT_PHYSICS 33
62
+ // enabled, sound (-1 = none), min speed, max speed, volume, haptic.
63
+ #define ENGINE_SLOT_IMPACT 50
64
+ #define ENGINE_SLOT_ACCELERATION 56 // x y z (entities without a dynamic body)
65
+ #define ENGINE_SLOT_PICKABLE 59 // 0 or 1
66
+ #define ENGINE_SLOT_REGION 60 // texture region u0 v0 u1 v1
67
+
68
+ // ── Animations and particle bursts ───────────────────────────────────────
69
+ // Animation: a header, then `entity count` entity ids, then `keyframe count` keyframes.
70
+ // Header: entity count, keyframe count (1..64), duration, delay, easing (0 linear, 1 in, 2 out, 3 in-out,
71
+ // 4 back, 5 bounce, 6 elastic), repeat (-1 = forever), yoyo, stagger (seconds per entity), smooth path,
72
+ // spring stiffness (0 = timed tween), spring damping, spring mass.
73
+ // Keyframe: flags (1 position, 2 rotation, 4 scale, 8 color, 16 move by, 32 turn, 64 shake, 128 has time),
74
+ // time 0..1, position xyz, rotation xyzw, scale xyz, color rgba, move by xyz, turn xyz (radians), shake.
75
+ // Each animated property is its own track: a new one replaces only the same property on the same entity.
76
+ #define ENGINE_ANIM_HEADER 12
77
+ #define ENGINE_ANIM_KEY_LEN 23
78
+ #define ENGINE_DONE_PER_ENTITY 5 // room in engine_world_done: capacity * 5 + 64 ids
79
+ // Burst: position xyz, direction xyz, spread (radians), count, mesh, size, speed, lifetime, gravity,
80
+ // color count (1..4), colors rgba x 4, end size (x start size), has end color (0 / 1), end color rgba.
81
+ #define ENGINE_BURST_LEN 36
82
+
83
+ // ── Worlds and entities ──────────────────────────────────────────────────
84
+ // Capacity is fixed: every pointer below stays valid until engine_world_free.
85
+ World *engine_world_new(uint32_t capacity);
86
+ void engine_world_free(World *w);
87
+
88
+ // Returns the entity id, or ENGINE_NO_ENTITY if the world is full or the description is rejected.
89
+ uint32_t engine_world_spawn_desc(World *w, const double *desc, size_t len);
90
+ // Returns 1 if everything was applied; 0 if the entity is gone or a field was rejected.
91
+ int32_t engine_world_set_desc(World *w, uint32_t id, const double *desc, size_t len);
92
+ // Draw-only transform batch: 16 doubles per record (id, flags, position xyz, rotation xyzw,
93
+ // scale xyz, color rgba). Flags match ENGINE_FLAG_POSITION/ROTATION/SCALE/COLOR. Returns applied count.
94
+ uint32_t engine_world_set_transforms(World *w, const double *data, size_t len, size_t count);
95
+ // Returns 1 if the entity existed. Stale ids are ignored everywhere.
96
+ int32_t engine_world_despawn(World *w, uint32_t id);
97
+
98
+ // Instant change in momentum (dynamic bodies only).
99
+ void engine_world_apply_impulse(World *w, uint32_t id, float x, float y, float z);
100
+ void engine_world_set_gravity(World *w, float x, float y, float z);
101
+ // Moving non-dynamic entities are clamped to this XZ rectangle (dynamic bodies use walls).
102
+ void engine_world_set_bounds(World *w, float min_x, float min_z, float max_x, float max_z);
103
+ // Entity used to pan/attenuate impact sounds; ENGINE_NO_ENTITY clears it.
104
+ void engine_world_set_listener(World *w, uint32_t id);
105
+
106
+ // Hits non-sensor colliders whose layer & mask != 0. Returns the entity or ENGINE_NO_ENTITY;
107
+ // on a hit scratch[0..7] = distance, normal xyz, point xyz.
108
+ uint32_t engine_world_raycast(World *w, float ox, float oy, float oz, float dx, float dy, float dz,
109
+ float max_distance, uint32_t mask);
110
+ // Nearest pickable, visible entity along a ray (bounding boxes, as last drawn). Returns it or
111
+ // ENGINE_NO_ENTITY; on a hit scratch[0..4] = distance, point xyz.
112
+ uint32_t engine_world_pick(World *w, float ox, float oy, float oz, float dx, float dy, float dz);
113
+ // Write position / velocity to engine_world_scratch()[0..3]. Return 1 on success. Positions are simulated
114
+ // (relative to the parent), or with rendered != 0 where the entity was last drawn, in world space.
115
+ int32_t engine_world_read_position(World *w, uint32_t id, int32_t rendered);
116
+ int32_t engine_world_read_velocity(World *w, uint32_t id);
117
+
118
+ // Starts an animation (layout above). Returns its id (> 0), reported by engine_world_done when every
119
+ // track has ended (finished, replaced, stopped or despawned); 0 if nothing started.
120
+ uint32_t engine_world_animate(World *w, const double *anim, size_t len);
121
+ // Stops every animation on the entity where it is. Returns 1 if it had any.
122
+ int32_t engine_world_stop_animation(World *w, uint32_t id);
123
+ // Spawns particles (ENGINE_BURST_LEN doubles). Returns how many were spawned.
124
+ uint32_t engine_world_burst(World *w, const double *burst, size_t len);
125
+
126
+ // Runs whole ENGINE_FIXED_DT steps and interpolates the render output between the last two.
127
+ void engine_world_update(World *w, float dt);
128
+ // Timers on the world's clock (update dt): the id is reported in done (like an animation's) at the
129
+ // end of the update that reaches it. Returns the id, or 0.
130
+ uint32_t engine_world_after(World *w, float seconds);
131
+ // Drops every pending timer (they never fire). Returns how many were dropped.
132
+ uint32_t engine_world_cancel_timers(World *w);
133
+ // Score, lives and the game clock, advanced by engine_world_update. op: 0 add score, 1 set score,
134
+ // 2 add lives, 3 set lives, 4 start clock (a = countdown seconds or 0 to count up, b = points per
135
+ // second), 5 stop, 6 resume, 7 reset (a = lives), 8 add time (a = seconds), 9 time bonus (a = points per second saved, b = expected seconds
136
+ // for a clock counting up). Returns the score.
137
+ #define ENGINE_SCOREBOARD_LEN 8
138
+ double engine_world_scoreboard(World *w, uint32_t op, double a, double b);
139
+ // [score, lives, seconds, shown seconds, changed flags, running, points per second, best].
140
+ double *engine_world_scoreboard_state(World *w);
141
+ uint32_t engine_world_count(World *w);
142
+ uint32_t engine_world_capacity(World *w);
143
+
144
+ // Render output, valid after engine_world_update. Instances are grouped by mesh id.
145
+ const float *engine_world_matrices(World *w); // capacity * 16 floats, column-major
146
+ const float *engine_world_colors(World *w); // capacity * 4 floats (rgba)
147
+ const float *engine_world_regions(World *w); // capacity * 4 floats (texture region u0 v0 u1 v1)
148
+ // ENGINE_MAX_MESHES * 4 u32: [first, count] per mesh for opaque instances, then for transparent ones.
149
+ const uint32_t *engine_world_ranges(World *w);
150
+ // Ids of animations that ended since the last update began (room for capacity * 5 + 64).
151
+ const uint32_t *engine_world_done(World *w);
152
+ uint32_t engine_world_done_len(World *w);
153
+
154
+ // Collision events from the last update, ENGINE_EVENT_STRIDE u32s each; event_len counts u32 values.
155
+ const uint32_t *engine_world_events(World *w);
156
+ uint32_t engine_world_event_len(World *w);
157
+
158
+ const float *engine_world_scratch(World *w); // 16 floats
159
+
160
+ // ── Camera math (per world, after setView) ────────────────────────────
161
+ // Stores the view-projection matrix (16 column-major floats) and view size in points.
162
+ void engine_world_set_view(World *w, const float *view_proj, float width, float height);
163
+ // World-space ray through a view point. Writes origin xyz + direction xyz into scratch[0..6]. 1 on success.
164
+ int32_t engine_world_screen_ray(World *w, float x, float y);
165
+ // Where a view point lands on a plane. Writes into scratch[0..3]. 1 on success.
166
+ int32_t engine_world_screen_to_world(World *w, float x, float y, float ppx, float ppy, float ppz, float pnx, float pny, float pnz);
167
+ // Where a world position appears on screen (points from top-left). Writes into scratch[0..2]. 1 on success.
168
+ int32_t engine_world_to_screen(World *w, float x, float y, float z);
169
+ // Nearest pickable entity under a screen point. Returns it or ENGINE_NO_ENTITY; scratch[0..4] on hit.
170
+ uint32_t engine_world_pick_screen(World *w, float x, float y);
171
+
172
+ // ── Meshes, models, textures, fonts (global) ─────────────────────────────
173
+ // glTF 2.0 (.glb, or .gltf with embedded data), merged into one mesh. Returns the mesh id, or -1.
174
+ /* Skeletal models: metadata JSON; named clips loop/seek/crossfade natively. */
175
+ size_t engine_model_rig(uint32_t mesh, uint8_t *out, size_t capacity);
176
+ int32_t engine_world_play_clip(World *w, uint32_t entity, const uint8_t *name, size_t name_len, int32_t looping, float speed, float fade, float time);
177
+ int32_t engine_world_stop_clip(World *w, uint32_t entity, int32_t reset);
178
+ /* Model-space vertex samples. out has count*3 floats; after previews the next update. */
179
+ int32_t engine_world_skin_points(World *w, uint32_t entity, const uint32_t *indices, size_t count, float *out, float after);
180
+ int32_t engine_model_load(const uint8_t *data, size_t len, int32_t center, float fit);
181
+ // Geometry of a registered mesh (model, glyph, or what an alias points to). Valid for the process.
182
+ const float *engine_model_vertices(uint32_t mesh); // vertex_count * 11 floats: position, normal, color, uv
183
+ uint32_t engine_model_vertex_count(uint32_t mesh);
184
+ const uint32_t *engine_model_indices(uint32_t mesh);
185
+ uint32_t engine_model_index_count(uint32_t mesh);
186
+ int32_t engine_model_size(uint32_t mesh, float *out_xyz); // full bounding-box size; 1 if known
187
+ int32_t engine_model_texture(uint32_t mesh); // base color texture id, or -1
188
+ // A new mesh id drawn with base's geometry (so it can have its own texture). Returns it, or -1.
189
+ int32_t engine_mesh_alias(uint32_t base);
190
+ // Registers geometry (copied): vertex_count * 11 floats (position, normal, color, uv) and u32 triangle
191
+ // indices. Colliders use a box around the origin holding every vertex. Returns the mesh id, or -1.
192
+ /* Persistent assets: app-private storage, no TTL/eviction. cache_read results own their bytes. */
193
+ typedef struct EngineCacheBlob EngineCacheBlob;
194
+ int32_t engine_cache_directory(const uint8_t *path, size_t length);
195
+ EngineCacheBlob *engine_cache_read(const uint8_t *key, size_t length);
196
+ const uint8_t *engine_cache_data(const EngineCacheBlob *blob);
197
+ size_t engine_cache_size(const EngineCacheBlob *blob);
198
+ void engine_cache_free(EngineCacheBlob *blob);
199
+ int32_t engine_cache_write(const uint8_t *key, size_t length, const uint8_t *bytes, size_t count);
200
+ int32_t engine_cache_remove(const uint8_t *key, size_t length);
201
+ int32_t engine_cache_clear(void);
202
+ int32_t engine_shape_prepare(const float *vertices, size_t floats, const uint32_t *indices, size_t count, const uint8_t *options, size_t length);
203
+ int32_t engine_solid_prepare(const uint8_t *recipe, size_t count, const uint8_t *options, size_t length);
204
+
205
+ int32_t engine_mesh_create(const float *vertices, size_t vertex_count, const uint32_t *indices, size_t index_count);
206
+ // Fills 2D contours (points = [x, y] pairs, counts[k] points per contour; y up) by the non-zero or
207
+ // even-odd rule and extrudes them depth deep (0 = front face only, facing +Z). Returns the number of
208
+ // floats made (11 per vertex, unindexed triangles), copied out by engine_path_extrude_copy.
209
+ size_t engine_path_extrude(const float *points, const uint32_t *counts, size_t contour_count, float depth, int32_t even_odd);
210
+ size_t engine_path_extrude_copy(float *out, size_t cap);
211
+ // Geometry passes, in place (11 floats per vertex). Smooth: normals from the triangles, averaged
212
+ // across vertices at the same place. Face outward: flips triangles whose winding disagrees with
213
+ // their normals.
214
+ void engine_geometry_smooth_normals(float *vertices, size_t vertex_count, const uint32_t *indices, size_t index_count);
215
+
216
+ // Intermediate modelling results own their memory and allocate no registered mesh IDs. Data is
217
+ // [vertex_count, index_count, 11 floats per vertex (as u32 bits), u32 indices], valid until free.
218
+ typedef struct EngineGeometry EngineGeometry;
219
+ EngineGeometry *engine_geometry_solid(const uint8_t *recipe, size_t len);
220
+ EngineGeometry *engine_geometry_optimize(const float *vertices, size_t floats, const uint32_t *indices, size_t count, float ratio, float error, int32_t lock_borders);
221
+ const uint32_t *engine_geometry_data(const EngineGeometry *result);
222
+ size_t engine_geometry_size(const EngineGeometry *result);
223
+ const char *engine_geometry_error(const EngineGeometry *result);
224
+ void engine_geometry_free(EngineGeometry *result);
225
+ void engine_geometry_face_outward(const float *vertices, size_t vertex_count, uint32_t *indices, size_t index_count);
226
+ // Bakes a part into merged buffers: placement = position xyz, rotation quat xyzw, scale xyz, color
227
+ // rgb (13 floats). Writes vertex_count vertices and index_count indices (plus first).
228
+ void engine_geometry_place(const float *vertices, size_t vertex_count, const uint32_t *indices, size_t index_count, const float *placement,
229
+ uint32_t first, float *out_vertices, uint32_t *out_indices);
230
+
231
+ // PNG or JPEG. Returns the texture id, or -1.
232
+ int32_t engine_texture_load(const uint8_t *data, size_t len);
233
+ const uint8_t *engine_texture_pixels(uint32_t id); // width * height RGBA8, top row first
234
+ int32_t engine_texture_size(uint32_t id, uint32_t *out_wh);
235
+
236
+ // TrueType / OpenType: one extruded mesh per character of `chars` (UTF-8), depth in ems. Returns the
237
+ // font id, or -1. `weight` picks a variable font's weight (0 = its default). Glyphs: [codepoint, mesh
238
+ // (-1 = nothing drawn), advance in ems] floats.
239
+ int32_t engine_font_load(const uint8_t *data, size_t len, float depth, const char *chars, size_t chars_len, float weight);
240
+ const float *engine_font_glyphs(uint32_t font);
241
+ uint32_t engine_font_glyph_floats(uint32_t font);
242
+ float engine_font_cap_height(uint32_t font);
243
+
244
+ // Why the last model / texture / font / alias load failed (NUL-terminated into out). Returns the full
245
+ // length (0 = no error).
246
+ size_t engine_load_error(char *out, size_t cap);
247
+
248
+ // ── Audio (global) ───────────────────────────────────────────────────────
249
+ // The output stream starts on first use. WAV (PCM int or float, mono/stereo).
250
+ int32_t engine_audio_load_wav(const uint8_t *data, size_t len); // sound id, or -1
251
+ uint64_t engine_audio_play(uint32_t sound, float volume, float pan, float pitch, int32_t looping); // voice id, 0 = none
252
+ void engine_audio_stop(uint64_t voice);
253
+ void engine_audio_set_volume(float volume);
254
+ void engine_audio_set_muted(int32_t muted);
255
+ int32_t engine_audio_is_running(void);
256
+
257
+ // ── Android ──────────────────────────────────────────────────────────────
258
+ #ifdef __ANDROID__
259
+ // Call once at startup with the JavaVM and a JNI *global* reference to a Context (the Application):
260
+ // audio and haptics need them. Repeat calls are ignored.
261
+ void engine_android_init(void *java_vm, void *context);
262
+ #endif
263
+
264
+ // ── Built-in mesh generation and readback (global) ───────────────────
265
+ // Generates and registers all built-in shape meshes (cube, sphere, etc.) with the renderer.
266
+ void engine_generate_builtin_meshes(void);
267
+ // Vertex / index count of a registered renderer mesh, or 0.
268
+ /* engine_render_frame's arguments, but the frame is copied and drawn on the render thread; returns at once with the
269
+ * view-projection written. 1 once the surface has presented a frame, 0 before, -1 if the last frame failed. */
270
+ int32_t engine_render_publish(int32_t surface, const double *frame, size_t frame_len, const float *matrices, const float *colors,
271
+ const float *regions, size_t capacity, const uint32_t *ranges, size_t ranges_len, size_t count,
272
+ float *out_view_proj, const World *world);
273
+ /* [frames presented, smoothed render ms] for a surface drawn by the render thread. */
274
+ void engine_render_stats(int32_t surface, double *out);
275
+ /* A core model's geometry (mesh_create, glTF, glyphs) to the renderer, inside Rust; texture < 0 = none. 1, or 0 if unknown. */
276
+ int32_t engine_render_model(uint32_t mesh, int32_t texture, float shine);
277
+ size_t engine_render_mesh_vertex_count(uint32_t mesh);
278
+ size_t engine_render_mesh_index_count(uint32_t mesh);
279
+ // Copies geometry into caller-owned buffers. Returns the actual count.
280
+ size_t engine_render_mesh_vertices(uint32_t mesh, float *out, size_t cap);
281
+ size_t engine_render_mesh_indices(uint32_t mesh, uint32_t *out, size_t cap);
282
+
283
+ // ── Renderer (wgpu: Vulkan, else GLES 3.0, on Android; Metal on iOS) ───────
284
+ #define ENGINE_FRAME_LEN 26
285
+ // Geometry (copied) drawn for a mesh id: vertex_count * 11 floats, u32 indices; texture -1 = none.
286
+ void engine_render_mesh(uint32_t mesh, const float *vertices, size_t vertex_count, const uint32_t *indices, size_t index_count,
287
+ int32_t texture, float shine);
288
+ // Attaches (or resizes) surface `surface` drawing into `window` (ANativeWindow* on Android, CAMetalLayer*
289
+ // on iOS) at width x height pixels. `window` must stay valid until engine_render_detach returns.
290
+ // Returns 1, or 0 on failure (see engine_render_error).
291
+ int32_t engine_render_attach(int32_t surface, void *window, uint32_t width, uint32_t height);
292
+ // Builds the GPU device and pipelines on a background thread before any surface exists, so the first
293
+ // engine_render_attach doesn't (it waits for a warm-up in progress). Returns at once; repeat calls do nothing.
294
+ void engine_render_warm_up(void);
295
+ void engine_render_detach(int32_t surface);
296
+ // Draws a frame. `frame`: ENGINE_FRAME_LEN doubles (layout in native/core/src/render/gpu.rs, Frame::from_slice).
297
+ // Instance buffers hold `capacity` instances (regions may be NULL); `ranges` as engine_world_ranges.
298
+ // Returns 1 (drawn; out_view_proj gets 16 floats), 0 (surface not ready / frame skipped), -1 (error).
299
+ int32_t engine_render_frame(int32_t surface, const double *frame, size_t frame_len, const float *matrices, const float *colors,
300
+ const float *regions, size_t capacity, const uint32_t *ranges, size_t ranges_len, size_t count,
301
+ float *out_view_proj, const World *world);
302
+ // The screen-space overlay drawn over `surface` from its next frame on (scoreboards, buttons), copied
303
+ // from a world's buffers (as engine_render_frame). In points: x right and y up from the view's top-left
304
+ // (on screen y <= 0), z toward the viewer within -100..100; `width` x `height` is the view in points.
305
+ // Unlit and always in front of the scene. count 0 (or NULL buffers) removes it.
306
+ void engine_render_overlay(int32_t surface, const float *matrices, const float *colors, const float *regions, size_t capacity,
307
+ const uint32_t *ranges, size_t ranges_len, size_t count, float width, float height);
308
+ size_t engine_render_error(char *out, size_t cap);
309
+ // "vulkan", "gl", "metal", or "" before the first attach.
310
+ size_t engine_render_backend(char *out, size_t cap);
311
+
312
+ // ── Haptics (global; Core Haptics on iOS, the Vibrator service on Android) ──
313
+ int32_t engine_haptics_supported(void);
314
+ // `count` taps as [time, intensity 0..1, sharpness 0..1] triples.
315
+ void engine_haptics_play(const float *taps, uint32_t count, int32_t throttle);
316
+
317
+ // Engine-owned art documents. Positions are view points; pressure is normalized 0..1.
318
+ int32_t engine_drawing_create(float width, float height, float ratio);
319
+ void engine_drawing_destroy(int32_t document);
320
+ char *engine_drawing_command(int32_t document, const uint8_t *json, size_t length);
321
+ void engine_drawing_result_free(char *result);
322
+ // Returns null when unchanged. Free non-null events with engine_drawing_result_free.
323
+ char *engine_drawing_take_event(int32_t document);
324
+ void engine_drawing_touch(int32_t document, int32_t phase, float x, float y, float pressure);
325
+ void engine_drawing_transform(int32_t document, float dx, float dy, float scale);
326
+ void engine_drawing_invalidate(int32_t document);
327
+ int32_t engine_drawing_present(int32_t document, int32_t surface, float width, float height, uint32_t background_rgb);
328
+
329
+ #ifdef __cplusplus
330
+ }
331
+ #endif