From 17a7502003b373f5fb95038e055f2a7cf2de1b81 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 16 Apr 2025 14:28:08 +0200 Subject: [PATCH] don't store the rows on the heap; it works just fine on the stack --- src/game/game.c | 14 ++------------ src/game/game.h | 3 ++- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/game/game.c b/src/game/game.c index a410fd2..f1ddcf0 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -9,9 +9,7 @@ #include #include -#include "../error.h" #include "../window/audio.h" -#include "../window/colour/colour8.h" #include "./tetromino/shapes.h" #include "gametime.h" #include "tetromino/placing.h" @@ -54,6 +52,7 @@ void game_init(gamedata* const dat) { audiodevice* ad = audio_device_init(32000, AUDIO_S16, 1, 4096); *dat = (gamedata){ + {0}, // rowdat {0}, // row gt, // time ad, // audio_device @@ -72,10 +71,7 @@ void game_init(gamedata* const dat) { // initialize the rows within the game data for (int8_t i = 0; i < ROWS; i++) { - dat->rows[i] = calloc(COLUMNS, sizeof(colour8)); - - if (dat->rows[i] == NULL) - fatal(ERROR_STD_MEMORY_INIT, __FILE_NAME__, __LINE__, "something went wrong when allocating memory for row %i", i); + dat->rows[i] = dat->rowdat + (i * COLUMNS); } // set the shape data in each slot to it's corrsponding ID @@ -142,12 +138,6 @@ void game_free(gamedata* const dat) { audio_wav_unload(&dat->place_sfx); audio_device_free(dat->audio_device); - // clear each row - for (int8_t i = 0; i < ROWS; i++) { - free(dat->rows[i]); - dat->rows[i] = NULL; - } - // zero-out the rest of the data *dat = (gamedata){0}; } diff --git a/src/game/game.h b/src/game/game.h index 8697058..2979659 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -23,7 +23,8 @@ typedef colour8 const* const row_const; typedef colour8* row; typedef struct { - row rows[ROWS]; + colour8 rowdat[ROWS * COLUMNS]; + colour8* rows[ROWS]; struct gametime time; audiodevice* audio_device; audiodata music;