From 9da1a400fabccaa0dd3063eac39c181e1499bb4b Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 19 May 2013 04:21:43 +0000 Subject: svn merge ^/trunk/blender -c56907 -c56908 --- source/blender/blenkernel/BKE_particle.h | 2 - source/blender/blenkernel/intern/anim.c | 23 ++++------- source/blender/blenkernel/intern/effect.c | 1 - source/blender/blenkernel/intern/particle.c | 13 ++---- source/blender/blenkernel/intern/particle_system.c | 47 +++++++++------------- source/blender/blenkernel/intern/smoke.c | 3 -- 6 files changed, 30 insertions(+), 59 deletions(-) diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 846fe68c2b3..2b753cba098 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -61,7 +61,6 @@ struct SurfaceModifierData; struct BVHTreeRay; struct BVHTreeRayHit; struct EdgeHash; -struct RNG; #define PARTICLE_P ParticleData * pa; int p #define LOOP_PARTICLES for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++) @@ -83,7 +82,6 @@ typedef struct ParticleSimulationData { struct ParticleSystem *psys; struct ParticleSystemModifierData *psmd; struct ListBase *colliders; - struct RNG *rng; /* Courant number. This is used to implement an adaptive time step. Only the * maximum value per time step is important. Only sph_integrate makes use of * this at the moment. Other solvers could, too. */ diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 3494f68984c..f81d6a17ced 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -1263,7 +1263,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p ChildParticle *cpa = NULL; ParticleKey state; ParticleCacheKey *cache; - RNG *rng = NULL; float ctime, pa_time, scale = 1.0f; float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size = 0.0; float (*obmat)[4], (*oldobmat)[4]; @@ -1294,9 +1293,14 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p totpart = psys->totpart; totchild = psys->totchild; + BLI_srandom(31415926 + psys->seed); + if ((psys->renderdata || part->draw_as == PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { ParticleSimulationData sim = {NULL}; - + sim.scene = scene; + sim.ob = par; + sim.psys = psys; + sim.psmd = psys_get_modifier(par, psys); /* make sure emitter imat is in global coordinates instead of render view coordinates */ invert_m4_m4(par->imat, par->obmat); @@ -1328,12 +1332,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p psys_check_group_weights(part); - sim.scene = scene; - sim.ob = par; - sim.psys = psys; - sim.psmd = psys_get_modifier(par, psys); - sim.rng = BLI_rng_new(0); - psys->lattice = psys_get_lattice(&sim); /* gather list of objects or single object */ @@ -1380,8 +1378,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p obcopy = *ob; } - rng = BLI_rng_new_srandom(31415926 + psys->seed); - if (totchild == 0 || part->draw & PART_DRAW_PARENT) a = 0; else @@ -1421,7 +1417,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* for groups, pick the object based on settings */ if (part->draw & PART_DRAW_RAND_GR) - b = BLI_rng_get_int(rng) % totgroup; + b = BLI_rand() % totgroup; else b = a % totgroup; @@ -1565,8 +1561,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p } else *ob = obcopy; - - BLI_rng_free(sim.rng); } /* clean up */ @@ -1579,9 +1573,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p end_latt_deform(psys->lattice); psys->lattice = NULL; } - - if (rng) - BLI_rng_free(rng); } static Object *find_family_object(Object **obar, char *family, char ch) diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index e2f04e68bf3..db1012456ef 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -619,7 +619,6 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin sim.scene= eff->scene; sim.ob= eff->ob; sim.psys= eff->psys; - sim.rng= NULL; /* TODO: time from actual previous calculated frame (step might not be 1) */ state.time = cfra - 1.0f; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index b0ef6715382..4e78ab52499 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -264,12 +264,11 @@ static void psys_create_frand(ParticleSystem *psys) { int i; float *rand = psys->frand = MEM_callocN(PSYS_FRAND_COUNT * sizeof(float), "particle randoms"); - RNG *rng = BLI_rng_new_srandom(psys->seed); - for (i = 0; i < 1024; i++, rand++) - *rand = BLI_rng_get_float(rng); + BLI_srandom(psys->seed); - BLI_rng_free(rng); + for (i = 0; i < 1024; i++, rand++) + *rand = BLI_frand(); } int psys_check_enabled(Object *ob, ParticleSystem *psys) { @@ -3303,11 +3302,8 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf sim.ob = ob; sim.psys = psys; sim.psmd = psys_get_modifier(ob, psys); - sim.rng = BLI_rng_new(0); psys_cache_child_paths(&sim, cfra, 1); - - BLI_rng_free(sim.rng); } /* clear recalc flag if set here */ @@ -4664,7 +4660,6 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) sim.ob = ob; sim.psys = psys; sim.psmd = psys_get_modifier(ob, psys); - sim.rng = BLI_rng_new(0); psys->lattice = psys_get_lattice(&sim); @@ -4692,6 +4687,4 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) /* protect the applied shape */ psys->flag |= PSYS_EDITED; } - - BLI_rng_free(sim.rng); } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 74a50389cd5..1067abf4479 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -423,7 +423,7 @@ void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys) } } -static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *finaldm, ParticleSystem *psys, RNG *rng) +static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *finaldm, ParticleSystem *psys) { ChildParticle *cpa = NULL; int i, p; @@ -440,9 +440,9 @@ static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *fi /* create even spherical distribution inside unit sphere */ while (length>=1.0f) { - cpa->fuv[0]=2.0f*BLI_rng_get_float(rng)-1.0f; - cpa->fuv[1]=2.0f*BLI_rng_get_float(rng)-1.0f; - cpa->fuv[2]=2.0f*BLI_rng_get_float(rng)-1.0f; + cpa->fuv[0]=2.0f*BLI_frand()-1.0f; + cpa->fuv[1]=2.0f*BLI_frand()-1.0f; + cpa->fuv[2]=2.0f*BLI_frand()-1.0f; length=len_v3(cpa->fuv); } @@ -872,7 +872,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch pa->foffset *= ctx->jit[p % (2 * ctx->jitlevel)]; break; case PART_DISTR_RAND: - pa->foffset *= BLI_rng_get_float(ctx->sim.rng); + pa->foffset *= BLI_frand(); break; } } @@ -1065,15 +1065,15 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D if (from == PART_FROM_CHILD) { /* Simple children */ if (part->childtype != PART_CHILD_FACES) { - BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed + psys->child_seed); - distribute_simple_children(scene, ob, finaldm, psys, ctx->sim.rng); + BLI_srandom(31415926 + psys->seed + psys->child_seed); + distribute_simple_children(scene, ob, finaldm, psys); return 0; } } else { /* Grid distribution */ if (part->distr==PART_DISTR_GRID && from != PART_FROM_VERT) { - BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed); + BLI_srandom(31415926 + psys->seed); dm= CDDM_from_mesh((Mesh*)ob->data, ob); DM_ensure_tessface(dm); distribute_grid(dm,psys); @@ -1085,7 +1085,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D /* Create trees and original coordinates if needed */ if (from == PART_FROM_CHILD) { distr=PART_DISTR_RAND; - BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed + psys->child_seed); + BLI_srandom(31415926 + psys->seed + psys->child_seed); dm= finaldm; /* BMESH ONLY */ @@ -1108,7 +1108,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } else { distr = part->distr; - BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed); + BLI_srandom(31415926 + psys->seed); dm= CDDM_from_mesh((Mesh*)ob->data, ob); @@ -1264,7 +1264,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D for (p=0; psim.rng) * element_sum[totelem]; + pos= BLI_frand() * element_sum[totelem]; particle_element[p] = distribute_binary_search(element_sum, totelem, pos); particle_element[p] = MIN2(totelem-1, particle_element[p]); jitter_offset[particle_element[p]] = pos; @@ -2916,9 +2916,9 @@ static void basic_force_cb(void *efdata_v, ParticleKey *state, float *force, flo /* brownian force */ if (part->brownfac != 0.0f) { - force[0] += (BLI_rng_get_float(sim->rng)-0.5f) * part->brownfac; - force[1] += (BLI_rng_get_float(sim->rng)-0.5f) * part->brownfac; - force[2] += (BLI_rng_get_float(sim->rng)-0.5f) * part->brownfac; + force[0] += (BLI_frand()-0.5f) * part->brownfac; + force[1] += (BLI_frand()-0.5f) * part->brownfac; + force[2] += (BLI_frand()-0.5f) * part->brownfac; } if (part->flag & PART_ROT_DYN && epoint.ave) @@ -3497,7 +3497,7 @@ static int collision_detect(ParticleData *pa, ParticleCollision *col, BVHTreeRay return hit->index >= 0; } -static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, int kill, int dynamic_rotation, RNG *rng) +static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, int kill, int dynamic_rotation) { ParticleCollisionElement *pce = &col->pce; PartDeflect *pd = col->hit->pd; @@ -3506,7 +3506,7 @@ static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeR float f = col->f + x * (1.0f - col->f); /* time factor of collision between timestep */ float dt1 = (f - col->f) * col->total_time; /* time since previous collision (in seconds) */ float dt2 = (1.0f - f) * col->total_time; /* time left after collision (in seconds) */ - int through = (BLI_rng_get_float(rng) < pd->pdef_perm) ? 1 : 0; /* did particle pass through the collision surface? */ + int through = (BLI_frand() < pd->pdef_perm) ? 1 : 0; /* did particle pass through the collision surface? */ /* calculate exact collision location */ interp_v3_v3v3(co, col->co1, col->co2, x); @@ -3531,8 +3531,8 @@ static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeR float v0_tan[3];/* tangential component of v0 */ float vc_tan[3];/* tangential component of collision surface velocity */ float v0_dot, vc_dot; - float damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_rng_get_float(rng) - 0.5f); - float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_rng_get_float(rng) - 0.5f); + float damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_frand() - 0.5f); + float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_frand() - 0.5f); float distance, nor[3], dot; CLAMP(damp,0.0f, 1.0f); @@ -3740,7 +3740,7 @@ static void collision_check(ParticleSimulationData *sim, int p, float dfra, floa if (collision_count == COLLISION_MAX_COLLISIONS) collision_fail(pa, &col); - else if (collision_response(pa, &col, &hit, part->flag & PART_DIE_ON_COL, part->flag & PART_ROT_DYN, sim->rng)==0) + else if (collision_response(pa, &col, &hit, part->flag & PART_DIE_ON_COL, part->flag & PART_ROT_DYN)==0) return; } else @@ -4100,7 +4100,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) { ParticleSystem *psys = sim->psys; ParticleSettings *part=psys->part; - RNG *rng; BoidBrainData bbd; ParticleTexture ptex; PARTICLE_P; @@ -4127,7 +4126,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) return; } - rng = BLI_rng_new_srandom(31415926 + (int)cfra + psys->seed); + BLI_srandom(31415926 + (int)cfra + psys->seed); psys_update_effectors(sim); @@ -4144,7 +4143,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) bbd.cfra = cfra; bbd.dfra = dfra; bbd.timestep = timestep; - bbd.rng = rng; psys_update_particle_tree(psys, cfra); @@ -4328,7 +4326,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) } free_collider_cache(&sim->colliders); - BLI_rng_free(rng); } static void update_children(ParticleSimulationData *sim) { @@ -4825,8 +4822,6 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) if (!sim.psmd->dm) return; - sim.rng = BLI_rng_new(0); - if (part->from != PART_FROM_VERT) { DM_ensure_tessface(sim.psmd->dm); } @@ -4967,7 +4962,5 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) /* save matrix for duplicators, at rendertime the actual dupliobject's matrix is used so don't update! */ if (psys->renderdata==0) invert_m4_m4(psys->imat, ob->obmat); - - BLI_rng_free(sim.rng); } diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index b61cd63f503..f0c1542fd40 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -985,7 +985,6 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke sim.scene = scene; sim.ob = flow_ob; sim.psys = psys; - sim.rng = BLI_rng_new(psys->seed); if (psys->part->type == PART_HAIR) { @@ -1072,8 +1071,6 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke MEM_freeN(particle_pos); if (particle_vel) MEM_freeN(particle_vel); - - BLI_rng_free(sim.rng); } } -- cgit v1.2.3