diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 8df89adfdb..4d77ef478d 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -148,9 +148,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer base.AgentHasMovedAway(sp, logout); if (logout) { - // Reset the map - ResetMap(sp); - // Log them out of this grid m_aScene.PresenceService.LogoutAgent(sp.ControllingClient.SessionId); } @@ -285,28 +282,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } - protected void ResetMap(ScenePresence sp) - { - List regions = m_Scenes[0].GridService.GetRegionRange(m_Scenes[0].RegionInfo.ScopeID, 0, 17000 * (int)Constants.RegionSize, 0, 17000 * (int)Constants.RegionSize); - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Resetting {0} tiles on the map", regions.Count); - if (regions != null) - { - List mapBlocks = new List(); - foreach (GridRegion r in regions) - { - MapBlockData mblock = new MapBlockData(); - mblock.X = (ushort)(r.RegionLocX / Constants.RegionSize); - mblock.Y = (ushort)(r.RegionLocY / Constants.RegionSize); - mblock.Name = ""; - mblock.Access = 254; // means 'simulator is offline'. We need this because the viewer ignores 255's - mblock.MapImageId = UUID.Zero; - mapBlocks.Add(mblock); - } - sp.ControllingClient.SendMapBlock(mapBlocks, 0); - } - - } - #endregion #region IUserAgentVerificationModule diff --git a/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs b/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs index fd2cc20a1a..0c60391fe2 100644 --- a/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs +++ b/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs @@ -41,7 +41,10 @@ namespace OpenSim.Region.CoreModules.Hypergrid { public class HGWorldMapModule : WorldMapModule { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + // Remember the map area that each client has been exposed to in this region + private Dictionary> m_SeenMapBlocks = new Dictionary>(); #region INonSharedRegionModule Members @@ -52,6 +55,13 @@ namespace OpenSim.Region.CoreModules.Hypergrid m_Enabled = true; } + public override void AddRegion(Scene scene) + { + base.AddRegion(scene); + + scene.EventManager.OnClientClosed += new EventManager.ClientClosed(EventManager_OnClientClosed); + } + public override string Name { get { return "HGWorldMap"; } @@ -59,65 +69,70 @@ namespace OpenSim.Region.CoreModules.Hypergrid #endregion - //protected override void GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) - //{ - // List mapBlocks = new List(); - // List regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, - // minX * (int)Constants.RegionSize, maxX * (int)Constants.RegionSize, - // minY * (int)Constants.RegionSize, maxY * (int)Constants.RegionSize); - - // foreach (GridRegion r in regions) - // { - // uint x = 0, y = 0; - // long handle = 0; - // if (r.RegionSecret != null && r.RegionSecret != string.Empty) - // { - // if (long.TryParse(r.RegionSecret, out handle)) - // { - // Utils.LongToUInts((ulong)handle, out x, out y); - // x = x / Constants.RegionSize; - // y = y / Constants.RegionSize; - // } - // } - - // if (handle == 0 || - // // Check the distance from the current region - // (handle != 0 && Math.Abs((int)(x - m_scene.RegionInfo.RegionLocX)) < 4096 && Math.Abs((int)(y - m_scene.RegionInfo.RegionLocY)) < 4096)) - // { - // MapBlockData block = new MapBlockData(); - // MapBlockFromGridRegion(block, r); - // mapBlocks.Add(block); - // } - // } - - // // Different from super - // //FillInMap(mapBlocks, minX, minY, maxX, maxY); - // // - - // remoteClient.SendMapBlock(mapBlocks, 0); - - //} - - - private void FillInMap(List mapBlocks, int minX, int minY, int maxX, int maxY) + void EventManager_OnClientClosed(UUID clientID, Scene scene) { - for (int x = minX; x <= maxX; x++) + ScenePresence sp = scene.GetScenePresence(clientID); + if (sp != null) { - for (int y = minY; y <= maxY; y++) + if (m_SeenMapBlocks.ContainsKey(clientID)) { - MapBlockData mblock = mapBlocks.Find(delegate(MapBlockData mb) { return ((mb.X == x) && (mb.Y == y)); }); - if (mblock == null) + List mapBlocks = m_SeenMapBlocks[clientID]; + foreach (MapBlockData b in mapBlocks) { - mblock = new MapBlockData(); - mblock.X = (ushort)x; - mblock.Y = (ushort)y; - mblock.Name = ""; - mblock.Access = 254; // means 'simulator is offline'. We need this because the viewer ignores 255's - mblock.MapImageId = UUID.Zero; - mapBlocks.Add(mblock); + b.Name = string.Empty; + b.Access = 254; // means 'simulator is offline'. We need this because the viewer ignores 255's } + + m_log.DebugFormat("[HG MAP]: Reseting {0} blocks", mapBlocks.Count); + sp.ControllingClient.SendMapBlock(mapBlocks, 0); + m_SeenMapBlocks.Remove(clientID); } } } + + protected override List GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) + { + List mapBlocks = base.GetAndSendBlocks(remoteClient, minX, minY, maxX, maxY, flag); + lock (m_SeenMapBlocks) + { + if (!m_SeenMapBlocks.ContainsKey(remoteClient.AgentId)) + { + m_SeenMapBlocks.Add(remoteClient.AgentId, mapBlocks); + } + else + { + List seen = m_SeenMapBlocks[remoteClient.AgentId]; + List newBlocks = new List(); + foreach (MapBlockData b in mapBlocks) + if (seen.Find(delegate(MapBlockData bdata) { return bdata.X == b.X && bdata.Y == b.Y; }) == null) + newBlocks.Add(b); + seen.AddRange(newBlocks); + } + } + + return mapBlocks; + } + + } + + class MapArea + { + public int minX; + public int minY; + public int maxX; + public int maxY; + + public MapArea(int mix, int miy, int max, int may) + { + minX = mix; + minY = miy; + maxX = max; + maxY = may; + } + + public void Print() + { + Console.WriteLine(String.Format(" --> Area is minX={0} minY={1} minY={2} maxY={3}", minX, minY, maxY, maxY)); + } } } diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index 69d300553c..3553c9af45 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -845,7 +845,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap } } - protected virtual void GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) + protected virtual List GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) { List mapBlocks = new List(); List regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, @@ -860,6 +860,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap mapBlocks.Add(block); } remoteClient.SendMapBlock(mapBlocks, 0); + + return mapBlocks; } protected void MapBlockFromGridRegion(MapBlockData block, GridRegion r)