From a5dd9657774d0725b5f6c8e025a3bda5b824ddf6 Mon Sep 17 00:00:00 2001 From: alistair Date: Sun, 9 May 2021 23:05:34 +1000 Subject: [PATCH] fix score loading crash --- src/draw.c | 2 +- src/game.c | 6 +++++- src/game.h | 7 ++++++- src/logger.c | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/draw.c b/src/draw.c index cc3326a..417e9b7 100644 --- a/src/draw.c +++ b/src/draw.c @@ -598,7 +598,7 @@ int draw_end_screen(SDL_Renderer *ren) { int margin = height / 10; // Vect position = {.x = width - width / 10, .y = height - margin}; - long fastest = get_best_time(); + long fastest = draw_watch.best_time; int minutes = level_time / 60000; float seconds = level_time * 0.001; diff --git a/src/game.c b/src/game.c index ebdfbd6..5646649 100644 --- a/src/game.c +++ b/src/game.c @@ -10,7 +10,7 @@ #define FLOOR_THICKNESS 200 #define MAX_ROPE_GRAB_LEN 80000 -#define MIN_PHYSICS_STEP 2.0 +#define MIN_PHYSICS_STEP 6.0 #define TIMESTEP_LENGTH 5.0 @@ -57,6 +57,9 @@ void get_new_physics(Body **phys); void ratcheted_winch_motor_update(Motor* motor); void winch_motor_update (struct motorstruct *motor); +/* object that draw.c watches */ +struct draw_watcher draw_watch; + // move the collision poly to the position of the player void default_update_collision_poly(Body *body) { for (int i=0; i < body->collision_poly_size; i++) { @@ -723,6 +726,7 @@ void next_level() { level += 1;; get_floor_ceiling(); + draw_watch.best_time = get_best_time(); load_score_times("saves/times"); v = world.uniques_index[ROOM_W]->room->ceil.items[2]->collision_poly[0]; diff --git a/src/game.h b/src/game.h index 791ad2e..613a81e 100644 --- a/src/game.h +++ b/src/game.h @@ -15,6 +15,12 @@ extern int level; extern bool in_game; extern int quality; +struct draw_watcher { + long best_time; +}; + +extern struct draw_watcher draw_watch; + void handle_input_event(SDL_Event event); // add a motor to the world @@ -38,7 +44,6 @@ struct sg_times_list { }; int load_score_times(char *filename); -long get_best_time(void); /* array of all the things in the world and their kinds */ diff --git a/src/logger.c b/src/logger.c index 19fceb3..6bfd67e 100644 --- a/src/logger.c +++ b/src/logger.c @@ -32,7 +32,7 @@ void logwrite(loggerlevel level, char message[]) { // delete the \n time_str[24] = ' '; - char prepend[15]; + char prepend[150]; copy_str(prepend, time_str);