Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSergej Reich <sergej.reich@googlemail.com>2013-02-16 03:48:36 +0400
committerSergej Reich <sergej.reich@googlemail.com>2013-02-16 03:48:36 +0400
commit6072322312308fe13e51ce4c394eeb79434f38f2 (patch)
treeeda21c3b287908b7b42980c09c07d2c3471b02c7 /source
parent207dca55f46e8c9e6948adf0d45f834dced9a274 (diff)
rigidbody: Avoid unnecessary simulation updates
Now we flag the world for update on frame change and only call BKE_rigidbody_do_simulation() when needed.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c2
-rw-r--r--source/blender/blenkernel/intern/scene.c15
-rw-r--r--source/blender/makesdna/DNA_rigidbody_types.h4
3 files changed, 18 insertions, 3 deletions
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);
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index ca703130edc..1636f2f4e4b 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -80,7 +80,9 @@ 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)
+ RBW_FLAG_USE_SPLIT_IMPULSE = (1 << 2),
+ /* need to step simulation after frame update */
+ RBW_FLAG_FRAME_UPDATE = (1 << 3)
} eRigidBodyWorld_Flag;
/* ******************************** */