1
1
Fork 0
Browse Source

environment

master
alistair 3 years ago
parent
commit
bdc1499f1a
  1. 14
      src/environment.c

14
src/environment.c

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

Loading…
Cancel
Save