mirror of https://github.com/bjornbytes/lovr.git
RandomGenerator: cleanup;
This commit is contained in:
parent
1f8a7e073f
commit
8c76e6f19b
|
@ -5,9 +5,9 @@
|
||||||
#include "core/util.h"
|
#include "core/util.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
typedef struct Curve {
|
struct Curve {
|
||||||
arr_t(float, 16) points;
|
arr_t(float, 16) points;
|
||||||
} Curve;
|
};
|
||||||
|
|
||||||
// Explicit curve evaluation, unroll simple cases to avoid pow overhead
|
// Explicit curve evaluation, unroll simple cases to avoid pow overhead
|
||||||
static void evaluate(float* P, size_t n, float t, vec3 p) {
|
static void evaluate(float* P, size_t n, float t, vec3 p) {
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
#include "math/randomGenerator.h"
|
#include "math/randomGenerator.h"
|
||||||
|
#include "core/ref.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
struct RandomGenerator {
|
||||||
|
Seed seed;
|
||||||
|
Seed state;
|
||||||
|
double lastRandomNormal;
|
||||||
|
};
|
||||||
|
|
||||||
// Thomas Wang's 64-bit integer hashing function:
|
// Thomas Wang's 64-bit integer hashing function:
|
||||||
// https://web.archive.org/web/20110807030012/http://www.cris.com/%7ETtwang/tech/inthash.htm
|
// https://web.archive.org/web/20110807030012/http://www.cris.com/%7ETtwang/tech/inthash.htm
|
||||||
static uint64_t wangHash64(uint64_t key) {
|
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
|
// 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
|
// 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 } };
|
Seed seed = { .b32 = { .lo = 0xCBBF7A44, .hi = 0x0139408D } };
|
||||||
lovrRandomGeneratorSetSeed(generator, seed);
|
lovrRandomGeneratorSetSeed(generator, seed);
|
||||||
generator->lastRandomNormal = HUGE_VAL;
|
generator->lastRandomNormal = HUGE_VAL;
|
||||||
|
|
|
@ -13,14 +13,8 @@ typedef union {
|
||||||
} b32;
|
} b32;
|
||||||
} Seed;
|
} Seed;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct RandomGenerator RandomGenerator;
|
||||||
Seed seed;
|
RandomGenerator* lovrRandomGeneratorCreate(void);
|
||||||
Seed state;
|
|
||||||
double lastRandomNormal;
|
|
||||||
} RandomGenerator;
|
|
||||||
|
|
||||||
RandomGenerator* lovrRandomGeneratorInit(RandomGenerator* generator);
|
|
||||||
#define lovrRandomGeneratorCreate() lovrRandomGeneratorInit(lovrAlloc(RandomGenerator))
|
|
||||||
void lovrRandomGeneratorDestroy(void* ref);
|
void lovrRandomGeneratorDestroy(void* ref);
|
||||||
Seed lovrRandomGeneratorGetSeed(RandomGenerator* generator);
|
Seed lovrRandomGeneratorGetSeed(RandomGenerator* generator);
|
||||||
void lovrRandomGeneratorSetSeed(RandomGenerator* generator, Seed seed);
|
void lovrRandomGeneratorSetSeed(RandomGenerator* generator, Seed seed);
|
||||||
|
|
Loading…
Reference in New Issue