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.
user_profiles
Robert Adams 2013-01-28 15:11:50 -08:00
parent e4c6a19940
commit e9aff0a91d
7 changed files with 118 additions and 96 deletions

View File

@ -56,7 +56,6 @@ public sealed class BSCharacter : BSPhysObject
private int _physicsActorType; private int _physicsActorType;
private bool _isPhysical; private bool _isPhysical;
private bool _flying; private bool _flying;
private bool _wasWalking; // 'true' if the avatar was walking/moving last frame
private bool _setAlwaysRun; private bool _setAlwaysRun;
private bool _throttleUpdates; private bool _throttleUpdates;
private bool _floatOnWater; private bool _floatOnWater;
@ -84,7 +83,6 @@ public sealed class BSCharacter : BSPhysObject
_position = pos; _position = pos;
_flying = isFlying; _flying = isFlying;
_wasWalking = true; // causes first step to initialize standing
_orientation = OMV.Quaternion.Identity; _orientation = OMV.Quaternion.Identity;
_velocity = OMV.Vector3.Zero; _velocity = OMV.Vector3.Zero;
_buoyancy = ComputeBuoyancyFromFlying(isFlying); _buoyancy = ComputeBuoyancyFromFlying(isFlying);
@ -220,7 +218,13 @@ public sealed class BSCharacter : BSPhysObject
{ {
// The avatar shouldn't be moving // The avatar shouldn't be moving
_velocityMotor.Zero(); _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 // Standing has more friction on the ground
if (_currentFriction != BSParam.AvatarStandingFriction) if (_currentFriction != BSParam.AvatarStandingFriction)
@ -229,8 +233,6 @@ public sealed class BSCharacter : BSPhysObject
PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
} }
DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue); DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue);
_wasWalking = false;
} }
else 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); DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce);
PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce);
_wasWalking = true;
} }
}); });
} }

View File

@ -96,6 +96,7 @@ public abstract class BSPhysObject : PhysicsActor
CollidingStep = 0; CollidingStep = 0;
CollidingGroundStep = 0; CollidingGroundStep = 0;
CollisionAccumulation = 0; CollisionAccumulation = 0;
ColliderIsMoving = false;
CollisionScore = 0; CollisionScore = 0;
} }
@ -177,13 +178,14 @@ public abstract class BSPhysObject : PhysicsActor
public abstract OMV.Vector3 RawPosition { get; set; } public abstract OMV.Vector3 RawPosition { get; set; }
public abstract OMV.Vector3 ForcePosition { 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, // 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 // sometimes it is necessary to displace the position the physics engine thinks
// the position is. PositionDisplacement must be added and removed from the // the position is. PositionDisplacement must be added and removed from the
// position as the simulator position is stored and fetched from the physics // 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.Vector3 PositionDisplacement { get; set; }
public virtual OMV.Quaternion OrientationDisplacement { get; set; }
public abstract OMV.Quaternion RawOrientation { get; set; } public abstract OMV.Quaternion RawOrientation { get; set; }
public abstract OMV.Quaternion ForceOrientation { get; set; } public abstract OMV.Quaternion ForceOrientation { get; set; }
@ -240,6 +242,9 @@ public abstract class BSPhysObject : PhysicsActor
protected long CollidingObjectStep { get; set; } protected long CollidingObjectStep { get; set; }
// The collision flags we think are set in Bullet // The collision flags we think are set in Bullet
protected CollisionFlags CurrentCollisionFlags { get; set; } 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 // Count of collisions for this object
protected long CollisionAccumulation { get; set; } protected long CollisionAccumulation { get; set; }
@ -307,7 +312,10 @@ public abstract class BSPhysObject : PhysicsActor
CollisionAccumulation++; 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()) { if (SubscribedEvents()) {
CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}", 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() { public override bool SubscribedEvents() {
return (SubscribedEventsMs > 0); 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 // 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. // all the processing when the user asks for the info.
public void ComputeCollisionScore() 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; long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1;
CollisionScore = CollisionAccumulation / timeAgo; CollisionScore = CollisionAccumulation / timeAgo;
} }
@ -423,13 +432,15 @@ public abstract class BSPhysObject : PhysicsActor
UnRegisterPreStepAction(op, id); UnRegisterPreStepAction(op, id);
RegisteredPrestepActions[identifier] = actn; RegisteredPrestepActions[identifier] = actn;
PhysicsScene.BeforeStep += actn;
} }
PhysicsScene.BeforeStep += actn;
DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier);
} }
// Unregister a pre step action. Safe to call if the action has not been registered. // 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(); string identifier = op + "-" + id.ToString();
bool removed = false; bool removed = false;
@ -443,6 +454,7 @@ public abstract class BSPhysObject : PhysicsActor
} }
} }
DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed); DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed);
return removed;
} }
protected void UnRegisterAllPreStepActions() protected void UnRegisterAllPreStepActions()
@ -468,13 +480,15 @@ public abstract class BSPhysObject : PhysicsActor
UnRegisterPostStepAction(op, id); UnRegisterPostStepAction(op, id);
RegisteredPoststepActions[identifier] = actn; RegisteredPoststepActions[identifier] = actn;
PhysicsScene.AfterStep += actn;
} }
PhysicsScene.AfterStep += actn;
DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier);
} }
// Unregister a pre step action. Safe to call if the action has not been registered. // 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(); string identifier = op + "-" + id.ToString();
bool removed = false; bool removed = false;
@ -488,6 +502,7 @@ public abstract class BSPhysObject : PhysicsActor
} }
} }
DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed); DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed);
return removed;
} }
protected void UnRegisterAllPostStepActions() protected void UnRegisterAllPostStepActions()

