From 66c40dd3debf240f88d87feda42e9a48a4ed0ce7 Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Thu, 20 Aug 2009 19:24:31 -0400 Subject: * Switch border cross tests over to the new Border class. * Use List for each cardinal to allow for irregular regions. --- OpenSim/Region/Framework/Scenes/Scene.cs | 107 ++++++++++++++++++++- .../Region/Framework/Scenes/SceneObjectGroup.cs | 4 +- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 17 ++-- .../Region/Framework/Scenes/Tests/BorderTests.cs | 2 +- 4 files changed, 116 insertions(+), 14 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index d1f7a4b..cb4e443 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -81,6 +81,11 @@ namespace OpenSim.Region.Framework.Scenes protected List m_regionRestartNotifyList = new List(); protected List m_neighbours = new List(); + public List NorthBorders = new List(); + public List EastBorders = new List(); + public List SouthBorders = new List(); + public List WestBorders = new List(); + /// /// The scene graph for this scene /// @@ -326,6 +331,28 @@ namespace OpenSim.Region.Framework.Scenes m_config = config; Random random = new Random(); + + Border northBorder = new Border(); + northBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<--- + northBorder.CrossDirection = Cardinals.N; + NorthBorders.Add(northBorder); + + Border southBorder = new Border(); + southBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //---> + southBorder.CrossDirection = Cardinals.S; + SouthBorders.Add(southBorder); + + Border eastBorder = new Border(); + eastBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<--- + eastBorder.CrossDirection = Cardinals.E; + EastBorders.Add(eastBorder); + + Border westBorder = new Border(); + westBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //---> + westBorder.CrossDirection = Cardinals.W; + WestBorders.Add(westBorder); + + m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4); m_moduleLoader = moduleLoader; m_authenticateHandler = authen; @@ -455,6 +482,26 @@ namespace OpenSim.Region.Framework.Scenes /// public Scene(RegionInfo regInfo) { + Border northBorder = new Border(); + northBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<--- + northBorder.CrossDirection = Cardinals.N; + NorthBorders.Add(northBorder); + + Border southBorder = new Border(); + southBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //---> + southBorder.CrossDirection = Cardinals.S; + SouthBorders.Add(southBorder); + + Border eastBorder = new Border(); + eastBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<--- + eastBorder.CrossDirection = Cardinals.E; + EastBorders.Add(eastBorder); + + Border westBorder = new Border(); + westBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //---> + westBorder.CrossDirection = Cardinals.W; + WestBorders.Add(westBorder); + m_regInfo = regInfo; m_eventManager = new EventManager(); } @@ -1659,14 +1706,16 @@ namespace OpenSim.Region.Framework.Scenes ulong newRegionHandle = 0; Vector3 pos = attemptedPosition; - if (attemptedPosition.X > Constants.RegionSize + 0.1f) + + + if (TestBorderCross(attemptedPosition, Cardinals.E)) { pos.X = ((pos.X - Constants.RegionSize)); newRegionHandle = Util.UIntsToLong((uint)((thisx + 1) * Constants.RegionSize), (uint)(thisy * Constants.RegionSize)); // x + 1 } - else if (attemptedPosition.X < -0.1f) + else if (TestBorderCross(attemptedPosition, Cardinals.W)) { pos.X = ((pos.X + Constants.RegionSize)); newRegionHandle @@ -1674,14 +1723,14 @@ namespace OpenSim.Region.Framework.Scenes // x - 1 } - if (attemptedPosition.Y > Constants.RegionSize + 0.1f) + if (TestBorderCross(attemptedPosition, Cardinals.N)) { pos.Y = ((pos.Y - Constants.RegionSize)); newRegionHandle = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + 1) * Constants.RegionSize)); // y + 1 } - else if (attemptedPosition.Y < -0.1f) + else if (TestBorderCross(attemptedPosition, Cardinals.S)) { pos.Y = ((pos.Y + Constants.RegionSize)); newRegionHandle @@ -1701,6 +1750,56 @@ namespace OpenSim.Region.Framework.Scenes } } + public bool TestBorderCross(Vector3 position, Cardinals border) + { + switch (border) + { + case Cardinals.N: + lock (NorthBorders) + { + foreach(Border b in NorthBorders) + { + if (b.TestCross(position)) + return true; + } + } + break; + case Cardinals.E: + lock (EastBorders) + { + foreach (Border b in EastBorders) + { + if (b.TestCross(position)) + return true; + } + } + break; + case Cardinals.S: + lock (SouthBorders) + { + foreach (Border b in SouthBorders) + { + if (b.TestCross(position)) + return true; + } + } + break; + case Cardinals.W: + lock (WestBorders) + { + foreach (Border b in WestBorders) + { + if (b.TestCross(position)) + return true; + } + } + break; + + } + return false; + } + + /// /// Move the given scene object into a new region /// diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 1b541c4..e5c6bf1 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -264,7 +264,9 @@ namespace OpenSim.Region.Framework.Scenes { Vector3 val = value; - if ((val.X > 257f || val.X < -1f || val.Y > 257f || val.Y < -1f) && !IsAttachment) + if ((m_scene.TestBorderCross(val,Cardinals.E) || m_scene.TestBorderCross(val,Cardinals.W) + || m_scene.TestBorderCross(val, Cardinals.N) || m_scene.TestBorderCross(val, Cardinals.S)) + && !IsAttachment) { m_scene.CrossPrimGroupIntoNewRegion(val, this, true); } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 5281c4f..aae1823 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2830,27 +2830,28 @@ namespace OpenSim.Region.Framework.Scenes if (!IsInTransit) { // Checks if where it's headed exists a region - if (pos2.X < 0) + + if (m_scene.TestBorderCross(pos2, Cardinals.W)) { - if (pos2.Y < 0) + if (m_scene.TestBorderCross(pos2, Cardinals.S)) neighbor = HaveNeighbor(Cardinals.SW, ref fix); - else if (pos2.Y > Constants.RegionSize) + else if (m_scene.TestBorderCross(pos2, Cardinals.N)) neighbor = HaveNeighbor(Cardinals.NW, ref fix); else neighbor = HaveNeighbor(Cardinals.W, ref fix); } - else if (pos2.X > Constants.RegionSize) + else if (m_scene.TestBorderCross(pos2, Cardinals.E)) { - if (pos2.Y < 0) + if (m_scene.TestBorderCross(pos2, Cardinals.S)) neighbor = HaveNeighbor(Cardinals.SE, ref fix); - else if (pos2.Y > Constants.RegionSize) + else if (m_scene.TestBorderCross(pos2, Cardinals.N)) neighbor = HaveNeighbor(Cardinals.NE, ref fix); else neighbor = HaveNeighbor(Cardinals.E, ref fix); } - else if (pos2.Y < 0) + else if (m_scene.TestBorderCross(pos2, Cardinals.S)) neighbor = HaveNeighbor(Cardinals.S, ref fix); - else if (pos2.Y > Constants.RegionSize) + else if (m_scene.TestBorderCross(pos2, Cardinals.N)) neighbor = HaveNeighbor(Cardinals.N, ref fix); // Makes sure avatar does not end up outside region diff --git a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs index 6f77062..272c96e 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs @@ -6,7 +6,7 @@ using OpenSim.Region.Framework.Scenes; using NUnit.Framework; -namespace OpenSim.Region.Framework.Tests +namespace OpenSim.Region.Framework.Scenes.Tests { [TestFixture] public class BorderTests -- cgit v1.1