[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51538] trunk/blender/source/blender: code cleanup: give rng functions BLI prefix.

Campbell Barton ideasman42 at gmail.com
Tue Oct 23 15:50:45 CEST 2012


Revision: 51538
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51538
Author:   campbellbarton
Date:     2012-10-23 13:50:44 +0000 (Tue, 23 Oct 2012)
Log Message:
-----------
code cleanup: give rng functions BLI prefix.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/effect.c
    trunk/blender/source/blender/blenkernel/intern/particle.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/blenlib/BLI_rand.h
    trunk/blender/source/blender/blenlib/intern/rand.c
    trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c
    trunk/blender/source/blender/render/intern/source/convertblender.c

Modified: trunk/blender/source/blender/blenkernel/intern/effect.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/effect.c	2012-10-23 13:29:56 UTC (rev 51537)
+++ trunk/blender/source/blender/blenkernel/intern/effect.c	2012-10-23 13:50:44 UTC (rev 51538)
@@ -166,7 +166,7 @@
 		pd->tex->id.us--;
 
 	if (pd->rng)
-		rng_free(pd->rng);
+		BLI_rng_free(pd->rng);
 
 	MEM_freeN(pd);
 }
@@ -175,9 +175,9 @@
 {
 	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 @@
 // 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;
 	

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c	2012-10-23 13:29:56 UTC (rev 51537)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c	2012-10-23 13:50:44 UTC (rev 51538)
@@ -2464,7 +2464,7 @@
 		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;
 	}
 

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c	2012-10-23 13:29:56 UTC (rev 51537)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2012-10-23 13:50:44 UTC (rev 51538)
@@ -632,10 +632,10 @@
 	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 @@
 	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 @@
 		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 @@
 			}
 			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 @@
 
 		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 @@
 	}
 
 	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 @@
 
 		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 @@
 	
 	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 @@
 	/* 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);

Modified: trunk/blender/source/blender/blenlib/BLI_rand.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_rand.h	2012-10-23 13:29:56 UTC (rev 51537)
+++ trunk/blender/source/blender/blenlib/BLI_rand.h	2012-10-23 13:50:44 UTC (rev 51538)
@@ -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 @@
 /** Allows up to BLENDER_MAX_THREADS threads to address */
 float   BLI_thread_frand(int thread);
 
-
-
-#endif
-
+#endif  /* __BLI_RAND_H__ */

Modified: trunk/blender/source/blender/blenlib/intern/rand.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/rand.c	2012-10-23 13:29:56 UTC (rev 51537)
+++ trunk/blender/source/blender/blenlib/intern/rand.c	2012-10-23 13:50:44 UTC (rev 51538)
@@ -64,51 +64,51 @@
 	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 @@
 	/* 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 @@
 	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 @@
 /* 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 @@
 	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);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list