platform: protocol skeleton (types + api, no backend yet)
First commit of the Phase 8 platform abstraction (see current/PLATFORM_PLAN.md):
- `library/modules/platform/types.sx` — `FrameContext` (viewport_w/h,
pixel_w/h, dpi_scale, delta_time) and `KeyboardState` (visible, height
+ `zero()`). `EdgeInsets`/`Point`/`Size` and `Event` are reused from
`modules/ui/types.sx` / `modules/ui/events.sx`.
- `library/modules/platform/api.sx` — `Platform :: protocol { init,
run_frame_loop, poll_events, begin_frame, end_frame, safe_insets,
keyboard, show_keyboard, hide_keyboard, shutdown }`. Protocol bodies
omit `self` (matches the `View`/`Allocator` convention).
- `run_frame_loop` takes `Closure()` so backends own the run loop:
SDL drives a `while !quit`, UIKit hands it to a `CADisplayLink` tick,
Emscripten hands it to `emscripten_set_main_loop`.
No backend yet. Regression suite still 50/50; game build still green.
This commit is contained in:
22
library/modules/platform/api.sx
Normal file
22
library/modules/platform/api.sx
Normal file
@@ -0,0 +1,22 @@
|
||||
#import "modules/std.sx";
|
||||
#import "modules/ui/types.sx";
|
||||
#import "modules/ui/events.sx";
|
||||
#import "modules/platform/types.sx";
|
||||
|
||||
Platform :: protocol {
|
||||
init :: (title: [:0]u8, w: s32, h: s32) -> bool;
|
||||
|
||||
run_frame_loop :: (frame_fn: Closure());
|
||||
|
||||
poll_events :: () -> []Event;
|
||||
|
||||
begin_frame :: () -> FrameContext;
|
||||
end_frame :: ();
|
||||
|
||||
safe_insets :: () -> EdgeInsets;
|
||||
keyboard :: () -> KeyboardState;
|
||||
show_keyboard :: ();
|
||||
hide_keyboard :: ();
|
||||
|
||||
shutdown :: ();
|
||||
}
|
||||
19
library/modules/platform/types.sx
Normal file
19
library/modules/platform/types.sx
Normal file
@@ -0,0 +1,19 @@
|
||||
#import "modules/std.sx";
|
||||
#import "modules/ui/types.sx";
|
||||
#import "modules/ui/events.sx";
|
||||
|
||||
FrameContext :: struct {
|
||||
viewport_w: f32;
|
||||
viewport_h: f32;
|
||||
pixel_w: s32;
|
||||
pixel_h: s32;
|
||||
dpi_scale: f32;
|
||||
delta_time: f32;
|
||||
}
|
||||
|
||||
KeyboardState :: struct {
|
||||
visible: bool;
|
||||
height: f32;
|
||||
|
||||
zero :: () -> KeyboardState => .{ visible = false, height = 0.0 };
|
||||
}
|
||||
Reference in New Issue
Block a user