Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-06-12 18:13:23 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-06-12 18:13:47 +0300
commit2af7c38682d6d4fd87bd175dd90e40f15591ec5c (patch)
treea06f790e6c2ef7c192a4e718b9ff247b872fe6d7 /source/blender/editors/sculpt_paint
parent376bc88dc027a8dfc5bd2f92253b17738b825c39 (diff)
Cleanup: get rid of global RNG usage in paint stroke code.
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index b63f9461401..2e16ddb628f 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -38,6 +38,8 @@
#include "BLI_rand.h"
#include "BLI_listbase.h"
+#include "PIL_time.h"
+
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_brush_types.h"
@@ -86,6 +88,7 @@ typedef struct PaintStroke {
void *mode_data;
void *stroke_cursor;
wmTimer *timer;
+ struct RNG *rng;
/* Cached values */
ViewContext vc;
@@ -403,17 +406,24 @@ static bool paint_brush_update(bContext *C,
}
}
+ if ((do_random || do_random_mask) && stroke->rng == NULL) {
+ /* Lazy initialization. */
+ uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
+ rng_seed ^= (uint)(brush);
+ stroke->rng = BLI_rng_new(rng_seed);
+ }
+
if (do_random) {
if (brush->mtex.brush_angle_mode & MTEX_ANGLE_RANDOM) {
ups->brush_rotation += -brush->mtex.random_angle / 2.0f +
- brush->mtex.random_angle * BLI_frand();
+ brush->mtex.random_angle * BLI_rng_get_float(stroke->rng);
}
}
if (do_random_mask) {
if (brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RANDOM) {
ups->brush_rotation_sec += -brush->mask_mtex.random_angle / 2.0f +
- brush->mask_mtex.random_angle * BLI_frand();
+ brush->mask_mtex.random_angle * BLI_rng_get_float(stroke->rng);
}
}
@@ -785,6 +795,10 @@ static void stroke_done(struct bContext *C, struct wmOperator *op)
stroke->timer);
}
+ if (stroke->rng) {
+ BLI_rng_free(stroke->rng);
+ }
+
if (stroke->stroke_cursor)
WM_paint_cursor_end(CTX_wm_manager(C), stroke->stroke_cursor);