summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libs/din/din.c20
-rw-r--r--src/libs/din/din.h2
-rw-r--r--src/modules/meta2d/meta2d.c4
-rw-r--r--src/modules/swab/swab.c2
4 files changed, 15 insertions, 13 deletions
diff --git a/src/libs/din/din.c b/src/libs/din/din.c
index c0bac93..4290d41 100644
--- a/src/libs/din/din.c
+++ b/src/libs/din/din.c
@@ -8,16 +8,17 @@
#include "v3f.h"
typedef struct din_t {
- int width, height, depth;
- int W_x_H;
- v3f_t grid[];
+ int width, height, depth;
+ unsigned seed;
+ int W_x_H;
+ v3f_t grid[];
} din_t;
/* return random number between -1 and +1 */
-static inline float randf(void)
+static inline float randf(unsigned *seed)
{
- return 2.f / RAND_MAX * rand() - 1.f;
+ return 2.f / RAND_MAX * rand_r(seed) - 1.f;
}
@@ -30,9 +31,9 @@ void din_randomize(din_t *din)
for (x = 0; x < din->width; x++) {
v3f_t r;
- r.x = randf();
- r.y = randf();
- r.z = randf();
+ r.x = randf(&din->seed);
+ r.y = randf(&din->seed);
+ r.z = randf(&din->seed);
din->grid[z * din->W_x_H + y * din->width + x] = v3f_normalize(&r);
}
@@ -41,7 +42,7 @@ void din_randomize(din_t *din)
}
-din_t * din_new(int width, int height, int depth)
+din_t * din_new(int width, int height, int depth, unsigned seed)
{
din_t *din;
@@ -56,6 +57,7 @@ din_t * din_new(int width, int height, int depth)
din->width = width;
din->height = height;
din->depth = depth;
+ din->seed = seed;
/* premultiply this since we do it a lot in addressing din->grid[] */
din->W_x_H = width * height;
diff --git a/src/libs/din/din.h b/src/libs/din/din.h
index baa3ebb..97823b6 100644
--- a/src/libs/din/din.h
+++ b/src/libs/din/din.h
@@ -4,7 +4,7 @@
typedef struct din_t din_t;
typedef struct v3f_t v3f_t;
-din_t * din_new(int width, int height, int depth);
+din_t * din_new(int width, int height, int depth, unsigned seed);
void din_free(din_t *din);
void din_randomize(din_t *din);
float din(din_t *din, v3f_t *coordinate);
diff --git a/src/modules/meta2d/meta2d.c b/src/modules/meta2d/meta2d.c
index 1ab444c..1bb8827 100644
--- a/src/modules/meta2d/meta2d.c
+++ b/src/modules/meta2d/meta2d.c
@@ -76,8 +76,8 @@ static til_module_context_t * meta2d_create_context(unsigned seed, unsigned tick
return NULL;
/* perlin noise is used for some organic-ish random movement of the balls */
- ctxt->din_a = din_new(10, 10, META2D_NUM_BALLS + 2);
- ctxt->din_b = din_new(10, 10, META2D_NUM_BALLS + 2);
+ ctxt->din_a = din_new(10, 10, META2D_NUM_BALLS + 2, seed);
+ ctxt->din_b = din_new(10, 10, META2D_NUM_BALLS + 2, seed);
for (int i = 0; i < META2D_NUM_BALLS; i++) {
meta2d_ball_t *ball = &ctxt->balls[i];
diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c
index 5424bf6..9047f68 100644
--- a/src/modules/swab/swab.c
+++ b/src/modules/swab/swab.c
@@ -74,7 +74,7 @@ static til_module_context_t * swab_create_context(unsigned seed, unsigned ticks,
if (!ctxt)
return NULL;
- ctxt->din = din_new(12, 12, 100);
+ ctxt->din = din_new(12, 12, 100, seed);
if (!ctxt->din) {
free(ctxt);
return NULL;
© All Rights Reserved