Thank you, Marck00, for a patch that implemented region distance sorting

for fallback regions. Applied with changes.
avinationmerge
Melanie Thielker 2010-08-08 17:51:43 +02:00
parent d2b3d45d76
commit 1cde77293e
3 changed files with 31 additions and 4 deletions

View File

@ -79,4 +79,26 @@ namespace OpenSim.Data
Authenticate = 256, // Require authentication
Hyperlink = 512 // Record represents a HG link
}
public class RegionDataDistanceCompare : IComparer<RegionData>
{
private Vector2 m_origin;
public RegionDataDistanceCompare(int x, int y)
{
m_origin = new Vector2(x, y);
}
public int Compare(RegionData regionA, RegionData regionB)
{
Vector2 vectorA = new Vector2(regionA.posX, regionA.posY);
Vector2 vectorB = new Vector2(regionB.posX, regionB.posY);
return Math.Sign(VectorDistance(m_origin, vectorA) - VectorDistance(m_origin, vectorB));
}
private float VectorDistance(Vector2 x, Vector2 y)
{
return (x - y).Length();
}
}
}

View File

@ -315,8 +315,11 @@ namespace OpenSim.Data.MSSQL
public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
{
// TODO: distance-sort results
return Get((int)RegionFlags.FallbackRegion, scopeID);
List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID);
RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y);
regions.Sort(distanceComparer);
return regions;
}
public List<RegionData> GetHyperlinks(UUID scopeID)

View File

@ -289,8 +289,10 @@ namespace OpenSim.Data.MySQL
public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
{
// TODO: distance-sort results
return Get((int)RegionFlags.FallbackRegion, scopeID);
List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID);
RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y);
regions.Sort(distanceComparer);
return regions;
}
public List<RegionData> GetHyperlinks(UUID scopeID)