Jelajahi Sumber

Eliminated unnecessary recreation/readdition of physics components when attributes change.
Increased the default smoothing snap threshold.

Lasse Öörni 13 tahun lalu
induk
melakukan
9123d1c3d3

+ 1 - 1
Bin/Data/Scenes/NinjaSnowWar.xml

@@ -5,7 +5,7 @@
 	<attribute name="Rotation" value="1 0 0 0" />
 	<attribute name="Rotation" value="1 0 0 0" />
 	<attribute name="Scale" value="1 1 1" />
 	<attribute name="Scale" value="1 1 1" />
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Smoothing Constant" value="50" />
-	<attribute name="Snap Threshold" value="100" />
+	<attribute name="Snap Threshold" value="500" />
 	<attribute name="Next Replicated Node ID" value="2" />
 	<attribute name="Next Replicated Node ID" value="2" />
 	<attribute name="Next Replicated Component ID" value="1" />
 	<attribute name="Next Replicated Component ID" value="1" />
 	<attribute name="Next Local Node ID" value="16777220" />
 	<attribute name="Next Local Node ID" value="16777220" />

+ 5 - 4
Engine/Physics/CollisionShape.cpp

@@ -227,8 +227,8 @@ void CollisionShape::RegisterObject(Context* context)
     
     
     ENUM_ATTRIBUTE(CollisionShape, "Shape Type", shapeType_, typeNames, SHAPE_BOX, AM_DEFAULT);
     ENUM_ATTRIBUTE(CollisionShape, "Shape Type", shapeType_, typeNames, SHAPE_BOX, AM_DEFAULT);
     ATTRIBUTE(CollisionShape, VAR_VECTOR3, "Size", size_, Vector3::ONE, AM_DEFAULT);
     ATTRIBUTE(CollisionShape, VAR_VECTOR3, "Size", size_, Vector3::ONE, AM_DEFAULT);
-    ATTRIBUTE(CollisionShape, VAR_VECTOR3, "Offset Position", position_, Vector3::ZERO, AM_DEFAULT);
-    ATTRIBUTE(CollisionShape, VAR_QUATERNION, "Offset Rotation", rotation_, Quaternion::IDENTITY, AM_DEFAULT);
+    REF_ACCESSOR_ATTRIBUTE(CollisionShape, VAR_VECTOR3, "Offset Position", GetPosition, SetPosition, Vector3, Vector3::ZERO, AM_DEFAULT);
+    REF_ACCESSOR_ATTRIBUTE(CollisionShape, VAR_QUATERNION, "Offset Rotation", GetRotation, SetRotation, Quaternion, Quaternion::IDENTITY, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(CollisionShape, VAR_RESOURCEREF, "Model", GetModelAttr, SetModelAttr, ResourceRef, ResourceRef(Model::GetTypeStatic()), AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(CollisionShape, VAR_RESOURCEREF, "Model", GetModelAttr, SetModelAttr, ResourceRef, ResourceRef(Model::GetTypeStatic()), AM_DEFAULT);
     ATTRIBUTE(CollisionShape, VAR_INT, "LOD Level", lodLevel_, 0, AM_DEFAULT);
     ATTRIBUTE(CollisionShape, VAR_INT, "LOD Level", lodLevel_, 0, AM_DEFAULT);
     ATTRIBUTE(CollisionShape, VAR_FLOAT, "Collision Margin", margin_, DEFAULT_COLLISION_MARGIN, AM_DEFAULT);
     ATTRIBUTE(CollisionShape, VAR_FLOAT, "Collision Margin", margin_, DEFAULT_COLLISION_MARGIN, AM_DEFAULT);
@@ -238,8 +238,9 @@ void CollisionShape::OnSetAttribute(const AttributeInfo& attr, const Variant& sr
 {
 {
     Component::OnSetAttribute(attr, src);
     Component::OnSetAttribute(attr, src);
     
     
-    // Change of any attribute needs the collision shape to be recreated
-    recreateShape_ = true;
+    // Change of any non-accessor attribute requires recreation of the collision shape
+    if (!attr.accessor_)
+        recreateShape_ = true;
 }
 }
 
 
 void CollisionShape::ApplyAttributes()
 void CollisionShape::ApplyAttributes()

+ 1 - 1
Engine/Physics/Constraint.cpp

@@ -93,7 +93,7 @@ void Constraint::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
 {
 {
     Component::OnSetAttribute(attr, src);
     Component::OnSetAttribute(attr, src);
     
     
-    // Change of any attribute needs recreation of the constraint
+    // Change of any attribute requires recreation of the constraint
     recreateConstraint_ = true;
     recreateConstraint_ = true;
 }
 }
 
 

+ 7 - 4
Engine/Physics/RigidBody.cpp

@@ -73,7 +73,7 @@ RigidBody::RigidBody(Context* context) :
     phantom_(false),
     phantom_(false),
     inSetTransform_(false),
     inSetTransform_(false),
     hasSmoothedTransform_(false),
     hasSmoothedTransform_(false),
-    dirty_(false)
+    readdBody_(false)
 {
 {
     compoundShape_ = new btCompoundShape();
     compoundShape_ = new btCompoundShape();
 }
 }
@@ -120,15 +120,18 @@ void RigidBody::RegisterObject(Context* context)
 void RigidBody::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
 void RigidBody::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
 {
 {
     Component::OnSetAttribute(attr, src);
     Component::OnSetAttribute(attr, src);
-    dirty_ = true;
+    
+    // Change of any non-accessor attribute requires the rigid body to be re-added to the physics world
+    if (!attr.accessor_)
+        readdBody_ = true;
 }
 }
 
 
 void RigidBody::ApplyAttributes()
 void RigidBody::ApplyAttributes()
 {
 {
-    if (dirty_)
+    if (readdBody_)
     {
     {
         AddBodyToWorld();
         AddBodyToWorld();
-        dirty_ = false;
+        readdBody_ = false;
     }
     }
 }
 }
 
 

+ 2 - 2
Engine/Physics/RigidBody.h

@@ -238,6 +238,6 @@ private:
     bool inSetTransform_;
     bool inSetTransform_;
     /// Smoothed transform mode.
     /// Smoothed transform mode.
     bool hasSmoothedTransform_;
     bool hasSmoothedTransform_;
-    /// Dirty flag.
-    bool dirty_;
+    /// Readd body to world flag.
+    bool readdBody_;
 };
 };

+ 1 - 1
Engine/Scene/Scene.cpp

@@ -39,7 +39,7 @@
 static const int ASYNC_LOAD_MIN_FPS = 30;
 static const int ASYNC_LOAD_MIN_FPS = 30;
 static const int ASYNC_LOAD_MAX_MSEC = (int)(1000.0f / ASYNC_LOAD_MIN_FPS);
 static const int ASYNC_LOAD_MAX_MSEC = (int)(1000.0f / ASYNC_LOAD_MIN_FPS);
 static const float DEFAULT_SMOOTHING_CONSTANT = 50.0f;
 static const float DEFAULT_SMOOTHING_CONSTANT = 50.0f;
-static const float DEFAULT_SNAP_THRESHOLD = 1.0f;
+static const float DEFAULT_SNAP_THRESHOLD = 5.0f;
 static const String emptyVarName;
 static const String emptyVarName;
 
 
 OBJECTTYPESTATIC(Scene);
 OBJECTTYPESTATIC(Scene);