RandomGenerator: cleanup;

This commit is contained in:
bjorn 2019-07-11 11:24:34 -07:00
parent 1f8a7e073f
commit 8c76e6f19b
3 changed files with 13 additions and 11 deletions

View File

@ -5,9 +5,9 @@
#include "core/util.h"
#include <math.h>
typedef struct Curve {
struct Curve {
arr_t(float, 16) points;
} Curve;
};
// Explicit curve evaluation, unroll simple cases to avoid pow overhead
static void evaluate(float* P, size_t n, float t, vec3 p) {

View File

@ -1,10 +1,17 @@
#include "math/randomGenerator.h"
#include "core/ref.h"
#include "util.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
struct RandomGenerator {
Seed seed;
Seed state;
double lastRandomNormal;
};
// Thomas Wang's 64-bit integer hashing function:
// https://web.archive.org/web/20110807030012/http://www.cris.com/%7ETtwang/tech/inthash.htm
static uint64_t wangHash64(uint64_t key) {
@ -22,7 +29,8 @@ static uint64_t wangHash64(uint64_t key) {
// George Marsaglia, "Xorshift RNGs", Journal of Statistical Software, Vol.8 (Issue 14), 2003
// Use an 'Xorshift*' variant, as shown here: http://xorshift.di.unimi.it
RandomGenerator* lovrRandomGeneratorInit(RandomGenerator* generator) {
RandomGenerator* lovrRandomGeneratorCreate(void) {
RandomGenerator* generator = lovrAlloc(RandomGenerator);
Seed seed = { .b32 = { .lo = 0xCBBF7A44, .hi = 0x0139408D } };
lovrRandomGeneratorSetSeed(generator, seed);
generator->lastRandomNormal = HUGE_VAL;

View File

@ -13,14 +13,8 @@ typedef union {
} b32;
} Seed;
typedef struct {
Seed seed;
Seed state;
double lastRandomNormal;
} RandomGenerator;
RandomGenerator* lovrRandomGeneratorInit(RandomGenerator* generator);
#define lovrRandomGeneratorCreate() lovrRandomGeneratorInit(lovrAlloc(RandomGenerator))
typedef struct RandomGenerator RandomGenerator;
RandomGenerator* lovrRandomGeneratorCreate(void);
void lovrRandomGeneratorDestroy(void* ref);
Seed lovrRandomGeneratorGetSeed(RandomGenerator* generator);
void lovrRandomGeneratorSetSeed(RandomGenerator* generator, Seed seed);