From e9aff0a91d6a4d02498ce45759389bb09b34fcbc Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 28 Jan 2013 15:11:50 -0800 Subject: BulletSim: do not zero an avatar's standing velocity if it is standing on a moving object. Rearrange pre/post action subscription code to put more in locks. Add meshmerizer params to BulletSimTestUtil scene creation (and fix line endings). Rebuilt version of DLLs and SOs with cleaned up code and no profiling for sure. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 13 +- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 33 ++-- .../BulletSPlugin/Tests/BulletSimTestsUtil.cs | 168 +++++++++++---------- 3 files changed, 118 insertions(+), 96 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 7603254..3884a5d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -56,7 +56,6 @@ public sealed class BSCharacter : BSPhysObject private int _physicsActorType; private bool _isPhysical; private bool _flying; - private bool _wasWalking; // 'true' if the avatar was walking/moving last frame private bool _setAlwaysRun; private bool _throttleUpdates; private bool _floatOnWater; @@ -84,7 +83,6 @@ public sealed class BSCharacter : BSPhysObject _position = pos; _flying = isFlying; - _wasWalking = true; // causes first step to initialize standing _orientation = OMV.Quaternion.Identity; _velocity = OMV.Vector3.Zero; _buoyancy = ComputeBuoyancyFromFlying(isFlying); @@ -220,7 +218,13 @@ public sealed class BSCharacter : BSPhysObject { // The avatar shouldn't be moving _velocityMotor.Zero(); - ZeroMotion(true /* inTaintTime */); + + // If we are colliding with a stationary object, presume we're standing and don't move around + if (!ColliderIsMoving) + { + DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", LocalID); + ZeroMotion(true /* inTaintTime */); + } // Standing has more friction on the ground if (_currentFriction != BSParam.AvatarStandingFriction) @@ -229,8 +233,6 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); } DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue); - - _wasWalking = false; } else { @@ -260,7 +262,6 @@ public sealed class BSCharacter : BSPhysObject DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); - _wasWalking = true; } }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 5e8143c..a113530 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -96,6 +96,7 @@ public abstract class BSPhysObject : PhysicsActor CollidingStep = 0; CollidingGroundStep = 0; CollisionAccumulation = 0; + ColliderIsMoving = false; CollisionScore = 0; } @@ -177,13 +178,14 @@ public abstract class BSPhysObject : PhysicsActor public abstract OMV.Vector3 RawPosition { get; set; } public abstract OMV.Vector3 ForcePosition { get; set; } - // Position is what the simulator thinks the positions of the prim is. + // 'Position' and 'Orientation' is what the simulator thinks the positions of the prim is. // Because Bullet needs the zero coordinate to be the center of mass of the linkset, // sometimes it is necessary to displace the position the physics engine thinks // the position is. PositionDisplacement must be added and removed from the // position as the simulator position is stored and fetched from the physics - // engine. + // engine. Similar to OrientationDisplacement. public virtual OMV.Vector3 PositionDisplacement { get; set; } + public virtual OMV.Quaternion OrientationDisplacement { get; set; } public abstract OMV.Quaternion RawOrientation { get; set; } public abstract OMV.Quaternion ForceOrientation { get; set; } @@ -240,6 +242,9 @@ public abstract class BSPhysObject : PhysicsActor protected long CollidingObjectStep { get; set; } // The collision flags we think are set in Bullet protected CollisionFlags CurrentCollisionFlags { get; set; } + // On a collision, check the collider and remember if the last collider was moving + // Used to modify the standing of avatars (avatars on stationary things stand still) + protected bool ColliderIsMoving; // Count of collisions for this object protected long CollisionAccumulation { get; set; } @@ -307,7 +312,10 @@ public abstract class BSPhysObject : PhysicsActor CollisionAccumulation++; - // if someone has subscribed for collision events.... + // For movement tests, remember if we are colliding with an object that is moving. + ColliderIsMoving = collidee != null ? collidee.RawVelocity != OMV.Vector3.Zero : false; + + // If someone has subscribed for collision events log the collision so it will be reported up if (SubscribedEvents()) { CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}", @@ -393,12 +401,13 @@ public abstract class BSPhysObject : PhysicsActor public override bool SubscribedEvents() { return (SubscribedEventsMs > 0); } - // Because 'CollisionScore' is calls many times while sorting it should not be recomputed + // Because 'CollisionScore' is called many times while sorting, it should not be recomputed // each time called. So this is built to be light weight for each collision and to do // all the processing when the user asks for the info. public void ComputeCollisionScore() { - // Scale the collision count by the time since the last collision + // Scale the collision count by the time since the last collision. + // The "+1" prevents dividing by zero. long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1; CollisionScore = CollisionAccumulation / timeAgo; } @@ -423,13 +432,15 @@ public abstract class BSPhysObject : PhysicsActor UnRegisterPreStepAction(op, id); RegisteredPrestepActions[identifier] = actn; + + PhysicsScene.BeforeStep += actn; } - PhysicsScene.BeforeStep += actn; DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); } // Unregister a pre step action. Safe to call if the action has not been registered. - protected void UnRegisterPreStepAction(string op, uint id) + // Returns 'true' if an action was actually removed + protected bool UnRegisterPreStepAction(string op, uint id) { string identifier = op + "-" + id.ToString(); bool removed = false; @@ -443,6 +454,7 @@ public abstract class BSPhysObject : PhysicsActor } } DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed); + return removed; } protected void UnRegisterAllPreStepActions() @@ -468,13 +480,15 @@ public abstract class BSPhysObject : PhysicsActor UnRegisterPostStepAction(op, id); RegisteredPoststepActions[identifier] = actn; + + PhysicsScene.AfterStep += actn; } - PhysicsScene.AfterStep += actn; DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); } // Unregister a pre step action. Safe to call if the action has not been registered. - protected void UnRegisterPostStepAction(string op, uint id) + // Returns 'true' if an action was actually removed. + protected bool UnRegisterPostStepAction(string op, uint id) { string identifier = op + "-" + id.ToString(); bool removed = false; @@ -488,6 +502,7 @@ public abstract class BSPhysObject : PhysicsActor } } DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed); + return removed; } protected void UnRegisterAllPostStepActions() diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs index 6c2247a..e7657f9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs @@ -1,81 +1,87 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using Nini.Config; - -using OpenSim.Framework; -using OpenSim.Region.Physics.BulletSPlugin; -using OpenSim.Region.Physics.Meshing; - -namespace OpenSim.Region.Physics.BulletSPlugin.Tests -{ -// Utility functions for building up and tearing down the sample physics environments -public static class BulletSimTestsUtil -{ - // 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" - // 'params' is a set of keyValue pairs to set in the engine's configuration file (override defaults) - // May be 'null' if there are no overrides. - public static BSScene CreateBasicPhysicsEngine(string engineName, Dictionary paramOverrides) - { - if (engineName == null) - engineName = "BulletUnmanaged"; - - IConfigSource openSimINI = new IniConfigSource(); - IConfig startupConfig = openSimINI.AddConfig("StartUp"); - startupConfig.Set("meshing", "Meshmerizer"); - startupConfig.Set("physics", "BulletSim"); - - IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); - bulletSimConfig.Set("BulletEngine", engineName); - if (paramOverrides != null) - { - foreach (KeyValuePair kvp in paramOverrides) - { - bulletSimConfig.Set(kvp.Key, kvp.Value); - } - } - // bulletSimConfig.Set("PhysicsLoggingEnabled","True"); - // bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); - // bulletSimConfig.Set("VehicleLoggingEnabled","True"); - - BSPlugin bsPlugin = new BSPlugin(); - - BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion"); - - Meshing.Meshmerizer mesher = new Meshmerizer(openSimINI); - bsScene.Initialise(mesher, openSimINI); - - return bsScene; - } - -} -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Nini.Config; + +using OpenSim.Framework; +using OpenSim.Region.Physics.BulletSPlugin; +using OpenSim.Region.Physics.Meshing; + +namespace OpenSim.Region.Physics.BulletSPlugin.Tests +{ +// Utility functions for building up and tearing down the sample physics environments +public static class BulletSimTestsUtil +{ + // 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" + // 'params' is a set of keyValue pairs to set in the engine's configuration file (override defaults) + // May be 'null' if there are no overrides. + public static BSScene CreateBasicPhysicsEngine(Dictionary paramOverrides) + { + IConfigSource openSimINI = new IniConfigSource(); + IConfig startupConfig = openSimINI.AddConfig("StartUp"); + startupConfig.Set("physics", "BulletSim"); + startupConfig.Set("meshing", "Meshmerizer"); + startupConfig.Set("cacheSculptMaps", "false"); // meshmerizer shouldn't save maps + + IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); + // If the caller cares, specify the bullet engine otherwise it will default to "BulletUnmanaged". + // bulletSimConfig.Set("BulletEngine", "BulletUnmanaged"); + // bulletSimConfig.Set("BulletEngine", "BulletXNA"); + bulletSimConfig.Set("MeshSculptedPrim", "false"); + bulletSimConfig.Set("ForceSimplePrimMeshing", "true"); + if (paramOverrides != null) + { + foreach (KeyValuePair kvp in paramOverrides) + { + bulletSimConfig.Set(kvp.Key, kvp.Value); + } + } + // bulletSimConfig.Set("PhysicsLoggingEnabled","True"); + // bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); + // bulletSimConfig.Set("VehicleLoggingEnabled","True"); + + BSPlugin bsPlugin = new BSPlugin(); + + BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion"); + + // Since the asset requestor is not initialized, any mesh or sculptie will be a cube. + // In the future, add a fake asset fetcher to get meshes and sculpts. + // bsScene.RequestAssetMethod = ???; + + Meshing.Meshmerizer mesher = new Meshmerizer(openSimINI); + bsScene.Initialise(mesher, openSimINI); + + return bsScene; + } + +} +} -- cgit v1.1