From 3f91c1d9edb6cd7c251b51c18a5db54fe185ffed Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 1 Sep 2025 14:50:37 -0700 Subject: Update to match new gfx-app --- demos/checkerboard/checkerboard.c | 18 +++++++++++------- demos/isomap/isomap.c | 37 ++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 22 deletions(-) (limited to 'demos') diff --git a/demos/checkerboard/checkerboard.c b/demos/checkerboard/checkerboard.c index b408fc2..0c8ff37 100644 --- a/demos/checkerboard/checkerboard.c +++ b/demos/checkerboard/checkerboard.c @@ -66,9 +66,9 @@ static void make_checkerboard(IsoGfx* iso, Tile black, Tile white) { } } -static bool init(GfxAppState* state, int argc, const char** argv) { +static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { + assert(app); assert(state); - (void)argc; (void)argv; @@ -100,14 +100,16 @@ static bool init(GfxAppState* state, int argc, const char** argv) { return true; } -static void shutdown(GfxAppState* state) { +static void shutdown(GfxApp* app, GfxAppState* state) { + assert(app); assert(state); iso_backend_shutdown(&state->backend); isogfx_del(&state->iso); } -static void update(GfxAppState* state, double t, double dt) { +static void update(GfxApp* app, GfxAppState* state, double t, double dt) { + assert(app); assert(state); (void)dt; @@ -117,7 +119,7 @@ static void update(GfxAppState* state, double t, double dt) { // Get mouse position in window coordinates. double mouse_x, mouse_y; - gfx_app_get_mouse_position(&mouse_x, &mouse_y); + gfx_app_get_mouse_position(app, &mouse_x, &mouse_y); // Map from window coordinates to virtual screen coordinates. iso_backend_get_mouse_position( @@ -128,7 +130,8 @@ static void update(GfxAppState* state, double t, double dt) { printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); } -static void render(GfxAppState* state) { +static void render(const GfxApp* app, GfxAppState* state) { + assert(app); assert(state); IsoGfx* iso = state->iso; @@ -142,7 +145,8 @@ static void render(GfxAppState* state) { iso_backend_render(state->backend, iso); } -static void resize(GfxAppState* state, int width, int height) { +static void resize(GfxApp* app, GfxAppState* state, int width, int height) { + assert(app); assert(state); iso_backend_resize_window(state->backend, state->iso, width, height); diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c index a940535..27c2bf3 100644 --- a/demos/isomap/isomap.c +++ b/demos/isomap/isomap.c @@ -16,9 +16,9 @@ static const int MAX_FPS = 60; static const int SCREEN_WIDTH = 704; static const int SCREEN_HEIGHT = 480; -static const R CAMERA_SPEED = 400; +static const R CAMERA_SPEED = 800; -#define MEMORY_SIZE (2 * 1024 * 1024) +#define MEMORY_SIZE (8 * 1024 * 1024) uint8_t MEMORY[MEMORY_SIZE]; typedef struct GfxAppState { @@ -31,7 +31,8 @@ typedef struct GfxAppState { Sprite stag; } GfxAppState; -static bool init(GfxAppState* state, int argc, const char** argv) { +static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { + assert(app); assert(state); (void)argc; (void)argv; @@ -45,7 +46,8 @@ static bool init(GfxAppState* state, int argc, const char** argv) { } IsoGfx* iso = state->iso; - if (!isogfx_load_world(iso, "/home/jeanne/Nextcloud/assets/maps/demo-1.tm")) { + if (!isogfx_load_world( + iso, "/home/jeanne/Nextcloud/assets/tilemaps/scrabling1.tm")) { return false; } @@ -66,23 +68,25 @@ static bool init(GfxAppState* state, int argc, const char** argv) { return true; } -static void shutdown(GfxAppState* state) { +static void shutdown(GfxApp* app, GfxAppState* state) { + assert(app); assert(state); - // } -static vec2 get_camera_movement(R dt) { +static vec2 get_camera_movement(GfxApp* app, R dt) { + assert(app); + vec2 offset = {0}; - if (gfx_app_is_key_pressed(KeyA)) { + if (gfx_app_is_key_pressed(app, KeyA)) { offset.x -= 1; } - if (gfx_app_is_key_pressed(KeyD)) { + if (gfx_app_is_key_pressed(app, KeyD)) { offset.x += 1; } - if (gfx_app_is_key_pressed(KeyW)) { + if (gfx_app_is_key_pressed(app, KeyW)) { offset.y -= 1; } - if (gfx_app_is_key_pressed(KeyS)) { + if (gfx_app_is_key_pressed(app, KeyS)) { offset.y += 1; } if ((offset.x != 0) || (offset.y != 0)) { @@ -91,17 +95,19 @@ static vec2 get_camera_movement(R dt) { return offset; } -static void update(GfxAppState* state, double t, double dt) { +static void update(GfxApp* app, GfxAppState* state, double t, double dt) { + assert(app); assert(state); - state->camera = vec2_add(state->camera, get_camera_movement((R)dt)); + state->camera = vec2_add(state->camera, get_camera_movement(app, (R)dt)); IsoGfx* iso = state->iso; isogfx_set_camera(iso, (int)state->camera.x, (int)state->camera.y); isogfx_update(iso, t); } -static void render(GfxAppState* state) { +static void render(const GfxApp* app, GfxAppState* state) { + assert(app); assert(state); IsoGfx* iso = state->iso; @@ -109,7 +115,8 @@ static void render(GfxAppState* state) { iso_backend_render(state->backend, iso); } -static void resize(GfxAppState* state, int width, int height) { +static void resize(GfxApp* app, GfxAppState* state, int width, int height) { + assert(app); assert(state); iso_backend_resize_window(state->backend, state->iso, width, height); -- cgit v1.2.3