diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/effect.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 36 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_rand.h | 23 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rand.c | 70 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_parametrizer.c | 6 | ||||
-rw-r--r-- | source/blender/render/intern/source/convertblender.c | 6 |
7 files changed, 75 insertions, 78 deletions
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 88490dbb960..1f6db19ac27 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -166,7 +166,7 @@ void free_partdeflect(PartDeflect *pd) pd->tex->id.us--; if (pd->rng) - rng_free(pd->rng); + BLI_rng_free(pd->rng); MEM_freeN(pd); } @@ -175,9 +175,9 @@ static void precalculate_effector(EffectorCache *eff) { unsigned int cfra = (unsigned int)(eff->scene->r.cfra >= 0 ? eff->scene->r.cfra : -eff->scene->r.cfra); if (!eff->pd->rng) - eff->pd->rng = rng_new(eff->pd->seed + cfra); + eff->pd->rng = BLI_rng_new(eff->pd->seed + cfra); else - rng_srandom(eff->pd->rng, eff->pd->seed + cfra); + BLI_rng_srandom(eff->pd->rng, eff->pd->seed + cfra); if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type==OB_CURVE) { Curve *cu= eff->ob->data; @@ -455,8 +455,8 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect // noise function for wind e.g. static float wind_func(struct RNG *rng, float strength) { - int random = (rng_getInt(rng)+1) % 128; // max 2357 - float force = rng_getFloat(rng) + 1.0f; + int random = (BLI_rng_get_int(rng)+1) % 128; // max 2357 + float force = BLI_rng_get_float(rng) + 1.0f; float ret; float sign = 0; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 8bf11723fd5..50927d705e2 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -2464,7 +2464,7 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c totthread = 1; for (i = 0; i < totthread; i++) { - threads[i].rng_path = rng_new(seed); + threads[i].rng_path = BLI_rng_new(seed); threads[i].tot = totthread; } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index d3f416b34ae..3354ea7ddce 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -632,10 +632,10 @@ static void hammersley_create(float *out, int n, int seed, float amount) double p, t, offs[2]; int k, kk; - rng = rng_new(31415926 + n + seed); - offs[0] = rng_getDouble(rng) + (double)amount; - offs[1] = rng_getDouble(rng) + (double)amount; - rng_free(rng); + rng = BLI_rng_new(31415926 + n + seed); + offs[0] = BLI_rng_get_double(rng) + (double)amount; + offs[1] = BLI_rng_get_double(rng) + (double)amount; + BLI_rng_free(rng); for (k = 0; k < n; k++) { t = 0; @@ -661,13 +661,13 @@ static void init_mv_jit(float *jit, int num, int seed2, float amount) rad2= (float)(1.0f/((float)num)); rad3= (float)sqrt((float)num)/((float)num); - rng = rng_new(31415926 + num + seed2); + rng = BLI_rng_new(31415926 + num + seed2); x= 0; num2 = 2 * num; for (i=0; i<num2; i+=2) { - jit[i] = x + amount*rad1*(0.5f - rng_getFloat(rng)); - jit[i+1] = i/(2.0f*num) + amount*rad1*(0.5f - rng_getFloat(rng)); + jit[i] = x + amount*rad1*(0.5f - BLI_rng_get_float(rng)); + jit[i+1] = i/(2.0f*num) + amount*rad1*(0.5f - BLI_rng_get_float(rng)); jit[i]-= (float)floor(jit[i]); jit[i+1]-= (float)floor(jit[i+1]); @@ -684,7 +684,7 @@ static void init_mv_jit(float *jit, int num, int seed2, float amount) BLI_jitterate2(jit, jit2, num, rad2); } MEM_freeN(jit2); - rng_free(rng); + BLI_rng_free(rng); } static void psys_uv_to_w(float u, float v, int quad, float *w) @@ -804,8 +804,8 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch } break; case PART_DISTR_RAND: - randu= rng_getFloat(thread->rng); - randv= rng_getFloat(thread->rng); + randu= BLI_rng_get_float(thread->rng); + randv= BLI_rng_get_float(thread->rng); rng_skip_tot -= 2; psys_uv_to_w(randu, randv, mface->v4, pa->fuv); @@ -881,8 +881,8 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch mf= dm->getTessFaceData(dm, ctx->index[p], CD_MFACE); - randu= rng_getFloat(thread->rng); - randv= rng_getFloat(thread->rng); + randu= BLI_rng_get_float(thread->rng); + randv= BLI_rng_get_float(thread->rng); rng_skip_tot -= 2; psys_uv_to_w(randu, randv, mf->v4, cpa->fuv); @@ -934,7 +934,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch } if (rng_skip_tot > 0) /* should never be below zero */ - rng_skip(thread->rng, rng_skip_tot); + BLI_rng_skip(thread->rng, rng_skip_tot); } static void *distribute_threads_exec_cb(void *data) @@ -951,12 +951,12 @@ static void *distribute_threads_exec_cb(void *data) for (p=0; p<totpart; p++, cpa++) { if (thread->ctx->skip) /* simplification skip */ - rng_skip(thread->rng, PSYS_RND_DIST_SKIP * thread->ctx->skip[p]); + BLI_rng_skip(thread->rng, PSYS_RND_DIST_SKIP * thread->ctx->skip[p]); if ((p+thread->num) % thread->tot == 0) distribute_threads_exec(thread, NULL, cpa, p); else /* thread skip */ - rng_skip(thread->rng, PSYS_RND_DIST_SKIP); + BLI_rng_skip(thread->rng, PSYS_RND_DIST_SKIP); } } else { @@ -1353,7 +1353,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D seed= 31415926 + ctx->sim.psys->seed; for (i=0; i<totthread; i++) { - threads[i].rng= rng_new(seed); + threads[i].rng= BLI_rng_new(seed); threads[i].tot= totthread; } @@ -1492,9 +1492,9 @@ void psys_threads_free(ParticleThread *threads) /* threads */ for (i=0; i<totthread; i++) { if (threads[i].rng) - rng_free(threads[i].rng); + BLI_rng_free(threads[i].rng); if (threads[i].rng_path) - rng_free(threads[i].rng_path); + BLI_rng_free(threads[i].rng_path); } MEM_freeN(ctx); diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h index 7dd6c8575c9..3bc9a3bdb32 100644 --- a/source/blender/blenlib/BLI_rand.h +++ b/source/blender/blenlib/BLI_rand.h @@ -40,18 +40,18 @@ struct RNG; typedef struct RNG RNG; -struct RNG *rng_new(unsigned int seed); -void rng_free(struct RNG *rng); +struct RNG *BLI_rng_new(unsigned int seed); +void BLI_rng_free(struct RNG *rng); -void rng_seed(struct RNG *rng, unsigned int seed); -void rng_srandom(struct RNG *rng, unsigned int seed); -int rng_getInt(struct RNG *rng); -double rng_getDouble(struct RNG *rng); -float rng_getFloat(struct RNG *rng); -void rng_shuffleArray(struct RNG *rng, void *data, int elemSize, int numElems); +void BLI_rng_seed(struct RNG *rng, unsigned int seed); +void BLI_rng_srandom(struct RNG *rng, unsigned int seed); +int BLI_rng_get_int(struct RNG *rng); +double BLI_rng_get_double(struct RNG *rng); +float BLI_rng_get_float(struct RNG *rng); +void BLI_rng_shuffle_array(struct RNG *rng, void *data, int elemSize, int numElems); /** Note that skipping is as slow as generating n numbers! */ -void rng_skip(struct RNG *rng, int n); +void BLI_rng_skip(struct RNG *rng, int n); /** Seed the random number generator */ void BLI_srand(unsigned int seed); @@ -94,7 +94,4 @@ int BLI_thread_rand(int thread); /** Allows up to BLENDER_MAX_THREADS threads to address */ float BLI_thread_frand(int thread); - - -#endif - +#endif /* __BLI_RAND_H__ */ diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 3c22d73d113..76d17f34b5e 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -64,51 +64,51 @@ struct RNG { r_uint64 X; }; -RNG *rng_new(unsigned int seed) +RNG *BLI_rng_new(unsigned int seed) { RNG *rng = MEM_mallocN(sizeof(*rng), "rng"); - rng_seed(rng, seed); + BLI_rng_seed(rng, seed); return rng; } -void rng_free(RNG *rng) +void BLI_rng_free(RNG *rng) { MEM_freeN(rng); } -void rng_seed(RNG *rng, unsigned int seed) +void BLI_rng_seed(RNG *rng, unsigned int seed) { rng->X = (((r_uint64) seed) << 16) | LOWSEED; } -void rng_srandom(RNG *rng, unsigned int seed) +void BLI_rng_srandom(RNG *rng, unsigned int seed) { - rng_seed(rng, seed + hash[seed & 255]); - seed = rng_getInt(rng); - rng_seed(rng, seed + hash[seed & 255]); - seed = rng_getInt(rng); - rng_seed(rng, seed + hash[seed & 255]); + BLI_rng_seed(rng, seed + hash[seed & 255]); + seed = BLI_rng_get_int(rng); + BLI_rng_seed(rng, seed + hash[seed & 255]); + seed = BLI_rng_get_int(rng); + BLI_rng_seed(rng, seed + hash[seed & 255]); } -int rng_getInt(RNG *rng) +int BLI_rng_get_int(RNG *rng) { rng->X = (MULTIPLIER * rng->X + ADDEND) & MASK; return (int) (rng->X >> 17); } -double rng_getDouble(RNG *rng) +double BLI_rng_get_double(RNG *rng) { - return (double) rng_getInt(rng) / 0x80000000; + return (double) BLI_rng_get_int(rng) / 0x80000000; } -float rng_getFloat(RNG *rng) +float BLI_rng_get_float(RNG *rng) { - return (float) rng_getInt(rng) / 0x80000000; + return (float) BLI_rng_get_int(rng) / 0x80000000; } -void rng_shuffleArray(RNG *rng, void *data, int elemSize, int numElems) +void BLI_rng_shuffle_array(RNG *rng, void *data, int elemSize, int numElems) { int i = numElems; void *temp; @@ -122,7 +122,7 @@ void rng_shuffleArray(RNG *rng, void *data, int elemSize, int numElems) /* XXX Shouldn't it rather be "while (i--) {" ? * Else we have no guaranty first (0) element has a chance to be shuffled... --mont29 */ while (--i) { - int j = rng_getInt(rng) % numElems; + int j = BLI_rng_get_int(rng) % numElems; if (i != j) { void *iElem = (unsigned char *)data + i * elemSize; void *jElem = (unsigned char *)data + j * elemSize; @@ -135,12 +135,12 @@ void rng_shuffleArray(RNG *rng, void *data, int elemSize, int numElems) free(temp); } -void rng_skip(RNG *rng, int n) +void BLI_rng_skip(RNG *rng, int n) { int i; for (i = 0; i < n; i++) - rng_getInt(rng); + BLI_rng_get_int(rng); } /***/ @@ -150,28 +150,28 @@ static RNG theBLI_rng = {0}; /* note, this one creates periodical patterns */ void BLI_srand(unsigned int seed) { - rng_seed(&theBLI_rng, seed); + BLI_rng_seed(&theBLI_rng, seed); } /* using hash table to create better seed */ void BLI_srandom(unsigned int seed) { - rng_srandom(&theBLI_rng, seed); + BLI_rng_srandom(&theBLI_rng, seed); } int BLI_rand(void) { - return rng_getInt(&theBLI_rng); + return BLI_rng_get_int(&theBLI_rng); } double BLI_drand(void) { - return rng_getDouble(&theBLI_rng); + return BLI_rng_get_double(&theBLI_rng); } float BLI_frand(void) { - return rng_getFloat(&theBLI_rng); + return BLI_rng_get_float(&theBLI_rng); } void BLI_fillrand(void *addr, int len) @@ -179,16 +179,16 @@ void BLI_fillrand(void *addr, int len) RNG rng; unsigned char *p = addr; - rng_seed(&rng, (unsigned int) (PIL_check_seconds_timer() * 0x7FFFFFFF)); - while (len--) *p++ = rng_getInt(&rng) & 0xFF; + BLI_rng_seed(&rng, (unsigned int) (PIL_check_seconds_timer() * 0x7FFFFFFF)); + while (len--) *p++ = BLI_rng_get_int(&rng) & 0xFF; } void BLI_array_randomize(void *data, int elemSize, int numElems, unsigned int seed) { RNG rng; - rng_seed(&rng, seed); - rng_shuffleArray(&rng, data, elemSize, numElems); + BLI_rng_seed(&rng, seed); + BLI_rng_shuffle_array(&rng, data, elemSize, numElems); } /* ********* for threaded random ************** */ @@ -200,20 +200,20 @@ void BLI_thread_srandom(int thread, unsigned int seed) if (thread >= BLENDER_MAX_THREADS) thread = 0; - rng_seed(&rng_tab[thread], seed + hash[seed & 255]); - seed = rng_getInt(&rng_tab[thread]); - rng_seed(&rng_tab[thread], seed + hash[seed & 255]); - seed = rng_getInt(&rng_tab[thread]); - rng_seed(&rng_tab[thread], seed + hash[seed & 255]); + BLI_rng_seed(&rng_tab[thread], seed + hash[seed & 255]); + seed = BLI_rng_get_int(&rng_tab[thread]); + BLI_rng_seed(&rng_tab[thread], seed + hash[seed & 255]); + seed = BLI_rng_get_int(&rng_tab[thread]); + BLI_rng_seed(&rng_tab[thread], seed + hash[seed & 255]); } int BLI_thread_rand(int thread) { - return rng_getInt(&rng_tab[thread]); + return BLI_rng_get_int(&rng_tab[thread]); } float BLI_thread_frand(int thread) { - return rng_getFloat(&rng_tab[thread]); + return BLI_rng_get_float(&rng_tab[thread]); } diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 83817e758af..8d34108011a 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -3306,7 +3306,7 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) trusted_radius /= 2 * nedges; - random_angle = rng_getFloat(rng) * 2.0f * (float)M_PI; + random_angle = BLI_rng_get_float(rng) * 2.0f * (float)M_PI; dir[0] = trusted_radius * cosf(random_angle); dir[1] = trusted_radius * sinf(random_angle); @@ -4285,7 +4285,7 @@ void param_stretch_begin(ParamHandle *handle) param_assert(phandle->state == PHANDLE_STATE_CONSTRUCTED); phandle->state = PHANDLE_STATE_STRETCH; - phandle->rng = rng_new(31415926); + phandle->rng = BLI_rng_new(31415926); phandle->blend = 0.0f; for (i = 0; i < phandle->ncharts; i++) { @@ -4332,7 +4332,7 @@ void param_stretch_end(ParamHandle *handle) param_assert(phandle->state == PHANDLE_STATE_STRETCH); phandle->state = PHANDLE_STATE_CONSTRUCTED; - rng_free(phandle->rng); + BLI_rng_free(phandle->rng); phandle->rng = NULL; } diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index f1e8d532cda..6034fd5c52f 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -1613,7 +1613,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem psys->flag |= PSYS_DRAWING; - rng= rng_new(psys->seed); + rng= BLI_rng_new(psys->seed); totpart=psys->totpart; @@ -1763,7 +1763,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem /* 3. start creating renderable things */ for (a=0, pa=pars; a<totpart+totchild; a++, pa++, seed++) { - random = rng_getFloat(rng); + random = BLI_rng_get_float(rng); /* setup per particle individual stuff */ if (a<totpart) { if (pa->flag & PARS_UNEXIST) continue; @@ -2099,7 +2099,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem if (states) MEM_freeN(states); - rng_free(rng); + BLI_rng_free(rng); psys->flag &= ~PSYS_DRAWING; |