rigidbody: Revert to running simulation on frame update

Instead of flagging the rigid body world for frame update just call
BKE_rigidbody_do_simulation() recursively for all scenes.

This avoids having to constantly check if the simulation needs to be
updated.
This commit is contained in:
Sergej Reich 2013-03-03 06:09:48 +00:00
parent 5ff6a5c6ab
commit ceaf8e48ef
3 changed files with 13 additions and 32 deletions

View File

@ -1262,8 +1262,6 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
BKE_ptcache_id_time(&pid, scene, ctime, &startframe, &endframe, NULL);
cache = rbw->pointcache;
rbw->flag &= ~RBW_FLAG_FRAME_UPDATE;
if (ctime <= startframe) {
rbw->ltime = startframe;
return;

View File

@ -1081,15 +1081,6 @@ static void scene_depsgraph_hack(Scene *scene, Scene *scene_parent)
}
static void scene_flag_rbw_recursive(Scene *scene)
{
if (scene->set)
scene_flag_rbw_recursive(scene->set);
if (BKE_scene_check_rigidbody_active(scene))
scene->rigidbody_world->flag |= RBW_FLAG_FRAME_UPDATE;
}
static void scene_rebuild_rbw_recursive(Scene *scene, float ctime)
{
if (scene->set)
@ -1099,6 +1090,15 @@ static void scene_rebuild_rbw_recursive(Scene *scene, float ctime)
BKE_rigidbody_rebuild_world(scene, ctime);
}
static void scene_do_rb_simulation_recursive(Scene *scene, float ctime)
{
if (scene->set)
scene_do_rb_simulation_recursive(scene->set, ctime);
if (BKE_scene_check_rigidbody_active(scene))
BKE_rigidbody_do_simulation(scene, ctime);
}
static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent)
{
Base *base;
@ -1110,22 +1110,6 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen
if (scene->set)
scene_update_tagged_recursive(bmain, scene->set, scene_parent);
/* run rigidbody sim
* - calculate/read values from cache into RBO's, to get flushed
* later when objects are evaluated (if they're tagged for eval)
*/
// XXX: this position may still change, objects not being updated correctly before simulation is run
// NOTE: current position is so that rigidbody sim affects other objects
if (BKE_scene_check_rigidbody_active(scene) && scene->rigidbody_world->flag & RBW_FLAG_FRAME_UPDATE) {
/* we use frame time of parent (this is "scene" itself for top-level of sets recursion),
* as that is the active scene controlling all timing in file at the moment
*/
float ctime = BKE_scene_frame_get(scene_parent);
/* however, "scene" contains the rigidbody world needed for eval... */
BKE_rigidbody_do_simulation(scene, ctime);
}
/* scene objects */
for (base = scene->base.first; base; base = base->next) {
Object *ob = base->object;
@ -1249,8 +1233,9 @@ void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
tag_main_idcode(bmain, ID_MA, FALSE);
tag_main_idcode(bmain, ID_LA, FALSE);
/* flag rigid body worlds for update */
scene_flag_rbw_recursive(sce);
/* run rigidbody sim */
/* NOTE: current position is so that rigidbody sim affects other objects, might change in the future */
scene_do_rb_simulation_recursive(sce, ctime);
/* BKE_object_handle_update() on all objects, groups and sets */
scene_update_tagged_recursive(bmain, sce, sce);

View File

@ -80,9 +80,7 @@ typedef enum eRigidBodyWorld_Flag {
/* sim data needs to be rebuilt */
RBW_FLAG_NEEDS_REBUILD = (1 << 1),
/* usse split impulse when stepping the simulation */
RBW_FLAG_USE_SPLIT_IMPULSE = (1 << 2),
/* need to step simulation after frame update */
RBW_FLAG_FRAME_UPDATE = (1 << 3)
RBW_FLAG_USE_SPLIT_IMPULSE = (1 << 2)
} eRigidBodyWorld_Flag;
/* ******************************** */