From: Holger Schemel Date: Sun, 25 Feb 2024 01:56:33 +0000 (+0100) Subject: replaced glib function calls to g_byte_array*() X-Git-Tag: 4.4.0.0-test-1~282 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=90378d2b4a1f6f48f542d68576b3fedac70ea8a4;p=rocksndiamonds.git replaced glib function calls to g_byte_array*() --- diff --git a/src/game_bd/bd_cave.c b/src/game_bd/bd_cave.c index 7d5aca5d..87d51af2 100644 --- a/src/game_bd/bd_cave.c +++ b/src/game_bd/bd_cave.c @@ -1378,8 +1378,7 @@ GdReplay *gd_replay_new(void) GdReplay *rep; rep = checked_calloc(sizeof(GdReplay)); - - rep->movements = g_byte_array_new(); + rep->movements = checked_calloc(sizeof(GdReplayMovements)); return rep; } @@ -1392,15 +1391,14 @@ GdReplay *gd_replay_new_from_replay(GdReplay *orig) /* replicate dynamic data */ rep->comment = getStringCopy(orig->comment); - rep->movements = g_byte_array_new(); - g_byte_array_append(rep->movements, orig->movements->data, orig->movements->len); + rep->movements = get_memcpy(orig->movements, sizeof(GdReplayMovements)); return rep; } void gd_replay_free(GdReplay *replay) { - g_byte_array_free(replay->movements, TRUE); + checked_free(replay->movements); checked_free(replay->comment); free(replay); } @@ -1415,7 +1413,13 @@ void gd_replay_store_movement(GdReplay *replay, GdDirection player_move, (player_fire ? GD_REPLAY_FIRE_MASK : 0) | (suicide ? GD_REPLAY_SUICIDE_MASK : 0)); - g_byte_array_append(replay->movements, data, 1); + if (replay->movements->len < MAX_REPLAY_LEN) + { + replay->movements->data[replay->movements->len++] = data[0]; + + if (replay->movements->len == MAX_REPLAY_LEN) + Warn("BD replay truncated: size exceeds maximum replay size %d", MAX_REPLAY_LEN); + } } /* calculate adler checksum for a rendered cave; this can be used for more caves. */ diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index cc0f3ebe..038c61fd 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -152,6 +152,9 @@ void gd_struct_set_defaults_from_array(gpointer str, const GdStructDescriptor *p for example diamond + arrow = falling diamond */ #define GD_NUM_OF_CELLS (GD_NUM_OF_CELLS_X*GD_NUM_OF_CELLS_Y+80) +/* maximum replay size (maximum seconds x game cycles per second) */ +#define MAX_REPLAY_LEN (10000 * FRAMES_PER_SECOND / 8) + extern const GdColor gd_flash_color; extern const GdColor gd_select_color; @@ -313,6 +316,12 @@ typedef struct _highscore int score; } GdHighScore; +typedef struct _replay_movements +{ + unsigned char data[MAX_REPLAY_LEN]; + unsigned int len; +} GdReplayMovements; + /* maximum seed value for the cave random generator. should be smaller than a signed int. */ #define GD_CAVE_SEED_MAX (1 << 30) @@ -333,7 +342,7 @@ typedef struct _gd_cave_replay guint32 checksum; /* checksum of the rendered cave. */ boolean wrong_checksum; - GByteArray *movements; + GdReplayMovements *movements; int current_playing_pos; } GdReplay;