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 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;
}
});
}

View File

@ -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()

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
@ -44,18 +44,20 @@ 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<string,string> paramOverrides)
public static BSScene CreateBasicPhysicsEngine(Dictionary<string,string> paramOverrides)
{
if (engineName == null)
engineName = "BulletUnmanaged";
IConfigSource openSimINI = new IniConfigSource();
IConfig startupConfig = openSimINI.AddConfig("StartUp");
startupConfig.Set("meshing", "Meshmerizer");
startupConfig.Set("physics", "BulletSim");
startupConfig.Set("meshing", "Meshmerizer");
startupConfig.Set("cacheSculptMaps", "false"); // meshmerizer shouldn't save maps
IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim");
bulletSimConfig.Set("BulletEngine", engineName);
// 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<string, string> kvp in paramOverrides)
@ -71,6 +73,10 @@ public static class BulletSimTestsUtil
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);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.