From 76e135b835b09fcba29b4bd4044f6e26da8d6e31 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 15 Apr 2015 21:58:54 +0200 Subject: [PATCH] Improve behaviour of get_deactivation_enabled/is_deactivation_enabled --- panda/src/bullet/bulletBodyNode.cxx | 21 +++++++++++++-------- panda/src/bullet/bulletBodyNode.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/panda/src/bullet/bulletBodyNode.cxx b/panda/src/bullet/bulletBodyNode.cxx index ef1a68df96..8a82b92577 100644 --- a/panda/src/bullet/bulletBodyNode.cxx +++ b/panda/src/bullet/bulletBodyNode.cxx @@ -155,6 +155,8 @@ output(ostream &out) const { out << " (" << get_num_shapes() << " shapes)"; + out << (is_active() ? " active" : " inactive"); + if (is_static()) out << " static"; if (is_kinematic()) out << " kinematic"; } @@ -448,19 +450,22 @@ set_active(bool active, bool force) { //////////////////////////////////////////////////////////////////// // Function: BulletBodyNode::set_deactivation_enabled // Access: Published -// Description: +// Description: If true, this object will be deactivated after a +// certain amount of time has passed without movement. +// If false, the object will always remain active. //////////////////////////////////////////////////////////////////// void BulletBodyNode:: -set_deactivation_enabled(const bool enabled, const bool force) { +set_deactivation_enabled(bool enabled) { - int state = (enabled) ? WANTS_DEACTIVATION : DISABLE_DEACTIVATION; + // Don't change the state if it's currently active and we enable + // deactivation. + if (enabled != is_deactivation_enabled()) { - if (force) { + // It's OK to set to ACTIVE_TAG even if we don't mean to activate it; it + // will be disabled right away if the deactivation timer has run out. + int state = (enabled) ? ACTIVE_TAG : DISABLE_DEACTIVATION; get_object()->forceActivationState(state); } - else { - get_object()->setActivationState(state); - } } //////////////////////////////////////////////////////////////////// @@ -471,7 +476,7 @@ set_deactivation_enabled(const bool enabled, const bool force) { bool BulletBodyNode:: is_deactivation_enabled() const { - return (get_object()->getActivationState() & DISABLE_DEACTIVATION) == 0; + return (get_object()->getActivationState() != DISABLE_DEACTIVATION); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/bullet/bulletBodyNode.h b/panda/src/bullet/bulletBodyNode.h index 59c1ecb32c..eda0fb30f0 100644 --- a/panda/src/bullet/bulletBodyNode.h +++ b/panda/src/bullet/bulletBodyNode.h @@ -82,7 +82,7 @@ PUBLISHED: void set_deactivation_time(PN_stdfloat dt); PN_stdfloat get_deactivation_time() const; - void set_deactivation_enabled(const bool enabled, const bool force=false); + void set_deactivation_enabled(bool enabled); bool is_deactivation_enabled() const; // Debug Visualistion