Parallelise rendering
This commit is contained in:
24
src/rng.c
24
src/rng.c
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user