diff options
author | Melanie Thielker | 2010-08-08 17:51:43 +0200 |
---|---|---|
committer | Melanie | 2010-08-08 17:37:50 +0100 |
commit | 1f25b9e8dbf500d22df55fa2a8f7f9b7bf873aa3 (patch) | |
tree | f779307b0abfa3be35871ea86e06da9a9922cf68 /OpenSim/Data | |
parent | In my crusade against facelights, I am striking the killing blow. Add a (diff) | |
download | opensim-SC-1f25b9e8dbf500d22df55fa2a8f7f9b7bf873aa3.zip opensim-SC-1f25b9e8dbf500d22df55fa2a8f7f9b7bf873aa3.tar.gz opensim-SC-1f25b9e8dbf500d22df55fa2a8f7f9b7bf873aa3.tar.bz2 opensim-SC-1f25b9e8dbf500d22df55fa2a8f7f9b7bf873aa3.tar.xz |
Thank you, Marck00, for a patch that implemented region distance sorting
for fallback regions. Applied with changes.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/IRegionData.cs | 22 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLRegionData.cs | 7 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/MySQLRegionData.cs | 6 |
3 files changed, 31 insertions, 4 deletions
diff --git a/OpenSim/Data/IRegionData.cs b/OpenSim/Data/IRegionData.cs index 42533c6..46dc4fb 100644 --- a/OpenSim/Data/IRegionData.cs +++ b/OpenSim/Data/IRegionData.cs | |||
@@ -79,4 +79,26 @@ namespace OpenSim.Data | |||
79 | Authenticate = 256, // Require authentication | 79 | Authenticate = 256, // Require authentication |
80 | Hyperlink = 512 // Record represents a HG link | 80 | Hyperlink = 512 // Record represents a HG link |
81 | } | 81 | } |
82 | |||
83 | public class RegionDataDistanceCompare : IComparer<RegionData> | ||
84 | { | ||
85 | private Vector2 m_origin; | ||
86 | |||
87 | public RegionDataDistanceCompare(int x, int y) | ||
88 | { | ||
89 | m_origin = new Vector2(x, y); | ||
90 | } | ||
91 | |||
92 | public int Compare(RegionData regionA, RegionData regionB) | ||
93 | { | ||
94 | Vector2 vectorA = new Vector2(regionA.posX, regionA.posY); | ||
95 | Vector2 vectorB = new Vector2(regionB.posX, regionB.posY); | ||
96 | return Math.Sign(VectorDistance(m_origin, vectorA) - VectorDistance(m_origin, vectorB)); | ||
97 | } | ||
98 | |||
99 | private float VectorDistance(Vector2 x, Vector2 y) | ||
100 | { | ||
101 | return (x - y).Length(); | ||
102 | } | ||
103 | } | ||
82 | } | 104 | } |
diff --git a/OpenSim/Data/MSSQL/MSSQLRegionData.cs b/OpenSim/Data/MSSQL/MSSQLRegionData.cs index 9656be1..cdf8ec0 100644 --- a/OpenSim/Data/MSSQL/MSSQLRegionData.cs +++ b/OpenSim/Data/MSSQL/MSSQLRegionData.cs | |||
@@ -315,8 +315,11 @@ namespace OpenSim.Data.MSSQL | |||
315 | 315 | ||
316 | public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y) | 316 | public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y) |
317 | { | 317 | { |
318 | // TODO: distance-sort results | 318 | List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID); |
319 | return Get((int)RegionFlags.FallbackRegion, scopeID); | 319 | RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y); |
320 | regions.Sort(distanceComparer); | ||
321 | |||
322 | return regions; | ||
320 | } | 323 | } |
321 | 324 | ||
322 | public List<RegionData> GetHyperlinks(UUID scopeID) | 325 | public List<RegionData> GetHyperlinks(UUID scopeID) |
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 | |||
289 | 289 | ||
290 | public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y) | 290 | public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y) |
291 | { | 291 | { |
292 | // TODO: distance-sort results | 292 | List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID); |
293 | return Get((int)RegionFlags.FallbackRegion, scopeID); | 293 | RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y); |
294 | regions.Sort(distanceComparer); | ||
295 | return regions; | ||
294 | } | 296 | } |
295 | 297 | ||
296 | public List<RegionData> GetHyperlinks(UUID scopeID) | 298 | public List<RegionData> GetHyperlinks(UUID scopeID) |