From 6072322312308fe13e51ce4c394eeb79434f38f2 Mon Sep 17 00:00:00 2001 From: Sergej Reich Date: Fri, 15 Feb 2013 23:48:36 +0000 Subject: rigidbody: Avoid unnecessary simulation updates Now we flag the world for update on frame change and only call BKE_rigidbody_do_simulation() when needed. --- source/blender/blenkernel/intern/rigidbody.c | 2 ++ source/blender/blenkernel/intern/scene.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 055ada33867..9ae82422ca2 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1223,6 +1223,8 @@ 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; + /* flag cache as outdated if we don't have a world or number of objects in the simulation has changed */ if (rbw->physics_world == NULL || rbw->numbodies != BLI_countlist(&rbw->group->gobject)) { cache->flag |= PTCACHE_OUTDATED; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 13e050f12b7..269751e79d4 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1089,6 +1089,15 @@ 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_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent) { Base *base; @@ -1106,8 +1115,7 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen */ // 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 - // FIXME: this now gets executed on every update, not just frame change now!!! - if (BKE_scene_check_rigidbody_active(scene)) { + 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 */ @@ -1230,6 +1238,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); + /* BKE_object_handle_update() on all objects, groups and sets */ scene_update_tagged_recursive(bmain, sce, sce); -- cgit v1.2.3