diff options
author | Robert Adams | 2012-09-18 11:26:19 -0700 |
---|---|---|
committer | Robert Adams | 2012-09-27 22:01:16 -0700 |
commit | 91efccabdcb45ed95ae35ab24ed5d3ed5508b463 (patch) | |
tree | fb801ca0bd72aae3427a5ca439f807ec3802d7c3 /OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | |
parent | BulletSim: move a bunch of common logic out of BSPrim and BSCharacter (diff) | |
download | opensim-SC-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.zip opensim-SC-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.gz opensim-SC-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.bz2 opensim-SC-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/Region/Physics/BulletSPlugin/BSTerrainManager.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | 67 |
1 files changed, 34 insertions, 33 deletions
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 | } |