Parallelise rendering

This commit is contained in:
Camden Dixie O'Brien
2025-09-23 15:35:26 +01:00
parent d07ccec5ba
commit 259f0922b3
4 changed files with 93 additions and 39 deletions

View File

@@ -1,23 +1,31 @@
#include "rng.h"
#include <limits.h>
#include <stdlib.h>
#include <sys/time.h>
void rng_init()
static uint32_t next(rng_t *rng)
{
uint32_t x = rng->state;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return rng->state = x;
}
rng_t rng_init(unsigned seed)
{
struct timeval tv;
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
gettimeofday(&tv, nullptr);
return (rng_t) { .state = tv.tv_usec + seed };
}
double rng_double()
double rng_double(rng_t *rng)
{
return 2.0 * (double)rand() / (double)INT_MAX - 1.0;
return 2.0 * (double)next(rng) / (double)UINT32_MAX - 1.0;
}
vec3_t rng_vec3()
vec3_t rng_vec3(rng_t *rng)
{
const vec3_t v = { rng_double(), rng_double(), rng_double() };
const vec3_t v = { rng_double(rng), rng_double(rng), rng_double(rng) };
return vec3_unit(v);
}