[Bf-blender-cvs] [2af7c38682d] blender2.8: Cleanup: get rid of global RNG usage in paint stroke code.

Bastien Montagne noreply at git.blender.org
Tue Jun 12 17:14:03 CEST 2018


Commit: 2af7c38682d6d4fd87bd175dd90e40f15591ec5c
Author: Bastien Montagne
Date:   Tue Jun 12 17:13:23 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB2af7c38682d6d4fd87bd175dd90e40f15591ec5c

Cleanup: get rid of global RNG usage in paint stroke code.

===================================================================

M	source/blender/editors/sculpt_paint/paint_stroke.c

===================================================================

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);



More information about the Bf-blender-cvs mailing list