aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorRobert Adams2012-08-10 16:35:00 -0700
committerRobert Adams2012-08-10 16:35:00 -0700
commit3ecd39068cf756fc9de2f8f30bc2a703be90d7dc (patch)
tree27dbc031a986f76215c3587ec647df14b6d63b75 /OpenSim/Region
parentBulletSim: actually update the DLLs and SOs (diff)
parentBulletSim: many, many detailed logging messages for physical linkset (diff)
downloadopensim-SC-3ecd39068cf756fc9de2f8f30bc2a703be90d7dc.zip
opensim-SC-3ecd39068cf756fc9de2f8f30bc2a703be90d7dc.tar.gz
opensim-SC-3ecd39068cf756fc9de2f8f30bc2a703be90d7dc.tar.bz2
opensim-SC-3ecd39068cf756fc9de2f8f30bc2a703be90d7dc.tar.xz
Merge branch 'bulletsim7'
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs80
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs86
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs64
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs18
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs114
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs167
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs87
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs46
8 files changed, 377 insertions, 285 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs
new file mode 100755
index 0000000..72df6b9
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs
@@ -0,0 +1,80 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30using OpenMetaverse;
31
32namespace OpenSim.Region.Physics.BulletSPlugin
33{
34
35public class BS6DofConstraint : BSConstraint
36{
37 // Create a btGeneric6DofConstraint
38 public BS6DofConstraint(BulletSim world, BulletBody obj1, BulletBody obj2,
39 Vector3 frame1, Quaternion frame1rot,
40 Vector3 frame2, Quaternion frame2rot )
41 {
42 m_world = world;
43 m_body1 = obj1;
44 m_body2 = obj2;
45 m_constraint = new BulletConstraint(
46 BulletSimAPI.Create6DofConstraint2(m_world.Ptr, m_body1.Ptr, m_body2.Ptr,
47 frame1, frame1rot,
48 frame2, frame2rot,
49 true /*useLinearReferenceFrameA*/, true /*disableCollisionsBetweenLinkedBodies*/));
50 m_enabled = true;
51 }
52
53 public bool SetCFMAndERP(float cfm, float erp)
54 {
55 bool ret = true;
56 BulletSimAPI.SetConstraintParam2(m_constraint.Ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
57 BulletSimAPI.SetConstraintParam2(m_constraint.Ptr, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL);
58 BulletSimAPI.SetConstraintParam2(m_constraint.Ptr, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
59 return ret;
60 }
61
62 public bool UseFrameOffset(bool useOffset)
63 {
64 bool ret = false;
65 float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
66 if (m_enabled)
67 ret = BulletSimAPI.UseFrameOffset2(m_constraint.Ptr, onOff);
68 return ret;
69 }
70
71 public bool TranslationalLimitMotor(bool enable, float targetVelocity, float maxMotorForce)
72 {
73 bool ret = false;
74 float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
75 if (m_enabled)
76 ret = BulletSimAPI.TranslationalLimitMotor2(m_constraint.Ptr, onOff, targetVelocity, maxMotorForce);
77 return ret;
78 }
79}
80}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index d4f5c63..f164afe 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -122,7 +122,7 @@ public class BSCharacter : PhysicsActor
122 shapeData.Restitution = _scene.Params.avatarRestitution; 122 shapeData.Restitution = _scene.Params.avatarRestitution;
123 123
124 // do actual create at taint time 124 // do actual create at taint time
125 _scene.TaintedObject(delegate() 125 _scene.TaintedObject("BSCharacter.create", delegate()
126 { 126 {
127 BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); 127 BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData);
128 128
@@ -138,7 +138,7 @@ public class BSCharacter : PhysicsActor
138 public void Destroy() 138 public void Destroy()
139 { 139 {
140 // DetailLog("{0},Destroy", LocalID); 140 // DetailLog("{0},Destroy", LocalID);
141 _scene.TaintedObject(delegate() 141 _scene.TaintedObject("BSCharacter.destroy", delegate()
142 { 142 {
143 BulletSimAPI.DestroyObject(_scene.WorldID, _localID); 143 BulletSimAPI.DestroyObject(_scene.WorldID, _localID);
144 }); 144 });
@@ -169,7 +169,7 @@ public class BSCharacter : PhysicsActor
169 169
170 ComputeAvatarVolumeAndMass(); 170 ComputeAvatarVolumeAndMass();
171 171
172 _scene.TaintedObject(delegate() 172 _scene.TaintedObject("BSCharacter.setSize", delegate()
173 { 173 {
174 BulletSimAPI.SetObjectScaleMass(_scene.WorldID, LocalID, _scale, _mass, true); 174 BulletSimAPI.SetObjectScaleMass(_scene.WorldID, LocalID, _scale, _mass, true);
175 }); 175 });
@@ -205,13 +205,37 @@ public class BSCharacter : PhysicsActor
205 } 205 }
206 set { 206 set {
207 _position = value; 207 _position = value;
208 _scene.TaintedObject(delegate() 208 PositionSanityCheck();
209
210 _scene.TaintedObject("BSCharacter.setPosition", delegate()
209 { 211 {
210 DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 212 DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
211 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); 213 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
212 }); 214 });
213 } 215 }
214 } 216 }
217
218 // Check that the current position is sane and, if not, modify the position to make it so.
219 // Check for being below terrain and being out of bounds.
220 // Returns 'true' of the position was made sane by some action.
221 private bool PositionSanityCheck()
222 {
223 bool ret = false;
224
225 // If below the ground, move the avatar up
226 float terrainHeight = Scene.GetTerrainHeightAtXYZ(_position);
227 if (_position.Z < terrainHeight)
228 {
229 DetailLog("{0},PositionAdjustUnderGround,call,pos={1},orient={2}", LocalID, _position, _orientation);
230 _position.Z = terrainHeight + 2.0f;
231 ret = true;
232 }
233
234 // TODO: check for out of bounds
235
236 return ret;
237 }
238
215 public override float Mass { 239 public override float Mass {
216 get { 240 get {
217 return _mass; 241 return _mass;
@@ -222,9 +246,9 @@ public class BSCharacter : PhysicsActor
222 set { 246 set {
223 _force = value; 247 _force = value;
224 // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); 248 // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force);
225 Scene.TaintedObject(delegate() 249 Scene.TaintedObject("BSCharacter.SetForce", delegate()
226 { 250 {
227 DetailLog("{0},setForce,taint,force={1}", LocalID, _force); 251 DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force);
228 BulletSimAPI.SetObjectForce(Scene.WorldID, LocalID, _force); 252 BulletSimAPI.SetObjectForce(Scene.WorldID, LocalID, _force);
229 }); 253 });
230 } 254 }
@@ -249,9 +273,9 @@ public class BSCharacter : PhysicsActor
249 set { 273 set {
250 _velocity = value; 274 _velocity = value;
251 // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); 275 // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity);
252 _scene.TaintedObject(delegate() 276 _scene.TaintedObject("BSCharacter.setVelocity", delegate()
253 { 277 {
254 DetailLog("{0},setVelocity,taint,vel={1}", LocalID, _velocity); 278 DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity);
255 BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity); 279 BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity);
256 }); 280 });
257 } 281 }
@@ -275,7 +299,7 @@ public class BSCharacter : PhysicsActor
275 set { 299 set {
276 _orientation = value; 300 _orientation = value;
277 // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); 301 // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation);
278 _scene.TaintedObject(delegate() 302 _scene.TaintedObject("BSCharacter.setOrientation", delegate()
279 { 303 {
280 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); 304 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
281 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); 305 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
@@ -342,7 +366,7 @@ public class BSCharacter : PhysicsActor
342 public override float Buoyancy { 366 public override float Buoyancy {
343 get { return _buoyancy; } 367 get { return _buoyancy; }
344 set { _buoyancy = value; 368 set { _buoyancy = value;
345 _scene.TaintedObject(delegate() 369 _scene.TaintedObject("BSCharacter.setBuoyancy", delegate()
346 { 370 {
347 DetailLog("{0},setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 371 DetailLog("{0},setBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
348 BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); 372 BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy);
@@ -389,7 +413,7 @@ public class BSCharacter : PhysicsActor
389 _force.Y += force.Y; 413 _force.Y += force.Y;
390 _force.Z += force.Z; 414 _force.Z += force.Z;
391 // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); 415 // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force);
392 _scene.TaintedObject(delegate() 416 _scene.TaintedObject("BSCharacter.AddForce", delegate()
393 { 417 {
394 DetailLog("{0},setAddForce,taint,addedForce={1}", LocalID, _force); 418 DetailLog("{0},setAddForce,taint,addedForce={1}", LocalID, _force);
395 BulletSimAPI.AddObjectForce2(Body.Ptr, _force); 419 BulletSimAPI.AddObjectForce2(Body.Ptr, _force);
@@ -415,7 +439,7 @@ public class BSCharacter : PhysicsActor
415 // make sure first collision happens 439 // make sure first collision happens
416 _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; 440 _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs;
417 441
418 Scene.TaintedObject(delegate() 442 Scene.TaintedObject("BSCharacter.SubscribeEvents", delegate()
419 { 443 {
420 BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 444 BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
421 }); 445 });
@@ -425,7 +449,7 @@ public class BSCharacter : PhysicsActor
425 public override void UnSubscribeEvents() { 449 public override void UnSubscribeEvents() {
426 _subscribedEventsMs = 0; 450 _subscribedEventsMs = 0;
427 // Avatars get all their collision events 451 // Avatars get all their collision events
428 // Scene.TaintedObject(delegate() 452 // Scene.TaintedObject("BSCharacter.UnSubscribeEvents", delegate()
429 // { 453 // {
430 // BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 454 // BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
431 // }); 455 // });
@@ -456,43 +480,17 @@ public class BSCharacter : PhysicsActor
456 // the world that things have changed. 480 // the world that things have changed.
457 public void UpdateProperties(EntityProperties entprop) 481 public void UpdateProperties(EntityProperties entprop)
458 { 482 {
459 /*
460 bool changed = false;
461 // we assign to the local variables so the normal set action does not happen
462 if (_position != entprop.Position) {
463 _position = entprop.Position;
464 changed = true;
465 }
466 if (_orientation != entprop.Rotation) {
467 _orientation = entprop.Rotation;
468 changed = true;
469 }
470 if (_velocity != entprop.Velocity) {
471 _velocity = entprop.Velocity;
472 changed = true;
473 }
474 if (_acceleration != entprop.Acceleration) {
475 _acceleration = entprop.Acceleration;
476 changed = true;
477 }
478 if (_rotationalVelocity != entprop.RotationalVelocity) {
479 _rotationalVelocity = entprop.RotationalVelocity;
480 changed = true;
481 }
482 if (changed) {
483 // m_log.DebugFormat("{0}: UpdateProperties: id={1}, c={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation);
484 // Avatar movement is not done by generating this event. There is code in the heartbeat
485 // loop that updates avatars.
486 // base.RequestPhysicsterseUpdate();
487 }
488 */
489 _position = entprop.Position; 483 _position = entprop.Position;
490 _orientation = entprop.Rotation; 484 _orientation = entprop.Rotation;
491 _velocity = entprop.Velocity; 485 _velocity = entprop.Velocity;
492 _acceleration = entprop.Acceleration; 486 _acceleration = entprop.Acceleration;
493 _rotationalVelocity = entprop.RotationalVelocity; 487 _rotationalVelocity = entprop.RotationalVelocity;
494 // Avatars don't report theirr changes the usual way. Changes are checked for in the heartbeat loop. 488 // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop.
495 // base.RequestPhysicsterseUpdate(); 489 // base.RequestPhysicsterseUpdate();
490
491 DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
492 LocalID, entprop.Position, entprop.Rotation, entprop.Velocity,
493 entprop.Acceleration, entprop.RotationalVelocity);
496 } 494 }
497 495
498 // Called by the scene when a collision with this object is reported 496 // Called by the scene when a collision with this object is reported
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
index ea3093a..da26b72 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
@@ -32,35 +32,26 @@ using OpenMetaverse;
32namespace OpenSim.Region.Physics.BulletSPlugin 32namespace OpenSim.Region.Physics.BulletSPlugin
33{ 33{
34 34
35public class BSConstraint : IDisposable 35public abstract class BSConstraint : IDisposable
36{ 36{
37 private BulletSim m_world; 37 protected BulletSim m_world;
38 private BulletBody m_body1; 38 protected BulletBody m_body1;
39 private BulletBody m_body2; 39 protected BulletBody m_body2;
40 private BulletConstraint m_constraint; 40 protected BulletConstraint m_constraint;
41 private bool m_enabled = false; 41 protected bool m_enabled = false;
42 42
43 public BSConstraint(BulletSim world, BulletBody obj1, BulletBody obj2, 43 public BSConstraint()
44 Vector3 frame1, Quaternion frame1rot,
45 Vector3 frame2, Quaternion frame2rot
46 )
47 { 44 {
48 m_world = world;
49 m_body1 = obj1;
50 m_body2 = obj2;
51 m_constraint = new BulletConstraint(BulletSimAPI.CreateConstraint2(m_world.Ptr, m_body1.Ptr, m_body2.Ptr,
52 frame1, frame1rot,
53 frame2, frame2rot,
54 true /*useLinearReferenceFrameA*/, true /*disableCollisionsBetweenLinkedBodies*/));
55 m_enabled = true;
56 } 45 }
57 46
58 public void Dispose() 47 public virtual void Dispose()
59 { 48 {
60 if (m_enabled) 49 if (m_enabled)
61 { 50 {
62 // BulletSimAPI.RemoveConstraint(m_world.ID, m_body1.ID, m_body2.ID); 51 // BulletSimAPI.RemoveConstraint(m_world.ID, m_body1.ID, m_body2.ID);
63 BulletSimAPI.DestroyConstraint2(m_world.Ptr, m_constraint.Ptr); 52 bool success = BulletSimAPI.DestroyConstraint2(m_world.Ptr, m_constraint.Ptr);
53 m_world.scene.DetailLog("{0},BSConstraint.Dispose,taint,body1={1},body2={2},success={3}", BSScene.DetailLogZero, m_body1.ID, m_body2.ID, success);
54 m_constraint.Ptr = System.IntPtr.Zero;
64 m_enabled = false; 55 m_enabled = false;
65 } 56 }
66 } 57 }
@@ -68,7 +59,7 @@ public class BSConstraint : IDisposable
68 public BulletBody Body1 { get { return m_body1; } } 59 public BulletBody Body1 { get { return m_body1; } }
69 public BulletBody Body2 { get { return m_body2; } } 60 public BulletBody Body2 { get { return m_body2; } }
70 61
71 public bool SetLinearLimits(Vector3 low, Vector3 high) 62 public virtual bool SetLinearLimits(Vector3 low, Vector3 high)
72 { 63 {
73 bool ret = false; 64 bool ret = false;
74 if (m_enabled) 65 if (m_enabled)
@@ -76,7 +67,7 @@ public class BSConstraint : IDisposable
76 return ret; 67 return ret;
77 } 68 }
78 69
79 public bool SetAngularLimits(Vector3 low, Vector3 high) 70 public virtual bool SetAngularLimits(Vector3 low, Vector3 high)
80 { 71 {
81 bool ret = false; 72 bool ret = false;
82 if (m_enabled) 73 if (m_enabled)
@@ -84,34 +75,7 @@ public class BSConstraint : IDisposable
84 return ret; 75 return ret;
85 } 76 }
86 77
87 public bool SetCFMAndERP(float cfm, float erp) 78 public virtual bool CalculateTransforms()
88 {
89 bool ret = true;
90 BulletSimAPI.SetConstraintParam2(m_constraint.Ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
91 BulletSimAPI.SetConstraintParam2(m_constraint.Ptr, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL);
92 BulletSimAPI.SetConstraintParam2(m_constraint.Ptr, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
93 return ret;
94 }
95
96 public bool UseFrameOffset(bool useOffset)
97 {
98 bool ret = false;
99 float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
100 if (m_enabled)
101 ret = BulletSimAPI.UseFrameOffset2(m_constraint.Ptr, onOff);
102 return ret;
103 }
104
105 public bool TranslationalLimitMotor(bool enable, float targetVelocity, float maxMotorForce)
106 {
107 bool ret = false;
108 float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
109 if (m_enabled)
110 ret = BulletSimAPI.TranslationalLimitMotor2(m_constraint.Ptr, onOff, targetVelocity, maxMotorForce);
111 return ret;
112 }
113
114 public bool CalculateTransforms()
115 { 79 {
116 bool ret = false; 80 bool ret = false;
117 if (m_enabled) 81 if (m_enabled)
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
index c88e645..3df2ddc 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
@@ -63,21 +63,13 @@ public class BSConstraintCollection : IDisposable
63 m_constraints.Clear(); 63 m_constraints.Clear();
64 } 64 }
65 65
66 public BSConstraint CreateConstraint(BulletSim world, BulletBody obj1, BulletBody obj2,
67 Vector3 frame1, Quaternion frame1rot,
68 Vector3 frame2, Quaternion frame2rot)
69 {
70 BSConstraint constrain = new BSConstraint(world, obj1, obj2, frame1, frame1rot, frame2, frame2rot);
71
72 this.AddConstraint(constrain);
73 return constrain;
74 }
75
76 public bool AddConstraint(BSConstraint cons) 66 public bool AddConstraint(BSConstraint cons)
77 { 67 {
78 // There is only one constraint between any bodies. Remove any old just to make sure. 68 // There is only one constraint between any bodies. Remove any old just to make sure.
79 RemoveAndDestroyConstraint(cons.Body1, cons.Body2); 69 RemoveAndDestroyConstraint(cons.Body1, cons.Body2);
80 70
71 m_world.scene.DetailLog("{0},BSConstraintCollection.AddConstraint,call,body1={1},body2={2}", BSScene.DetailLogZero, cons.Body1.ID, cons.Body2.ID);
72
81 m_constraints.Add(cons); 73 m_constraints.Add(cons);
82 74
83 return true; 75 return true;
@@ -118,6 +110,7 @@ public class BSConstraintCollection : IDisposable
118 110
119 if (this.TryGetConstraint(body1, body2, out constrain)) 111 if (this.TryGetConstraint(body1, body2, out constrain))
120 { 112 {
113 m_world.scene.DetailLog("{0},BSConstraintCollection.RemoveAndDestroyConstraint,taint,body1={1},body2={2}", BSScene.DetailLogZero, body1.ID, body2.ID);
121 // remove the constraint from our collection 114 // remove the constraint from our collection
122 m_constraints.Remove(constrain); 115 m_constraints.Remove(constrain);
123 // tell the engine that all its structures need to be freed 116 // tell the engine that all its structures need to be freed
@@ -158,10 +151,11 @@ public class BSConstraintCollection : IDisposable
158 151
159 public bool RecalculateAllConstraints() 152 public bool RecalculateAllConstraints()
160 { 153 {
161 foreach (BSConstraint constrain in m_constraints) 154 ForEachConstraint(delegate(BSConstraint constrain)
162 { 155 {
163 constrain.CalculateTransforms(); 156 constrain.CalculateTransforms();
164 } 157 return false;
158 });
165 return true; 159 return true;
166 } 160 }
167 161
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 6f8430c..4a71612 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -40,6 +40,7 @@ public class BSLinkset
40 public BSPrim Root { get { return m_linksetRoot; } } 40 public BSPrim Root { get { return m_linksetRoot; } }
41 41
42 private BSScene m_scene; 42 private BSScene m_scene;
43 public BSScene Scene { get { return m_scene; } }
43 44
44 private List<BSPrim> m_children; 45 private List<BSPrim> m_children;
45 46
@@ -80,14 +81,14 @@ public class BSLinkset
80 81
81 // Link to a linkset where the child knows the parent. 82 // Link to a linkset where the child knows the parent.
82 // Parent changing should not happen so do some sanity checking. 83 // Parent changing should not happen so do some sanity checking.
83 // We return the parent's linkset so the child can track it's membership. 84 // We return the parent's linkset so the child can track its membership.
84 public BSLinkset AddMeToLinkset(BSPrim child, BSPrim parent) 85 public BSLinkset AddMeToLinkset(BSPrim child)
85 { 86 {
86 lock (m_linksetActivityLock) 87 lock (m_linksetActivityLock)
87 { 88 {
88 parent.Linkset.AddChildToLinkset(child); 89 AddChildToLinkset(child);
89 } 90 }
90 return parent.Linkset; 91 return this;
91 } 92 }
92 93
93 public BSLinkset RemoveMeFromLinkset(BSPrim child) 94 public BSLinkset RemoveMeFromLinkset(BSPrim child)
@@ -101,7 +102,7 @@ public class BSLinkset
101 { 102 {
102 // Note that we don't do a foreach because the remove routine 103 // Note that we don't do a foreach because the remove routine
103 // takes it out of the list. 104 // takes it out of the list.
104 RemoveChildFromLinkset(m_children[0]); 105 RemoveChildFromOtherLinkset(m_children[0]);
105 } 106 }
106 m_children.Clear(); // just to make sure 107 m_children.Clear(); // just to make sure
107 } 108 }
@@ -113,9 +114,10 @@ public class BSLinkset
113 } 114 }
114 115
115 // The child is down to a linkset of just itself 116 // The child is down to a linkset of just itself
116 return new BSLinkset(m_scene, child); 117 return new BSLinkset(Scene, child);
117 } 118 }
118 119
120 /* DEPRECATED: this is really bad in that it trys to unlink other prims.
119 // An existing linkset had one of its members rebuilt or something. 121 // An existing linkset had one of its members rebuilt or something.
120 // Go through the linkset and rebuild the pointers to the bodies of the linkset members. 122 // Go through the linkset and rebuild the pointers to the bodies of the linkset members.
121 public BSLinkset RefreshLinkset(BSPrim requestor) 123 public BSLinkset RefreshLinkset(BSPrim requestor)
@@ -124,6 +126,7 @@ public class BSLinkset
124 126
125 lock (m_linksetActivityLock) 127 lock (m_linksetActivityLock)
126 { 128 {
129 // The body pointer is refetched in case anything has moved.
127 System.IntPtr aPtr = BulletSimAPI.GetBodyHandle2(m_scene.World.Ptr, m_linksetRoot.LocalID); 130 System.IntPtr aPtr = BulletSimAPI.GetBodyHandle2(m_scene.World.Ptr, m_linksetRoot.LocalID);
128 if (aPtr == System.IntPtr.Zero) 131 if (aPtr == System.IntPtr.Zero)
129 { 132 {
@@ -155,13 +158,14 @@ public class BSLinkset
155 } 158 }
156 foreach (BSPrim bsp in toRemove) 159 foreach (BSPrim bsp in toRemove)
157 { 160 {
158 RemoveChildFromLinkset(bsp); 161 RemoveChildFromOtherLinkset(bsp);
159 } 162 }
160 } 163 }
161 } 164 }
162 165
163 return ret; 166 return ret;
164 } 167 }
168 */
165 169
166 170
167 // Return 'true' if the passed object is the root object of this linkset 171 // Return 'true' if the passed object is the root object of this linkset
@@ -170,6 +174,8 @@ public class BSLinkset
170 return (requestor.LocalID == m_linksetRoot.LocalID); 174 return (requestor.LocalID == m_linksetRoot.LocalID);
171 } 175 }
172 176
177 public int NumberOfChildren { get { return m_children.Count; } }
178
173 // Return 'true' if this linkset has any children (more than the root member) 179 // Return 'true' if this linkset has any children (more than the root member)
174 public bool HasAnyChildren { get { return (m_children.Count > 0); } } 180 public bool HasAnyChildren { get { return (m_children.Count > 0); } }
175 181
@@ -208,7 +214,8 @@ public class BSLinkset
208 com += bp.Position * bp.MassRaw; 214 com += bp.Position * bp.MassRaw;
209 totalMass += bp.MassRaw; 215 totalMass += bp.MassRaw;
210 } 216 }
211 com /= totalMass; 217 if (totalMass != 0f)
218 com /= totalMass;
212 219
213 return com; 220 return com;
214 } 221 }
@@ -221,51 +228,54 @@ public class BSLinkset
221 { 228 {
222 com += bp.Position * bp.MassRaw; 229 com += bp.Position * bp.MassRaw;
223 } 230 }
224 com /= m_children.Count + 1; 231 com /= (m_children.Count + 1);
225 232
226 return com; 233 return com;
227 } 234 }
228 235
229 // I am the root of a linkset and a new child is being added 236 // I am the root of a linkset and a new child is being added
230 public void AddChildToLinkset(BSPrim pchild) 237 // Called while LinkActivity is locked.
238 public void AddChildToLinkset(BSPrim child)
231 { 239 {
232 BSPrim child = pchild;
233 if (!HasChild(child)) 240 if (!HasChild(child))
234 { 241 {
235 m_children.Add(child); 242 m_children.Add(child);
236 243
237 m_scene.TaintedObject(delegate() 244 BSPrim root = Root; // capture the root as of now
245 m_scene.TaintedObject("AddChildToLinkset", delegate()
238 { 246 {
239 DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, m_linksetRoot.LocalID); 247 DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, m_linksetRoot.LocalID);
240 DetailLog("{0},AddChildToLinkset,child={1}", m_linksetRoot.LocalID, pchild.LocalID); 248 DetailLog("{0},AddChildToLinkset,taint,child={1}", m_linksetRoot.LocalID, child.LocalID);
241 PhysicallyLinkAChildToRoot(pchild); // build the physical binding between me and the child 249 PhysicallyLinkAChildToRoot(root, child); // build the physical binding between me and the child
242 }); 250 });
243 } 251 }
244 return; 252 return;
245 } 253 }
246 254
255 // Forcefully removing a child from a linkset.
256 // This is not being called by the child so we have to make sure the child doesn't think
257 // it's still connected to the linkset.
258 // Normal OpenSimulator operation will never do this because other SceneObjectPart information
259 // has to be updated also (like pointer to prim's parent).
260 public void RemoveChildFromOtherLinkset(BSPrim pchild)
261 {
262 pchild.Linkset = new BSLinkset(m_scene, pchild);
263 RemoveChildFromLinkset(pchild);
264 }
265
247 // I am the root of a linkset and one of my children is being removed. 266 // I am the root of a linkset and one of my children is being removed.
248 // Safe to call even if the child is not really in my linkset. 267 // Safe to call even if the child is not really in my linkset.
249 public void RemoveChildFromLinkset(BSPrim pchild) 268 public void RemoveChildFromLinkset(BSPrim child)
250 { 269 {
251 BSPrim child = pchild;
252
253 if (m_children.Remove(child)) 270 if (m_children.Remove(child))
254 { 271 {
255 m_scene.TaintedObject(delegate() 272 BSPrim root = Root; // capture the root as of now
273 m_scene.TaintedObject("RemoveChildFromLinkset", delegate()
256 { 274 {
257 DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID); 275 DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID);
258 DetailLog("{0},RemoveChildFromLinkset,child={1}", m_linksetRoot.LocalID, pchild.LocalID); 276 DetailLog("{0},RemoveChildFromLinkset,taint,child={1}", m_linksetRoot.LocalID, child.LocalID);
259 277
260 if (m_children.Count == 0) 278 PhysicallyUnlinkAChildFromRoot(root, child);
261 {
262 // if the linkset is empty, make sure all linkages have been removed
263 PhysicallyUnlinkAllChildrenFromRoot();
264 }
265 else
266 {
267 PhysicallyUnlinkAChildFromRoot(pchild);
268 }
269 }); 279 });
270 } 280 }
271 else 281 else
@@ -278,14 +288,14 @@ public class BSLinkset
278 288
279 // Create a constraint between me (root of linkset) and the passed prim (the child). 289 // Create a constraint between me (root of linkset) and the passed prim (the child).
280 // Called at taint time! 290 // Called at taint time!
281 private void PhysicallyLinkAChildToRoot(BSPrim childPrim) 291 private void PhysicallyLinkAChildToRoot(BSPrim rootPrim, BSPrim childPrim)
282 { 292 {
283 // Zero motion for children so they don't interpolate 293 // Zero motion for children so they don't interpolate
284 childPrim.ZeroMotion(); 294 childPrim.ZeroMotion();
285 295
286 // relative position normalized to the root prim 296 // relative position normalized to the root prim
287 OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(m_linksetRoot.Orientation); 297 OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation);
288 OMV.Vector3 childRelativePosition = (childPrim.Position - m_linksetRoot.Position) * invThisOrientation; 298 OMV.Vector3 childRelativePosition = (childPrim.Position - rootPrim.Position) * invThisOrientation;
289 299
290 // relative rotation of the child to the parent 300 // relative rotation of the child to the parent
291 OMV.Quaternion childRelativeRotation = invThisOrientation * childPrim.Orientation; 301 OMV.Quaternion childRelativeRotation = invThisOrientation * childPrim.Orientation;
@@ -293,16 +303,17 @@ public class BSLinkset
293 // create a constraint that allows no freedom of movement between the two objects 303 // create a constraint that allows no freedom of movement between the two objects
294 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 304 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
295 // DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID); 305 // DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID);
296 DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", m_linksetRoot.LocalID, m_linksetRoot.LocalID, childPrim.LocalID); 306 DetailLog("{0},PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, childPrim.LocalID);
297 BSConstraint constrain = m_scene.Constraints.CreateConstraint( 307 BS6DofConstraint constrain = new BS6DofConstraint(
298 m_scene.World, m_linksetRoot.Body, childPrim.Body, 308 m_scene.World, rootPrim.Body, childPrim.Body,
299 // childRelativePosition, 309 childRelativePosition,
300 // childRelativeRotation, 310 childRelativeRotation,
301 OMV.Vector3.Zero,
302 OMV.Quaternion.Identity,
303 OMV.Vector3.Zero, 311 OMV.Vector3.Zero,
304 OMV.Quaternion.Identity 312 -childRelativeRotation
305 ); 313 );
314 m_scene.Constraints.AddConstraint(constrain);
315
316 // zero linear and angular limits makes the objects unable to move in relation to each other
306 constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); 317 constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
307 constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); 318 constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
308 319
@@ -317,29 +328,32 @@ public class BSLinkset
317 328
318 // Remove linkage between myself and a particular child 329 // Remove linkage between myself and a particular child
319 // Called at taint time! 330 // Called at taint time!
320 private void PhysicallyUnlinkAChildFromRoot(BSPrim childPrim) 331 private void PhysicallyUnlinkAChildFromRoot(BSPrim rootPrim, BSPrim childPrim)
321 { 332 {
322 DebugLog("{0}: PhysicallyUnlinkAChildFromRoot: RemoveConstraint between root prim {1} and child prim {2}", 333 // DebugLog("{0}: PhysicallyUnlinkAChildFromRoot: RemoveConstraint between root prim {1} and child prim {2}",
323 LogHeader, m_linksetRoot.LocalID, childPrim.LocalID); 334 // LogHeader, rootPrim.LocalID, childPrim.LocalID);
324 DetailLog("{0},PhysicallyUnlinkAChildFromRoot,taint,root={1},child={2}", m_linksetRoot.LocalID, m_linksetRoot.LocalID, childPrim.LocalID); 335 DetailLog("{0},PhysicallyUnlinkAChildFromRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, childPrim.LocalID);
325 // BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, childPrim.LocalID); 336
326 m_scene.Constraints.RemoveAndDestroyConstraint(m_linksetRoot.Body, childPrim.Body); 337 m_scene.Constraints.RemoveAndDestroyConstraint(rootPrim.Body, childPrim.Body);
338 // Make the child refresh its location
339 BulletSimAPI.PushUpdate2(childPrim.Body.Ptr);
327 } 340 }
328 341
329 // Remove linkage between myself and any possible children I might have 342 // Remove linkage between myself and any possible children I might have
330 // Called at taint time! 343 // Called at taint time!
331 private void PhysicallyUnlinkAllChildrenFromRoot() 344 private void PhysicallyUnlinkAllChildrenFromRoot(BSPrim rootPrim)
332 { 345 {
333 // DebugLog("{0}: PhysicallyUnlinkAllChildren:", LogHeader); 346 // DebugLog("{0}: PhysicallyUnlinkAllChildren:", LogHeader);
334 DetailLog("{0},PhysicallyUnlinkAllChildren,taint", m_linksetRoot.LocalID); 347 DetailLog("{0},PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID);
335 m_scene.Constraints.RemoveAndDestroyConstraint(m_linksetRoot.Body); 348
336 // BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID); 349 m_scene.Constraints.RemoveAndDestroyConstraint(rootPrim.Body);
337 } 350 }
338 351
339 // Invoke the detailed logger and output something if it's enabled. 352 // Invoke the detailed logger and output something if it's enabled.
340 private void DebugLog(string msg, params Object[] args) 353 private void DebugLog(string msg, params Object[] args)
341 { 354 {
342 m_scene.Logger.DebugFormat(msg, args); 355 if (m_scene.ShouldDebugLog)
356 m_scene.Logger.DebugFormat(msg, args);
343 } 357 }
344 358
345 // Invoke the detailed logger and output something if it's enabled. 359 // Invoke the detailed logger and output something if it's enabled.
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 11868bc..05cc822 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -42,7 +42,7 @@ public sealed class BSPrim : PhysicsActor
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 private static readonly string LogHeader = "[BULLETS PRIM]"; 43 private static readonly string LogHeader = "[BULLETS PRIM]";
44 44
45 private void DebugLog(string mm, params Object[] xx) { if (_scene.shouldDebugLog) m_log.DebugFormat(mm, xx); } 45 private void DebugLog(string mm, params Object[] xx) { if (_scene.ShouldDebugLog) m_log.DebugFormat(mm, xx); }
46 46
47 private IMesh _mesh; 47 private IMesh _mesh;
48 private PrimitiveBaseShape _pbs; 48 private PrimitiveBaseShape _pbs;
@@ -138,14 +138,15 @@ public sealed class BSPrim : PhysicsActor
138 _isPhysical = pisPhysical; 138 _isPhysical = pisPhysical;
139 _isVolumeDetect = false; 139 _isVolumeDetect = false;
140 _subscribedEventsMs = 0; 140 _subscribedEventsMs = 0;
141 _friction = _scene.Params.defaultFriction; // TODO: compute based on object material 141 _friction = _scene.Params.defaultFriction; // TODO: compute based on object material
142 _density = _scene.Params.defaultDensity; // TODO: compute based on object material 142 _density = _scene.Params.defaultDensity; // TODO: compute based on object material
143 _restitution = _scene.Params.defaultRestitution; 143 _restitution = _scene.Params.defaultRestitution;
144 _linkset = new BSLinkset(_scene, this); // a linkset of one 144 _linkset = new BSLinkset(_scene, this); // a linkset of one
145 _vehicle = new BSDynamics(this); // add vehicleness 145 _vehicle = new BSDynamics(this); // add vehicleness
146 _mass = CalculateMass(); 146 _mass = CalculateMass();
147 // do the actual object creation at taint time 147 // do the actual object creation at taint time
148 _scene.TaintedObject(delegate() 148 DetailLog("{0},BSPrim.constructor,call", LocalID);
149 _scene.TaintedObject("BSPrim.create", delegate()
149 { 150 {
150 RecreateGeomAndObject(); 151 RecreateGeomAndObject();
151 152
@@ -160,17 +161,22 @@ public sealed class BSPrim : PhysicsActor
160 public void Destroy() 161 public void Destroy()
161 { 162 {
162 // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); 163 // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID);
163 // DetailLog("{0},Destroy", LocalID); 164
165 // Undo any links between me and any other object
166 BSPrim parentBefore = _linkset.Root;
167 int childrenBefore = _linkset.NumberOfChildren;
168
169 _linkset = _linkset.RemoveMeFromLinkset(this);
170
171 DetailLog("{0},BSPrim.Destroy,call,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}",
172 LocalID, parentBefore.LocalID, childrenBefore, _linkset.Root.LocalID, _linkset.NumberOfChildren);
164 173
165 // Undo any vehicle properties 174 // Undo any vehicle properties
166 _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); 175 this.VehicleType = (int)Vehicle.TYPE_NONE;
167 _scene.RemoveVehiclePrim(this); // just to make sure
168 176
169 _scene.TaintedObject(delegate() 177 _scene.TaintedObject("BSPrim.destroy", delegate()
170 { 178 {
171 // Undo any links between me and any other object 179 DetailLog("{0},BSPrim.Destroy,taint,", LocalID);
172 _linkset = _linkset.RemoveMeFromLinkset(this);
173
174 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. 180 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff.
175 BulletSimAPI.DestroyObject(_scene.WorldID, LocalID); 181 BulletSimAPI.DestroyObject(_scene.WorldID, LocalID);
176 }); 182 });
@@ -183,11 +189,11 @@ public sealed class BSPrim : PhysicsActor
183 get { return _size; } 189 get { return _size; }
184 set { 190 set {
185 _size = value; 191 _size = value;
186 _scene.TaintedObject(delegate() 192 _scene.TaintedObject("BSPrim.setSize", delegate()
187 { 193 {
188 _mass = CalculateMass(); // changing size changes the mass 194 _mass = CalculateMass(); // changing size changes the mass
189 BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical); 195 BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical);
190 // DetailLog("{0}: setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical); 196 // DetailLog("{0}: BSPrim.setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical);
191 RecreateGeomAndObject(); 197 RecreateGeomAndObject();
192 }); 198 });
193 } 199 }
@@ -195,7 +201,7 @@ public sealed class BSPrim : PhysicsActor
195 public override PrimitiveBaseShape Shape { 201 public override PrimitiveBaseShape Shape {
196 set { 202 set {
197 _pbs = value; 203 _pbs = value;
198 _scene.TaintedObject(delegate() 204 _scene.TaintedObject("BSPrim.setShape", delegate()
199 { 205 {
200 _mass = CalculateMass(); // changing the shape changes the mass 206 _mass = CalculateMass(); // changing the shape changes the mass
201 RecreateGeomAndObject(); 207 RecreateGeomAndObject();
@@ -213,7 +219,7 @@ public sealed class BSPrim : PhysicsActor
213 public override bool Selected { 219 public override bool Selected {
214 set { 220 set {
215 _isSelected = value; 221 _isSelected = value;
216 _scene.TaintedObject(delegate() 222 _scene.TaintedObject("BSPrim.setSelected", delegate()
217 { 223 {
218 SetObjectDynamic(); 224 SetObjectDynamic();
219 }); 225 });
@@ -224,10 +230,17 @@ public sealed class BSPrim : PhysicsActor
224 // link me to the specified parent 230 // link me to the specified parent
225 public override void link(PhysicsActor obj) { 231 public override void link(PhysicsActor obj) {
226 BSPrim parent = obj as BSPrim; 232 BSPrim parent = obj as BSPrim;
227 DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID); 233 if (parent != null)
228 DetailLog("{0},link,parent={1}", LocalID, obj.LocalID); 234 {
235 DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, parent.LocalID);
236 BSPrim parentBefore = _linkset.Root;
237 int childrenBefore = _linkset.NumberOfChildren;
229 238
230 _linkset = _linkset.AddMeToLinkset(this, parent); 239 _linkset = parent.Linkset.AddMeToLinkset(this);
240
241 DetailLog("{0},BSPrim.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}",
242 LocalID, parentBefore.LocalID, childrenBefore, _linkset.Root.LocalID, _linkset.NumberOfChildren);
243 }
231 return; 244 return;
232 } 245 }
233 246
@@ -237,9 +250,14 @@ public sealed class BSPrim : PhysicsActor
237 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen 250 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen
238 DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID, 251 DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID,
239 _linkset.Root._avName+"/"+_linkset.Root.LocalID.ToString()); 252 _linkset.Root._avName+"/"+_linkset.Root.LocalID.ToString());
240 DetailLog("{0},delink,parent={1}", LocalID, _linkset.Root.LocalID.ToString());
241 253
242 _linkset.RemoveMeFromLinkset(this); 254 BSPrim parentBefore = _linkset.Root;
255 int childrenBefore = _linkset.NumberOfChildren;
256
257 _linkset = _linkset.RemoveMeFromLinkset(this);
258
259 DetailLog("{0},BSPrim.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ",
260 LocalID, parentBefore.LocalID, childrenBefore, _linkset.Root.LocalID, _linkset.NumberOfChildren);
243 return; 261 return;
244 } 262 }
245 263
@@ -262,7 +280,7 @@ public sealed class BSPrim : PhysicsActor
262 280
263 public override void LockAngularMotion(OMV.Vector3 axis) 281 public override void LockAngularMotion(OMV.Vector3 axis)
264 { 282 {
265 DetailLog("{0},LockAngularMotion,call,axis={1}", LocalID, axis); 283 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis);
266 return; 284 return;
267 } 285 }
268 286
@@ -279,9 +297,9 @@ public sealed class BSPrim : PhysicsActor
279 set { 297 set {
280 _position = value; 298 _position = value;
281 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? 299 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint?
282 _scene.TaintedObject(delegate() 300 _scene.TaintedObject("BSPrim.setPosition", delegate()
283 { 301 {
284 DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 302 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
285 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); 303 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
286 }); 304 });
287 } 305 }
@@ -316,9 +334,9 @@ public sealed class BSPrim : PhysicsActor
316 get { return _force; } 334 get { return _force; }
317 set { 335 set {
318 _force = value; 336 _force = value;
319 _scene.TaintedObject(delegate() 337 _scene.TaintedObject("BSPrim.setForce", delegate()
320 { 338 {
321 DetailLog("{0},setForce,taint,force={1}", LocalID, _force); 339 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force);
322 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); 340 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
323 BulletSimAPI.SetObjectForce2(Body.Ptr, _force); 341 BulletSimAPI.SetObjectForce2(Body.Ptr, _force);
324 }); 342 });
@@ -331,53 +349,41 @@ public sealed class BSPrim : PhysicsActor
331 } 349 }
332 set { 350 set {
333 Vehicle type = (Vehicle)value; 351 Vehicle type = (Vehicle)value;
334 _scene.TaintedObject(delegate() 352 BSPrim vehiclePrim = this;
353 _scene.TaintedObject("setVehicleType", delegate()
335 { 354 {
336 DetailLog("{0},SetVehicleType,taint,type={1}", LocalID, type); 355 // Done at taint time so we're sure the physics engine is not using the variables
356 // Vehicle code changes the parameters for this vehicle type.
337 _vehicle.ProcessTypeChange(type); 357 _vehicle.ProcessTypeChange(type);
338 if (type == Vehicle.TYPE_NONE) 358 // Tell the scene about the vehicle so it will get processing each frame.
339 { 359 _scene.VehicleInSceneTypeChanged(this, type);
340 _scene.RemoveVehiclePrim(this);
341 }
342 else
343 {
344 _scene.TaintedObject(delegate()
345 {
346 // Tell the physics engine to clear state
347 BulletSimAPI.ClearForces2(this.Body.Ptr);
348 });
349
350 // make it so the scene will call us each tick to do vehicle things
351 _scene.AddVehiclePrim(this);
352 }
353 return;
354 }); 360 });
355 } 361 }
356 } 362 }
357 public override void VehicleFloatParam(int param, float value) 363 public override void VehicleFloatParam(int param, float value)
358 { 364 {
359 _scene.TaintedObject(delegate() 365 _scene.TaintedObject("BSPrim.VehicleFloatParam", delegate()
360 { 366 {
361 _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); 367 _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep);
362 }); 368 });
363 } 369 }
364 public override void VehicleVectorParam(int param, OMV.Vector3 value) 370 public override void VehicleVectorParam(int param, OMV.Vector3 value)
365 { 371 {
366 _scene.TaintedObject(delegate() 372 _scene.TaintedObject("BSPrim.VehicleVectorParam", delegate()
367 { 373 {
368 _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); 374 _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep);
369 }); 375 });
370 } 376 }
371 public override void VehicleRotationParam(int param, OMV.Quaternion rotation) 377 public override void VehicleRotationParam(int param, OMV.Quaternion rotation)
372 { 378 {
373 _scene.TaintedObject(delegate() 379 _scene.TaintedObject("BSPrim.VehicleRotationParam", delegate()
374 { 380 {
375 _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); 381 _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
376 }); 382 });
377 } 383 }
378 public override void VehicleFlags(int param, bool remove) 384 public override void VehicleFlags(int param, bool remove)
379 { 385 {
380 _scene.TaintedObject(delegate() 386 _scene.TaintedObject("BSPrim.VehicleFlags", delegate()
381 { 387 {
382 _vehicle.ProcessVehicleFlags(param, remove); 388 _vehicle.ProcessVehicleFlags(param, remove);
383 }); 389 });
@@ -395,7 +401,7 @@ public sealed class BSPrim : PhysicsActor
395 public override void SetVolumeDetect(int param) { 401 public override void SetVolumeDetect(int param) {
396 bool newValue = (param != 0); 402 bool newValue = (param != 0);
397 _isVolumeDetect = newValue; 403 _isVolumeDetect = newValue;
398 _scene.TaintedObject(delegate() 404 _scene.TaintedObject("BSPrim.SetVolumeDetect", delegate()
399 { 405 {
400 SetObjectDynamic(); 406 SetObjectDynamic();
401 }); 407 });
@@ -406,9 +412,9 @@ public sealed class BSPrim : PhysicsActor
406 get { return _velocity; } 412 get { return _velocity; }
407 set { 413 set {
408 _velocity = value; 414 _velocity = value;
409 _scene.TaintedObject(delegate() 415 _scene.TaintedObject("BSPrim.setVelocity", delegate()
410 { 416 {
411 DetailLog("{0},SetVelocity,taint,vel={1}", LocalID, _velocity); 417 DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity);
412 BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity); 418 BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity);
413 }); 419 });
414 } 420 }
@@ -416,7 +422,7 @@ public sealed class BSPrim : PhysicsActor
416 public override OMV.Vector3 Torque { 422 public override OMV.Vector3 Torque {
417 get { return _torque; } 423 get { return _torque; }
418 set { _torque = value; 424 set { _torque = value;
419 DetailLog("{0},SetTorque,call,torque={1}", LocalID, _torque); 425 DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque);
420 } 426 }
421 } 427 }
422 public override float CollisionScore { 428 public override float CollisionScore {
@@ -440,10 +446,10 @@ public sealed class BSPrim : PhysicsActor
440 set { 446 set {
441 _orientation = value; 447 _orientation = value;
442 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? 448 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint?
443 _scene.TaintedObject(delegate() 449 _scene.TaintedObject("BSPrim.setOrientation", delegate()
444 { 450 {
445 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); 451 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
446 DetailLog("{0},setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); 452 DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
447 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); 453 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
448 }); 454 });
449 } 455 }
@@ -457,7 +463,7 @@ public sealed class BSPrim : PhysicsActor
457 get { return _isPhysical; } 463 get { return _isPhysical; }
458 set { 464 set {
459 _isPhysical = value; 465 _isPhysical = value;
460 _scene.TaintedObject(delegate() 466 _scene.TaintedObject("BSPrim.setIsPhysical", delegate()
461 { 467 {
462 SetObjectDynamic(); 468 SetObjectDynamic();
463 }); 469 });
@@ -478,7 +484,6 @@ public sealed class BSPrim : PhysicsActor
478 484
479 // Make gravity work if the object is physical and not selected 485 // Make gravity work if the object is physical and not selected
480 // No locking here because only called when it is safe 486 // No locking here because only called when it is safe
481 // Only called at taint time so it is save to call into Bullet.
482 private void SetObjectDynamic() 487 private void SetObjectDynamic()
483 { 488 {
484 // RA: remove this for the moment. 489 // RA: remove this for the moment.
@@ -490,8 +495,10 @@ public sealed class BSPrim : PhysicsActor
490 // Bullet wants static objects to have a mass of zero 495 // Bullet wants static objects to have a mass of zero
491 float mass = IsStatic ? 0f : _mass; 496 float mass = IsStatic ? 0f : _mass;
492 497
493 DetailLog("{0},SetObjectDynamic,taint,static={1},solid={2},mass={3}", LocalID, IsStatic, IsSolid, mass);
494 BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); 498 BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass);
499
500 CollisionFlags cf = BulletSimAPI.GetCollisionFlags2(Body.Ptr);
501 DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, cf);
495 } 502 }
496 503
497 // prims don't fly 504 // prims don't fly
@@ -546,9 +553,9 @@ public sealed class BSPrim : PhysicsActor
546 set { 553 set {
547 _rotationalVelocity = value; 554 _rotationalVelocity = value;
548 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); 555 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity);
549 _scene.TaintedObject(delegate() 556 _scene.TaintedObject("BSPrim.setRotationalVelocity", delegate()
550 { 557 {
551 DetailLog("{0},SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); 558 DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity);
552 BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity); 559 BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity);
553 }); 560 });
554 } 561 }
@@ -563,9 +570,9 @@ public sealed class BSPrim : PhysicsActor
563 get { return _buoyancy; } 570 get { return _buoyancy; }
564 set { 571 set {
565 _buoyancy = value; 572 _buoyancy = value;
566 _scene.TaintedObject(delegate() 573 _scene.TaintedObject("BSPrim.setBuoyancy", delegate()
567 { 574 {
568 DetailLog("{0},SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 575 DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
569 BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); 576 BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy);
570 }); 577 });
571 } 578 }
@@ -617,7 +624,7 @@ public sealed class BSPrim : PhysicsActor
617 m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader); 624 m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader);
618 return; 625 return;
619 } 626 }
620 _scene.TaintedObject(delegate() 627 _scene.TaintedObject("BSPrim.AddForce", delegate()
621 { 628 {
622 OMV.Vector3 fSum = OMV.Vector3.Zero; 629 OMV.Vector3 fSum = OMV.Vector3.Zero;
623 lock (m_accumulatedForces) 630 lock (m_accumulatedForces)
@@ -628,17 +635,17 @@ public sealed class BSPrim : PhysicsActor
628 } 635 }
629 m_accumulatedForces.Clear(); 636 m_accumulatedForces.Clear();
630 } 637 }
631 DetailLog("{0},AddObjectForce,taint,force={1}", LocalID, _force); 638 DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force);
632 BulletSimAPI.AddObjectForce2(Body.Ptr, fSum); 639 BulletSimAPI.AddObjectForce2(Body.Ptr, fSum);
633 }); 640 });
634 } 641 }
635 642
636 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { 643 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) {
637 DetailLog("{0},AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); 644 DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce);
638 // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); 645 // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce);
639 } 646 }
640 public override void SetMomentum(OMV.Vector3 momentum) { 647 public override void SetMomentum(OMV.Vector3 momentum) {
641 DetailLog("{0},SetMomentum,call,mom={1}", LocalID, momentum); 648 DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum);
642 } 649 }
643 public override void SubscribeEvents(int ms) { 650 public override void SubscribeEvents(int ms) {
644 _subscribedEventsMs = ms; 651 _subscribedEventsMs = ms;
@@ -647,7 +654,7 @@ public sealed class BSPrim : PhysicsActor
647 // make sure first collision happens 654 // make sure first collision happens
648 _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; 655 _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs;
649 656
650 Scene.TaintedObject(delegate() 657 Scene.TaintedObject("BSPrim.SubscribeEvents", delegate()
651 { 658 {
652 BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 659 BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
653 }); 660 });
@@ -655,7 +662,7 @@ public sealed class BSPrim : PhysicsActor
655 } 662 }
656 public override void UnSubscribeEvents() { 663 public override void UnSubscribeEvents() {
657 _subscribedEventsMs = 0; 664 _subscribedEventsMs = 0;
658 Scene.TaintedObject(delegate() 665 Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate()
659 { 666 {
660 BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 667 BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
661 }); 668 });
@@ -982,7 +989,7 @@ public sealed class BSPrim : PhysicsActor
982 // m_log.DebugFormat("{0}: CreateGeom: Defaulting to sphere of size {1}", LogHeader, _size); 989 // m_log.DebugFormat("{0}: CreateGeom: Defaulting to sphere of size {1}", LogHeader, _size);
983 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_SPHERE)) 990 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_SPHERE))
984 { 991 {
985 DetailLog("{0},CreateGeom,sphere", LocalID); 992 DetailLog("{0},BSPrim.CreateGeom,sphere (force={1}", LocalID, forceRebuild);
986 _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE; 993 _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE;
987 // Bullet native objects are scaled by the Bullet engine so pass the size in 994 // Bullet native objects are scaled by the Bullet engine so pass the size in
988 _scale = _size; 995 _scale = _size;
@@ -996,7 +1003,7 @@ public sealed class BSPrim : PhysicsActor
996 // m_log.DebugFormat("{0}: CreateGeom: Defaulting to box. lid={1}, type={2}, size={3}", LogHeader, LocalID, _shapeType, _size); 1003 // m_log.DebugFormat("{0}: CreateGeom: Defaulting to box. lid={1}, type={2}, size={3}", LogHeader, LocalID, _shapeType, _size);
997 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_BOX)) 1004 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_BOX))
998 { 1005 {
999 DetailLog("{0},CreateGeom,box", LocalID); 1006 DetailLog("{0},BSPrim.CreateGeom,box (force={1})", LocalID, forceRebuild);
1000 _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX; 1007 _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX;
1001 _scale = _size; 1008 _scale = _size;
1002 // TODO: do we need to check for and destroy a mesh or hull that might have been left from before? 1009 // TODO: do we need to check for and destroy a mesh or hull that might have been left from before?
@@ -1039,12 +1046,12 @@ public sealed class BSPrim : PhysicsActor
1039 // if this new shape is the same as last time, don't recreate the mesh 1046 // if this new shape is the same as last time, don't recreate the mesh
1040 if (_meshKey == newMeshKey) return; 1047 if (_meshKey == newMeshKey) return;
1041 1048
1042 DetailLog("{0},CreateGeomMesh,create,key={1}", LocalID, newMeshKey); 1049 DetailLog("{0},BSPrim.CreateGeomMesh,create,key={1}", LocalID, newMeshKey);
1043 // Since we're recreating new, get rid of any previously generated shape 1050 // Since we're recreating new, get rid of any previously generated shape
1044 if (_meshKey != 0) 1051 if (_meshKey != 0)
1045 { 1052 {
1046 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); 1053 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey);
1047 DetailLog("{0},CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); 1054 DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey);
1048 BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); 1055 BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey);
1049 _mesh = null; 1056 _mesh = null;
1050 _meshKey = 0; 1057 _meshKey = 0;
@@ -1074,7 +1081,7 @@ public sealed class BSPrim : PhysicsActor
1074 _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH; 1081 _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH;
1075 // meshes are already scaled by the meshmerizer 1082 // meshes are already scaled by the meshmerizer
1076 _scale = new OMV.Vector3(1f, 1f, 1f); 1083 _scale = new OMV.Vector3(1f, 1f, 1f);
1077 DetailLog("{0},CreateGeomMesh,done", LocalID); 1084 DetailLog("{0},BSPrim.CreateGeomMesh,done", LocalID);
1078 return; 1085 return;
1079 } 1086 }
1080 1087
@@ -1088,17 +1095,17 @@ public sealed class BSPrim : PhysicsActor
1088 // if the hull hasn't changed, don't rebuild it 1095 // if the hull hasn't changed, don't rebuild it
1089 if (newHullKey == _hullKey) return; 1096 if (newHullKey == _hullKey) return;
1090 1097
1091 DetailLog("{0},CreateGeomHull,create,key={1}", LocalID, _meshKey); 1098 DetailLog("{0},BSPrim.CreateGeomHull,create,key={1}", LocalID, _meshKey);
1092 1099
1093 // Since we're recreating new, get rid of any previously generated shape 1100 // Since we're recreating new, get rid of any previously generated shape
1094 if (_hullKey != 0) 1101 if (_hullKey != 0)
1095 { 1102 {
1096 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey); 1103 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey);
1097 DetailLog("{0},CreateGeomHull,deleteOldHull,key={1}", LocalID, _meshKey); 1104 DetailLog("{0},BSPrim.CreateGeomHull,deleteOldHull,key={1}", LocalID, _meshKey);
1098 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey); 1105 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey);
1099 _hullKey = 0; 1106 _hullKey = 0;
1100 _hulls.Clear(); 1107 _hulls.Clear();
1101 DetailLog("{0},CreateGeomHull,deleteOldMesh,key={1}", LocalID, _meshKey); 1108 DetailLog("{0},BSPrim.CreateGeomHull,deleteOldMesh,key={1}", LocalID, _meshKey);
1102 BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); 1109 BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey);
1103 _mesh = null; // the mesh cannot match either 1110 _mesh = null; // the mesh cannot match either
1104 _meshKey = 0; 1111 _meshKey = 0;
@@ -1195,7 +1202,7 @@ public sealed class BSPrim : PhysicsActor
1195 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; 1202 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL;
1196 // meshes are already scaled by the meshmerizer 1203 // meshes are already scaled by the meshmerizer
1197 _scale = new OMV.Vector3(1f, 1f, 1f); 1204 _scale = new OMV.Vector3(1f, 1f, 1f);
1198 DetailLog("{0},CreateGeomHull,done", LocalID); 1205 DetailLog("{0},BSPrim.CreateGeomHull,done", LocalID);
1199 return; 1206 return;
1200 } 1207 }
1201 1208
@@ -1221,7 +1228,7 @@ public sealed class BSPrim : PhysicsActor
1221 bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape); 1228 bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape);
1222 1229
1223 // the CreateObject() may have recreated the rigid body. Make sure we have the latest. 1230 // the CreateObject() may have recreated the rigid body. Make sure we have the latest.
1224 m_body.Ptr = BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID); 1231 Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID));
1225 1232
1226 return ret; 1233 return ret;
1227 } 1234 }
@@ -1333,20 +1340,18 @@ public sealed class BSPrim : PhysicsActor
1333 1340
1334 // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}, vel={5}, acc={6}, rvel={7}", 1341 // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}, vel={5}, acc={6}, rvel={7}",
1335 // LogHeader, LocalID, changed, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); 1342 // LogHeader, LocalID, changed, _position, _orientation, _velocity, _acceleration, _rotationalVelocity);
1336 DetailLog("{0},UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", 1343 DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
1337 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); 1344 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity);
1338 1345
1339 base.RequestPhysicsterseUpdate(); 1346 base.RequestPhysicsterseUpdate();
1340 } 1347 }
1341 /*
1342 else 1348 else
1343 { 1349 {
1344 // For debugging, we also report the movement of children 1350 // For debugging, we also report the movement of children
1345 DetailLog("{0},UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", 1351 DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
1346 LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, 1352 LocalID, entprop.Position, entprop.Rotation, entprop.Velocity,
1347 entprop.Acceleration, entprop.RotationalVelocity); 1353 entprop.Acceleration, entprop.RotationalVelocity);
1348 } 1354 }
1349 */
1350 } 1355 }
1351 1356
1352 // I've collided with something 1357 // I've collided with something
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 0e257b6..beaea1f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -73,7 +73,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
73 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 73 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
74 private static readonly string LogHeader = "[BULLETS SCENE]"; 74 private static readonly string LogHeader = "[BULLETS SCENE]";
75 75
76 public void DebugLog(string mm, params Object[] xx) { if (shouldDebugLog) m_log.DebugFormat(mm, xx); } 76 public void DebugLog(string mm, params Object[] xx) { if (ShouldDebugLog) m_log.DebugFormat(mm, xx); }
77 77
78 public string BulletSimVersion = "?"; 78 public string BulletSimVersion = "?";
79 79
@@ -162,14 +162,24 @@ public class BSScene : PhysicsScene, IPhysicsParameters
162 } 162 }
163 163
164 public delegate void TaintCallback(); 164 public delegate void TaintCallback();
165 private List<TaintCallback> _taintedObjects; 165 private struct TaintCallbackEntry
166 {
167 public String ident;
168 public TaintCallback callback;
169 public TaintCallbackEntry(string i, TaintCallback c)
170 {
171 ident = i;
172 callback = c;
173 }
174 }
175 private List<TaintCallbackEntry> _taintedObjects;
166 private Object _taintLock = new Object(); 176 private Object _taintLock = new Object();
167 177
168 // A pointer to an instance if this structure is passed to the C++ code 178 // A pointer to an instance if this structure is passed to the C++ code
169 ConfigurationParameters[] m_params; 179 ConfigurationParameters[] m_params;
170 GCHandle m_paramsHandle; 180 GCHandle m_paramsHandle;
171 181
172 public bool shouldDebugLog { get; private set; } 182 public bool ShouldDebugLog { get; private set; }
173 183
174 private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; 184 private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle;
175 185
@@ -232,7 +242,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
232 BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); 242 BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle);
233 } 243 }
234 244
235 _taintedObjects = new List<TaintCallback>(); 245 _taintedObjects = new List<TaintCallbackEntry>();
236 246
237 mesher = meshmerizer; 247 mesher = meshmerizer;
238 // The bounding box for the simulated world 248 // The bounding box for the simulated world
@@ -245,7 +255,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
245 255
246 // Initialization to support the transition to a new API which puts most of the logic 256 // Initialization to support the transition to a new API which puts most of the logic
247 // into the C# code so it is easier to modify and add to. 257 // into the C# code so it is easier to modify and add to.
248 m_worldSim = new BulletSim(m_worldID, BulletSimAPI.GetSimHandle2(m_worldID)); 258 m_worldSim = new BulletSim(m_worldID, this, BulletSimAPI.GetSimHandle2(m_worldID));
249 m_constraintCollection = new BSConstraintCollection(World); 259 m_constraintCollection = new BSConstraintCollection(World);
250 260
251 m_initialized = true; 261 m_initialized = true;
@@ -352,6 +362,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
352 BSPrim bsprim = prim as BSPrim; 362 BSPrim bsprim = prim as BSPrim;
353 if (bsprim != null) 363 if (bsprim != null)
354 { 364 {
365 DetailLog("{0},RemovePrim,call", bsprim.LocalID);
355 // m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID); 366 // m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID);
356 try 367 try
357 { 368 {
@@ -377,6 +388,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
377 388
378 if (!m_initialized) return null; 389 if (!m_initialized) return null;
379 390
391 DetailLog("{0},AddPrimShape,call", localID);
392
380 BSPrim prim = new BSPrim(localID, primName, this, position, size, rotation, pbs, isPhysical); 393 BSPrim prim = new BSPrim(localID, primName, this, position, size, rotation, pbs, isPhysical);
381 lock (m_prims) m_prims.Add(localID, prim); 394 lock (m_prims) m_prims.Add(localID, prim);
382 return prim; 395 return prim;
@@ -416,12 +429,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters
416 { 429 {
417 numSubSteps = BulletSimAPI.PhysicsStep(m_worldID, timeStep, m_maxSubSteps, m_fixedTimeStep, 430 numSubSteps = BulletSimAPI.PhysicsStep(m_worldID, timeStep, m_maxSubSteps, m_fixedTimeStep,
418 out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); 431 out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr);
419 DetailLog("{0},Simulate,call, substeps={1}, updates={2}, colliders={3}", "0000000000", numSubSteps, updatedEntityCount, collidersCount); 432 DetailLog("{0},Simulate,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount);
420 } 433 }
421 catch (Exception e) 434 catch (Exception e)
422 { 435 {
423 m_log.WarnFormat("{0},PhysicsStep Exception: substeps={1}, updates={2}, colliders={3}, e={4}", LogHeader, numSubSteps, updatedEntityCount, collidersCount, e); 436 m_log.WarnFormat("{0},PhysicsStep Exception: substeps={1}, updates={2}, colliders={3}, e={4}", LogHeader, numSubSteps, updatedEntityCount, collidersCount, e);
424 DetailLog("{0},PhysicsStepException,call, substeps={1}, updates={2}, colliders={3}", "0000000000", numSubSteps, updatedEntityCount, collidersCount); 437 DetailLog("{0},PhysicsStepException,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount);
425 // updatedEntityCount = 0; 438 // updatedEntityCount = 0;
426 collidersCount = 0; 439 collidersCount = 0;
427 } 440 }
@@ -535,7 +548,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
535 548
536 public override void SetTerrain(float[] heightMap) { 549 public override void SetTerrain(float[] heightMap) {
537 m_heightMap = heightMap; 550 m_heightMap = heightMap;
538 this.TaintedObject(delegate() 551 this.TaintedObject("BSScene.SetTerrain", delegate()
539 { 552 {
540 BulletSimAPI.SetHeightmap(m_worldID, m_heightMap); 553 BulletSimAPI.SetHeightmap(m_worldID, m_heightMap);
541 }); 554 });
@@ -727,12 +740,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters
727 // Calls to the PhysicsActors can't directly call into the physics engine 740 // Calls to the PhysicsActors can't directly call into the physics engine
728 // because it might be busy. We delay changes to a known time. 741 // because it might be busy. We delay changes to a known time.
729 // We rely on C#'s closure to save and restore the context for the delegate. 742 // We rely on C#'s closure to save and restore the context for the delegate.
730 public void TaintedObject(TaintCallback callback) 743 public void TaintedObject(String ident, TaintCallback callback)
731 { 744 {
732 if (!m_initialized) return; 745 if (!m_initialized) return;
733 746
734 lock (_taintLock) 747 lock (_taintLock)
735 _taintedObjects.Add(callback); 748 _taintedObjects.Add(new TaintCallbackEntry(ident, callback));
736 return; 749 return;
737 } 750 }
738 751
@@ -744,22 +757,22 @@ public class BSScene : PhysicsScene, IPhysicsParameters
744 if (_taintedObjects.Count > 0) // save allocating new list if there is nothing to process 757 if (_taintedObjects.Count > 0) // save allocating new list if there is nothing to process
745 { 758 {
746 // swizzle a new list into the list location so we can process what's there 759 // swizzle a new list into the list location so we can process what's there
747 List<TaintCallback> oldList; 760 List<TaintCallbackEntry> oldList;
748 lock (_taintLock) 761 lock (_taintLock)
749 { 762 {
750 oldList = _taintedObjects; 763 oldList = _taintedObjects;
751 _taintedObjects = new List<TaintCallback>(); 764 _taintedObjects = new List<TaintCallbackEntry>();
752 } 765 }
753 766
754 foreach (TaintCallback callback in oldList) 767 foreach (TaintCallbackEntry tcbe in oldList)
755 { 768 {
756 try 769 try
757 { 770 {
758 callback(); 771 tcbe.callback();
759 } 772 }
760 catch (Exception e) 773 catch (Exception e)
761 { 774 {
762 m_log.ErrorFormat("{0}: ProcessTaints: Exception: {1}", LogHeader, e); 775 m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, tcbe.ident, e);
763 } 776 }
764 } 777 }
765 oldList.Clear(); 778 oldList.Clear();
@@ -767,6 +780,20 @@ public class BSScene : PhysicsScene, IPhysicsParameters
767 } 780 }
768 781
769 #region Vehicles 782 #region Vehicles
783
784 public void VehicleInSceneTypeChanged(BSPrim vehic, Vehicle newType)
785 {
786 if (newType == Vehicle.TYPE_NONE)
787 {
788 RemoveVehiclePrim(vehic);
789 }
790 else
791 {
792 // make it so the scene will call us each tick to do vehicle things
793 AddVehiclePrim(vehic);
794 }
795 }
796
770 // Make so the scene will call this prim for vehicle actions each tick. 797 // Make so the scene will call this prim for vehicle actions each tick.
771 // Safe to call if prim is already in the vehicle list. 798 // Safe to call if prim is already in the vehicle list.
772 public void AddVehiclePrim(BSPrim vehicle) 799 public void AddVehiclePrim(BSPrim vehicle)
@@ -812,12 +839,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters
812 839
813 private struct ParameterDefn 840 private struct ParameterDefn
814 { 841 {
815 public string name; 842 public string name; // string name of the parameter
816 public string desc; 843 public string desc; // a short description of what the parameter means
817 public float defaultValue; 844 public float defaultValue; // default value if not specified anywhere else
818 public ParamUser userParam; 845 public ParamUser userParam; // get the value from the configuration file
819 public ParamGet getter; 846 public ParamGet getter; // return the current value stored for this parameter
820 public ParamSet setter; 847 public ParamSet setter; // set the current value for this parameter
821 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) 848 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s)
822 { 849 {
823 name = n; 850 name = n;
@@ -834,7 +861,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
834 // To add a new externally referencable/settable parameter, add the paramter storage 861 // To add a new externally referencable/settable parameter, add the paramter storage
835 // location somewhere in the program and make an entry in this table with the 862 // location somewhere in the program and make an entry in this table with the
836 // getters and setters. 863 // getters and setters.
837 // To add a new variable, it is easiest to find an existing definition and copy it. 864 // It is easiest to find an existing definition and copy it.
838 // Parameter values are floats. Booleans are converted to a floating value. 865 // Parameter values are floats. Booleans are converted to a floating value.
839 // 866 //
840 // A ParameterDefn() takes the following parameters: 867 // A ParameterDefn() takes the following parameters:
@@ -870,7 +897,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
870 (s) => { return (float)s.m_meshLOD; }, 897 (s) => { return (float)s.m_meshLOD; },
871 (s,p,l,v) => { s.m_meshLOD = (int)v; } ), 898 (s,p,l,v) => { s.m_meshLOD = (int)v; } ),
872 new ParameterDefn("SculptLOD", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", 899 new ParameterDefn("SculptLOD", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)",
873 32, 900 32f,
874 (s,cf,p,v) => { s.m_sculptLOD = cf.GetInt(p, (int)v); }, 901 (s,cf,p,v) => { s.m_sculptLOD = cf.GetInt(p, (int)v); },
875 (s) => { return (float)s.m_sculptLOD; }, 902 (s) => { return (float)s.m_sculptLOD; },
876 (s,p,l,v) => { s.m_sculptLOD = (int)v; } ), 903 (s,p,l,v) => { s.m_sculptLOD = (int)v; } ),
@@ -1106,9 +1133,9 @@ public class BSScene : PhysicsScene, IPhysicsParameters
1106 (s,p,l,v) => { s.m_detailedStatsStep = (int)v; } ), 1133 (s,p,l,v) => { s.m_detailedStatsStep = (int)v; } ),
1107 new ParameterDefn("ShouldDebugLog", "Enables detailed DEBUG log statements", 1134 new ParameterDefn("ShouldDebugLog", "Enables detailed DEBUG log statements",
1108 ConfigurationParameters.numericFalse, 1135 ConfigurationParameters.numericFalse,
1109 (s,cf,p,v) => { s.shouldDebugLog = cf.GetBoolean(p, s.BoolNumeric(v)); }, 1136 (s,cf,p,v) => { s.ShouldDebugLog = cf.GetBoolean(p, s.BoolNumeric(v)); },
1110 (s) => { return s.NumericBool(s.shouldDebugLog); }, 1137 (s) => { return s.NumericBool(s.ShouldDebugLog); },
1111 (s,p,l,v) => { s.shouldDebugLog = s.BoolNumeric(v); } ), 1138 (s,p,l,v) => { s.ShouldDebugLog = s.BoolNumeric(v); } ),
1112 1139
1113 }; 1140 };
1114 1141
@@ -1248,7 +1275,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
1248 List<uint> objectIDs = lIDs; 1275 List<uint> objectIDs = lIDs;
1249 string xparm = parm.ToLower(); 1276 string xparm = parm.ToLower();
1250 float xval = val; 1277 float xval = val;
1251 TaintedObject(delegate() { 1278 TaintedObject("BSScene.UpdateParameterSet", delegate() {
1252 foreach (uint lID in objectIDs) 1279 foreach (uint lID in objectIDs)
1253 { 1280 {
1254 BulletSimAPI.UpdateParameter(m_worldID, lID, xparm, xval); 1281 BulletSimAPI.UpdateParameter(m_worldID, lID, xparm, xval);
@@ -1268,7 +1295,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
1268 uint xlocalID = localID; 1295 uint xlocalID = localID;
1269 string xparm = parm.ToLower(); 1296 string xparm = parm.ToLower();
1270 float xval = val; 1297 float xval = val;
1271 TaintedObject(delegate() { 1298 TaintedObject("BSScene.TaintedUpdateParameter", delegate() {
1272 BulletSimAPI.UpdateParameter(m_worldID, xlocalID, xparm, xval); 1299 BulletSimAPI.UpdateParameter(m_worldID, xlocalID, xparm, xval);
1273 }); 1300 });
1274 } 1301 }
@@ -1294,10 +1321,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters
1294 #endregion Runtime settable parameters 1321 #endregion Runtime settable parameters
1295 1322
1296 // Invoke the detailed logger and output something if it's enabled. 1323 // Invoke the detailed logger and output something if it's enabled.
1297 private void DetailLog(string msg, params Object[] args) 1324 public void DetailLog(string msg, params Object[] args)
1298 { 1325 {
1299 PhysicsLogging.Write(msg, args); 1326 PhysicsLogging.Write(msg, args);
1300 } 1327 }
1328 // used to fill in the LocalID when there isn't one
1329 public const string DetailLogZero = "0000000000";
1301 1330
1302} 1331}
1303} 1332}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index 86fc9d2..6800b96 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -35,9 +35,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin {
35// Classes to allow some type checking for the API 35// Classes to allow some type checking for the API
36public struct BulletSim 36public struct BulletSim
37{ 37{
38 public BulletSim(uint id, IntPtr xx) { ID = id; Ptr = xx; } 38 public BulletSim(uint id, BSScene bss, IntPtr xx) { ID = id; scene = bss; Ptr = xx; }
39 public IntPtr Ptr;
40 public uint ID; 39 public uint ID;
40 // The scene is only in here so very low level routines have a handle to print debug/error messages
41 public BSScene scene;
42 public IntPtr Ptr;
41} 43}
42 44
43public struct BulletBody 45public struct BulletBody
@@ -363,7 +365,7 @@ public static extern IntPtr GetSimHandle2(uint worldID);
363public static extern IntPtr GetBodyHandleWorldID2(uint worldID, uint id); 365public static extern IntPtr GetBodyHandleWorldID2(uint worldID, uint id);
364 366
365[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 367[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
366public static extern IntPtr GetBodyHandle2(IntPtr sim, uint id); 368public static extern IntPtr GetBodyHandle2(IntPtr world, uint id);
367 369
368// =============================================================================== 370// ===============================================================================
369[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 371[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -372,40 +374,43 @@ public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
372 int maxUpdates, IntPtr updateArray); 374 int maxUpdates, IntPtr updateArray);
373 375
374[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 376[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
375public static extern bool UpdateParameter2(IntPtr sim, uint localID, String parm, float value); 377public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
376 378
377[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 379[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
378public static extern void SetHeightmap2(IntPtr sim, float[] heightmap); 380public static extern void SetHeightmap2(IntPtr world, float[] heightmap);
379 381
380[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 382[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
381public static extern void Shutdown2(IntPtr sim); 383public static extern void Shutdown2(IntPtr sim);
382 384
383[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 385[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
384public static extern int PhysicsStep2(IntPtr sim, float timeStep, int maxSubSteps, float fixedTimeStep, 386public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
385 out int updatedEntityCount, 387 out int updatedEntityCount,
386 out IntPtr updatedEntitiesPtr, 388 out IntPtr updatedEntitiesPtr,
387 out int collidersCount, 389 out int collidersCount,
388 out IntPtr collidersPtr); 390 out IntPtr collidersPtr);
389 391
392[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
393public static extern bool PushUpdate2(IntPtr obj);
394
390/* 395/*
391[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 396[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
392public static extern IntPtr CreateMesh2(IntPtr sim, int indicesCount, int* indices, int verticesCount, float* vertices ); 397public static extern IntPtr CreateMesh2(IntPtr world, int indicesCount, int* indices, int verticesCount, float* vertices );
393 398
394[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 399[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
395public static extern bool BuildHull2(IntPtr sim, IntPtr mesh); 400public static extern bool BuildHull2(IntPtr world, IntPtr mesh);
396 401
397[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 402[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
398public static extern bool ReleaseHull2(IntPtr sim, IntPtr mesh); 403public static extern bool ReleaseHull2(IntPtr world, IntPtr mesh);
399 404
400[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 405[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
401public static extern bool DestroyMesh2(IntPtr sim, IntPtr mesh); 406public static extern bool DestroyMesh2(IntPtr world, IntPtr mesh);
402 407
403[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 408[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
404public static extern IntPtr CreateObject2(IntPtr sim, ShapeData shapeData); 409public static extern IntPtr CreateObject2(IntPtr world, ShapeData shapeData);
405*/ 410*/
406 411
407[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 412[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
408public static extern IntPtr CreateConstraint2(IntPtr sim, IntPtr obj1, IntPtr obj2, 413public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
409 Vector3 frame1loc, Quaternion frame1rot, 414 Vector3 frame1loc, Quaternion frame1rot,
410 Vector3 frame2loc, Quaternion frame2rot, 415 Vector3 frame2loc, Quaternion frame2rot,
411 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); 416 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
@@ -429,7 +434,13 @@ public static extern bool CalculateTransforms2(IntPtr constrain);
429public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); 434public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
430 435
431[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 436[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
432public static extern bool DestroyConstraint2(IntPtr sim, IntPtr constrain); 437public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
438
439[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
440public static extern Vector3 AddObjectToWorld2(IntPtr world, IntPtr obj);
441
442[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
443public static extern Vector3 RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
433 444
434[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 445[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
435public static extern Vector3 GetPosition2(IntPtr obj); 446public static extern Vector3 GetPosition2(IntPtr obj);
@@ -483,6 +494,9 @@ public static extern bool SetLinearVelocity2(IntPtr obj, Vector3 val);
483public static extern bool SetInterpolation2(IntPtr obj, Vector3 lin, Vector3 ang); 494public static extern bool SetInterpolation2(IntPtr obj, Vector3 lin, Vector3 ang);
484 495
485[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 496[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
497public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
498
499[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
486public static extern IntPtr SetCollisionFlags2(IntPtr obj, CollisionFlags flags); 500public static extern IntPtr SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
487 501
488[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 502[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -510,12 +524,6 @@ public static extern bool SetMargin2(IntPtr obj, float val);
510public static extern bool UpdateSingleAabb2(IntPtr world, IntPtr obj); 524public static extern bool UpdateSingleAabb2(IntPtr world, IntPtr obj);
511 525
512[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 526[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
513public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
514
515[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
516public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
517
518[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
519public static extern bool DestroyObject2(IntPtr world, uint id); 527public static extern bool DestroyObject2(IntPtr world, uint id);
520 528
521[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 529[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]