refactor: combine the checks for megaregion view range into a single place.

user_profiles
Justin Clark-Casey (justincc) 2013-03-28 00:57:43 +00:00
parent dd7d7683c9
commit cfb20f09a9
1 changed files with 51 additions and 51 deletions

View File

@ -117,6 +117,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
new ExpiringCache<UUID, ExpiringCache<ulong, DateTime>>(); new ExpiringCache<UUID, ExpiringCache<ulong, DateTime>>();
private IEventQueue m_eqModule; private IEventQueue m_eqModule;
private IRegionCombinerModule m_regionCombinerModule;
#region ISharedRegionModule #region ISharedRegionModule
@ -267,6 +268,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
return; return;
m_eqModule = Scene.RequestModuleInterface<IEventQueue>(); m_eqModule = Scene.RequestModuleInterface<IEventQueue>();
m_regionCombinerModule = Scene.RequestModuleInterface<IRegionCombinerModule>();
} }
#endregion #endregion
@ -1005,41 +1007,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
protected virtual bool NeedsNewAgent(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY) protected virtual bool NeedsNewAgent(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY)
{ {
Border[] northBorders = Scene.NorthBorders.ToArray(); if (m_regionCombinerModule != null && m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID))
Border[] southBorders = Scene.SouthBorders.ToArray();
Border[] eastBorders = Scene.EastBorders.ToArray();
Border[] westBorders = Scene.WestBorders.ToArray();
// Leaving this as a "megaregions" computation vs "non-megaregions" computation; it isn't
// clear what should be done with a "far view" given that megaregions already extended the
// view to include everything in the megaregion
if (northBorders.Length > 1 || southBorders.Length > 1 || eastBorders.Length > 1 || westBorders.Length > 1)
{ {
Vector2 extent = Vector2.Zero; Vector2 swCorner, neCorner;
for (int i = 0; i < eastBorders.Length; i++) GetMegaregionViewRange(out swCorner, out neCorner);
{
extent.X = (eastBorders[i].BorderLine.Z > extent.X) ? eastBorders[i].BorderLine.Z : extent.X;
}
for (int i = 0; i < northBorders.Length; i++)
{
extent.Y = (northBorders[i].BorderLine.Z > extent.Y) ? northBorders[i].BorderLine.Z : extent.Y;
}
// Loss of fraction on purpose
extent.X = ((int)extent.X / (int)Constants.RegionSize) + 1;
extent.Y = ((int)extent.Y / (int)Constants.RegionSize) + 1;
uint startX = oldRegionX - 1;
uint startY = oldRegionY - 1;
uint endX = oldRegionX + (uint)extent.X;
uint endY = oldRegionY + (uint)extent.Y;
m_log.DebugFormat( m_log.DebugFormat(
"[ENTITY TRANSFER MODULE]: Megaregion view of {0} is from {1},{2} to {3},{4} with new agent check for {5},{6}", "[ENTITY TRANSFER MODULE]: Megaregion view of {0} is from {1} to {2} with new agent check for {3},{4}",
Scene.Name, startX, startY, endX, endY, newRegionX, newRegionY); Scene.Name, swCorner, neCorner, newRegionX, newRegionY);
return !(newRegionX >= startX && newRegionX <= endX && newRegionY >= startY && newRegionY <= endY); return !(newRegionX >= swCorner.X && newRegionX <= neCorner.X && newRegionY >= swCorner.Y && newRegionY <= neCorner.Y);
} }
else else
{ {
@ -1902,6 +1879,37 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
reg.RegionName, sp.Name, sp.UUID, reason); reg.RegionName, sp.Name, sp.UUID, reason);
} }
/// <summary>
/// Gets the range considered in view of this megaregion (assuming this is a megaregion).
/// </summary>
/// <remarks>Expressed in 256m units</remarks>
/// <param name='swCorner'></param>
/// <param name='neCorner'></param>
private void GetMegaregionViewRange(out Vector2 swCorner, out Vector2 neCorner)
{
Border[] northBorders = Scene.NorthBorders.ToArray();
Border[] eastBorders = Scene.EastBorders.ToArray();
Vector2 extent = Vector2.Zero;
for (int i = 0; i < eastBorders.Length; i++)
{
extent.X = (eastBorders[i].BorderLine.Z > extent.X) ? eastBorders[i].BorderLine.Z : extent.X;
}
for (int i = 0; i < northBorders.Length; i++)
{
extent.Y = (northBorders[i].BorderLine.Z > extent.Y) ? northBorders[i].BorderLine.Z : extent.Y;
}
// Loss of fraction on purpose
extent.X = ((int)extent.X / (int)Constants.RegionSize) + 1;
extent.Y = ((int)extent.Y / (int)Constants.RegionSize) + 1;
swCorner.X = Scene.RegionInfo.RegionLocX - 1;
swCorner.Y = Scene.RegionInfo.RegionLocY - 1;
neCorner.X = Scene.RegionInfo.RegionLocX + extent.X;
neCorner.Y = Scene.RegionInfo.RegionLocY + extent.Y;
}
/// <summary> /// <summary>
/// Return the list of regions that are considered to be neighbours to the given scene. /// Return the list of regions that are considered to be neighbours to the given scene.
/// </summary> /// </summary>
@ -1922,8 +1930,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
// Leaving this as a "megaregions" computation vs "non-megaregions" computation; it isn't // Leaving this as a "megaregions" computation vs "non-megaregions" computation; it isn't
// clear what should be done with a "far view" given that megaregions already extended the // clear what should be done with a "far view" given that megaregions already extended the
// view to include everything in the megaregion // view to include everything in the megaregion
if (northBorders.Length <= 1 && southBorders.Length <= 1 && eastBorders.Length <= 1 && westBorders.Length <= 1) if (m_regionCombinerModule == null || !m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID))
{ {
Console.WriteLine("NOT MEGA");
int dd = avatar.DrawDistance < Constants.RegionSize ? (int)Constants.RegionSize : (int)avatar.DrawDistance; int dd = avatar.DrawDistance < Constants.RegionSize ? (int)Constants.RegionSize : (int)avatar.DrawDistance;
int startX = (int)pRegionLocX * (int)Constants.RegionSize - dd + (int)(Constants.RegionSize/2); int startX = (int)pRegionLocX * (int)Constants.RegionSize - dd + (int)(Constants.RegionSize/2);
@ -1940,27 +1949,18 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
} }
else else
{ {
Vector2 extent = Vector2.Zero; Console.WriteLine("MEGA");
for (int i = 0; i < eastBorders.Length; i++) Vector2 swCorner, neCorner;
{ GetMegaregionViewRange(out swCorner, out neCorner);
extent.X = (eastBorders[i].BorderLine.Z > extent.X) ? eastBorders[i].BorderLine.Z : extent.X;
}
for (int i = 0; i < northBorders.Length; i++)
{
extent.Y = (northBorders[i].BorderLine.Z > extent.Y) ? northBorders[i].BorderLine.Z : extent.Y;
}
// Loss of fraction on purpose List<GridRegion> neighbours
extent.X = ((int)extent.X / (int)Constants.RegionSize) + 1; = pScene.GridService.GetRegionRange(
extent.Y = ((int)extent.Y / (int)Constants.RegionSize) + 1; m_regionInfo.ScopeID,
(int)swCorner.X * (int)Constants.RegionSize,
(int)neCorner.X * (int)Constants.RegionSize,
(int)swCorner.Y * (int)Constants.RegionSize,
(int)neCorner.Y * (int)Constants.RegionSize);
int startX = (int)(pRegionLocX - 1) * (int)Constants.RegionSize;
int startY = (int)(pRegionLocY - 1) * (int)Constants.RegionSize;
int endX = ((int)pRegionLocX + (int)extent.X) * (int)Constants.RegionSize;
int endY = ((int)pRegionLocY + (int)extent.Y) * (int)Constants.RegionSize;
List<GridRegion> neighbours = pScene.GridService.GetRegionRange(m_regionInfo.ScopeID, startX, endX, startY, endY);
neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; }); neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; });
return neighbours; return neighbours;