From d1370b955f9a86c82f92d7368237ed96318de330 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 19 Jul 2025 09:29:12 -0700 Subject: Allocate data from a stack allocator --- demos/checkerboard/checkerboard.c | 29 +++++++++++++++++------------ demos/isomap/isomap.c | 24 ++++++++++++++---------- 2 files changed, 31 insertions(+), 22 deletions(-) (limited to 'demos') diff --git a/demos/checkerboard/checkerboard.c b/demos/checkerboard/checkerboard.c index 9d1791e..b408fc2 100644 --- a/demos/checkerboard/checkerboard.c +++ b/demos/checkerboard/checkerboard.c @@ -20,6 +20,9 @@ static const int TILE_HEIGHT = TILE_WIDTH / 2; static const int WORLD_WIDTH = 20; static const int WORLD_HEIGHT = 20; +#define MEMORY_SIZE (2 * 1024 * 1024) +uint8_t MEMORY[MEMORY_SIZE]; + static const TileDesc tile_set[] = { {.type = TileFromColour, .width = TILE_WIDTH, @@ -35,6 +38,8 @@ static const TileDesc tile_set[] = { .colour = (Pixel){.r = 0xdc, .g = 0x76, .b = 0x84, .a = 0xff}}, }; +#define NUM_TILES (sizeof(tile_set) / sizeof(tile_set[0])) + typedef enum Colour { Black, White, @@ -67,28 +72,28 @@ static bool init(GfxAppState* state, int argc, const char** argv) { (void)argc; (void)argv; - if (!(state->iso = isogfx_new(&(IsoGfxDesc){ - .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { + if (!((state->iso = + isogfx_new(&(IsoGfxDesc){.memory = MEMORY, + .memory_size = MEMORY_SIZE, + .screen_width = SCREEN_WIDTH, + .screen_height = SCREEN_HEIGHT})))) { return false; } IsoGfx* iso = state->iso; - isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); - - if (!isogfx_make_world( - iso, &(WorldDesc){.tile_width = TILE_WIDTH, - .tile_height = TILE_HEIGHT, - .world_width = WORLD_WIDTH, - .world_height = WORLD_HEIGHT})) { - return false; - } + isogfx_make_world( + iso, &(WorldDesc){.tile_width = TILE_WIDTH, + .tile_height = TILE_HEIGHT, + .world_width = WORLD_WIDTH, + .world_height = WORLD_HEIGHT, + .num_tiles = NUM_TILES}); const Tile black = isogfx_make_tile(iso, &tile_set[Black]); const Tile white = isogfx_make_tile(iso, &tile_set[White]); state->red = isogfx_make_tile(iso, &tile_set[Red]); make_checkerboard(iso, black, white); - if (!(state->backend = iso_backend_init(iso))) { + if (!((state->backend = iso_backend_init(iso)))) { return false; } diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c index b328bfa..efae7fd 100644 --- a/demos/isomap/isomap.c +++ b/demos/isomap/isomap.c @@ -5,6 +5,7 @@ #include #include +#include static const int WINDOW_WIDTH = 1408; static const int WINDOW_HEIGHT = 960; @@ -14,6 +15,9 @@ static const int MAX_FPS = 60; static const int SCREEN_WIDTH = 704; static const int SCREEN_HEIGHT = 480; +#define MEMORY_SIZE (2 * 1024 * 1024) +uint8_t MEMORY[MEMORY_SIZE]; + typedef struct GfxAppState { IsoBackend* backend; IsoGfx* iso; @@ -28,30 +32,30 @@ static bool init(GfxAppState* state, int argc, const char** argv) { (void)argc; (void)argv; - if (!(state->iso = isogfx_new(&(IsoGfxDesc){ - .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { + if (!((state->iso = + isogfx_new(&(IsoGfxDesc){.memory = MEMORY, + .memory_size = MEMORY_SIZE, + .screen_width = SCREEN_WIDTH, + .screen_height = SCREEN_HEIGHT})))) { return false; } IsoGfx* iso = state->iso; - isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); - if (!isogfx_load_world(iso, "/home/jeanne/Nextcloud/assets/maps/demo-1.tm")) { return false; } - if (!isogfx_load_sprite_sheet( - iso, - "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/" - "stag.ss", - &state->stag_sheet)) { + if (!((state->stag_sheet = isogfx_load_sprite_sheet( + iso, + "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/" + "stag.ss")))) { return false; } state->stag = isogfx_make_sprite(iso, state->stag_sheet); isogfx_set_sprite_position(iso, state->stag, 5, 4); - if (!(state->backend = iso_backend_init(iso))) { + if (!((state->backend = iso_backend_init(iso)))) { return false; } -- cgit v1.2.3