Commit bbd0179
authored
Make games run on watchOS (FFI stubs, string FFI, file reading, 2D camera) (#60)
* fix(watchos): generate the full FFI stub set so games link
gen_stubs.js threw on `string` params (rustType only knew f64/i64/void), so
it crashed before writing src/ffi_stubs.rs and the checked-in file went stale —
a game linking against the watchOS lib failed with undefined `_bloom_*`
(post-pass, ssao, wind, …). Map `string` -> i64 (Perry passes string pointers
in an integer register) for both params and returns, and add bloom_get_language
/ bloom_set_direct_2d_mode to OVERRIDES (real impls in lib.rs that regen would
otherwise duplicate). Regenerate.
Four functions (bloom_set_material_params, bloom_splat_impulse,
bloom_profiler_frame_history, bloom_profiler_overlay_text) are declared in the
engine's core/index.ts but absent from package.json's nativeLibrary.functions,
so gen_stubs can't see them — add hand-written no-op stubs in
src/ffi_stubs_manual.rs (perry validates the manifest cross-platform, so the
manifest gap is left for a separate change).
* fix(watchos): correct string FFI, implement file reading + 2D camera
Three runtime gaps that kept games from actually rendering on watchOS:
- StringHeader was 16 bytes (4×u32), but Perry 0.5.x's canonical header is 20
bytes (5×u32 incl `flags`, data at +20). `perry_str` read every incoming
string 4 bytes early — text rendered with a 4-null prefix + truncated tail
("BLOOM JUMP" -> "BLOOM") and file paths came back corrupted so levels
never loaded. Add the missing `flags` field.
- bloom_read_file was a stub returning 0 (null); the game's inline `.length`
then dereferenced null and crashed. Implement it: resolve the bundle-relative
path, read the file, and return a real StringHeader via a new
alloc_perry_string (empty string on a miss, never null).
- bloom_begin_mode_2d / bloom_end_mode_2d were no-ops, so world-space draws
(tiles, sprites) rendered at raw coordinates off-screen while the screen-space
HUD showed. Emit BEGIN_2D/END_2D marker commands carrying the camera; the
SwiftUI Canvas applies the matching affine transform (world -> screen) to
every command in between.
Also drop the watchOS `metal_sources` post-fx shader: SCNTechnique/SCNRenderer
is absent from the watchOS SDK so it can't run, and compiling it needs the
separately-downloadable Metal Toolchain. The app renders fine without the
metallib.1 parent e941577 commit bbd0179
7 files changed
Lines changed: 440 additions & 71 deletions
File tree
- native/watchos
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
78 | 83 | | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
| |||
307 | 309 | | |
308 | 310 | | |
309 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
310 | 317 | | |
311 | 318 | | |
312 | 319 | | |
313 | 320 | | |
314 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
315 | 336 | | |
316 | 337 | | |
317 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
| |||
0 commit comments