aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs86
1 files changed, 48 insertions, 38 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index c68fd69..3428b9c 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -332,6 +332,13 @@ public sealed class BSTerrainManager : IDisposable
332 return newTerrainPhys; 332 return newTerrainPhys;
333 } 333 }
334 334
335 // Return 'true' of this position is somewhere in known physical terrain space
336 public bool IsWithinKnownTerrain(Vector3 pos)
337 {
338 Vector3 terrainBaseXYZ;
339 BSTerrainPhys physTerrain;
340 return GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ);
341 }
335 342
336 // Given an X and Y, find the height of the terrain. 343 // Given an X and Y, find the height of the terrain.
337 // Since we could be handling multiple terrains for a mega-region, 344 // Since we could be handling multiple terrains for a mega-region,
@@ -342,13 +349,13 @@ public sealed class BSTerrainManager : IDisposable
342 private float lastHeightTX = 999999f; 349 private float lastHeightTX = 999999f;
343 private float lastHeightTY = 999999f; 350 private float lastHeightTY = 999999f;
344 private float lastHeight = HEIGHT_INITIAL_LASTHEIGHT; 351 private float lastHeight = HEIGHT_INITIAL_LASTHEIGHT;
345 public float GetTerrainHeightAtXYZ(Vector3 loc) 352 public float GetTerrainHeightAtXYZ(Vector3 pos)
346 { 353 {
347 float tX = loc.X; 354 float tX = pos.X;
348 float tY = loc.Y; 355 float tY = pos.Y;
349 // You'd be surprized at the number of times this routine is called 356 // You'd be surprized at the number of times this routine is called
350 // with the same parameters as last time. 357 // with the same parameters as last time.
351 if (!m_terrainModified && lastHeightTX == tX && lastHeightTY == tY) 358 if (!m_terrainModified && (lastHeightTX == tX) && (lastHeightTY == tY))
352 return lastHeight; 359 return lastHeight;
353 m_terrainModified = false; 360 m_terrainModified = false;
354 361
@@ -356,26 +363,20 @@ public sealed class BSTerrainManager : IDisposable
356 lastHeightTY = tY; 363 lastHeightTY = tY;
357 float ret = HEIGHT_GETHEIGHT_RET; 364 float ret = HEIGHT_GETHEIGHT_RET;
358 365
359 int offsetX = ((int)(tX / (int)DefaultRegionSize.X)) * (int)DefaultRegionSize.X; 366 Vector3 terrainBaseXYZ;
360 int offsetY = ((int)(tY / (int)DefaultRegionSize.Y)) * (int)DefaultRegionSize.Y; 367 BSTerrainPhys physTerrain;
361 Vector3 terrainBaseXYZ = new Vector3(offsetX, offsetY, 0f); 368 if (GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ))
362
363 lock (m_terrains)
364 { 369 {
365 BSTerrainPhys physTerrain; 370 ret = physTerrain.GetTerrainHeightAtXYZ(pos - terrainBaseXYZ);
366 if (m_terrains.TryGetValue(terrainBaseXYZ, out physTerrain))
367 {
368 ret = physTerrain.GetTerrainHeightAtXYZ(loc - terrainBaseXYZ);
369 }
370 else
371 {
372 PhysicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}",
373 LogHeader, PhysicsScene.RegionName, tX, tY);
374 DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,loc={1},base={2}",
375 BSScene.DetailLogZero, loc, terrainBaseXYZ);
376 Util.PrintCallStack(); // DEBUG DEBUG DEBUG
377 }
378 } 371 }
372 else
373 {
374 PhysicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}",
375 LogHeader, PhysicsScene.RegionName, tX, tY);
376 DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,pos={1},base={2}",
377 BSScene.DetailLogZero, pos, terrainBaseXYZ);
378 }
379
379 lastHeight = ret; 380 lastHeight = ret;
380 return ret; 381 return ret;
381 } 382 }
@@ -384,27 +385,36 @@ public sealed class BSTerrainManager : IDisposable
384 { 385 {
385 float ret = WATER_HEIGHT_GETHEIGHT_RET; 386 float ret = WATER_HEIGHT_GETHEIGHT_RET;
386 387
387 float tX = pos.X; 388 Vector3 terrainBaseXYZ;
388 float tY = pos.Y; 389 BSTerrainPhys physTerrain;
390 if (GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ))
391 {
392 ret = physTerrain.GetWaterLevelAtXYZ(pos);
393 }
394 else
395 {
396 PhysicsScene.Logger.ErrorFormat("{0} GetWaterHeightAtXY: terrain not found: pos={1}, terrainBase={2}, height={3}",
397 LogHeader, PhysicsScene.RegionName, pos, terrainBaseXYZ, ret);
398 }
399 return ret;
400 }
389 401
390 Vector3 terrainBaseXYZ = Vector3.Zero; 402 // Given an address, return 'true' of there is a description of that terrain and output
391 terrainBaseXYZ.X = ((int)(tX / (int)DefaultRegionSize.X)) * (int)DefaultRegionSize.X; 403 // the descriptor class and the 'base' fo the addresses therein.
392 terrainBaseXYZ.Y = ((int)(tY / (int)DefaultRegionSize.Y)) * (int)DefaultRegionSize.Y; 404 private bool GetTerrainPhysicalAtXYZ(Vector3 pos, out BSTerrainPhys outPhysTerrain, out Vector3 outTerrainBase)
405 {
406 int offsetX = ((int)(pos.X / (int)DefaultRegionSize.X)) * (int)DefaultRegionSize.X;
407 int offsetY = ((int)(pos.Y / (int)DefaultRegionSize.Y)) * (int)DefaultRegionSize.Y;
408 Vector3 terrainBaseXYZ = new Vector3(offsetX, offsetY, 0f);
393 409
410 BSTerrainPhys physTerrain = null;
394 lock (m_terrains) 411 lock (m_terrains)
395 { 412 {
396 BSTerrainPhys physTerrain; 413 m_terrains.TryGetValue(terrainBaseXYZ, out physTerrain);
397 if (m_terrains.TryGetValue(terrainBaseXYZ, out physTerrain))
398 {
399 ret = physTerrain.GetWaterLevelAtXYZ(pos);
400 }
401 else
402 {
403 PhysicsScene.Logger.ErrorFormat("{0} GetWaterHeightAtXY: terrain not found: region={1}, x={2}, y={3}",
404 LogHeader, PhysicsScene.RegionName, tX, tY);
405 }
406 } 414 }
407 return ret; 415 outTerrainBase = terrainBaseXYZ;
416 outPhysTerrain = physTerrain;
417 return (physTerrain != null);
408 } 418 }
409 419
410 // Although no one seems to check this, I do support combining. 420 // Although no one seems to check this, I do support combining.