From 062ec0efbda0e4ca6df5541039569e023d0d0e79 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 23 Aug 2015 21:15:04 -0700 Subject: BulletSim: delay adding a scene presence to the list of presences until it is fully configured. Another addition to fixing the collisions stopping problem. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 13 +++++++---- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 12 ++++++++-- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 27 +++++++++++----------- 3 files changed, 33 insertions(+), 19 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 9c3f160..cfcccac 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -75,9 +75,10 @@ public sealed class BSCharacter : BSPhysObject // Avatars are always complete (in the physics engine sense) public override bool IsIncomplete { get { return false; } } + // 'activate' is called with this character after all initialization is complete public BSCharacter( - uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 vel, OMV.Vector3 size, bool isFlying) - + uint localID, String avName, BSScene parent_scene, + OMV.Vector3 pos, OMV.Vector3 vel, OMV.Vector3 size, bool isFlying, Action activate) : base(parent_scene, localID, avName, "BSCharacter") { _physicsActorType = (int)ActorTypes.Agent; @@ -124,6 +125,9 @@ public sealed class BSCharacter : BSPhysObject SetPhysicalProperties(); IsInitialized = true; + + if (activate != null) + activate(this); }); return; } @@ -472,12 +476,13 @@ public sealed class BSCharacter : BSPhysObject } } + // Force the setting of velocity. Called at taint time. + // Exists so that setting force by anyone can be overridden by a subcless. public override OMV.Vector3 ForceVelocity { get { return RawVelocity; } set { PhysScene.AssertInTaintTime("BSCharacter.ForceVelocity"); -// Util.PrintCallStack(); - DetailLog("{0}: set ForceVelocity = {1}", LocalID, value); + DetailLog("{0},BSCharacter.setForceVelocity,call,vel={1}", LocalID, value); RawVelocity = value; PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 90da7a6..4669d91 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -72,6 +72,11 @@ public abstract class BSPhysObject : PhysicsActor } protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName) { + InitializePhysObject(parentScene, localID, name, typeName); + } + + protected void InitializePhysObject(BSScene parentScene, uint localID, string name, string typeName) + { IsInitialized = false; PhysScene = parentScene; @@ -119,6 +124,8 @@ public abstract class BSPhysObject : PhysicsActor // Tell the object to clean up. public virtual void Destroy() { + SubscribedEventsMs = 0; + PhysicalActors.Enable(false); PhysScene.TaintedObject(LocalID, "BSPhysObject.Destroy", delegate() { @@ -455,6 +462,7 @@ public abstract class BSPhysObject : PhysicsActor // Return 'true' if a collision was processed and should be sent up. // Return 'false' if this object is not enabled/subscribed/appropriate for or has already seen this collision. // Called at taint time from within the Step() function + // Both 'CollisionLock' and 'PhysObjects' are locked when this is called by 'SendCollisions'. public delegate bool CollideCall(uint collidingWith, BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth); public virtual bool Collide(uint collidingWith, BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) @@ -512,7 +520,7 @@ public abstract class BSPhysObject : PhysicsActor // If no collisions this call but there were collisions last call, force the collision // event to be happen right now so quick collision_end. - bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0); + bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0); // throttle the collisions to the number of milliseconds specified in the subscription if (force || (PhysScene.SimulationNowTime >= NextCollisionOkTime)) @@ -545,7 +553,7 @@ public abstract class BSPhysObject : PhysicsActor // Subscribe for collision events. // Parameter is the millisecond rate the caller wishes collision events to occur. public override void SubscribeEvents(int ms) { - // DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms); + DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms); SubscribedEventsMs = ms; if (ms > 0) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 8a19944..2a8a6a5 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -477,16 +477,19 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters if (!m_initialized) return null; - BSCharacter actor = new BSCharacter(localID, avName, this, position, velocity, size, isFlying); - lock (PhysObjects) - PhysObjects.Add(localID, actor); - - // TODO: Remove kludge someday. - // We must generate a collision for avatars whether they collide or not. - // This is required by OpenSim to update avatar animations, etc. - lock (AvatarsInSceneLock) - AvatarsInScene.Add(actor); + BSCharacter actor = new BSCharacter(localID, avName, this, position, velocity, size, isFlying, + (aa) => + { + // While the actor exists, don't add it to the active avatar lists until completely initialized + lock (PhysObjects) + PhysObjects.Add(localID, aa); + // TODO: Remove kludge someday. + // We must generate a collision for avatars whether they collide or not. + // This is required by OpenSim to update avatar animations, etc. + lock (AvatarsInSceneLock) + AvatarsInScene.Add(aa); + }); return actor; } @@ -830,10 +833,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration)) { // If a collision was 'good', remember to send it to the simulator - lock (CollisionLock) - { - ObjectsWithCollisions.Add(collider); - } + // Note that 'CollisionLock' was locked before the call to 'SendCollsions' + ObjectsWithCollisions.Add(collider); } } -- cgit v1.1