From beeec1c46726a266edf5c8260f9cf4e4e6f91c8a Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Fri, 8 Nov 2013 20:53:37 -0800
Subject: varregion: elimination of Constants.RegionSize from all over
OpenSimulator. Routines in Util to compute region world coordinates from
region coordinates as well as the conversion to and from region handles.
These routines have replaced a lot of math scattered throughout the
simulator. Should be no functional changes.
---
OpenSim/Region/Framework/Scenes/Scene.cs | 48 ++++++++++++++--------
.../Framework/Scenes/SceneCommunicationService.cs | 4 +-
OpenSim/Region/Framework/Scenes/ScenePresence.cs | 34 +++++++--------
OpenSim/Region/Framework/Scenes/TerrainChannel.cs | 2 +-
.../Region/Framework/Scenes/TerrainCompressor.cs | 2 +-
5 files changed, 51 insertions(+), 39 deletions(-)
(limited to 'OpenSim/Region/Framework')
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 64b3baf..99c7079 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -1099,8 +1099,11 @@ namespace OpenSim.Region.Framework.Scenes
/// True after all operations complete, throws exceptions otherwise.
public override void OtherRegionUp(GridRegion otherRegion)
{
- uint xcell = (uint)((int)otherRegion.RegionLocX / (int)Constants.RegionSize);
- uint ycell = (uint)((int)otherRegion.RegionLocY / (int)Constants.RegionSize);
+ // uint xcell = (uint)((int)otherRegion.RegionLocX / (int)Constants.RegionSize);
+ // uint ycell = (uint)((int)otherRegion.RegionLocY / (int)Constants.RegionSize);
+ uint xcell = Util.WorldToRegionLoc((uint)otherRegion.RegionLocX);
+ uint ycell = Util.WorldToRegionLoc((uint)otherRegion.RegionLocY);
+
//m_log.InfoFormat("[SCENE]: (on region {0}): Region {1} up in coords {2}-{3}",
// RegionInfo.RegionName, otherRegion.RegionName, xcell, ycell);
@@ -1198,9 +1201,11 @@ namespace OpenSim.Region.Framework.Scenes
else if (dir > 3 && dir < 7) // Heading Sout
neighboury--;
- int x = (int)(neighbourx * Constants.RegionSize);
- int y = (int)(neighboury * Constants.RegionSize);
- GridRegion neighbourRegion = GridService.GetRegionByPosition(RegionInfo.ScopeID, x, y);
+ // int x = (int)(neighbourx * Constants.RegionSize);
+ // int y = (int)(neighboury * Constants.RegionSize);
+ uint x = Util.RegionToWorldLoc(neighbourx);
+ uint y = Util.RegionToWorldLoc(neighboury);
+ GridRegion neighbourRegion = GridService.GetRegionByPosition(RegionInfo.ScopeID, (int)x, (int)y);
if (neighbourRegion == null)
{
@@ -4293,7 +4298,7 @@ namespace OpenSim.Region.Framework.Scenes
"[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName);
// TODO: This check should probably be in QueryAccess().
- ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
+ ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, RegionInfo.RegionSizeX / 2, RegionInfo.RegionSizeY / 2);
if (nearestParcel == null)
{
m_log.InfoFormat(
@@ -4600,13 +4605,22 @@ namespace OpenSim.Region.Framework.Scenes
ScenePresence sp = GetScenePresence(remoteClient.AgentId);
if (sp != null)
{
+ /*
uint regionX = RegionInfo.LegacyRegionLocX;
uint regionY = RegionInfo.LegacyRegionLocY;
+ Util.RegionHandleToWorldLoc(regionHandle, out regionX, out regionY);
Utils.LongToUInts(regionHandle, out regionX, out regionY);
int shiftx = (int) regionX - (int) RegionInfo.LegacyRegionLocX * (int)Constants.RegionSize;
int shifty = (int) regionY - (int) RegionInfo.LegacyRegionLocY * (int)Constants.RegionSize;
+ */
+
+ uint regionX, regionY;
+ Util.RegionHandleToWorldLoc(regionHandle, out regionX, out regionY);
+
+ int shiftx = (int) regionX - (int)RegionInfo.RegionWorldLocX;
+ int shifty = (int) regionY - (int)RegionInfo.RegionWorldLocY;
position.X += shiftx;
position.Y += shifty;
@@ -4817,7 +4831,7 @@ namespace OpenSim.Region.Framework.Scenes
else
{
- if (pos.X > 0f && pos.X < Constants.RegionSize && pos.Y > 0f && pos.Y < Constants.RegionSize)
+ if (pos.X > 0f && pos.X < RegionInfo.RegionSizeX && pos.Y > 0f && pos.Y < RegionInfo.RegionSizeY)
{
// The only time parcel != null when an object is inside a region is when
// there is nothing behind the landchannel. IE, no land plugin loaded.
@@ -5478,7 +5492,7 @@ namespace OpenSim.Region.Framework.Scenes
{
Vector3 unitDirection = Vector3.Normalize(direction);
//Making distance to search go through some sane limit of distance
- for (float distance = 0; distance < Constants.RegionSize * 2; distance += .5f)
+ for (float distance = 0; distance < Math.Max(RegionInfo.RegionSizeX, RegionInfo.RegionSizeY) * 2; distance += .5f)
{
Vector3 testPos = Vector3.Add(pos, Vector3.Multiply(unitDirection, distance));
if (parcel.ContainsPoint((int)testPos.X, (int)testPos.Y))
@@ -5532,9 +5546,9 @@ namespace OpenSim.Region.Framework.Scenes
int count = 0;
int avgx = 0;
int avgy = 0;
- for (int x = 0; x < Constants.RegionSize; x++)
+ for (int x = 0; x < RegionInfo.RegionSizeX; x++)
{
- for (int y = 0; y < Constants.RegionSize; y++)
+ for (int y = 0; y < RegionInfo.RegionSizeY; y++)
{
//Just keep a running average as we check if all the points are inside or not
if (parcel.ContainsPoint(x, y))
@@ -5558,31 +5572,33 @@ namespace OpenSim.Region.Framework.Scenes
private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)
{
- float xdistance = avatar.AbsolutePosition.X < Constants.RegionSize / 2 ? avatar.AbsolutePosition.X : Constants.RegionSize - avatar.AbsolutePosition.X;
- float ydistance = avatar.AbsolutePosition.Y < Constants.RegionSize / 2 ? avatar.AbsolutePosition.Y : Constants.RegionSize - avatar.AbsolutePosition.Y;
+ float xdistance = avatar.AbsolutePosition.X < RegionInfo.RegionSizeX / 2
+ ? avatar.AbsolutePosition.X : RegionInfo.RegionSizeX - avatar.AbsolutePosition.X;
+ float ydistance = avatar.AbsolutePosition.Y < RegionInfo.RegionSizeY / 2
+ ? avatar.AbsolutePosition.Y : RegionInfo.RegionSizeY - avatar.AbsolutePosition.Y;
//find out what vertical edge to go to
if (xdistance < ydistance)
{
- if (avatar.AbsolutePosition.X < Constants.RegionSize / 2)
+ if (avatar.AbsolutePosition.X < RegionInfo.RegionSizeX / 2)
{
return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y);
}
else
{
- return GetPositionAtAvatarHeightOrGroundHeight(avatar, Constants.RegionSize, avatar.AbsolutePosition.Y);
+ return GetPositionAtAvatarHeightOrGroundHeight(avatar, RegionInfo.RegionSizeY, avatar.AbsolutePosition.Y);
}
}
//find out what horizontal edge to go to
else
{
- if (avatar.AbsolutePosition.Y < Constants.RegionSize / 2)
+ if (avatar.AbsolutePosition.Y < RegionInfo.RegionSizeY / 2)
{
return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f);
}
else
{
- return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, Constants.RegionSize);
+ return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, RegionInfo.RegionSizeY);
}
}
}
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 77889fa..262b882 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -92,7 +92,7 @@ namespace OpenSim.Region.Framework.Scenes
{
m_log.DebugFormat(
"[SCENE COMMUNICATION SERVICE]: Region {0} successfully informed neighbour {1} at {2}-{3} that it is up",
- m_scene.Name, neighbour.RegionName, x / Constants.RegionSize, y / Constants.RegionSize);
+ m_scene.Name, neighbour.RegionName, Util.WorldToRegionLoc(x), Util.WorldToRegionLoc(y));
m_scene.EventManager.TriggerOnRegionUp(neighbour);
}
@@ -100,7 +100,7 @@ namespace OpenSim.Region.Framework.Scenes
{
m_log.WarnFormat(
"[SCENE COMMUNICATION SERVICE]: Region {0} failed to inform neighbour at {1}-{2} that it is up.",
- m_scene.Name, x / Constants.RegionSize, y / Constants.RegionSize);
+ m_scene.Name, Util.WorldToRegionLoc(x), Util.WorldToRegionLoc(y));
}
}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 297ee5f..2c64c85 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -707,9 +707,8 @@ namespace OpenSim.Region.Framework.Scenes
foreach (ulong handle in seeds.Keys)
{
uint x, y;
- Utils.LongToUInts(handle, out x, out y);
- x = x / Constants.RegionSize;
- y = y / Constants.RegionSize;
+ Util.RegionHandleToRegionLoc(handle, out x, out y);
+
if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.LegacyRegionLocX, y, Scene.RegionInfo.LegacyRegionLocY))
{
old.Add(handle);
@@ -731,9 +730,7 @@ namespace OpenSim.Region.Framework.Scenes
foreach (KeyValuePair kvp in KnownRegions)
{
uint x, y;
- Utils.LongToUInts(kvp.Key, out x, out y);
- x = x / Constants.RegionSize;
- y = y / Constants.RegionSize;
+ Util.RegionHandleToRegionLoc(kvp.Key, out x, out y);
m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
}
}
@@ -971,7 +968,7 @@ namespace OpenSim.Region.Framework.Scenes
float posZLimit = 0;
- if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
+ if (pos.X < m_scene.RegionInfo.RegionSizeX && pos.Y < m_scene.RegionInfo.RegionSizeY)
posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
float newPosZ = posZLimit + localAVHeight / 2;
@@ -2076,7 +2073,7 @@ namespace OpenSim.Region.Framework.Scenes
if (regionCombinerModule != null)
regionSize = regionCombinerModule.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID);
else
- regionSize = new Vector2(Constants.RegionSize);
+ regionSize = new Vector2(m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);
if (pos.X < 0 || pos.X >= regionSize.X
|| pos.Y < 0 || pos.Y >= regionSize.Y
@@ -2106,7 +2103,7 @@ namespace OpenSim.Region.Framework.Scenes
if (!SceneManager.Instance.TryGetScene(target_regionID, out targetScene))
targetScene = m_scene;
- float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % Constants.RegionSize), (int)(pos.Y % Constants.RegionSize)];
+ float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % regionSize.X), (int)(pos.Y % regionSize.Y)];
pos.Z = Math.Max(terrainHeight, pos.Z);
// Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is
@@ -3199,11 +3196,11 @@ namespace OpenSim.Region.Framework.Scenes
Vector3 pos = AbsolutePosition;
if (AbsolutePosition.X < 0)
pos.X += Velocity.X * 2;
- else if (AbsolutePosition.X > Constants.RegionSize)
+ else if (AbsolutePosition.X > m_scene.RegionInfo.RegionSizeX)
pos.X -= Velocity.X * 2;
if (AbsolutePosition.Y < 0)
pos.Y += Velocity.Y * 2;
- else if (AbsolutePosition.Y > Constants.RegionSize)
+ else if (AbsolutePosition.Y > m_scene.RegionInfo.RegionSizeY)
pos.Y -= Velocity.Y * 2;
Velocity = Vector3.Zero;
AbsolutePosition = pos;
@@ -3226,11 +3223,11 @@ namespace OpenSim.Region.Framework.Scenes
Vector3 pos = AbsolutePosition;
if (AbsolutePosition.X < 0)
pos.X += Velocity.X * 2;
- else if (AbsolutePosition.X > Constants.RegionSize)
+ else if (AbsolutePosition.X > m_scene.RegionInfo.RegionSizeX)
pos.X -= Velocity.X * 2;
if (AbsolutePosition.Y < 0)
pos.Y += Velocity.Y * 2;
- else if (AbsolutePosition.Y > Constants.RegionSize)
+ else if (AbsolutePosition.Y > m_scene.RegionInfo.RegionSizeY)
pos.Y -= Velocity.Y * 2;
Velocity = Vector3.Zero;
AbsolutePosition = pos;
@@ -3279,7 +3276,7 @@ namespace OpenSim.Region.Framework.Scenes
// Put the child agent back at the center
AbsolutePosition
- = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70);
+ = new Vector3(((float)m_scene.RegionInfo.RegionSizeX * 0.5f), ((float)m_scene.RegionInfo.RegionSizeY * 0.5f), 70);
Animator.ResetAnimations();
}
@@ -3306,9 +3303,7 @@ namespace OpenSim.Region.Framework.Scenes
if (handle != Scene.RegionInfo.RegionHandle)
{
uint x, y;
- Utils.LongToUInts(handle, out x, out y);
- x = x / Constants.RegionSize;
- y = y / Constants.RegionSize;
+ Util.RegionHandleToRegionLoc(handle, out x, out y);
// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
@@ -3389,8 +3384,9 @@ namespace OpenSim.Region.Framework.Scenes
return;
//m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY);
- int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize;
- int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize;
+ // Find the distance (in meters) between the two regions
+ uint shiftx = Util.RegionToWorldLoc(rRegionX - tRegionX);
+ uint shifty = Util.RegionToWorldLoc(rRegionY - tRegionY);
Vector3 offset = new Vector3(shiftx, shifty, 0f);
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
index 03499e8..a5b42ff 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
@@ -264,7 +264,7 @@ namespace OpenSim.Region.Framework.Scenes
byte[] dataArray = (byte[])serializer.Deserialize(xmlReader);
int index = 0;
- m_terrainData = new HeightmapTerrainData((int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
+ m_terrainData = new HeightmapTerrainData(Height, Width, (int)Constants.RegionHeight);
for (int y = 0; y < Height; y++)
{
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
index 5ecde87..ced62e2 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
@@ -194,7 +194,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
int wbits;
int[] patch = CompressPatch(patchData, header, 10, out wbits);
- wbits = EncodePatchHeader(output, header, patch, Constants.RegionSize, Constants.RegionSize, wbits);
+ wbits = EncodePatchHeader(output, header, patch, (uint)pRegionSizeX, (uint)pRegionSizeY, wbits);
EncodePatch(output, patch, 0, wbits);
}
--
cgit v1.1