diff options
| author | 3gg <3gg@shellblade.net> | 2025-09-01 14:50:37 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-09-01 14:50:37 -0700 |
| commit | 3f91c1d9edb6cd7c251b51c18a5db54fe185ffed (patch) | |
| tree | de5df333389825dde02b631178f71a616d0d3982 | |
| parent | db3fd5aac9c66e64aa56fabc1a865fb64a65fc1c (diff) | |
Update to match new gfx-app
| -rw-r--r-- | demos/checkerboard/checkerboard.c | 18 | ||||
| -rw-r--r-- | demos/isomap/isomap.c | 37 |
2 files changed, 33 insertions, 22 deletions
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) { | |||
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | static bool init(GfxAppState* state, int argc, const char** argv) { | 69 | static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { |
| 70 | assert(app); | ||
| 70 | assert(state); | 71 | assert(state); |
| 71 | |||
| 72 | (void)argc; | 72 | (void)argc; |
| 73 | (void)argv; | 73 | (void)argv; |
| 74 | 74 | ||
| @@ -100,14 +100,16 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
| 100 | return true; | 100 | return true; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | static void shutdown(GfxAppState* state) { | 103 | static void shutdown(GfxApp* app, GfxAppState* state) { |
| 104 | assert(app); | ||
| 104 | assert(state); | 105 | assert(state); |
| 105 | 106 | ||
| 106 | iso_backend_shutdown(&state->backend); | 107 | iso_backend_shutdown(&state->backend); |
| 107 | isogfx_del(&state->iso); | 108 | isogfx_del(&state->iso); |
| 108 | } | 109 | } |
| 109 | 110 | ||
| 110 | static void update(GfxAppState* state, double t, double dt) { | 111 | static void update(GfxApp* app, GfxAppState* state, double t, double dt) { |
| 112 | assert(app); | ||
| 111 | assert(state); | 113 | assert(state); |
| 112 | (void)dt; | 114 | (void)dt; |
| 113 | 115 | ||
| @@ -117,7 +119,7 @@ static void update(GfxAppState* state, double t, double dt) { | |||
| 117 | 119 | ||
| 118 | // Get mouse position in window coordinates. | 120 | // Get mouse position in window coordinates. |
| 119 | double mouse_x, mouse_y; | 121 | double mouse_x, mouse_y; |
| 120 | gfx_app_get_mouse_position(&mouse_x, &mouse_y); | 122 | gfx_app_get_mouse_position(app, &mouse_x, &mouse_y); |
| 121 | 123 | ||
| 122 | // Map from window coordinates to virtual screen coordinates. | 124 | // Map from window coordinates to virtual screen coordinates. |
| 123 | iso_backend_get_mouse_position( | 125 | iso_backend_get_mouse_position( |
| @@ -128,7 +130,8 @@ static void update(GfxAppState* state, double t, double dt) { | |||
| 128 | printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); | 130 | printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); |
| 129 | } | 131 | } |
| 130 | 132 | ||
| 131 | static void render(GfxAppState* state) { | 133 | static void render(const GfxApp* app, GfxAppState* state) { |
| 134 | assert(app); | ||
| 132 | assert(state); | 135 | assert(state); |
| 133 | 136 | ||
| 134 | IsoGfx* iso = state->iso; | 137 | IsoGfx* iso = state->iso; |
| @@ -142,7 +145,8 @@ static void render(GfxAppState* state) { | |||
| 142 | iso_backend_render(state->backend, iso); | 145 | iso_backend_render(state->backend, iso); |
| 143 | } | 146 | } |
| 144 | 147 | ||
| 145 | static void resize(GfxAppState* state, int width, int height) { | 148 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { |
| 149 | assert(app); | ||
| 146 | assert(state); | 150 | assert(state); |
| 147 | 151 | ||
| 148 | iso_backend_resize_window(state->backend, state->iso, width, height); | 152 | 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; | |||
| 16 | static const int SCREEN_WIDTH = 704; | 16 | static const int SCREEN_WIDTH = 704; |
| 17 | static const int SCREEN_HEIGHT = 480; | 17 | static const int SCREEN_HEIGHT = 480; |
| 18 | 18 | ||
| 19 | static const R CAMERA_SPEED = 400; | 19 | static const R CAMERA_SPEED = 800; |
| 20 | 20 | ||
| 21 | #define MEMORY_SIZE (2 * 1024 * 1024) | 21 | #define MEMORY_SIZE (8 * 1024 * 1024) |
| 22 | uint8_t MEMORY[MEMORY_SIZE]; | 22 | uint8_t MEMORY[MEMORY_SIZE]; |
| 23 | 23 | ||
| 24 | typedef struct GfxAppState { | 24 | typedef struct GfxAppState { |
| @@ -31,7 +31,8 @@ typedef struct GfxAppState { | |||
| 31 | Sprite stag; | 31 | Sprite stag; |
| 32 | } GfxAppState; | 32 | } GfxAppState; |
| 33 | 33 | ||
| 34 | static bool init(GfxAppState* state, int argc, const char** argv) { | 34 | static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { |
| 35 | assert(app); | ||
| 35 | assert(state); | 36 | assert(state); |
| 36 | (void)argc; | 37 | (void)argc; |
| 37 | (void)argv; | 38 | (void)argv; |
| @@ -45,7 +46,8 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
| 45 | } | 46 | } |
| 46 | IsoGfx* iso = state->iso; | 47 | IsoGfx* iso = state->iso; |
| 47 | 48 | ||
| 48 | if (!isogfx_load_world(iso, "/home/jeanne/Nextcloud/assets/maps/demo-1.tm")) { | 49 | if (!isogfx_load_world( |
| 50 | iso, "/home/jeanne/Nextcloud/assets/tilemaps/scrabling1.tm")) { | ||
| 49 | return false; | 51 | return false; |
| 50 | } | 52 | } |
| 51 | 53 | ||
| @@ -66,23 +68,25 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
| 66 | return true; | 68 | return true; |
| 67 | } | 69 | } |
| 68 | 70 | ||
| 69 | static void shutdown(GfxAppState* state) { | 71 | static void shutdown(GfxApp* app, GfxAppState* state) { |
| 72 | assert(app); | ||
| 70 | assert(state); | 73 | assert(state); |
| 71 | // | ||
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | static vec2 get_camera_movement(R dt) { | 76 | static vec2 get_camera_movement(GfxApp* app, R dt) { |
| 77 | assert(app); | ||
| 78 | |||
| 75 | vec2 offset = {0}; | 79 | vec2 offset = {0}; |
| 76 | if (gfx_app_is_key_pressed(KeyA)) { | 80 | if (gfx_app_is_key_pressed(app, KeyA)) { |
| 77 | offset.x -= 1; | 81 | offset.x -= 1; |
| 78 | } | 82 | } |
| 79 | if (gfx_app_is_key_pressed(KeyD)) { | 83 | if (gfx_app_is_key_pressed(app, KeyD)) { |
| 80 | offset.x += 1; | 84 | offset.x += 1; |
| 81 | } | 85 | } |
| 82 | if (gfx_app_is_key_pressed(KeyW)) { | 86 | if (gfx_app_is_key_pressed(app, KeyW)) { |
| 83 | offset.y -= 1; | 87 | offset.y -= 1; |
| 84 | } | 88 | } |
| 85 | if (gfx_app_is_key_pressed(KeyS)) { | 89 | if (gfx_app_is_key_pressed(app, KeyS)) { |
| 86 | offset.y += 1; | 90 | offset.y += 1; |
| 87 | } | 91 | } |
| 88 | if ((offset.x != 0) || (offset.y != 0)) { | 92 | if ((offset.x != 0) || (offset.y != 0)) { |
| @@ -91,17 +95,19 @@ static vec2 get_camera_movement(R dt) { | |||
| 91 | return offset; | 95 | return offset; |
| 92 | } | 96 | } |
| 93 | 97 | ||
| 94 | static void update(GfxAppState* state, double t, double dt) { | 98 | static void update(GfxApp* app, GfxAppState* state, double t, double dt) { |
| 99 | assert(app); | ||
| 95 | assert(state); | 100 | assert(state); |
| 96 | 101 | ||
| 97 | state->camera = vec2_add(state->camera, get_camera_movement((R)dt)); | 102 | state->camera = vec2_add(state->camera, get_camera_movement(app, (R)dt)); |
| 98 | 103 | ||
| 99 | IsoGfx* iso = state->iso; | 104 | IsoGfx* iso = state->iso; |
| 100 | isogfx_set_camera(iso, (int)state->camera.x, (int)state->camera.y); | 105 | isogfx_set_camera(iso, (int)state->camera.x, (int)state->camera.y); |
| 101 | isogfx_update(iso, t); | 106 | isogfx_update(iso, t); |
| 102 | } | 107 | } |
| 103 | 108 | ||
| 104 | static void render(GfxAppState* state) { | 109 | static void render(const GfxApp* app, GfxAppState* state) { |
| 110 | assert(app); | ||
| 105 | assert(state); | 111 | assert(state); |
| 106 | 112 | ||
| 107 | IsoGfx* iso = state->iso; | 113 | IsoGfx* iso = state->iso; |
| @@ -109,7 +115,8 @@ static void render(GfxAppState* state) { | |||
| 109 | iso_backend_render(state->backend, iso); | 115 | iso_backend_render(state->backend, iso); |
| 110 | } | 116 | } |
| 111 | 117 | ||
| 112 | static void resize(GfxAppState* state, int width, int height) { | 118 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { |
| 119 | assert(app); | ||
| 113 | assert(state); | 120 | assert(state); |
| 114 | 121 | ||
| 115 | iso_backend_resize_window(state->backend, state->iso, width, height); | 122 | iso_backend_resize_window(state->backend, state->iso, width, height); |
