From 7c3b71d294987943058c8b3bcb18a424ca70dea5 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 14 Aug 2013 14:13:08 -0700 Subject: [PATCH] BulletSim: add physical object initialized flag so updates and collisions don't happen until the object is completely initialized. This fixes the problem of doing a teleport while the simulator is running. The destruction of the physical object while the engine is running means that the physics parameter update would overwrite the new position of the newly created avatar. --- .../Physics/BulletSPlugin/BSActorAvatarMove.cs | 4 +++- OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 4 ++++ OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 4 ++++ OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 4 ++++ OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 12 ++++++++---- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs index 5f232a4b99..c0589cd7db 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs @@ -69,7 +69,9 @@ public class BSActorAvatarMove : BSActor // BSActor.Dispose() public override void Dispose() { - Enabled = false; + base.SetEnabled(false); + // Now that turned off, remove any state we have in the scene. + Refresh(); } // Called when physical parameters (properties set in Bullet) need to be re-applied. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 502f85f02b..291dfcd9d8 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -107,6 +107,8 @@ public sealed class BSCharacter : BSPhysObject PhysicalActors.Add(AvatarMoveActorName, m_moveActor); SetPhysicalProperties(); + + IsInitialized = true; }); return; } @@ -114,6 +116,8 @@ public sealed class BSCharacter : BSPhysObject // called when this character is being destroyed and the resources should be released public override void Destroy() { + IsInitialized = false; + base.Destroy(); DetailLog("{0},BSCharacter.Destroy", LocalID); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 27caf62873..b26fef02e3 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -72,6 +72,8 @@ public abstract class BSPhysObject : PhysicsActor } protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName) { + IsInitialized = false; + PhysScene = parentScene; LocalID = localID; PhysObjectName = name; @@ -130,6 +132,8 @@ public abstract class BSPhysObject : PhysicsActor public string PhysObjectName { get; protected set; } public string TypeName { get; protected set; } + // Set to 'true' when the object is completely initialized + public bool IsInitialized { get; protected set; } // Return the object mass without calculating it or having side effects public abstract float RawMass { get; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 6b5dea39ff..d5b999d839 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -110,6 +110,8 @@ public class BSPrim : BSPhysObject CreateGeomAndObject(true); CurrentCollisionFlags = PhysScene.PE.GetCollisionFlags(PhysBody); + + IsInitialized = true; }); } @@ -117,6 +119,8 @@ public class BSPrim : BSPhysObject public override void Destroy() { // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); + IsInitialized = false; + base.Destroy(); // Undo any vehicle properties diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 79ac5a5ba0..88d50b438b 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -639,7 +639,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters BSPhysObject pobj; if (PhysObjects.TryGetValue(entprop.ID, out pobj)) { - pobj.UpdateProperties(entprop); + if (pobj.IsInitialized) + pobj.UpdateProperties(entprop); } } } @@ -766,10 +767,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith); - if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration)) + if (collider.IsInitialized) { - // If a collision was 'good', remember to send it to the simulator - ObjectsWithCollisions.Add(collider); + if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration)) + { + // If a collision was 'good', remember to send it to the simulator + ObjectsWithCollisions.Add(collider); + } } return;