diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
| commit | 537b2d768b31deb0f95c5122e0d562e4406ae9a0 (patch) | |
| tree | cc3e85cb2990672c11b4e35c6dbcfaac733d09f5 /examples/game.c | |
| parent | 98f0d51157fa2a2b8ccaae54ed4850a88d223d01 (diff) | |
Unify core and runner events into struct yasl_event
The core input queue and the yasl_run() runner each had their own event
type, and the runner translated one into the other. Both now share
struct yasl_event in <yasl/yasl.h>: yasl_surface_poll_event() returns the
same events the app event callback receives, so the runner forwards them
unchanged.
Pointer input becomes POINTER_DOWN/UP/MOTION/SCROLL/LEAVE with a named
yasl_pointer_button and a motion delta computed in the input queue. TEXT,
PASTE and DROP share one text payload, scale changes fold into
WINDOW_RESIZE, and every event carries a monotonic time_ns.
yasl_surface_set_mouse_mode() is replaced by
yasl_surface_set_pointer_mode(); no backend implements relative mode yet.
The export check now only counts YASL_API declarations, so function
pointer fields returning enum yasl_app_result are not mistaken for
exports.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'examples/game.c')
| -rw-r--r-- | examples/game.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/examples/game.c b/examples/game.c index 7ec28e1..065ff99 100644 --- a/examples/game.c +++ b/examples/game.c @@ -6,7 +6,7 @@ * - Continuous display-synchronized ticks (YASL_PACING_CONTINUOUS) * - 3D software rendering (rotating shaded cube + starfield) * - WASD continuous player movement & key state tracking - * - Relative mouse mode (YASL_MOUSE_RELATIVE) for smooth first-person camera orbit + * - Relative pointer mode (YASL_POINTER_RELATIVE) for smooth first-person camera orbit * - Spacebar toggles pointer lock (Relative vs Normal cursor) * - Real-time FPS counter and frame latency display * - Dynamic window resizing with automatic aspect ratio adjustment @@ -140,7 +140,7 @@ static bool project_point(struct vec3 p, int w, int h, int *out_x, int *out_y) return true; } -static int on_init(void *ud, struct yasl_display *d) +static enum yasl_app_result on_init(void *ud, struct yasl_display *d) { struct game_state *game = ud; game->display = d; @@ -169,14 +169,13 @@ static int on_init(void *ud, struct yasl_display *d) return YASL_APP_CONTINUE; } -static int on_event(void *ud, const struct yasl_event *ev) +static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev) { struct game_state *game = ud; switch (ev->type) { case YASL_EVENT_KEY: { - bool down = (ev->key.action == YASL_KEY_PRESS || ev->key.action == YASL_KEY_REPEAT); - if (ev->key.action == YASL_KEY_RELEASE) down = false; + bool down = ev->key.action != YASL_KEY_RELEASE; switch (ev->key.key) { case YASL_KEY_W: game->key_w = down; break; @@ -187,17 +186,17 @@ static int on_event(void *ud, const struct yasl_event *ev) case YASL_KEY_E: game->key_e = down; break; case YASL_KEY_SPACE: if (ev->key.action == YASL_KEY_PRESS) { - /* Toggle relative mouse mode */ + /* Toggle relative pointer mode */ game->relative_mouse = !game->relative_mouse; - yasl_surface_set_mouse_mode(game->surface, - game->relative_mouse ? YASL_MOUSE_RELATIVE : YASL_MOUSE_NORMAL); + yasl_surface_set_pointer_mode(game->surface, + game->relative_mouse ? YASL_POINTER_RELATIVE : YASL_POINTER_NORMAL); } break; case YASL_KEY_ESCAPE: if (ev->key.action == YASL_KEY_PRESS) { if (game->relative_mouse) { game->relative_mouse = false; - yasl_surface_set_mouse_mode(game->surface, YASL_MOUSE_NORMAL); + yasl_surface_set_pointer_mode(game->surface, YASL_POINTER_NORMAL); } else { return YASL_APP_QUIT; } @@ -209,25 +208,25 @@ static int on_event(void *ud, const struct yasl_event *ev) break; } - case YASL_EVENT_MOUSE_MOTION: + case YASL_EVENT_POINTER_MOTION: if (game->relative_mouse) { /* Smooth first-person camera orbit */ - game->cam_yaw += (float)ev->mouse_motion.delta.x * 0.005f; - game->cam_pitch += (float)ev->mouse_motion.delta.y * 0.005f; + game->cam_yaw += (float)ev->pointer.delta.x * 0.005f; + game->cam_pitch += (float)ev->pointer.delta.y * 0.005f; if (game->cam_pitch > 1.4f) game->cam_pitch = 1.4f; if (game->cam_pitch < -1.4f) game->cam_pitch = -1.4f; } break; - case YASL_EVENT_MOUSE_BUTTON: - if (ev->mouse_button.pressed && !game->relative_mouse) { + case YASL_EVENT_POINTER_DOWN: + if (!game->relative_mouse) { /* Click window to capture cursor */ game->relative_mouse = true; - yasl_surface_set_mouse_mode(game->surface, YASL_MOUSE_RELATIVE); + yasl_surface_set_pointer_mode(game->surface, YASL_POINTER_RELATIVE); } break; - case YASL_EVENT_WINDOW_CLOSE_REQUEST: + case YASL_EVENT_WINDOW_CLOSE: return YASL_APP_QUIT; default: |
