From ad81b453b38b538d5b4c40a326decee2577e024e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 5 Oct 2009 09:02:52 -0700 Subject: GetRegionByPosition: use the cache, Luke. --- .../ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | 14 ++++++++++++++ .../CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs | 14 ++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 3ca4882..1c72488 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -206,6 +206,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { + GridRegion region = null; + + // First see if it's a neighbour, even if it isn't on this sim. + // Neighbour data is cached in memory, so this is fast + foreach (RegionCache rcache in m_LocalCache.Values) + { + region = rcache.GetRegionByPosition(x, y); + if (region != null) + { + return region; + } + } + + // Then try on this sim (may be a lookup in DB if this is using MySql). return m_GridService.GetRegionByPosition(scopeID, x, y); } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs index 2b336bb..44e850b 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs @@ -29,10 +29,12 @@ using System; using System.Collections.Generic; using System.Reflection; +using OpenSim.Framework; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenMetaverse; using log4net; namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid @@ -75,5 +77,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { return new List(m_neighbours.Values); } + + public GridRegion GetRegionByPosition(int x, int y) + { + uint xsnap = (uint)(x / Constants.RegionSize) * Constants.RegionSize; + uint ysnap = (uint)(y / Constants.RegionSize) * Constants.RegionSize; + ulong handle = Utils.UIntsToLong(xsnap, ysnap); + + if (m_neighbours.ContainsKey(handle)) + return m_neighbours[handle]; + + return null; + } } } -- cgit v1.1