From bdc1499f1af004422eaaa1a1e9e5ee5b306f9606 Mon Sep 17 00:00:00 2001 From: alistair Date: Mon, 10 May 2021 15:46:29 +1000 Subject: [PATCH] environment --- src/environment.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/environment.c b/src/environment.c index b88370f..a2632c0 100644 --- a/src/environment.c +++ b/src/environment.c @@ -2,6 +2,8 @@ #include "game.h" #include "types.h" + + double linear_interpolate(double a0, double a1, double w) { return (1.0f - w) * a0 + w * a1; } @@ -109,6 +111,16 @@ int comp(const void *one, const void *two) { } struct environment get_scene_at(Vect coordinate, int seed) { + // TODO: Environment needs to be shared between threads + // - this implementation duplicates it: each thread that calls + // get_scene_at gets manages its state in its own static vairables in + // this function but share pointers to the malloced environment object- + // it is thoroughly broken. + // - Fix by having a heap allocated environment object that the draw thread + // (T0) can watch and the physics thread (T3) can modify + // - the entry point can either be through a function returning + // a pointer or just a global const pointer + // // basic cache for the last room generated static bool init; static Vect last_room; @@ -120,6 +132,8 @@ struct environment get_scene_at(Vect coordinate, int seed) { if (init && room_coord.x == last_room.x && oldseed == seed) { return e; + } else if (init) { + destroy_environment(&e); } last_room = room_coord; oldseed = seed;