aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorRobert Adams2012-09-18 11:26:19 -0700
committerRobert Adams2012-09-27 22:01:16 -0700
commit91efccabdcb45ed95ae35ab24ed5d3ed5508b463 (patch)
treefb801ca0bd72aae3427a5ca439f807ec3802d7c3 /OpenSim
parentBulletSim: move a bunch of common logic out of BSPrim and BSCharacter (diff)
downloadopensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.zip
opensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.gz
opensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.bz2
opensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.xz
BulletSim: Convert BSCharacter to use common BSPhysObject code and variables.
Fix avatar height calculation to properly account for the capsule ends. Rearrange some locking in TerrainManager to eliminate possible race conditions. Move DetailLog() definition into common BSPhysObject class. Some variable renaming to make usage clearer (refactor.rename makes this so easy).
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs66
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs28
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs29
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs40
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs67
5 files changed, 113 insertions, 117 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 57d5726..19eb1e6 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -39,18 +39,16 @@ public class BSCharacter : BSPhysObject
39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40 private static readonly string LogHeader = "[BULLETS CHAR]"; 40 private static readonly string LogHeader = "[BULLETS CHAR]";
41 41
42 private String _avName;
43 // private bool _stopped; 42 // private bool _stopped;
44 private OMV.Vector3 _size; 43 private OMV.Vector3 _size;
45 private OMV.Vector3 _scale; 44 private OMV.Vector3 _scale;
46 private PrimitiveBaseShape _pbs; 45 private PrimitiveBaseShape _pbs;
47 private uint _localID = 0;
48 private bool _grabbed; 46 private bool _grabbed;
49 private bool _selected; 47 private bool _selected;
50 private OMV.Vector3 _position; 48 private OMV.Vector3 _position;
51 private float _mass; 49 private float _mass;
52 public float _density; 50 private float _avatarDensity;
53 public float _avatarVolume; 51 private float _avatarVolume;
54 private OMV.Vector3 _force; 52 private OMV.Vector3 _force;
55 private OMV.Vector3 _velocity; 53 private OMV.Vector3 _velocity;
56 private OMV.Vector3 _torque; 54 private OMV.Vector3 _torque;
@@ -63,18 +61,12 @@ public class BSCharacter : BSPhysObject
63 private bool _setAlwaysRun; 61 private bool _setAlwaysRun;
64 private bool _throttleUpdates; 62 private bool _throttleUpdates;
65 private bool _isColliding; 63 private bool _isColliding;
66 private long _collidingStep;
67 private bool _collidingGround;
68 private long _collidingGroundStep;
69 private bool _collidingObj; 64 private bool _collidingObj;
70 private bool _floatOnWater; 65 private bool _floatOnWater;
71 private OMV.Vector3 _rotationalVelocity; 66 private OMV.Vector3 _rotationalVelocity;
72 private bool _kinematic; 67 private bool _kinematic;
73 private float _buoyancy; 68 private float _buoyancy;
74 69
75 private int _subscribedEventsMs = 0;
76 private int _nextCollisionOkTime = 0;
77
78 private OMV.Vector3 _PIDTarget; 70 private OMV.Vector3 _PIDTarget;
79 private bool _usePID; 71 private bool _usePID;
80 private float _PIDTau; 72 private float _PIDTau;
@@ -85,9 +77,7 @@ public class BSCharacter : BSPhysObject
85 77
86 public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying) 78 public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying)
87 { 79 {
88 base.BaseInitialize(parent_scene); 80 base.BaseInitialize(parent_scene, localID, avName);
89 _localID = localID;
90 _avName = avName;
91 _physicsActorType = (int)ActorTypes.Agent; 81 _physicsActorType = (int)ActorTypes.Agent;
92 _position = pos; 82 _position = pos;
93 _size = size; 83 _size = size;
@@ -95,14 +85,15 @@ public class BSCharacter : BSPhysObject
95 _orientation = OMV.Quaternion.Identity; 85 _orientation = OMV.Quaternion.Identity;
96 _velocity = OMV.Vector3.Zero; 86 _velocity = OMV.Vector3.Zero;
97 _buoyancy = ComputeBuoyancyFromFlying(isFlying); 87 _buoyancy = ComputeBuoyancyFromFlying(isFlying);
88
98 // The dimensions of the avatar capsule are kept in the scale. 89 // The dimensions of the avatar capsule are kept in the scale.
99 // Physics creates a unit capsule which is scaled by the physics engine. 90 // Physics creates a unit capsule which is scaled by the physics engine.
100 _scale = new OMV.Vector3(PhysicsScene.Params.avatarCapsuleRadius, PhysicsScene.Params.avatarCapsuleRadius, size.Z); 91 ComputeAvatarScale(_size);
101 _density = PhysicsScene.Params.avatarDensity; 92 _avatarDensity = PhysicsScene.Params.avatarDensity;
102 ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale 93 ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale
103 94
104 ShapeData shapeData = new ShapeData(); 95 ShapeData shapeData = new ShapeData();
105 shapeData.ID = _localID; 96 shapeData.ID = LocalID;
106 shapeData.Type = ShapeData.PhysicsShapeType.SHAPE_AVATAR; 97 shapeData.Type = ShapeData.PhysicsShapeType.SHAPE_AVATAR;
107 shapeData.Position = _position; 98 shapeData.Position = _position;
108 shapeData.Rotation = _orientation; 99 shapeData.Rotation = _orientation;
@@ -117,7 +108,7 @@ public class BSCharacter : BSPhysObject
117 // do actual create at taint time 108 // do actual create at taint time
118 PhysicsScene.TaintedObject("BSCharacter.create", delegate() 109 PhysicsScene.TaintedObject("BSCharacter.create", delegate()
119 { 110 {
120 DetailLog("{0},BSCharacter.create", _localID); 111 DetailLog("{0},BSCharacter.create,taint", LocalID);
121 BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData); 112 BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData);
122 113
123 // Set the buoyancy for flying. This will be refactored when all the settings happen in C# 114 // Set the buoyancy for flying. This will be refactored when all the settings happen in C#
@@ -135,7 +126,7 @@ public class BSCharacter : BSPhysObject
135 DetailLog("{0},BSCharacter.Destroy", LocalID); 126 DetailLog("{0},BSCharacter.Destroy", LocalID);
136 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() 127 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate()
137 { 128 {
138 BulletSimAPI.DestroyObject(PhysicsScene.WorldID, _localID); 129 BulletSimAPI.DestroyObject(PhysicsScene.WorldID, LocalID);
139 }); 130 });
140 } 131 }
141 132
@@ -158,7 +149,7 @@ public class BSCharacter : BSPhysObject
158 // When an avatar's size is set, only the height is changed 149 // When an avatar's size is set, only the height is changed
159 // and that really only depends on the radius. 150 // and that really only depends on the radius.
160 _size = value; 151 _size = value;
161 _scale.Z = (_size.Z * 1.15f) - (_scale.X + _scale.Y); 152 ComputeAvatarScale(_size);
162 153
163 // TODO: something has to be done with the avatar's vertical position 154 // TODO: something has to be done with the avatar's vertical position
164 155
@@ -175,11 +166,6 @@ public class BSCharacter : BSPhysObject
175 set { _pbs = value; 166 set { _pbs = value;
176 } 167 }
177 } 168 }
178 public override uint LocalID {
179 set { _localID = value;
180 }
181 get { return _localID; }
182 }
183 public override bool Grabbed { 169 public override bool Grabbed {
184 set { _grabbed = value; 170 set { _grabbed = value;
185 } 171 }
@@ -223,7 +209,7 @@ public class BSCharacter : BSPhysObject
223 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() 209 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate()
224 { 210 {
225 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 211 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
226 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); 212 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
227 }); 213 });
228 } 214 }
229 } 215 }
@@ -261,7 +247,7 @@ public class BSCharacter : BSPhysObject
261 PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", delegate() 247 PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", delegate()
262 { 248 {
263 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); 249 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
264 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); 250 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
265 }); 251 });
266 ret = true; 252 ret = true;
267 } 253 }
@@ -312,7 +298,7 @@ public class BSCharacter : BSPhysObject
312 PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() 298 PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate()
313 { 299 {
314 DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); 300 DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity);
315 BulletSimAPI.SetObjectVelocity(PhysicsScene.WorldID, _localID, _velocity); 301 BulletSimAPI.SetObjectVelocity(PhysicsScene.WorldID, LocalID, _velocity);
316 }); 302 });
317 } 303 }
318 } 304 }
@@ -338,7 +324,7 @@ public class BSCharacter : BSPhysObject
338 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() 324 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate()
339 { 325 {
340 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); 326 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID);
341 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); 327 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
342 }); 328 });
343 } 329 }
344 } 330 }
@@ -375,12 +361,12 @@ public class BSCharacter : BSPhysObject
375 set { _throttleUpdates = value; } 361 set { _throttleUpdates = value; }
376 } 362 }
377 public override bool IsColliding { 363 public override bool IsColliding {
378 get { return (_collidingStep == PhysicsScene.SimulationStep); } 364 get { return (CollidingStep == PhysicsScene.SimulationStep); }
379 set { _isColliding = value; } 365 set { _isColliding = value; }
380 } 366 }
381 public override bool CollidingGround { 367 public override bool CollidingGround {
382 get { return (_collidingGroundStep == PhysicsScene.SimulationStep); } 368 get { return (CollidingGroundStep == PhysicsScene.SimulationStep); }
383 set { _collidingGround = value; } 369 set { CollidingGround = value; }
384 } 370 }
385 public override bool CollidingObj { 371 public override bool CollidingObj {
386 get { return _collidingObj; } 372 get { return _collidingObj; }
@@ -466,6 +452,16 @@ public class BSCharacter : BSPhysObject
466 public override void SetMomentum(OMV.Vector3 momentum) { 452 public override void SetMomentum(OMV.Vector3 momentum) {
467 } 453 }
468 454
455 private void ComputeAvatarScale(OMV.Vector3 size)
456 {
457 _scale.X = PhysicsScene.Params.avatarCapsuleRadius;
458 _scale.Y = PhysicsScene.Params.avatarCapsuleRadius;
459
460 // The 1.15 came from ODE but it seems to cause the avatar to float off the ground
461 // _scale.Z = (_size.Z * 1.15f) - (_scale.X + _scale.Y);
462 _scale.Z = (_size.Z) - (_scale.X + _scale.Y);
463 }
464
469 // set _avatarVolume and _mass based on capsule size, _density and _scale 465 // set _avatarVolume and _mass based on capsule size, _density and _scale
470 private void ComputeAvatarVolumeAndMass() 466 private void ComputeAvatarVolumeAndMass()
471 { 467 {
@@ -480,7 +476,7 @@ public class BSCharacter : BSPhysObject
480 * Math.Min(_scale.X, _scale.Y) 476 * Math.Min(_scale.X, _scale.Y)
481 * _scale.Y // plus the volume of the capsule end caps 477 * _scale.Y // plus the volume of the capsule end caps
482 ); 478 );
483 _mass = _density * _avatarVolume; 479 _mass = _avatarDensity * _avatarVolume;
484 } 480 }
485 481
486 // The physics engine says that properties have updated. Update same and inform 482 // The physics engine says that properties have updated. Update same and inform
@@ -502,11 +498,5 @@ public class BSCharacter : BSPhysObject
502 DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}", 498 DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}",
503 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere); 499 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere);
504 } 500 }
505
506 // Invoke the detailed logger and output something if it's enabled.
507 private void DetailLog(string msg, params Object[] args)
508 {
509 PhysicsScene.PhysicsLogging.Write(msg, args);
510 }
511} 501}
512} 502}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 005a758..1e8fe52 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -77,7 +77,7 @@ public class BSLinkset
77 // A simple linkset of one (no children) 77 // A simple linkset of one (no children)
78 LinksetID = m_nextLinksetID++; 78 LinksetID = m_nextLinksetID++;
79 // We create LOTS of linksets. 79 // We create LOTS of linksets.
80 if (m_nextLinksetID < 0) 80 if (m_nextLinksetID <= 0)
81 m_nextLinksetID = 1; 81 m_nextLinksetID = 1;
82 PhysicsScene = scene; 82 PhysicsScene = scene;
83 LinksetRoot = parent; 83 LinksetRoot = parent;
@@ -157,21 +157,26 @@ public class BSLinkset
157 157
158 private float ComputeLinksetMass() 158 private float ComputeLinksetMass()
159 { 159 {
160 float mass = LinksetRoot.MassRaw; 160 float mass;
161 foreach (BSPhysObject bp in m_children) 161 lock (m_linksetActivityLock)
162 { 162 {
163 mass += bp.MassRaw; 163 mass = LinksetRoot.MassRaw;
164 foreach (BSPhysObject bp in m_children)
165 {
166 mass += bp.MassRaw;
167 }
164 } 168 }
165 return mass; 169 return mass;
166 } 170 }
167 171
168 private OMV.Vector3 ComputeLinksetCenterOfMass() 172 private OMV.Vector3 ComputeLinksetCenterOfMass()
169 { 173 {
170 OMV.Vector3 com = LinksetRoot.Position * LinksetRoot.MassRaw; 174 OMV.Vector3 com;
171 float totalMass = LinksetRoot.MassRaw;
172
173 lock (m_linksetActivityLock) 175 lock (m_linksetActivityLock)
174 { 176 {
177 com = LinksetRoot.Position * LinksetRoot.MassRaw;
178 float totalMass = LinksetRoot.MassRaw;
179
175 foreach (BSPhysObject bp in m_children) 180 foreach (BSPhysObject bp in m_children)
176 { 181 {
177 com += bp.Position * bp.MassRaw; 182 com += bp.Position * bp.MassRaw;
@@ -186,10 +191,11 @@ public class BSLinkset
186 191
187 private OMV.Vector3 ComputeLinksetGeometricCenter() 192 private OMV.Vector3 ComputeLinksetGeometricCenter()
188 { 193 {
189 OMV.Vector3 com = LinksetRoot.Position; 194 OMV.Vector3 com;
190
191 lock (m_linksetActivityLock) 195 lock (m_linksetActivityLock)
192 { 196 {
197 com = LinksetRoot.Position;
198
193 foreach (BSPhysObject bp in m_children) 199 foreach (BSPhysObject bp in m_children)
194 { 200 {
195 com += bp.Position * bp.MassRaw; 201 com += bp.Position * bp.MassRaw;
@@ -208,8 +214,8 @@ public class BSLinkset
208 // Called at taint-time! 214 // Called at taint-time!
209 public bool MakeDynamic(BSPhysObject child) 215 public bool MakeDynamic(BSPhysObject child)
210 { 216 {
211 bool ret = false; 217 // What is done for each object in BSPrim is what we want.
212 return ret; 218 return false;
213 } 219 }
214 220
215 // The object is going static (non-physical). Do any setup necessary 221 // The object is going static (non-physical). Do any setup necessary
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 242aa80..b575e37 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -39,9 +39,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
39// unless the difference is significant. 39// unless the difference is significant.
40public abstract class BSPhysObject : PhysicsActor 40public abstract class BSPhysObject : PhysicsActor
41{ 41{
42 protected void BaseInitialize(BSScene parentScene) 42 protected void BaseInitialize(BSScene parentScene, uint localID, string name)
43 { 43 {
44 PhysicsScene = parentScene; 44 PhysicsScene = parentScene;
45 LocalID = localID;
46 PhysObjectName = name;
47
45 Linkset = new BSLinkset(PhysicsScene, this); 48 Linkset = new BSLinkset(PhysicsScene, this);
46 49
47 CollisionCollection = new CollisionEventUpdate(); 50 CollisionCollection = new CollisionEventUpdate();
@@ -51,6 +54,8 @@ public abstract class BSPhysObject : PhysicsActor
51 } 54 }
52 55
53 public BSScene PhysicsScene { get; protected set; } 56 public BSScene PhysicsScene { get; protected set; }
57 // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor
58 public string PhysObjectName { get; protected set; }
54 59
55 public BSLinkset Linkset { get; set; } 60 public BSLinkset Linkset { get; set; }
56 61
@@ -111,13 +116,13 @@ public abstract class BSPhysObject : PhysicsActor
111 return ret; 116 return ret;
112 } 117 }
113 118
114 PhysicsScene.PhysicsLogging.Write("{0},BSPhysObject.Collison,call,with={1}", LocalID, collidingWith); 119 DetailLog("{0},BSPhysObject.Collison,call,with={1}", LocalID, collidingWith);
115 120
116 // if someone has subscribed for collision events.... 121 // if someone has subscribed for collision events....
117 if (SubscribedEvents()) { 122 if (SubscribedEvents()) {
118 CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); 123 CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
119 PhysicsScene.PhysicsLogging.Write("{0},BSPhysObject.Collison.AddCollider,call,with={1},point={2},normal={3},depth={4},next={5}", 124 DetailLog("{0},BSPhysObject.Collison.AddCollider,call,with={1},point={2},normal={3},depth={4}",
120 LocalID, collidingWith, contactPoint, contactNormal, pentrationDepth, NextCollisionOkTime.ToString("yyyyMMddHHmmssfff")); 125 LocalID, collidingWith, contactPoint, contactNormal, pentrationDepth);
121 ret = true; 126 ret = true;
122 } 127 }
123 return ret; 128 return ret;
@@ -127,6 +132,8 @@ public abstract class BSPhysObject : PhysicsActor
127 // Also handles removal of this from the collection of objects with collisions if 132 // Also handles removal of this from the collection of objects with collisions if
128 // there are no collisions from this object. Mechanism is create one last 133 // there are no collisions from this object. Mechanism is create one last
129 // collision event to make collision_end work. 134 // collision event to make collision_end work.
135 // Called at taint time from within the Step() function thus no locking problems
136 // with CollisionCollection and ObjectsWithNoMoreCollisions.
130 public virtual void SendCollisions() 137 public virtual void SendCollisions()
131 { 138 {
132 // throttle the collisions to the number of milliseconds specified in the subscription 139 // throttle the collisions to the number of milliseconds specified in the subscription
@@ -140,10 +147,11 @@ public abstract class BSPhysObject : PhysicsActor
140 if (CollisionCollection.Count == 0) 147 if (CollisionCollection.Count == 0)
141 PhysicsScene.ObjectsWithNoMoreCollisions.Add(this); 148 PhysicsScene.ObjectsWithNoMoreCollisions.Add(this);
142 149
150 DetailLog("{0},SendCollisions.SendCollisionUpdate,call,numCollisions={1}", LocalID, CollisionCollection.Count);
143 base.SendCollisionUpdate(CollisionCollection); 151 base.SendCollisionUpdate(CollisionCollection);
144 152
145 // The collisionCollection structure is passed around in the simulator. 153 // The collisionCollection structure is passed around in the simulator.
146 // Make sure we don't have a handle to that one and that a new one is used next time. 154 // Make sure we don't have a handle to that one and that a new one is used for next time.
147 CollisionCollection = new CollisionEventUpdate(); 155 CollisionCollection = new CollisionEventUpdate();
148 } 156 }
149 } 157 }
@@ -156,8 +164,7 @@ public abstract class BSPhysObject : PhysicsActor
156 { 164 {
157 // make sure first collision happens 165 // make sure first collision happens
158 NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs); 166 NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs);
159 PhysicsScene.PhysicsLogging.Write("{0},SubscribeEvents,call,ms={1},nextOKTime={2}", 167 DetailLog("{0},SubscribeEvents,call,ms={1}", LocalID, SubscribedEventsMs);
160 LocalID, SubscribedEventsMs, NextCollisionOkTime.ToString("yyyyMMddHHmmssfff"));
161 168
162 PhysicsScene.TaintedObject("BSPhysObject.SubscribeEvents", delegate() 169 PhysicsScene.TaintedObject("BSPhysObject.SubscribeEvents", delegate()
163 { 170 {
@@ -172,7 +179,7 @@ public abstract class BSPhysObject : PhysicsActor
172 } 179 }
173 public override void UnSubscribeEvents() { 180 public override void UnSubscribeEvents() {
174 SubscribedEventsMs = 0; 181 SubscribedEventsMs = 0;
175 PhysicsScene.PhysicsLogging.Write("{0},UnSubscribeEvents,call", LocalID); 182 DetailLog("{0},UnSubscribeEvents,call", LocalID);
176 PhysicsScene.TaintedObject("BSPhysObject.UnSubscribeEvents", delegate() 183 PhysicsScene.TaintedObject("BSPhysObject.UnSubscribeEvents", delegate()
177 { 184 {
178 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 185 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
@@ -184,5 +191,11 @@ public abstract class BSPhysObject : PhysicsActor
184 } 191 }
185 192
186 #endregion // Collisions 193 #endregion // Collisions
194
195 // High performance detailed logging routine used by the physical objects.
196 protected void DetailLog(string msg, params Object[] args)
197 {
198 PhysicsScene.PhysicsLogging.Write(msg, args);
199 }
187} 200}
188} 201}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 29f27e8..4f10d46 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -49,9 +49,6 @@ public sealed class BSPrim : BSPhysObject
49 private ulong _hullKey; 49 private ulong _hullKey;
50 private List<ConvexResult> _hulls; 50 private List<ConvexResult> _hulls;
51 51
52 private String _avName;
53 private uint _localID = 0;
54
55 // _size is what the user passed. _scale is what we pass to the physics engine with the mesh. 52 // _size is what the user passed. _scale is what we pass to the physics engine with the mesh.
56 // Often _scale is unity because the meshmerizer will apply _size when creating the mesh. 53 // Often _scale is unity because the meshmerizer will apply _size when creating the mesh.
57 private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user 54 private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user
@@ -99,9 +96,7 @@ public sealed class BSPrim : BSPhysObject
99 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) 96 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
100 { 97 {
101 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); 98 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
102 base.BaseInitialize(parent_scene); 99 base.BaseInitialize(parent_scene, localID, primName);
103 _localID = localID;
104 _avName = primName;
105 _physicsActorType = (int)ActorTypes.Prim; 100 _physicsActorType = (int)ActorTypes.Prim;
106 _position = pos; 101 _position = pos;
107 _size = size; 102 _size = size;
@@ -187,10 +182,6 @@ public sealed class BSPrim : BSPhysObject
187 }); 182 });
188 } 183 }
189 } 184 }
190 public override uint LocalID {
191 set { _localID = value; }
192 get { return _localID; }
193 }
194 public override bool Grabbed { 185 public override bool Grabbed {
195 set { _grabbed = value; 186 set { _grabbed = value;
196 } 187 }
@@ -267,7 +258,7 @@ public sealed class BSPrim : BSPhysObject
267 _position = BulletSimAPI.GetPosition2(BSBody.Ptr); 258 _position = BulletSimAPI.GetPosition2(BSBody.Ptr);
268 259
269 // don't do the GetObjectPosition for root elements because this function is called a zillion times 260 // don't do the GetObjectPosition for root elements because this function is called a zillion times
270 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); 261 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID);
271 return _position; 262 return _position;
272 } 263 }
273 set { 264 set {
@@ -425,7 +416,7 @@ public sealed class BSPrim : BSPhysObject
425 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? 416 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint?
426 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() 417 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate()
427 { 418 {
428 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); 419 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID);
429 DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); 420 DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
430 BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation); 421 BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation);
431 }); 422 });
@@ -666,7 +657,7 @@ public sealed class BSPrim : BSPhysObject
666 // Buoyancy is faked by changing the gravity applied to the object 657 // Buoyancy is faked by changing the gravity applied to the object
667 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); 658 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
668 BulletSimAPI.SetGravity2(BSBody.Ptr, new OMV.Vector3(0f, 0f, grav)); 659 BulletSimAPI.SetGravity2(BSBody.Ptr, new OMV.Vector3(0f, 0f, grav));
669 // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, _localID, _buoyancy); 660 // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy);
670 }); 661 });
671 } 662 }
672 } 663 }
@@ -1127,7 +1118,7 @@ public sealed class BSPrim : BSPhysObject
1127 lod = PhysicsScene.MeshMegaPrimLOD; 1118 lod = PhysicsScene.MeshMegaPrimLOD;
1128 1119
1129 ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod); 1120 ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod);
1130 // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _meshKey, newMeshKey); 1121 // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, LocalID, _meshKey, newMeshKey);
1131 1122
1132 // if this new shape is the same as last time, don't recreate the mesh 1123 // if this new shape is the same as last time, don't recreate the mesh
1133 if (_meshKey == newMeshKey) return false; 1124 if (_meshKey == newMeshKey) return false;
@@ -1136,7 +1127,7 @@ public sealed class BSPrim : BSPhysObject
1136 // Since we're recreating new, get rid of any previously generated shape 1127 // Since we're recreating new, get rid of any previously generated shape
1137 if (_meshKey != 0) 1128 if (_meshKey != 0)
1138 { 1129 {
1139 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); 1130 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, LocalID, _meshKey);
1140 DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); 1131 DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey);
1141 BulletSimAPI.DestroyMesh(PhysicsScene.WorldID, _meshKey); 1132 BulletSimAPI.DestroyMesh(PhysicsScene.WorldID, _meshKey);
1142 _mesh = null; 1133 _mesh = null;
@@ -1145,7 +1136,7 @@ public sealed class BSPrim : BSPhysObject
1145 1136
1146 _meshKey = newMeshKey; 1137 _meshKey = newMeshKey;
1147 // always pass false for physicalness as this creates some sort of bounding box which we don't need 1138 // always pass false for physicalness as this creates some sort of bounding box which we don't need
1148 _mesh = PhysicsScene.mesher.CreateMesh(_avName, _pbs, _size, lod, false); 1139 _mesh = PhysicsScene.mesher.CreateMesh(PhysObjectName, _pbs, _size, lod, false);
1149 1140
1150 int[] indices = _mesh.getIndexListAsInt(); 1141 int[] indices = _mesh.getIndexListAsInt();
1151 List<OMV.Vector3> vertices = _mesh.getVertexList(); 1142 List<OMV.Vector3> vertices = _mesh.getVertexList();
@@ -1160,7 +1151,7 @@ public sealed class BSPrim : BSPhysObject
1160 } 1151 }
1161 1152
1162 // m_log.DebugFormat("{0}: CreateGeomMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", 1153 // m_log.DebugFormat("{0}: CreateGeomMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}",
1163 // LogHeader, _localID, _meshKey, indices.Length, vertices.Count); 1154 // LogHeader, LocalID, _meshKey, indices.Length, vertices.Count);
1164 BulletSimAPI.CreateMesh(PhysicsScene.WorldID, _meshKey, indices.GetLength(0), indices, 1155 BulletSimAPI.CreateMesh(PhysicsScene.WorldID, _meshKey, indices.GetLength(0), indices,
1165 vertices.Count, verticesAsFloats); 1156 vertices.Count, verticesAsFloats);
1166 1157
@@ -1176,7 +1167,7 @@ public sealed class BSPrim : BSPhysObject
1176 { 1167 {
1177 float lod = _pbs.SculptEntry ? PhysicsScene.SculptLOD : PhysicsScene.MeshLOD; 1168 float lod = _pbs.SculptEntry ? PhysicsScene.SculptLOD : PhysicsScene.MeshLOD;
1178 ulong newHullKey = (ulong)_pbs.GetMeshKey(_size, lod); 1169 ulong newHullKey = (ulong)_pbs.GetMeshKey(_size, lod);
1179 // m_log.DebugFormat("{0}: CreateGeomHull: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _hullKey, newHullKey); 1170 // m_log.DebugFormat("{0}: CreateGeomHull: lID={1}, oldKey={2}, newKey={3}", LogHeader, LocalID, _hullKey, newHullKey);
1180 1171
1181 // if the hull hasn't changed, don't rebuild it 1172 // if the hull hasn't changed, don't rebuild it
1182 if (newHullKey == _hullKey) return false; 1173 if (newHullKey == _hullKey) return false;
@@ -1276,7 +1267,7 @@ public sealed class BSPrim : BSPhysObject
1276 } 1267 }
1277 1268
1278 // create the hull definition in Bullet 1269 // create the hull definition in Bullet
1279 // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, _localID, _hullKey, hullCount); 1270 // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, LocalID, _hullKey, hullCount);
1280 BulletSimAPI.CreateHull(PhysicsScene.WorldID, _hullKey, hullCount, convHulls); 1271 BulletSimAPI.CreateHull(PhysicsScene.WorldID, _hullKey, hullCount, convHulls);
1281 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; 1272 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL;
1282 // meshes are already scaled by the meshmerizer 1273 // meshes are already scaled by the meshmerizer
@@ -1316,7 +1307,7 @@ public sealed class BSPrim : BSPhysObject
1316 // the mesh or hull must have already been created in Bullet 1307 // the mesh or hull must have already been created in Bullet
1317 ShapeData shape; 1308 ShapeData shape;
1318 FillShapeInfo(out shape); 1309 FillShapeInfo(out shape);
1319 // m_log.DebugFormat("{0}: CreateObject: lID={1}, shape={2}", LogHeader, _localID, shape.Type); 1310 // m_log.DebugFormat("{0}: CreateObject: lID={1}, shape={2}", LogHeader, LocalID, shape.Type);
1320 bool ret = BulletSimAPI.CreateObject(PhysicsScene.WorldID, shape); 1311 bool ret = BulletSimAPI.CreateObject(PhysicsScene.WorldID, shape);
1321 1312
1322 // the CreateObject() may have recreated the rigid body. Make sure we have the latest address. 1313 // the CreateObject() may have recreated the rigid body. Make sure we have the latest address.
@@ -1329,7 +1320,7 @@ public sealed class BSPrim : BSPhysObject
1329 // Copy prim's info into the BulletSim shape description structure 1320 // Copy prim's info into the BulletSim shape description structure
1330 public void FillShapeInfo(out ShapeData shape) 1321 public void FillShapeInfo(out ShapeData shape)
1331 { 1322 {
1332 shape.ID = _localID; 1323 shape.ID = LocalID;
1333 shape.Type = _shapeType; 1324 shape.Type = _shapeType;
1334 shape.Position = _position; 1325 shape.Position = _position;
1335 shape.Rotation = _orientation; 1326 shape.Rotation = _orientation;
@@ -1350,7 +1341,7 @@ public sealed class BSPrim : BSPhysObject
1350 // No locking here because this is done when the physics engine is not simulating 1341 // No locking here because this is done when the physics engine is not simulating
1351 private void CreateGeomAndObject(bool forceRebuild) 1342 private void CreateGeomAndObject(bool forceRebuild)
1352 { 1343 {
1353 // m_log.DebugFormat("{0}: CreateGeomAndObject. lID={1}, force={2}", LogHeader, _localID, forceRebuild); 1344 // m_log.DebugFormat("{0}: CreateGeomAndObject. lID={1}, force={2}", LogHeader, LocalID, forceRebuild);
1354 // Create the geometry that will make up the object 1345 // Create the geometry that will make up the object
1355 if (CreateGeom(forceRebuild)) 1346 if (CreateGeom(forceRebuild))
1356 { 1347 {
@@ -1453,10 +1444,5 @@ public sealed class BSPrim : BSPhysObject
1453 } 1444 }
1454 */ 1445 */
1455 } 1446 }
1456 // Invoke the detailed logger and output something if it's enabled.
1457 private void DetailLog(string msg, params Object[] args)
1458 {
1459 PhysicsScene.PhysicsLogging.Write(msg, args);
1460 }
1461} 1447}
1462} 1448}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index d48462e..c113db1 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -57,10 +57,10 @@ public class BSTerrainManager
57 public const float TERRAIN_COLLISION_MARGIN = 0.0f; 57 public const float TERRAIN_COLLISION_MARGIN = 0.0f;
58 58
59 // Until the whole simulator is changed to pass us the region size, we rely on constants. 59 // Until the whole simulator is changed to pass us the region size, we rely on constants.
60 public Vector3 DefaultRegionSize = new Vector3(Constants.RegionSize, Constants.RegionSize, 0f); 60 public Vector3 DefaultRegionSize = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
61 61
62 // The scene that I am part of 62 // The scene that I am part of
63 private BSScene m_physicsScene; 63 private BSScene PhysicsScene { get; set; }
64 64
65 // The ground plane created to keep thing from falling to infinity. 65 // The ground plane created to keep thing from falling to infinity.
66 private BulletBody m_groundPlane; 66 private BulletBody m_groundPlane;
@@ -84,18 +84,18 @@ public class BSTerrainManager
84 // If the parent region (region 0), this is the extent of the combined regions 84 // If the parent region (region 0), this is the extent of the combined regions
85 // relative to the origin of region zero 85 // relative to the origin of region zero
86 private Vector3 m_worldMax; 86 private Vector3 m_worldMax;
87 private PhysicsScene m_parentScene; 87 private PhysicsScene MegaRegionParentPhysicsScene { get; set; }
88 88
89 public BSTerrainManager(BSScene physicsScene) 89 public BSTerrainManager(BSScene physicsScene)
90 { 90 {
91 m_physicsScene = physicsScene; 91 PhysicsScene = physicsScene;
92 m_heightMaps = new Dictionary<Vector2,BulletHeightMapInfo>(); 92 m_heightMaps = new Dictionary<Vector2,BulletHeightMapInfo>();
93 m_terrainModified = false; 93 m_terrainModified = false;
94 94
95 // Assume one region of default size 95 // Assume one region of default size
96 m_worldOffset = Vector3.Zero; 96 m_worldOffset = Vector3.Zero;
97 m_worldMax = new Vector3(DefaultRegionSize.X, DefaultRegionSize.Y, 4096f); 97 m_worldMax = new Vector3(DefaultRegionSize);
98 m_parentScene = null; 98 MegaRegionParentPhysicsScene = null;
99 } 99 }
100 100
101 // Create the initial instance of terrain and the underlying ground plane. 101 // Create the initial instance of terrain and the underlying ground plane.
@@ -110,7 +110,7 @@ public class BSTerrainManager
110 BulletShape groundPlaneShape = new BulletShape(BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f, TERRAIN_COLLISION_MARGIN)); 110 BulletShape groundPlaneShape = new BulletShape(BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f, TERRAIN_COLLISION_MARGIN));
111 m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID, 111 m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID,
112 BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.Ptr, Vector3.Zero, Quaternion.Identity)); 112 BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.Ptr, Vector3.Zero, Quaternion.Identity));
113 BulletSimAPI.AddObjectToWorld2(m_physicsScene.World.Ptr, m_groundPlane.Ptr); 113 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.Ptr, m_groundPlane.Ptr);
114 114
115 Vector3 minTerrainCoords = new Vector3(0f, 0f, HEIGHT_INITIALIZATION - HEIGHT_EQUAL_FUDGE); 115 Vector3 minTerrainCoords = new Vector3(0f, 0f, HEIGHT_INITIALIZATION - HEIGHT_EQUAL_FUDGE);
116 Vector3 maxTerrainCoords = new Vector3(DefaultRegionSize.X, DefaultRegionSize.Y, HEIGHT_INITIALIZATION); 116 Vector3 maxTerrainCoords = new Vector3(DefaultRegionSize.X, DefaultRegionSize.Y, HEIGHT_INITIALIZATION);
@@ -128,9 +128,9 @@ public class BSTerrainManager
128 { 128 {
129 if (m_groundPlane.Ptr != IntPtr.Zero) 129 if (m_groundPlane.Ptr != IntPtr.Zero)
130 { 130 {
131 if (BulletSimAPI.RemoveObjectFromWorld2(m_physicsScene.World.Ptr, m_groundPlane.Ptr)) 131 if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.Ptr, m_groundPlane.Ptr))
132 { 132 {
133 BulletSimAPI.DestroyObject2(m_physicsScene.World.Ptr, m_groundPlane.Ptr); 133 BulletSimAPI.DestroyObject2(PhysicsScene.World.Ptr, m_groundPlane.Ptr);
134 } 134 }
135 m_groundPlane.Ptr = IntPtr.Zero; 135 m_groundPlane.Ptr = IntPtr.Zero;
136 } 136 }
@@ -143,9 +143,9 @@ public class BSTerrainManager
143 { 143 {
144 foreach (KeyValuePair<Vector2, BulletHeightMapInfo> kvp in m_heightMaps) 144 foreach (KeyValuePair<Vector2, BulletHeightMapInfo> kvp in m_heightMaps)
145 { 145 {
146 if (BulletSimAPI.RemoveObjectFromWorld2(m_physicsScene.World.Ptr, kvp.Value.terrainBody.Ptr)) 146 if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.Ptr, kvp.Value.terrainBody.Ptr))
147 { 147 {
148 BulletSimAPI.DestroyObject2(m_physicsScene.World.Ptr, kvp.Value.terrainBody.Ptr); 148 BulletSimAPI.DestroyObject2(PhysicsScene.World.Ptr, kvp.Value.terrainBody.Ptr);
149 BulletSimAPI.ReleaseHeightMapInfo2(kvp.Value.Ptr); 149 BulletSimAPI.ReleaseHeightMapInfo2(kvp.Value.Ptr);
150 } 150 }
151 } 151 }
@@ -155,19 +155,19 @@ public class BSTerrainManager
155 // The simulator wants to set a new heightmap for the terrain. 155 // The simulator wants to set a new heightmap for the terrain.
156 public void SetTerrain(float[] heightMap) { 156 public void SetTerrain(float[] heightMap) {
157 float[] localHeightMap = heightMap; 157 float[] localHeightMap = heightMap;
158 m_physicsScene.TaintedObject("TerrainManager.SetTerrain", delegate() 158 PhysicsScene.TaintedObject("TerrainManager.SetTerrain", delegate()
159 { 159 {
160 if (m_worldOffset != Vector3.Zero && m_parentScene != null) 160 if (m_worldOffset != Vector3.Zero && MegaRegionParentPhysicsScene != null)
161 { 161 {
162 // If a child of a mega-region, we shouldn't have any terrain allocated for us 162 // If a child of a mega-region, we shouldn't have any terrain allocated for us
163 ReleaseGroundPlaneAndTerrain(); 163 ReleaseGroundPlaneAndTerrain();
164 // If doing the mega-prim stuff and we are the child of the zero region, 164 // If doing the mega-prim stuff and we are the child of the zero region,
165 // the terrain is added to our parent 165 // the terrain is added to our parent
166 if (m_parentScene is BSScene) 166 if (MegaRegionParentPhysicsScene is BSScene)
167 { 167 {
168 DetailLog("{0},SetTerrain.ToParent,offset={1},worldMax={2}", 168 DetailLog("{0},SetTerrain.ToParent,offset={1},worldMax={2}",
169 BSScene.DetailLogZero, m_worldOffset, m_worldMax); 169 BSScene.DetailLogZero, m_worldOffset, m_worldMax);
170 ((BSScene)m_parentScene).TerrainManager.UpdateOrCreateTerrain(BSScene.CHILDTERRAIN_ID, 170 ((BSScene)MegaRegionParentPhysicsScene).TerrainManager.UpdateOrCreateTerrain(BSScene.CHILDTERRAIN_ID,
171 localHeightMap, m_worldOffset, m_worldOffset + DefaultRegionSize, true); 171 localHeightMap, m_worldOffset, m_worldOffset + DefaultRegionSize, true);
172 } 172 }
173 } 173 }
@@ -176,7 +176,8 @@ public class BSTerrainManager
176 // If not doing the mega-prim thing, just change the terrain 176 // If not doing the mega-prim thing, just change the terrain
177 DetailLog("{0},SetTerrain.Existing", BSScene.DetailLogZero); 177 DetailLog("{0},SetTerrain.Existing", BSScene.DetailLogZero);
178 178
179 UpdateOrCreateTerrain(BSScene.TERRAIN_ID, localHeightMap, m_worldOffset, m_worldOffset + DefaultRegionSize, true); 179 UpdateOrCreateTerrain(BSScene.TERRAIN_ID, localHeightMap,
180 m_worldOffset, m_worldOffset + DefaultRegionSize, true);
180 } 181 }
181 }); 182 });
182 } 183 }
@@ -232,7 +233,7 @@ public class BSTerrainManager
232 233
233 BSScene.TaintCallback rebuildOperation = delegate() 234 BSScene.TaintCallback rebuildOperation = delegate()
234 { 235 {
235 if (m_parentScene != null) 236 if (MegaRegionParentPhysicsScene != null)
236 { 237 {
237 // It's possible that Combine() was called after this code was queued. 238 // It's possible that Combine() was called after this code was queued.
238 // If we are a child of combined regions, we don't create any terrain for us. 239 // If we are a child of combined regions, we don't create any terrain for us.
@@ -252,10 +253,10 @@ public class BSTerrainManager
252 BSScene.DetailLogZero, terrainRegionBase, mapInfo.minCoords, mapInfo.maxCoords, mapInfo.sizeX, mapInfo.sizeY); 253 BSScene.DetailLogZero, terrainRegionBase, mapInfo.minCoords, mapInfo.maxCoords, mapInfo.sizeX, mapInfo.sizeY);
253 254
254 // Remove from the dynamics world because we're going to mangle this object 255 // Remove from the dynamics world because we're going to mangle this object
255 BulletSimAPI.RemoveObjectFromWorld2(m_physicsScene.World.Ptr, mapInfo.terrainBody.Ptr); 256 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.Ptr, mapInfo.terrainBody.Ptr);
256 257
257 // Get rid of the old terrain 258 // Get rid of the old terrain
258 BulletSimAPI.DestroyObject2(m_physicsScene.World.Ptr, mapInfo.terrainBody.Ptr); 259 BulletSimAPI.DestroyObject2(PhysicsScene.World.Ptr, mapInfo.terrainBody.Ptr);
259 BulletSimAPI.ReleaseHeightMapInfo2(mapInfo.Ptr); 260 BulletSimAPI.ReleaseHeightMapInfo2(mapInfo.Ptr);
260 mapInfo.Ptr = IntPtr.Zero; 261 mapInfo.Ptr = IntPtr.Zero;
261 262
@@ -286,7 +287,7 @@ public class BSTerrainManager
286 BSScene.DetailLogZero, mapInfo.minCoords.X, mapInfo.minCoords.Y, minZ, maxZ); 287 BSScene.DetailLogZero, mapInfo.minCoords.X, mapInfo.minCoords.Y, minZ, maxZ);
287 288
288 mapInfo.ID = id; 289 mapInfo.ID = id;
289 mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(m_physicsScene.World.Ptr, mapInfo.ID, 290 mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.Ptr, mapInfo.ID,
290 mapInfo.minCoords, mapInfo.maxCoords, mapInfo.heightMap, TERRAIN_COLLISION_MARGIN); 291 mapInfo.minCoords, mapInfo.maxCoords, mapInfo.heightMap, TERRAIN_COLLISION_MARGIN);
291 292
292 // The terrain object initial position is at the center of the object 293 // The terrain object initial position is at the center of the object
@@ -307,19 +308,19 @@ public class BSTerrainManager
307 m_heightMaps[terrainRegionBase] = mapInfo; 308 m_heightMaps[terrainRegionBase] = mapInfo;
308 309
309 // Set current terrain attributes 310 // Set current terrain attributes
310 BulletSimAPI.SetFriction2(mapInfo.terrainBody.Ptr, m_physicsScene.Params.terrainFriction); 311 BulletSimAPI.SetFriction2(mapInfo.terrainBody.Ptr, PhysicsScene.Params.terrainFriction);
311 BulletSimAPI.SetHitFraction2(mapInfo.terrainBody.Ptr, m_physicsScene.Params.terrainHitFraction); 312 BulletSimAPI.SetHitFraction2(mapInfo.terrainBody.Ptr, PhysicsScene.Params.terrainHitFraction);
312 BulletSimAPI.SetRestitution2(mapInfo.terrainBody.Ptr, m_physicsScene.Params.terrainRestitution); 313 BulletSimAPI.SetRestitution2(mapInfo.terrainBody.Ptr, PhysicsScene.Params.terrainRestitution);
313 BulletSimAPI.SetCollisionFlags2(mapInfo.terrainBody.Ptr, CollisionFlags.CF_STATIC_OBJECT); 314 BulletSimAPI.SetCollisionFlags2(mapInfo.terrainBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
314 315
315 BulletSimAPI.SetMassProps2(mapInfo.terrainBody.Ptr, 0f, Vector3.Zero); 316 BulletSimAPI.SetMassProps2(mapInfo.terrainBody.Ptr, 0f, Vector3.Zero);
316 BulletSimAPI.UpdateInertiaTensor2(mapInfo.terrainBody.Ptr); 317 BulletSimAPI.UpdateInertiaTensor2(mapInfo.terrainBody.Ptr);
317 318
318 // Return the new terrain to the world of physical objects 319 // Return the new terrain to the world of physical objects
319 BulletSimAPI.AddObjectToWorld2(m_physicsScene.World.Ptr, mapInfo.terrainBody.Ptr); 320 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.Ptr, mapInfo.terrainBody.Ptr);
320 321
321 // redo its bounding box now that it is in the world 322 // redo its bounding box now that it is in the world
322 BulletSimAPI.UpdateSingleAabb2(m_physicsScene.World.Ptr, mapInfo.terrainBody.Ptr); 323 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.Ptr, mapInfo.terrainBody.Ptr);
323 324
324 // Make sure the new shape is processed. 325 // Make sure the new shape is processed.
325 BulletSimAPI.Activate2(mapInfo.terrainBody.Ptr, true); 326 BulletSimAPI.Activate2(mapInfo.terrainBody.Ptr, true);
@@ -332,7 +333,7 @@ public class BSTerrainManager
332 if (doNow) 333 if (doNow)
333 rebuildOperation(); 334 rebuildOperation();
334 else 335 else
335 m_physicsScene.TaintedObject("BSScene.UpdateOrCreateTerrain:UpdateExisting", rebuildOperation); 336 PhysicsScene.TaintedObject("BSScene.UpdateOrCreateTerrain:UpdateExisting", rebuildOperation);
336 } 337 }
337 else 338 else
338 { 339 {
@@ -357,7 +358,7 @@ public class BSTerrainManager
357 DetailLog("{0},UpdateOrCreateTerrain:NewTerrain,taint,baseX={1},baseY={2}", BSScene.DetailLogZero, minCoords.X, minCoords.Y); 358 DetailLog("{0},UpdateOrCreateTerrain:NewTerrain,taint,baseX={1},baseY={2}", BSScene.DetailLogZero, minCoords.X, minCoords.Y);
358 // Create a new mapInfo that will be filled with the new info 359 // Create a new mapInfo that will be filled with the new info
359 mapInfo = new BulletHeightMapInfo(id, heightMapX, 360 mapInfo = new BulletHeightMapInfo(id, heightMapX,
360 BulletSimAPI.CreateHeightMapInfo2(m_physicsScene.World.Ptr, newTerrainID, 361 BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.Ptr, newTerrainID,
361 minCoordsX, maxCoordsX, heightMapX, TERRAIN_COLLISION_MARGIN)); 362 minCoordsX, maxCoordsX, heightMapX, TERRAIN_COLLISION_MARGIN));
362 // Put the unfilled heightmap info into the collection of same 363 // Put the unfilled heightmap info into the collection of same
363 m_heightMaps.Add(terrainRegionBase, mapInfo); 364 m_heightMaps.Add(terrainRegionBase, mapInfo);
@@ -371,7 +372,7 @@ public class BSTerrainManager
371 if (doNow) 372 if (doNow)
372 createOperation(); 373 createOperation();
373 else 374 else
374 m_physicsScene.TaintedObject("BSScene.UpdateOrCreateTerrain:NewTerrain", createOperation); 375 PhysicsScene.TaintedObject("BSScene.UpdateOrCreateTerrain:NewTerrain", createOperation);
375 } 376 }
376 } 377 }
377 378
@@ -419,7 +420,7 @@ public class BSTerrainManager
419 catch 420 catch
420 { 421 {
421 // Sometimes they give us wonky values of X and Y. Give a warning and return something. 422 // Sometimes they give us wonky values of X and Y. Give a warning and return something.
422 m_physicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, x={2}, y={3}", 423 PhysicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, x={2}, y={3}",
423 LogHeader, terrainBaseXY, regionX, regionY); 424 LogHeader, terrainBaseXY, regionX, regionY);
424 ret = HEIGHT_GETHEIGHT_RET; 425 ret = HEIGHT_GETHEIGHT_RET;
425 } 426 }
@@ -428,8 +429,8 @@ public class BSTerrainManager
428 } 429 }
429 else 430 else
430 { 431 {
431 m_physicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}", 432 PhysicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}",
432 LogHeader, m_physicsScene.RegionName, tX, tY); 433 LogHeader, PhysicsScene.RegionName, tX, tY);
433 } 434 }
434 m_terrainModified = false; 435 m_terrainModified = false;
435 lastHeight = ret; 436 lastHeight = ret;
@@ -453,7 +454,7 @@ public class BSTerrainManager
453 { 454 {
454 m_worldOffset = offset; 455 m_worldOffset = offset;
455 m_worldMax = extents; 456 m_worldMax = extents;
456 m_parentScene = pScene; 457 MegaRegionParentPhysicsScene = pScene;
457 if (pScene != null) 458 if (pScene != null)
458 { 459 {
459 // We are a child. 460 // We are a child.
@@ -474,7 +475,7 @@ public class BSTerrainManager
474 475
475 private void DetailLog(string msg, params Object[] args) 476 private void DetailLog(string msg, params Object[] args)
476 { 477 {
477 m_physicsScene.PhysicsLogging.Write(msg, args); 478 PhysicsScene.PhysicsLogging.Write(msg, args);
478 } 479 }
479} 480}
480} 481}