diff --git a/src/draw.c b/src/draw.c index 5b4f37f..1a8fcbf 100644 --- a/src/draw.c +++ b/src/draw.c @@ -81,7 +81,7 @@ void draw_player(SDL_Renderer * ren, int x, int y, bool red) { player_rect.w = 20; player_rect.h = 20; - struct colour c = get_scene_at(viewport_pos, level).colours.bg; + struct colour c = get_scene_watch()->colours.bg; SDL_SetRenderDrawColor(ren, c.r, c.g, c.b, 255); @@ -448,7 +448,7 @@ double interpolate_h(Vect left, Vect right, double x) { return x * m + c; } -void draw_environment(SDL_Renderer * ren, struct environment *scene) { +void draw_environment(SDL_Renderer * ren, const struct environment *scene) { struct colour c1 = scene->colours.bg; struct colour c2 = scene->colours.fg1; struct colour c3 = scene->colours.fg2; @@ -577,19 +577,19 @@ void draw_level_chooser_tbox(SDL_Renderer *ren) { char string[250]; snprintf(string, 250,"GOTO LEVEL: %s", gameui.currently_bound_textbox->text_input); - struct environment scene = get_scene_at(viewport_pos, level); + const struct environment *scene = get_scene_watch(); Vect pos = {.x= width - (width / 4), .y = height - (height / 10)}; - draw_text(ren, pos, scene.colours.fg1, string); + draw_text(ren, pos, scene->colours.fg1, string); } int draw_end_screen(SDL_Renderer *ren) { - struct environment scene = get_scene_at(viewport_pos, level); + const struct environment *scene = get_scene_watch(); - struct colour bg = scene.colours.bg; - struct colour colour = scene.colours.fg1; - struct colour_pallete pal = scene.colours; + struct colour bg = scene->colours.bg; + struct colour colour = scene->colours.fg1; + struct colour_pallete pal = scene->colours; SDL_SetRenderDrawColor(ren, bg.r, bg.g, bg.b,255); @@ -684,7 +684,7 @@ int draw_end_screen(SDL_Renderer *ren) { } -void draw_level_time(SDL_Renderer *ren, struct environment * e) { +void draw_level_time(SDL_Renderer *ren, const struct environment * e) { int margin = height / 10; @@ -794,9 +794,9 @@ void redraw_buffer(SDL_Renderer * ren) { //SDL_GetMouseState(&newmousex, &newmousey); - struct environment scene = get_scene_at(viewport_pos, level); - draw_environment(ren, &scene); - draw_level_time(ren, &scene); + const struct environment* scene = get_scene_watch(); + draw_environment(ren, scene); + draw_level_time(ren, scene); SDL_UnlockMutex(player.physics->lock); for (int i=0; i < world.items.size; i++) { @@ -846,7 +846,7 @@ void redraw_buffer(SDL_Renderer * ren) { SDL_SetRenderDrawColor(ren, 0, 0, 0, 90); SDL_RenderFillRect(ren, &r); if (in_game) - draw_pause_screen(ren, &scene); + draw_pause_screen(ren, scene); } /*if (newmousex != mousex || newmousey != mousey) {*/ /*mousey = newmousey;*/ diff --git a/src/environment.c b/src/environment.c index a2632c0..c496f56 100644 --- a/src/environment.c +++ b/src/environment.c @@ -2,7 +2,11 @@ #include "game.h" #include "types.h" +struct environment * environment_watch = NULL; +const struct environment* get_scene_watch(void) { + return environment_watch; +} double linear_interpolate(double a0, double a1, double w) { return (1.0f - w) * a0 + w * a1; @@ -227,7 +231,12 @@ struct environment get_scene_at(Vect coordinate, int seed) { // join the end and start together + if (!init) { + struct environment *ee = malloc(sizeof(struct environment)); + environment_watch = ee; + } + *environment_watch = e; init = true; diff --git a/src/environment.h b/src/environment.h index 5737fe0..aefe92b 100644 --- a/src/environment.h +++ b/src/environment.h @@ -7,4 +7,6 @@ struct environment get_scene_at(Vect coordinate, int seed); int destroy_environment(struct environment *e); +const struct environment *get_scene_watch(void); + #endif diff --git a/src/game.c b/src/game.c index b4d8031..e6f1b9b 100644 --- a/src/game.c +++ b/src/game.c @@ -763,7 +763,7 @@ void load_level() { destroy_physics_collection(&world.uniques_index[ROOM_W]->room->ceil); destroy_physics_collection(&world.uniques_index[ROOM_W]->room->floor); - destroy_environment(&world.uniques_index[ROOM_W]->room->env); + //destroy_environment(&world.uniques_index[ROOM_W]->room->env); get_floor_ceiling(); draw_watch.best_time = get_best_time(); diff --git a/src/main.c b/src/main.c index de2306f..77fe9c9 100644 --- a/src/main.c +++ b/src/main.c @@ -175,5 +175,6 @@ int main (int argc, char** argv) { * - fix that weird jitter * - make the end of level look sane * - restart level + * - make sure goto level doesn't log an end-0f-level time */