From 0a648cea10d6d52c42899bd79b4ddc611c0ef815 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Tue, 5 Jul 2022 16:02:37 +0200 Subject: [PATCH] Fix bug on game's structure declaration --- src/core.c | 3 ++- src/main.c | 27 +++++++++++++++++++-------- src/save.c | 6 +++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/core.c b/src/core.c index 19b05ff..f4f3c53 100644 --- a/src/core.c +++ b/src/core.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "core.h" @@ -20,7 +21,7 @@ int callback_tick(volatile int *tick) void default_values(struct calccity *calccity, struct camera *camera, struct map *map) { - srand(20211104); + srand(clock()); // Initialisation of struct calccity memset(calccity, 0, sizeof *calccity); diff --git a/src/main.c b/src/main.c index efc85ea..da19c40 100644 --- a/src/main.c +++ b/src/main.c @@ -8,20 +8,31 @@ int main(void) { extern font_t font_calccity; dfont(&font_calccity); - title_screen(); // Game initialisation - struct calccity calccity; - struct camera camera; - struct map map; - gint_world_switch(GINT_CALL(read_save, (void *)&calccity, (void *)&camera, (void *)&map)); + struct calccity *calccity; + calccity = (struct calccity*) malloc(sizeof *calccity); - // Game - main_loop(&calccity, &camera, &map); + struct camera *camera; + camera = (struct camera*) malloc(sizeof *camera); + + struct map *map; + map = (struct map*) malloc(sizeof *map); + + // Loading save + gint_world_switch(GINT_CALL(read_save, (void *)calccity, (void *)camera, (void *)map)); + + // Launch the game + main_loop(calccity, camera, map); // Backup data - gint_world_switch(GINT_CALL(write_save, (void *)&calccity, (void *)&camera, (void *)&map)); + gint_world_switch(GINT_CALL(write_save, (void *)calccity, (void *)camera, (void *)map)); + + // Free memory + free(calccity); + free(camera); + free(map); return 1; } \ No newline at end of file diff --git a/src/save.c b/src/save.c index 246b485..c616708 100644 --- a/src/save.c +++ b/src/save.c @@ -9,7 +9,7 @@ uint16_t const *filename_u16 = u"\\\\fls0\\CalcCity.sav"; void read_save(struct calccity *calccity, struct camera *camera, struct map *map) { - if(gint[HWCALC] == HWCALC_G35PE2) + if (gint[HWCALC] == HWCALC_G35PE2) { FILE *fp; fp = fopen(filename_u8, "rb"); @@ -29,7 +29,7 @@ void read_save(struct calccity *calccity, struct camera *camera, struct map *map else { int fd = BFile_Open(filename_u16, BFile_ReadOnly); - if(fd < 0) + if (fd < 0) default_values(calccity, camera, map); else { @@ -44,7 +44,7 @@ void read_save(struct calccity *calccity, struct camera *camera, struct map *map void write_save(const struct calccity *calccity, const struct camera *camera, const struct map *map) { - if(gint[HWCALC] == HWCALC_G35PE2) + if (gint[HWCALC] == HWCALC_G35PE2) { FILE *fp; fp = fopen(filename_u8, "wb");