on 0.8 grids compatibility code just do a BIG range request. It whould be done in most cases (open borders) plus 4 more. In future this code should not be used if the grid is >=0.9

LSLKeyTest
UbitUmarov 2016-07-31 23:12:09 +01:00
parent c0eae1f8f9
commit 159d722966
1 changed files with 25 additions and 49 deletions

View File

@ -2183,10 +2183,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
// Given a world position, get the GridRegion info for // Given a world position, get the GridRegion info for
// the region containing that point. // the region containing that point.
// Not needed on 0.9 grids
// 'pSizeHint' is the size of the source region but since the destination point can be anywhere
// the size of the target region is unknown thus the search area might have to be very large.
// Return 'null' if no such region exists.
protected GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID, protected GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID,
double px, double py, uint pSizeHint) double px, double py, uint pSizeHint)
{ {
@ -2194,11 +2190,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
GridRegion ret = null; GridRegion ret = null;
const double fudge = 2.0; const double fudge = 2.0;
// One problem with this routine is negative results. That is, this can be called lots of times
// for regions that don't exist. m_notFoundLocationCache remembers 'not found' results so they
// will be quick 'not found's next time.
// NotFoundLocationCache is an expiring cache so it will eventually forget about 'not found' and
// thus re-ask the GridService about the location.
if (m_notFoundLocationCache.Contains(px, py)) if (m_notFoundLocationCache.Contains(px, py))
{ {
// m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found via cache. loc=<{1},{2}>", LogHeader, px, py); // m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found via cache. loc=<{1},{2}>", LogHeader, px, py);
@ -2207,60 +2198,45 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
// As an optimization, since most regions will be legacy sized regions (256x256), first try to get // As an optimization, since most regions will be legacy sized regions (256x256), first try to get
// the region at the appropriate legacy region location. // the region at the appropriate legacy region location.
uint possibleX = (uint)Math.Floor(px); // this is all that is needed on 0.9 grids
possibleX -= possibleX % Constants.RegionSize; uint possibleX = (uint)px & 0xffffff00u;
uint possibleY = (uint)Math.Floor(py); uint possibleY = (uint)py & 0xffffff00u;
possibleY -= possibleY % Constants.RegionSize;
ret = pGridService.GetRegionByPosition(pScopeID, (int)possibleX, (int)possibleY); ret = pGridService.GetRegionByPosition(pScopeID, (int)possibleX, (int)possibleY);
if (ret != null) if (ret != null)
{ {
// m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Found region using legacy size. rloc=<{1},{2}>. Rname={3}", // m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Found region using legacy size. rloc=<{1},{2}>. Rname={3}",
// LogHeader, possibleX, possibleY, ret.RegionName); // LogHeader, possibleX, possibleY, ret.RegionName);
return ret;
} }
if (ret == null) // for 0.8 regions just make a BIG area request. old code whould do it plus 4 more smaller on region open edges
// this is what 0.9 grids now do internally
List<GridRegion> possibleRegions = pGridService.GetRegionRange(pScopeID,
(int)(px - Constants.MaximumRegionSize), (int)(px + 1), // +1 bc left mb not part of range
(int)(py - Constants.MaximumRegionSize), (int)(py + 1));
// m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegions cnt={1}, range={2}",
// LogHeader, possibleRegions.Count, range);
if (possibleRegions != null && possibleRegions.Count > 0)
{ {
// If the simple lookup failed, search the larger area for a region that contains this point // If we found some regions, check to see if the point is within
double range = (double)pSizeHint + fudge; foreach (GridRegion gr in possibleRegions)
while (ret == null && range <= (Constants.MaximumRegionSize + Constants.RegionSize))
{ {
// Get from the grid service a list of regions that might contain this point. // m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegion nm={1}, regionLoc=<{2},{3}>, regionSize=<{4},{5}>",
// The region origin will be in the zero direction so only subtract the range. // LogHeader, gr.RegionName, gr.RegionLocX, gr.RegionLocY, gr.RegionSizeX, gr.RegionSizeY);
List<GridRegion> possibleRegions = pGridService.GetRegionRange(pScopeID, if (px >= (double)gr.RegionLocX && px < (double)(gr.RegionLocX + gr.RegionSizeX)
(int)(px - range), (int)(px),
(int)(py - range), (int)(py));
// m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegions cnt={1}, range={2}",
// LogHeader, possibleRegions.Count, range);
if (possibleRegions != null && possibleRegions.Count > 0)
{
// If we found some regions, check to see if the point is within
foreach (GridRegion gr in possibleRegions)
{
// m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegion nm={1}, regionLoc=<{2},{3}>, regionSize=<{4},{5}>",
// LogHeader, gr.RegionName, gr.RegionLocX, gr.RegionLocY, gr.RegionSizeX, gr.RegionSizeY);
if (px >= (double)gr.RegionLocX && px < (double)(gr.RegionLocX + gr.RegionSizeX)
&& py >= (double)gr.RegionLocY && py < (double)(gr.RegionLocY + gr.RegionSizeY)) && py >= (double)gr.RegionLocY && py < (double)(gr.RegionLocY + gr.RegionSizeY))
{ {
// Found a region that contains the point // Found a region that contains the point
ret = gr; return gr;
// m_log.DebugFormat("{0} GetRegionContainingWorldLocation: found. RegionName={1}", LogHeader, ret.RegionName); // m_log.DebugFormat("{0} GetRegionContainingWorldLocation: found. RegionName={1}", LogHeader, ret.RegionName);
break;
}
}
} }
// Larger search area for next time around if not found
range *= 2;
} }
} }
if (ret == null) // remember this location was not found so we can quickly not find it next time
{ m_notFoundLocationCache.Add(px, py);
// remember this location was not found so we can quickly not find it next time // m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found. Remembering loc=<{1},{2}>", LogHeader, px, py);
m_notFoundLocationCache.Add(px, py); return null;
// m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found. Remembering loc=<{1},{2}>", LogHeader, px, py);
}
return ret;
} }
private void InformClientOfNeighbourCompleted(IAsyncResult iar) private void InformClientOfNeighbourCompleted(IAsyncResult iar)