diff options
| author | 3gg <3gg@shellblade.net> | 2025-07-19 09:29:12 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-07-19 09:29:12 -0700 |
| commit | d1370b955f9a86c82f92d7368237ed96318de330 (patch) | |
| tree | fe59a07927e560da5dfe88c89c547ec3c3a47307 /demos/checkerboard | |
| parent | 10cd24c9e5da615064c782effafc7477bf074054 (diff) | |
Allocate data from a stack allocator
Diffstat (limited to 'demos/checkerboard')
| -rw-r--r-- | demos/checkerboard/checkerboard.c | 29 |
1 files changed, 17 insertions, 12 deletions
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; | |||
| 20 | static const int WORLD_WIDTH = 20; | 20 | static const int WORLD_WIDTH = 20; |
| 21 | static const int WORLD_HEIGHT = 20; | 21 | static const int WORLD_HEIGHT = 20; |
| 22 | 22 | ||
| 23 | #define MEMORY_SIZE (2 * 1024 * 1024) | ||
| 24 | uint8_t MEMORY[MEMORY_SIZE]; | ||
| 25 | |||
| 23 | static const TileDesc tile_set[] = { | 26 | static const TileDesc tile_set[] = { |
| 24 | {.type = TileFromColour, | 27 | {.type = TileFromColour, |
| 25 | .width = TILE_WIDTH, | 28 | .width = TILE_WIDTH, |
| @@ -35,6 +38,8 @@ static const TileDesc tile_set[] = { | |||
| 35 | .colour = (Pixel){.r = 0xdc, .g = 0x76, .b = 0x84, .a = 0xff}}, | 38 | .colour = (Pixel){.r = 0xdc, .g = 0x76, .b = 0x84, .a = 0xff}}, |
| 36 | }; | 39 | }; |
| 37 | 40 | ||
| 41 | #define NUM_TILES (sizeof(tile_set) / sizeof(tile_set[0])) | ||
| 42 | |||
| 38 | typedef enum Colour { | 43 | typedef enum Colour { |
| 39 | Black, | 44 | Black, |
| 40 | White, | 45 | White, |
| @@ -67,28 +72,28 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
| 67 | (void)argc; | 72 | (void)argc; |
| 68 | (void)argv; | 73 | (void)argv; |
| 69 | 74 | ||
| 70 | if (!(state->iso = isogfx_new(&(IsoGfxDesc){ | 75 | if (!((state->iso = |
| 71 | .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { | 76 | isogfx_new(&(IsoGfxDesc){.memory = MEMORY, |
| 77 | .memory_size = MEMORY_SIZE, | ||
| 78 | .screen_width = SCREEN_WIDTH, | ||
| 79 | .screen_height = SCREEN_HEIGHT})))) { | ||
| 72 | return false; | 80 | return false; |
| 73 | } | 81 | } |
| 74 | IsoGfx* iso = state->iso; | 82 | IsoGfx* iso = state->iso; |
| 75 | 83 | ||
| 76 | isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); | 84 | isogfx_make_world( |
| 77 | 85 | iso, &(WorldDesc){.tile_width = TILE_WIDTH, | |
| 78 | if (!isogfx_make_world( | 86 | .tile_height = TILE_HEIGHT, |
| 79 | iso, &(WorldDesc){.tile_width = TILE_WIDTH, | 87 | .world_width = WORLD_WIDTH, |
| 80 | .tile_height = TILE_HEIGHT, | 88 | .world_height = WORLD_HEIGHT, |
| 81 | .world_width = WORLD_WIDTH, | 89 | .num_tiles = NUM_TILES}); |
| 82 | .world_height = WORLD_HEIGHT})) { | ||
| 83 | return false; | ||
| 84 | } | ||
| 85 | 90 | ||
| 86 | const Tile black = isogfx_make_tile(iso, &tile_set[Black]); | 91 | const Tile black = isogfx_make_tile(iso, &tile_set[Black]); |
| 87 | const Tile white = isogfx_make_tile(iso, &tile_set[White]); | 92 | const Tile white = isogfx_make_tile(iso, &tile_set[White]); |
| 88 | state->red = isogfx_make_tile(iso, &tile_set[Red]); | 93 | state->red = isogfx_make_tile(iso, &tile_set[Red]); |
| 89 | make_checkerboard(iso, black, white); | 94 | make_checkerboard(iso, black, white); |
| 90 | 95 | ||
| 91 | if (!(state->backend = iso_backend_init(iso))) { | 96 | if (!((state->backend = iso_backend_init(iso)))) { |
| 92 | return false; | 97 | return false; |
| 93 | } | 98 | } |
| 94 | 99 | ||