View File

@ -1,81 +1,87 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the * * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Nini.Config; using Nini.Config;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Physics.BulletSPlugin; using OpenSim.Region.Physics.BulletSPlugin;
using OpenSim.Region.Physics.Meshing; using OpenSim.Region.Physics.Meshing;
namespace OpenSim.Region.Physics.BulletSPlugin.Tests namespace OpenSim.Region.Physics.BulletSPlugin.Tests
{ {
// Utility functions for building up and tearing down the sample physics environments // Utility functions for building up and tearing down the sample physics environments
public static class BulletSimTestsUtil public static class BulletSimTestsUtil
{ {
// 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" // '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) // '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. // May be 'null' if there are no overrides.
public static BSScene CreateBasicPhysicsEngine(string engineName, Dictionary<string,string> paramOverrides) public static BSScene CreateBasicPhysicsEngine(Dictionary<string,string> paramOverrides)
{ {
if (engineName == null) IConfigSource openSimINI = new IniConfigSource();
engineName = "BulletUnmanaged"; IConfig startupConfig = openSimINI.AddConfig("StartUp");
startupConfig.Set("physics", "BulletSim");
IConfigSource openSimINI = new IniConfigSource(); startupConfig.Set("meshing", "Meshmerizer");
IConfig startupConfig = openSimINI.AddConfig("StartUp"); startupConfig.Set("cacheSculptMaps", "false"); // meshmerizer shouldn't save maps
startupConfig.Set("meshing", "Meshmerizer");
startupConfig.Set("physics", "BulletSim"); IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim");
// If the caller cares, specify the bullet engine otherwise it will default to "BulletUnmanaged".
IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); // bulletSimConfig.Set("BulletEngine", "BulletUnmanaged");
bulletSimConfig.Set("BulletEngine", engineName); // bulletSimConfig.Set("BulletEngine", "BulletXNA");
if (paramOverrides != null) bulletSimConfig.Set("MeshSculptedPrim", "false");
{ bulletSimConfig.Set("ForceSimplePrimMeshing", "true");
foreach (KeyValuePair<string, string> kvp in paramOverrides) if (paramOverrides != null)
{ {
bulletSimConfig.Set(kvp.Key, kvp.Value); foreach (KeyValuePair<string, string> kvp in paramOverrides)
} {
} bulletSimConfig.Set(kvp.Key, kvp.Value);
// bulletSimConfig.Set("PhysicsLoggingEnabled","True"); }
// bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); }
// bulletSimConfig.Set("VehicleLoggingEnabled","True"); // bulletSimConfig.Set("PhysicsLoggingEnabled","True");
// bulletSimConfig.Set("PhysicsLoggingDoFlush","True");
BSPlugin bsPlugin = new BSPlugin(); // bulletSimConfig.Set("VehicleLoggingEnabled","True");
BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion"); BSPlugin bsPlugin = new BSPlugin();
Meshing.Meshmerizer mesher = new Meshmerizer(openSimINI); BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion");
bsScene.Initialise(mesher, openSimINI);
// Since the asset requestor is not initialized, any mesh or sculptie will be a cube.
return bsScene; // 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;
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.