From 1cde77293e993c3a7329ea8e1fa013c8d7b898e5 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 8 Aug 2010 17:51:43 +0200 Subject: Thank you, Marck00, for a patch that implemented region distance sorting for fallback regions. Applied with changes. --- OpenSim/Data/MySQL/MySQLRegionData.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Data/MySQL/MySQLRegionData.cs') diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index aec37e2..878b8e8 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -289,8 +289,10 @@ namespace OpenSim.Data.MySQL public List GetFallbackRegions(UUID scopeID, int x, int y) { - // TODO: distance-sort results - return Get((int)RegionFlags.FallbackRegion, scopeID); + List regions = Get((int)RegionFlags.FallbackRegion, scopeID); + RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y); + regions.Sort(distanceComparer); + return regions; } public List GetHyperlinks(UUID scopeID) -- cgit v1.1 From f4719cfe1b7b7938f5319fb37d219c93bb857984 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 23 Aug 2015 18:10:51 +0100 Subject: fix db region search by a position, for varregions ( ignoring other that mysql for now ) --- OpenSim/Data/MySQL/MySQLRegionData.cs | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'OpenSim/Data/MySQL/MySQLRegionData.cs') diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index 2ad7590..fab0318 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -82,6 +82,7 @@ namespace OpenSim.Data.MySQL public RegionData Get(int posX, int posY, UUID scopeID) { +/* fixed size regions string command = "select * from `"+m_Realm+"` where locX = ?posX and locY = ?posY"; if (scopeID != UUID.Zero) command += " and ScopeID = ?scopeID"; @@ -98,6 +99,45 @@ namespace OpenSim.Data.MySQL return ret[0]; } +*/ + // extend database search for maximum region size area + string command = "select * from `" + m_Realm + "` where locX between ?startX and ?endX and locY between ?startY and ?endY"; + if (scopeID != UUID.Zero) + command += " and ScopeID = ?scopeID"; + + int startX = posX - (int)Constants.MaximumRegionSize; + int startY = posY - (int)Constants.MaximumRegionSize; + int endX = posX; + int endY = posY; + + List ret; + using (MySqlCommand cmd = new MySqlCommand(command)) + { + cmd.Parameters.AddWithValue("?startX", startX.ToString()); + cmd.Parameters.AddWithValue("?startY", startY.ToString()); + cmd.Parameters.AddWithValue("?endX", endX.ToString()); + cmd.Parameters.AddWithValue("?endY", endY.ToString()); + cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); + + ret = RunCommand(cmd); + } + + if (ret.Count == 0) + return null; + + // find the first that contains pos + RegionData rg = null; + foreach (RegionData r in ret) + { + if (posX >= r.posX && posX < r.posX + r.sizeX + && posY >= r.posY && posY < r.posY + r.sizeY) + { + rg = r; + break; + } + } + + return rg; } public RegionData Get(UUID regionID, UUID scopeID) -- cgit v1.1 From c3e5519bf3b35310d18170c2dac4ebbea728bdac Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 23 Aug 2015 18:25:15 +0100 Subject: fix db region find by range for varregions ( ignoring others than Mysql) --- OpenSim/Data/MySQL/MySQLRegionData.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'OpenSim/Data/MySQL/MySQLRegionData.cs') diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index fab0318..3dc049b 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -161,6 +161,7 @@ namespace OpenSim.Data.MySQL public List Get(int startX, int startY, int endX, int endY, UUID scopeID) { +/* fix size regions string command = "select * from `"+m_Realm+"` where locX between ?startX and ?endX and locY between ?startY and ?endY"; if (scopeID != UUID.Zero) command += " and ScopeID = ?scopeID"; @@ -175,6 +176,38 @@ namespace OpenSim.Data.MySQL return RunCommand(cmd); } + */ + string command = "select * from `" + m_Realm + "` where locX between ?startX and ?endX and locY between ?startY and ?endY"; + if (scopeID != UUID.Zero) + command += " and ScopeID = ?scopeID"; + + int qstartX = startX - (int)Constants.MaximumRegionSize; + int qstartY = startY - (int)Constants.MaximumRegionSize; + + List dbret; + using (MySqlCommand cmd = new MySqlCommand(command)) + { + cmd.Parameters.AddWithValue("?startX", qstartX.ToString()); + cmd.Parameters.AddWithValue("?startY", qstartY.ToString()); + cmd.Parameters.AddWithValue("?endX", endX.ToString()); + cmd.Parameters.AddWithValue("?endY", endY.ToString()); + cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); + + dbret = RunCommand(cmd); + } + + List ret = new List(); + + if (dbret.Count == 0) + return ret; + + foreach (RegionData r in dbret) + { + if (r.posX + r.sizeX > startX && r.posX <= endX + && r.posY + r.sizeX > startY && r.posY <= endY) + ret.Add(r); + } + return ret; } public List RunCommand(MySqlCommand cmd) -- cgit v1.1