BulletSim: fix problem with continuious rebuilding of physical linksets. This caused movement problems and large prim vehicles to take up a LOT of simulation time.

0.7.5-pf-bulletsim
Robert Adams 2012-12-13 16:23:51 -08:00
parent 60950bfab5
commit 31d3952477
3 changed files with 91 additions and 82 deletions

View File

@ -124,7 +124,7 @@ public abstract class BSLinkset
get { return ComputeLinksetGeometricCenter(); }
}
protected void Initialize(BSScene scene, BSPhysObject parent)
protected BSLinkset(BSScene scene, BSPhysObject parent)
{
// A simple linkset of one (no children)
LinksetID = m_nextLinksetID++;
@ -135,6 +135,7 @@ public abstract class BSLinkset
LinksetRoot = parent;
m_children = new HashSet<BSPhysObject>();
m_mass = parent.RawMass;
Rebuilding = false;
}
// Link to a linkset where the child knows the parent.
@ -237,6 +238,10 @@ public abstract class BSLinkset
// May be called at runtime or taint-time.
public abstract void Refresh(BSPhysObject requestor);
// Flag denoting the linkset is in the process of being rebuilt.
// Used to know not the schedule a rebuild in the middle of a rebuild.
protected bool Rebuilding { get; set; }
// The object is going dynamic (physical). Do any setup necessary
// for a dynamic linkset.
// Only the state of the passed object can be modified. The rest of the linkset

View File

@ -61,9 +61,8 @@ public sealed class BSLinksetCompound : BSLinkset
{
private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]";
public BSLinksetCompound(BSScene scene, BSPhysObject parent)
public BSLinksetCompound(BSScene scene, BSPhysObject parent) : base(scene, parent)
{
base.Initialize(scene, parent);
}
// For compound implimented linksets, if there are children, use compound shape for the root.
@ -81,8 +80,6 @@ public sealed class BSLinksetCompound : BSLinkset
// When physical properties are changed the linkset needs to recalculate
// its internal properties.
// This is queued in the 'post taint' queue so the
// refresh will happen once after all the other taints are applied.
public override void Refresh(BSPhysObject requestor)
{
// External request for Refresh (from BSPrim) doesn't need to do anything
@ -92,13 +89,19 @@ public sealed class BSLinksetCompound : BSLinkset
// Schedule a refresh to happen after all the other taint processing.
private void InternalRefresh(BSPhysObject requestor)
{
DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1}", LinksetRoot.LocalID, requestor.LocalID);
DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1},rebuilding={2}",
LinksetRoot.LocalID, requestor.LocalID, Rebuilding);
// When rebuilding, it is possible to set properties that would normally require a rebuild.
// If already rebuilding, don't request another rebuild.
if (!Rebuilding)
{
PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate()
{
if (IsRoot(requestor) && HasAnyChildren)
RecomputeLinksetCompound();
});
}
}
// The object is going dynamic (physical). Do any setup necessary
// for a dynamic linkset.
@ -115,12 +118,8 @@ public sealed class BSLinksetCompound : BSLinkset
// The root is going dynamic. Make sure mass is properly set.
m_mass = ComputeLinksetMass();
if (HasAnyChildren)
{
// Schedule a rebuilding as this will construct the complete compound shape
// and set all the properties correctly.
InternalRefresh(LinksetRoot);
}
}
else
{
// The origional prims are removed from the world as the shape of the root compound
@ -149,16 +148,13 @@ public sealed class BSLinksetCompound : BSLinkset
if (IsRoot(child))
{
if (HasAnyChildren)
{
// Schedule a rebuilding as this will construct the complete compound shape
// and set all the properties correctly.
InternalRefresh(LinksetRoot);
}
}
else
{
// The non-physical children can come back to life.
BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
child.PhysBody.collisionType = CollisionType.LinksetChild;
// Don't force activation so setting of DISABLE_SIMULATION can stay if used.
@ -307,6 +303,11 @@ public sealed class BSLinksetCompound : BSLinkset
// Called at taint time!!
private void RecomputeLinksetCompound()
{
try
{
// Suppress rebuilding while rebuilding
Rebuilding = true;
// Cause the root shape to be rebuilt as a compound object with just the root in it
LinksetRoot.ForceBodyShapeRebuild(true);
@ -368,13 +369,17 @@ public sealed class BSLinksetCompound : BSLinkset
BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos, lci.OffsetRot);
}
}
return false; // 'false' says to move onto the next child in the list
});
// With all of the linkset packed into the root prim, it has the mass of everyone.
float linksetMass = LinksetMass;
LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
}
finally
{
Rebuilding = false;
}
BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr);

View File

@ -36,9 +36,8 @@ public sealed class BSLinksetConstraints : BSLinkset
{
// private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";
public BSLinksetConstraints(BSScene scene, BSPhysObject parent)
public BSLinksetConstraints(BSScene scene, BSPhysObject parent) : base(scene, parent)
{
base.Initialize(scene, parent);
}
// When physical properties are changed the linkset needs to recalculate