@nayan-ui/engine 0.0.0-stage → 1.0.0-beta.3
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.
- package/LICENSE +21 -0
- package/NayanEngine.podspec +28 -0
- package/README.md +210 -2
- package/lib/module/assets/AssetBytesCache.js +76 -0
- package/lib/module/assets/AssetCache.js +19 -0
- package/lib/module/assets/AssetLoader.js +52 -0
- package/lib/module/assets/CacheGeneration.js +7 -0
- package/lib/module/assets/IndexedDbCache.web.js +149 -0
- package/lib/module/assets/ProceduralCache.js +222 -0
- package/lib/module/assets/font.js +136 -0
- package/lib/module/assets/loft.js +142 -0
- package/lib/module/assets/model.js +74 -0
- package/lib/module/assets/modelling.js +254 -0
- package/lib/module/assets/shape.js +926 -0
- package/lib/module/assets/source.js +58 -0
- package/lib/module/assets/source.web.js +22 -0
- package/lib/module/assets/storage.js +4 -0
- package/lib/module/assets/storage.shared.js +36 -0
- package/lib/module/assets/storage.web.js +37 -0
- package/lib/module/assets/surface.js +47 -0
- package/lib/module/assets/texture.js +66 -0
- package/lib/module/drawing/DrawingCanvas.js +38 -0
- package/lib/module/drawing/DrawingCanvas.web.js +206 -0
- package/lib/module/drawing/DrawingDocument.js +256 -0
- package/lib/module/drawing/types.js +4 -0
- package/lib/module/globals.d.ts +12 -0
- package/lib/module/index.js +36 -0
- package/lib/module/input/Joystick.js +84 -0
- package/lib/module/input/Joystick.web.js +93 -0
- package/lib/module/input/keyboard.js +250 -0
- package/lib/module/media/audio-worklet.js +34 -0
- package/lib/module/media/audio.js +94 -0
- package/lib/module/media/haptics.js +82 -0
- package/lib/module/media/output.web.js +66 -0
- package/lib/module/native/BrowserEngine.js +551 -0
- package/lib/module/native/EngineBridge.js +4 -0
- package/lib/module/native/NativeNayanEngine.js +7 -0
- package/lib/module/native/NativeNayanEngine.web.js +62 -0
- package/lib/module/native/prepare.js +7 -0
- package/lib/module/native/prepare.web.js +17 -0
- package/lib/module/native/spec/NativeNayanEngine.js +17 -0
- package/lib/module/package.json +1 -0
- package/lib/module/render/GameView.js +249 -0
- package/lib/module/render/camera.js +34 -0
- package/lib/module/render/host.js +39 -0
- package/lib/module/render/host.web.js +104 -0
- package/lib/module/render/meshes.js +159 -0
- package/lib/module/render/quality.js +112 -0
- package/lib/module/render/responder.js +4 -0
- package/lib/module/render/responder.web.js +97 -0
- package/lib/module/render/touch.js +185 -0
- package/lib/module/types.js +30 -0
- package/lib/module/world/Scoreboard.js +143 -0
- package/lib/module/world/TransformBatch.js +126 -0
- package/lib/module/world/World.js +690 -0
- package/lib/module/world/desc.js +186 -0
- package/lib/module/world/effects.js +451 -0
- package/lib/module/world/quat.js +86 -0
- package/lib/module/world/types.js +4 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/assets/AssetBytesCache.d.ts +7 -0
- package/lib/typescript/src/assets/AssetCache.d.ts +9 -0
- package/lib/typescript/src/assets/AssetLoader.d.ts +11 -0
- package/lib/typescript/src/assets/CacheGeneration.d.ts +3 -0
- package/lib/typescript/src/assets/IndexedDbCache.web.d.ts +20 -0
- package/lib/typescript/src/assets/ProceduralCache.d.ts +33 -0
- package/lib/typescript/src/assets/font.d.ts +53 -0
- package/lib/typescript/src/assets/loft.d.ts +31 -0
- package/lib/typescript/src/assets/model.d.ts +48 -0
- package/lib/typescript/src/assets/modelling.d.ts +157 -0
- package/lib/typescript/src/assets/shape.d.ts +203 -0
- package/lib/typescript/src/assets/source.d.ts +10 -0
- package/lib/typescript/src/assets/source.web.d.ts +8 -0
- package/lib/typescript/src/assets/storage.d.ts +2 -0
- package/lib/typescript/src/assets/storage.shared.d.ts +7 -0
- package/lib/typescript/src/assets/storage.web.d.ts +7 -0
- package/lib/typescript/src/assets/surface.d.ts +17 -0
- package/lib/typescript/src/assets/texture.d.ts +30 -0
- package/lib/typescript/src/drawing/DrawingCanvas.d.ts +5 -0
- package/lib/typescript/src/drawing/DrawingCanvas.web.d.ts +4 -0
- package/lib/typescript/src/drawing/DrawingDocument.d.ts +210 -0
- package/lib/typescript/src/drawing/types.d.ts +12 -0
- package/lib/typescript/src/index.d.ts +42 -0
- package/lib/typescript/src/input/Joystick.d.ts +20 -0
- package/lib/typescript/src/input/Joystick.web.d.ts +13 -0
- package/lib/typescript/src/input/keyboard.d.ts +17 -0
- package/lib/typescript/src/media/audio.d.ts +46 -0
- package/lib/typescript/src/media/haptics.d.ts +22 -0
- package/lib/typescript/src/media/output.web.d.ts +4 -0
- package/lib/typescript/src/native/BrowserEngine.d.ts +8 -0
- package/lib/typescript/src/native/EngineBridge.d.ts +22 -0
- package/lib/typescript/src/native/NativeNayanEngine.d.ts +5 -0
- package/lib/typescript/src/native/NativeNayanEngine.web.d.ts +10 -0
- package/lib/typescript/src/native/prepare.d.ts +3 -0
- package/lib/typescript/src/native/prepare.web.d.ts +2 -0
- package/lib/typescript/src/native/spec/NativeNayanEngine.d.ts +182 -0
- package/lib/typescript/src/render/GameView.d.ts +95 -0
- package/lib/typescript/src/render/camera.d.ts +6 -0
- package/lib/typescript/src/render/host.d.ts +29 -0
- package/lib/typescript/src/render/host.web.d.ts +16 -0
- package/lib/typescript/src/render/meshes.d.ts +45 -0
- package/lib/typescript/src/render/quality.d.ts +46 -0
- package/lib/typescript/src/render/responder.d.ts +2 -0
- package/lib/typescript/src/render/responder.web.d.ts +40 -0
- package/lib/typescript/src/render/touch.d.ts +26 -0
- package/lib/typescript/src/types.d.ts +72 -0
- package/lib/typescript/src/world/Scoreboard.d.ts +65 -0
- package/lib/typescript/src/world/TransformBatch.d.ts +39 -0
- package/lib/typescript/src/world/World.d.ts +199 -0
- package/lib/typescript/src/world/desc.d.ts +17 -0
- package/lib/typescript/src/world/effects.d.ts +156 -0
- package/lib/typescript/src/world/quat.d.ts +31 -0
- package/lib/typescript/src/world/types.d.ts +233 -0
- package/lib/web/audio-worklet.js +29 -0
- package/lib/web/engine_core_bg.wasm +0 -0
- package/lib/web/index.js +7974 -0
- package/lib/web/types/src/assets/AssetBytesCache.d.ts +6 -0
- package/lib/web/types/src/assets/AssetCache.d.ts +8 -0
- package/lib/web/types/src/assets/AssetLoader.d.ts +10 -0
- package/lib/web/types/src/assets/CacheGeneration.d.ts +2 -0
- package/lib/web/types/src/assets/IndexedDbCache.d.ts +19 -0
- package/lib/web/types/src/assets/ProceduralCache.d.ts +32 -0
- package/lib/web/types/src/assets/font.d.ts +52 -0
- package/lib/web/types/src/assets/loft.d.ts +30 -0
- package/lib/web/types/src/assets/model.d.ts +47 -0
- package/lib/web/types/src/assets/modelling.d.ts +156 -0
- package/lib/web/types/src/assets/shape.d.ts +202 -0
- package/lib/web/types/src/assets/source.d.ts +7 -0
- package/lib/web/types/src/assets/storage.d.ts +6 -0
- package/lib/web/types/src/assets/storage.shared.d.ts +6 -0
- package/lib/web/types/src/assets/surface.d.ts +16 -0
- package/lib/web/types/src/assets/texture.d.ts +29 -0
- package/lib/web/types/src/drawing/DrawingCanvas.d.ts +3 -0
- package/lib/web/types/src/drawing/DrawingDocument.d.ts +209 -0
- package/lib/web/types/src/drawing/types.d.ts +11 -0
- package/lib/web/types/src/index.d.ts +41 -0
- package/lib/web/types/src/input/Joystick.d.ts +12 -0
- package/lib/web/types/src/input/keyboard.d.ts +16 -0
- package/lib/web/types/src/media/audio.d.ts +45 -0
- package/lib/web/types/src/media/haptics.d.ts +21 -0
- package/lib/web/types/src/media/output.d.ts +3 -0
- package/lib/web/types/src/native/BrowserEngine.d.ts +7 -0
- package/lib/web/types/src/native/EngineBridge.d.ts +21 -0
- package/lib/web/types/src/native/NativeNayanEngine.d.ts +9 -0
- package/lib/web/types/src/native/prepare.d.ts +1 -0
- package/lib/web/types/src/native/spec/NativeNayanEngine.d.ts +181 -0
- package/lib/web/types/src/render/GameView.d.ts +94 -0
- package/lib/web/types/src/render/camera.d.ts +5 -0
- package/lib/web/types/src/render/host.d.ts +15 -0
- package/lib/web/types/src/render/meshes.d.ts +44 -0
- package/lib/web/types/src/render/quality.d.ts +45 -0
- package/lib/web/types/src/render/responder.d.ts +39 -0
- package/lib/web/types/src/render/touch.d.ts +25 -0
- package/lib/web/types/src/types.d.ts +71 -0
- package/lib/web/types/src/world/Scoreboard.d.ts +64 -0
- package/lib/web/types/src/world/TransformBatch.d.ts +38 -0
- package/lib/web/types/src/world/World.d.ts +198 -0
- package/lib/web/types/src/world/desc.d.ts +16 -0
- package/lib/web/types/src/world/effects.d.ts +155 -0
- package/lib/web/types/src/world/quat.d.ts +30 -0
- package/lib/web/types/src/world/types.d.ts +232 -0
- package/native/android/CMakeLists.txt +34 -0
- package/native/android/NayanEngineSpec.h +15 -0
- package/native/android/build.gradle +26 -0
- package/native/android/codegen/CMakeLists.txt +3 -0
- package/native/android/proguard-rules.pro +2 -0
- package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceView.java +234 -0
- package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceViewManager.java +45 -0
- package/native/android/src/main/java/com/nayanui/engine/NayanEnginePackage.java +24 -0
- package/native/core/build/EngineCore.xcframework/Info.plist +43 -0
- package/native/core/build/EngineCore.xcframework/ios-arm64/libengine_core.a +0 -0
- package/native/core/build/EngineCore.xcframework/ios-arm64-simulator/libengine_core.a +0 -0
- package/native/core/build/android/arm64-v8a/libengine_core.a +0 -0
- package/native/core/build/android/armeabi-v7a/libengine_core.a +0 -0
- package/native/core/build/android/x86/libengine_core.a +0 -0
- package/native/core/build/android/x86_64/libengine_core.a +0 -0
- package/native/core/include/drawing-licenses.txt +58 -0
- package/native/core/include/engine_core.h +322 -0
- package/native/cpp/NayanEngineModule.cpp +827 -0
- package/native/cpp/NayanEngineModule.h +144 -0
- package/native/cpp/generated/NayanEngineSpecJSI.cpp +2 -0
- package/native/cpp/generated/NayanEngineSpecJSI.h +921 -0
- package/native/ios/NayanEngineProvider.h +5 -0
- package/native/ios/NayanEngineProvider.mm +21 -0
- package/native/ios/NayanEngineSurface.mm +223 -0
- package/native/scripts/check-package.mjs +39 -0
- package/package.json +162 -4
- package/react-native.config.js +18 -0
- package/src/native/spec/NativeNayanEngine.ts +226 -0
|
@@ -0,0 +1,322 @@
|
|
|
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
|
+
size_t engine_render_mesh_vertex_count(uint32_t mesh);
|
|
269
|
+
size_t engine_render_mesh_index_count(uint32_t mesh);
|
|
270
|
+
// Copies geometry into caller-owned buffers. Returns the actual count.
|
|
271
|
+
size_t engine_render_mesh_vertices(uint32_t mesh, float *out, size_t cap);
|
|
272
|
+
size_t engine_render_mesh_indices(uint32_t mesh, uint32_t *out, size_t cap);
|
|
273
|
+
|
|
274
|
+
// ── Renderer (wgpu: Vulkan, else GLES 3.0, on Android; Metal on iOS) ───────
|
|
275
|
+
#define ENGINE_FRAME_LEN 26
|
|
276
|
+
// Geometry (copied) drawn for a mesh id: vertex_count * 11 floats, u32 indices; texture -1 = none.
|
|
277
|
+
void engine_render_mesh(uint32_t mesh, const float *vertices, size_t vertex_count, const uint32_t *indices, size_t index_count,
|
|
278
|
+
int32_t texture, float shine);
|
|
279
|
+
// Attaches (or resizes) surface `surface` drawing into `window` (ANativeWindow* on Android, CAMetalLayer*
|
|
280
|
+
// on iOS) at width x height pixels. `window` must stay valid until engine_render_detach returns.
|
|
281
|
+
// Returns 1, or 0 on failure (see engine_render_error).
|
|
282
|
+
int32_t engine_render_attach(int32_t surface, void *window, uint32_t width, uint32_t height);
|
|
283
|
+
// Builds the GPU device and pipelines on a background thread before any surface exists, so the first
|
|
284
|
+
// engine_render_attach doesn't (it waits for a warm-up in progress). Returns at once; repeat calls do nothing.
|
|
285
|
+
void engine_render_warm_up(void);
|
|
286
|
+
void engine_render_detach(int32_t surface);
|
|
287
|
+
// Draws a frame. `frame`: ENGINE_FRAME_LEN doubles (layout in native/core/src/render/gpu.rs, Frame::from_slice).
|
|
288
|
+
// Instance buffers hold `capacity` instances (regions may be NULL); `ranges` as engine_world_ranges.
|
|
289
|
+
// Returns 1 (drawn; out_view_proj gets 16 floats), 0 (surface not ready / frame skipped), -1 (error).
|
|
290
|
+
int32_t engine_render_frame(int32_t surface, const double *frame, size_t frame_len, const float *matrices, const float *colors,
|
|
291
|
+
const float *regions, size_t capacity, const uint32_t *ranges, size_t ranges_len, size_t count,
|
|
292
|
+
float *out_view_proj, const World *world);
|
|
293
|
+
// The screen-space overlay drawn over `surface` from its next frame on (scoreboards, buttons), copied
|
|
294
|
+
// from a world's buffers (as engine_render_frame). In points: x right and y up from the view's top-left
|
|
295
|
+
// (on screen y <= 0), z toward the viewer within -100..100; `width` x `height` is the view in points.
|
|
296
|
+
// Unlit and always in front of the scene. count 0 (or NULL buffers) removes it.
|
|
297
|
+
void engine_render_overlay(int32_t surface, const float *matrices, const float *colors, const float *regions, size_t capacity,
|
|
298
|
+
const uint32_t *ranges, size_t ranges_len, size_t count, float width, float height);
|
|
299
|
+
size_t engine_render_error(char *out, size_t cap);
|
|
300
|
+
// "vulkan", "gl", "metal", or "" before the first attach.
|
|
301
|
+
size_t engine_render_backend(char *out, size_t cap);
|
|
302
|
+
|
|
303
|
+
// ── Haptics (global; Core Haptics on iOS, the Vibrator service on Android) ──
|
|
304
|
+
int32_t engine_haptics_supported(void);
|
|
305
|
+
// `count` taps as [time, intensity 0..1, sharpness 0..1] triples.
|
|
306
|
+
void engine_haptics_play(const float *taps, uint32_t count, int32_t throttle);
|
|
307
|
+
|
|
308
|
+
// Engine-owned art documents. Positions are view points; pressure is normalized 0..1.
|
|
309
|
+
int32_t engine_drawing_create(float width, float height, float ratio);
|
|
310
|
+
void engine_drawing_destroy(int32_t document);
|
|
311
|
+
char *engine_drawing_command(int32_t document, const uint8_t *json, size_t length);
|
|
312
|
+
void engine_drawing_result_free(char *result);
|
|
313
|
+
// Returns null when unchanged. Free non-null events with engine_drawing_result_free.
|
|
314
|
+
char *engine_drawing_take_event(int32_t document);
|
|
315
|
+
void engine_drawing_touch(int32_t document, int32_t phase, float x, float y, float pressure);
|
|
316
|
+
void engine_drawing_transform(int32_t document, float dx, float dy, float scale);
|
|
317
|
+
void engine_drawing_invalidate(int32_t document);
|
|
318
|
+
int32_t engine_drawing_present(int32_t document, int32_t surface, float width, float height, uint32_t background_rgb);
|
|
319
|
+
|
|
320
|
+
#ifdef __cplusplus
|
|
321
|
+
}
|
|
322
|
+
#endif
|