Effector calculations are now thread safe.

* where_is_object_time was called for every effector evaluation only to determine the object velocity in some rare cases.
* Calculating the effector velocity is now done in the effector precalculation stage.
* Removing this makes the code thread safe and also should give some nice performance boosts when simulating a lot of points.
* Thanks to MiikaH for noticing this problem.
This commit is contained in:
Janne Karhu
2011-07-24 17:44:22 +00:00
parent 4ab7c6ae1a
commit a22de3f73c
2 changed files with 13 additions and 11 deletions

View File

@@ -105,6 +105,7 @@ typedef struct EffectorCache {
/* precalculated for guides */
struct GuideEffectorData *guide_data;
float guide_loc[4], guide_dir[3], guide_radius;
float velocity[3];
float frame;
int flag;

View File

@@ -241,6 +241,16 @@ static void precalculate_effector(EffectorCache *eff)
}
else if(eff->psys)
psys_update_particle_tree(eff->psys, eff->scene->r.cfra);
/* Store object velocity */
if(eff->ob) {
float old_vel[3];
where_is_object_time(eff->scene, eff->ob, cfra - 1.0f);
copy_v3_v3(old_vel, eff->ob->obmat[3]);
where_is_object_time(eff->scene, eff->ob, cfra);
sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel);
}
}
static EffectorCache *new_effector_cache(Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd)
{
@@ -680,10 +690,6 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
Object *ob = eff->ob;
Object obcopy = *ob;
/* XXX this is not thread-safe, but used from multiple threads by
particle system */
where_is_object_time(eff->scene, ob, cfra);
/* use z-axis as normal*/
normalize_v3_v3(efd->nor, ob->obmat[2]);
@@ -702,13 +708,8 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
VECCOPY(efd->loc, ob->obmat[3]);
}
if(real_velocity) {
VECCOPY(efd->vel, ob->obmat[3]);
where_is_object_time(eff->scene, ob, cfra - 1.0f);
sub_v3_v3v3(efd->vel, efd->vel, ob->obmat[3]);
}
if(real_velocity)
copy_v3_v3(efd->vel, eff->velocity);
*eff->ob = obcopy;