1
1
Fork 0
Browse Source

fix level change race/crash

master
alistair 3 years ago
parent
commit
4c6872b5fc
  1. 26
      src/draw.c
  2. 9
      src/environment.c
  3. 2
      src/environment.h
  4. 2
      src/game.c
  5. 1
      src/main.c

26
src/draw.c

@ -81,7 +81,7 @@ void draw_player(SDL_Renderer * ren, int x, int y, bool red) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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;*/

9
src/environment.c

@ -2,7 +2,11 @@ @@ -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) { @@ -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;

2
src/environment.h

@ -7,4 +7,6 @@ @@ -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

2
src/game.c

@ -763,7 +763,7 @@ void load_level() { @@ -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();

1
src/main.c

@ -175,5 +175,6 @@ int main (int argc, char** argv) { @@ -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
*/

Loading…
Cancel
Save