diff options
| author | 3gg <3gg@shellblade.net> | 2025-09-04 19:16:32 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-09-04 19:16:32 -0700 |
| commit | 5294ea7acb86de460e2426a6dac1d281979d0c3b (patch) | |
| tree | a93bd0dc61340ea282d01a48f106abc6d787e455 /demos | |
| parent | 17d7532c796eced679e7e234c4e6dc7546045c22 (diff) | |
Rename isogfx -> gfx2d
Diffstat (limited to 'demos')
| -rw-r--r-- | demos/checkerboard/checkerboard.c | 62 | ||||
| -rw-r--r-- | demos/isomap/isomap.c | 50 |
2 files changed, 56 insertions, 56 deletions
diff --git a/demos/checkerboard/checkerboard.c b/demos/checkerboard/checkerboard.c index 4f43526..467da61 100644 --- a/demos/checkerboard/checkerboard.c +++ b/demos/checkerboard/checkerboard.c | |||
| @@ -47,21 +47,21 @@ typedef enum Colour { | |||
| 47 | } Colour; | 47 | } Colour; |
| 48 | 48 | ||
| 49 | typedef struct GfxAppState { | 49 | typedef struct GfxAppState { |
| 50 | IsoBackend* backend; | 50 | Gfx2dBackend* backend; |
| 51 | IsoGfx* iso; | 51 | Gfx2d* gfx; |
| 52 | Tile red; | 52 | Tile red; |
| 53 | int xpick; | 53 | int xpick; |
| 54 | int ypick; | 54 | int ypick; |
| 55 | } GfxAppState; | 55 | } GfxAppState; |
| 56 | 56 | ||
| 57 | static void make_checkerboard(IsoGfx* iso, Tile black, Tile white) { | 57 | static void make_checkerboard(Gfx2d* iso, Tile black, Tile white) { |
| 58 | assert(iso); | 58 | assert(iso); |
| 59 | for (int y = 0; y < isogfx_world_height(iso); ++y) { | 59 | for (int y = 0; y < gfx2d_world_height(iso); ++y) { |
| 60 | for (int x = 0; x < isogfx_world_width(iso); ++x) { | 60 | for (int x = 0; x < gfx2d_world_width(iso); ++x) { |
| 61 | const int odd_col = x & 1; | 61 | const int odd_col = x & 1; |
| 62 | const int odd_row = y & 1; | 62 | const int odd_row = y & 1; |
| 63 | const Tile value = (odd_row ^ odd_col) == 0 ? black : white; | 63 | const Tile value = (odd_row ^ odd_col) == 0 ? black : white; |
| 64 | isogfx_set_tile(iso, x, y, value); | 64 | gfx2d_set_tile(iso, x, y, value); |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| @@ -72,28 +72,28 @@ static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { | |||
| 72 | (void)argc; | 72 | (void)argc; |
| 73 | (void)argv; | 73 | (void)argv; |
| 74 | 74 | ||
| 75 | if (!((state->iso = | 75 | if (!((state->gfx = |
| 76 | isogfx_new(&(IsoGfxDesc){.memory = MEMORY, | 76 | gfx2d_new(&(Gfx2dDesc){.memory = MEMORY, |
| 77 | .memory_size = MEMORY_SIZE, | 77 | .memory_size = MEMORY_SIZE, |
| 78 | .screen_width = SCREEN_WIDTH, | 78 | .screen_width = SCREEN_WIDTH, |
| 79 | .screen_height = SCREEN_HEIGHT})))) { | 79 | .screen_height = SCREEN_HEIGHT})))) { |
| 80 | return false; | 80 | return false; |
| 81 | } | 81 | } |
| 82 | IsoGfx* iso = state->iso; | 82 | Gfx2d* iso = state->gfx; |
| 83 | 83 | ||
| 84 | isogfx_make_map( | 84 | gfx2d_make_map( |
| 85 | iso, &(MapDesc){.tile_width = TILE_WIDTH, | 85 | iso, &(MapDesc){.tile_width = TILE_WIDTH, |
| 86 | .tile_height = TILE_HEIGHT, | 86 | .tile_height = TILE_HEIGHT, |
| 87 | .world_width = WORLD_WIDTH, | 87 | .world_width = WORLD_WIDTH, |
| 88 | .world_height = WORLD_HEIGHT, | 88 | .world_height = WORLD_HEIGHT, |
| 89 | .num_tiles = NUM_TILES}); | 89 | .num_tiles = NUM_TILES}); |
| 90 | 90 | ||
| 91 | const Tile black = isogfx_make_tile(iso, &tile_set[Black]); | 91 | const Tile black = gfx2d_make_tile(iso, &tile_set[Black]); |
| 92 | const Tile white = isogfx_make_tile(iso, &tile_set[White]); | 92 | const Tile white = gfx2d_make_tile(iso, &tile_set[White]); |
| 93 | state->red = isogfx_make_tile(iso, &tile_set[Red]); | 93 | state->red = gfx2d_make_tile(iso, &tile_set[Red]); |
| 94 | make_checkerboard(iso, black, white); | 94 | make_checkerboard(iso, black, white); |
| 95 | 95 | ||
| 96 | if (!((state->backend = iso_backend_init(iso)))) { | 96 | if (!((state->backend = gfx2d_backend_init(iso)))) { |
| 97 | return false; | 97 | return false; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| @@ -104,8 +104,8 @@ static void shutdown(GfxApp* app, GfxAppState* state) { | |||
| 104 | assert(app); | 104 | assert(app); |
| 105 | assert(state); | 105 | assert(state); |
| 106 | 106 | ||
| 107 | iso_backend_shutdown(&state->backend); | 107 | gfx2d_backend_shutdown(&state->backend); |
| 108 | isogfx_del(&state->iso); | 108 | gfx2d_del(&state->gfx); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static void update(GfxApp* app, GfxAppState* state, double t, double dt) { | 111 | static void update(GfxApp* app, GfxAppState* state, double t, double dt) { |
| @@ -113,19 +113,19 @@ static void update(GfxApp* app, GfxAppState* state, double t, double dt) { | |||
| 113 | assert(state); | 113 | assert(state); |
| 114 | (void)dt; | 114 | (void)dt; |
| 115 | 115 | ||
| 116 | IsoGfx* iso = state->iso; | 116 | Gfx2d* iso = state->gfx; |
| 117 | 117 | ||
| 118 | isogfx_update(iso, t); | 118 | gfx2d_update(iso, t); |
| 119 | 119 | ||
| 120 | // Get mouse position in window coordinates. | 120 | // Get mouse position in window coordinates. |
| 121 | double mouse_x, mouse_y; | 121 | double mouse_x, mouse_y; |
| 122 | gfx_app_get_mouse_position(app, &mouse_x, &mouse_y); | 122 | gfx_app_get_mouse_position(app, &mouse_x, &mouse_y); |
| 123 | 123 | ||
| 124 | // Map from window coordinates to virtual screen coordinates. | 124 | // Map from window coordinates to virtual screen coordinates. |
| 125 | iso_backend_get_mouse_position( | 125 | gfx2d_backend_get_mouse_position( |
| 126 | state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y); | 126 | state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y); |
| 127 | 127 | ||
| 128 | isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); | 128 | gfx2d_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); |
| 129 | 129 | ||
| 130 | printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); | 130 | printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); |
| 131 | } | 131 | } |
| @@ -134,22 +134,22 @@ static void render(const GfxApp* app, GfxAppState* state) { | |||
| 134 | assert(app); | 134 | assert(app); |
| 135 | assert(state); | 135 | assert(state); |
| 136 | 136 | ||
| 137 | IsoGfx* iso = state->iso; | 137 | Gfx2d* iso = state->gfx; |
| 138 | 138 | ||
| 139 | isogfx_render(iso); | 139 | gfx2d_render(iso); |
| 140 | 140 | ||
| 141 | if ((state->xpick != -1) && (state->ypick != -1)) { | 141 | if ((state->xpick != -1) && (state->ypick != -1)) { |
| 142 | isogfx_draw_tile(iso, state->xpick, state->ypick, state->red); | 142 | gfx2d_draw_tile(iso, state->xpick, state->ypick, state->red); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | iso_backend_render(state->backend, iso); | 145 | gfx2d_backend_render(state->backend, iso); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { | 148 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { |
| 149 | assert(app); | 149 | assert(app); |
| 150 | assert(state); | 150 | assert(state); |
| 151 | 151 | ||
| 152 | iso_backend_resize_window(state->backend, state->iso, width, height); | 152 | gfx2d_backend_resize_window(state->backend, state->gfx, width, height); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | int main(int argc, const char** argv) { | 155 | int main(int argc, const char** argv) { |
diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c index bca27f6..471ef57 100644 --- a/demos/isomap/isomap.c +++ b/demos/isomap/isomap.c | |||
| @@ -22,13 +22,13 @@ static const R CAMERA_SPEED = 800; | |||
| 22 | uint8_t MEMORY[MEMORY_SIZE]; | 22 | uint8_t MEMORY[MEMORY_SIZE]; |
| 23 | 23 | ||
| 24 | typedef struct GfxAppState { | 24 | typedef struct GfxAppState { |
| 25 | IsoBackend* backend; | 25 | Gfx2dBackend* backend; |
| 26 | IsoGfx* iso; | 26 | Gfx2d* gfx; |
| 27 | int xpick; | 27 | int xpick; |
| 28 | int ypick; | 28 | int ypick; |
| 29 | vec2 camera; | 29 | vec2 camera; |
| 30 | SpriteSheet stag_sheet; | 30 | SpriteSheet stag_sheet; |
| 31 | Sprite stag; | 31 | Sprite stag; |
| 32 | } GfxAppState; | 32 | } GfxAppState; |
| 33 | 33 | ||
| 34 | static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { | 34 | static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { |
| @@ -37,31 +37,31 @@ static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { | |||
| 37 | (void)argc; | 37 | (void)argc; |
| 38 | (void)argv; | 38 | (void)argv; |
| 39 | 39 | ||
| 40 | if (!((state->iso = | 40 | if (!((state->gfx = |
| 41 | isogfx_new(&(IsoGfxDesc){.memory = MEMORY, | 41 | gfx2d_new(&(Gfx2dDesc){.memory = MEMORY, |
| 42 | .memory_size = MEMORY_SIZE, | 42 | .memory_size = MEMORY_SIZE, |
| 43 | .screen_width = SCREEN_WIDTH, | 43 | .screen_width = SCREEN_WIDTH, |
| 44 | .screen_height = SCREEN_HEIGHT})))) { | 44 | .screen_height = SCREEN_HEIGHT})))) { |
| 45 | return false; | 45 | return false; |
| 46 | } | 46 | } |
| 47 | IsoGfx* iso = state->iso; | 47 | Gfx2d* iso = state->gfx; |
| 48 | 48 | ||
| 49 | if (!isogfx_load_map( | 49 | if (!gfx2d_load_map( |
| 50 | iso, "/home/jeanne/Nextcloud/assets/tilemaps/scrabling1.tm")) { | 50 | iso, "/home/jeanne/Nextcloud/assets/tilemaps/scrabling1.tm")) { |
| 51 | return false; | 51 | return false; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | if (!((state->stag_sheet = isogfx_load_sprite_sheet( | 54 | if (!((state->stag_sheet = gfx2d_load_sprite_sheet( |
| 55 | iso, | 55 | iso, |
| 56 | "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/" | 56 | "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/" |
| 57 | "stag.ss")))) { | 57 | "stag.ss")))) { |
| 58 | return false; | 58 | return false; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | state->stag = isogfx_make_sprite(iso, state->stag_sheet); | 61 | state->stag = gfx2d_make_sprite(iso, state->stag_sheet); |
| 62 | isogfx_set_sprite_position(iso, state->stag, 0, 0); | 62 | gfx2d_set_sprite_position(iso, state->stag, 0, 0); |
| 63 | 63 | ||
| 64 | if (!((state->backend = iso_backend_init(iso)))) { | 64 | if (!((state->backend = gfx2d_backend_init(iso)))) { |
| 65 | return false; | 65 | return false; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| @@ -101,25 +101,25 @@ static void update(GfxApp* app, GfxAppState* state, double t, double dt) { | |||
| 101 | 101 | ||
| 102 | state->camera = vec2_add(state->camera, get_camera_movement(app, (R)dt)); | 102 | state->camera = vec2_add(state->camera, get_camera_movement(app, (R)dt)); |
| 103 | 103 | ||
| 104 | IsoGfx* iso = state->iso; | 104 | Gfx2d* iso = state->gfx; |
| 105 | isogfx_set_camera(iso, (int)state->camera.x, (int)state->camera.y); | 105 | gfx2d_set_camera(iso, (int)state->camera.x, (int)state->camera.y); |
| 106 | isogfx_update(iso, t); | 106 | gfx2d_update(iso, t); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | static void render(const GfxApp* app, GfxAppState* state) { | 109 | static void render(const GfxApp* app, GfxAppState* state) { |
| 110 | assert(app); | 110 | assert(app); |
| 111 | assert(state); | 111 | assert(state); |
| 112 | 112 | ||
| 113 | IsoGfx* iso = state->iso; | 113 | Gfx2d* iso = state->gfx; |
| 114 | isogfx_render(iso); | 114 | gfx2d_render(iso); |
| 115 | iso_backend_render(state->backend, iso); | 115 | gfx2d_backend_render(state->backend, iso); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { | 118 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { |
| 119 | assert(app); | 119 | assert(app); |
| 120 | assert(state); | 120 | assert(state); |
| 121 | 121 | ||
| 122 | iso_backend_resize_window(state->backend, state->iso, width, height); | 122 | gfx2d_backend_resize_window(state->backend, state->gfx, width, height); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | int main(int argc, const char** argv) { | 125 | int main(int argc, const char** argv) { |
