Cleanup: get rid of global RNG usage in transform code.

This commit is contained in:
Bastien Montagne 2018-06-12 17:00:07 +02:00
parent 8826a00482
commit a9cfd8c910
2 changed files with 16 additions and 1 deletions

View File

@ -65,6 +65,7 @@ struct wmEvent;
struct wmTimer;
struct ARegion;
struct ReportList;
struct RNG;
struct EditBone;
struct RenderEngineType;
struct SnapObjectContext;
@ -536,6 +537,9 @@ typedef struct TransInfo {
void *draw_handle_pixel;
void *draw_handle_cursor;
/** Currently only used for random curve of proportional editing. */
struct RNG *rng;
/** Typically for mode settings. */
TransCustomDataContainer custom;
} TransInfo;

View File

@ -58,6 +58,8 @@
#include "BLI_rand.h"
#include "BLI_utildefines.h"
#include "PIL_time.h"
#include "BLT_translation.h"
#include "RNA_access.h"
@ -1695,6 +1697,10 @@ void postTrans(bContext *C, TransInfo *t)
MEM_freeN(t->mouse.data);
}
if (t->rng != NULL) {
BLI_rng_free(t->rng);
}
freeSnapping(t);
}
@ -2163,7 +2169,12 @@ void calculatePropRatio(TransInfo *t)
td->factor = sqrtf(2 * dist - dist * dist);
break;
case PROP_RANDOM:
td->factor = BLI_frand() * dist;
if (t->rng == NULL) {
/* Lazy initialization. */
uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
t->rng = BLI_rng_new(rng_seed);
}
td->factor = BLI_rng_get_float(t->rng) * dist;
break;
case PROP_INVSQUARE:
td->factor = dist * (2.0f - dist);