diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs index da74f30dee..84848095c6 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs @@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage /// [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageServiceModule")] - public class MapImageServiceModule : ISharedRegionModule, IMapTileModule + public class MapImageServiceModule : ISharedRegionModule, IMapTileModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -204,7 +204,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize) { ConvertAndUploadMaptile(mapTile, scene, - scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY); + scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, + scene.RegionInfo.RegionName); } else { @@ -226,8 +227,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage { ConvertAndUploadMaptile(subMapTile, scene, scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize), - scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize) - ); + scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize), + scene.Name); } } } @@ -260,7 +261,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage } } - private void ConvertAndUploadMaptile(Image tileImage, IScene scene, uint locX, uint locY) + private void ConvertAndUploadMaptile(Image tileImage, IScene scene, uint locX, uint locY, string regionName) { byte[] jpgData = Utils.EmptyBytes; @@ -275,7 +276,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, scene.RegionInfo.ScopeID, out reason)) { m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader, - scene.RegionInfo.RegionName, locX, locY, reason); + regionName, locX, locY, reason); } } else diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index 31b1c35488..9a6ee99861 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -72,6 +72,9 @@ namespace OpenSim.Region.CoreModules.World.WorldMap private ManualResetEvent m_mapBlockRequestEvent = new ManualResetEvent(false); private Dictionary> m_mapBlockRequests = new Dictionary>(); + private IMapImageGenerator m_mapImageGenerator; + private IMapTileModule m_mapImageServiceModule; + protected Scene m_scene; private List cachedMapBlocks = new List(); private int cachedTime = 0; @@ -139,6 +142,11 @@ namespace OpenSim.Region.CoreModules.World.WorldMap public virtual void RegionLoaded (Scene scene) { + if (!m_Enabled) + return; + + m_mapImageGenerator = m_scene.RequestModuleInterface(); + m_mapImageServiceModule = m_scene.RequestModuleInterface(); } @@ -1391,7 +1399,17 @@ namespace OpenSim.Region.CoreModules.World.WorldMap if (consoleScene != null && consoleScene != m_scene) return; - GenerateMaptile(); + if (m_mapImageGenerator == null) + { + Console.WriteLine("No map image generator available for {0}", m_scene.Name); + return; + } + + using (Bitmap mapbmp = m_mapImageGenerator.CreateMapTile()) + { + GenerateMaptile(mapbmp); +// m_mapImageServiceModule.UploadMapTile(m_scene, mapbmp); + } } public OSD HandleRemoteMapItemRequest(string path, OSD request, string endpoint) @@ -1514,20 +1532,35 @@ namespace OpenSim.Region.CoreModules.World.WorldMap public void GenerateMaptile() { - // Cannot create a map for a nonexistant heightmap + // Cannot create a map for a nonexistent heightmap if (m_scene.Heightmap == null) return; - //create a texture asset of the terrain - IMapImageGenerator terrain = m_scene.RequestModuleInterface(); - if (terrain == null) - return; + m_log.DebugFormat("[WORLD MAP]: Generating map image for {0}", m_scene.Name); - m_log.DebugFormat("[WORLD MAP]: Generating map image for {0}", m_scene.RegionInfo.RegionName); + using (Bitmap mapbmp = m_mapImageGenerator.CreateMapTile()) + { + // V1 (This Module) + GenerateMaptile(mapbmp); - byte[] data = terrain.WriteJpeg2000Image(); - if (data == null) + // v2/3 (MapImageServiceModule) + m_mapImageServiceModule.UploadMapTile(m_scene, mapbmp); + } + } + + private void GenerateMaptile(Bitmap mapbmp) + { + byte[] data; + + try + { + data = OpenJPEG.EncodeFromImage(mapbmp, true); + } + catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke + { + m_log.Error("[WORLD MAP]: Failed generating terrain map: " + e); return; + } byte[] overlay = GenerateOverlay(); diff --git a/OpenSim/Region/Framework/Interfaces/IMapTileModule.cs b/OpenSim/Region/Framework/Interfaces/IMapTileModule.cs index 4d6423631b..857d9238b3 100644 --- a/OpenSim/Region/Framework/Interfaces/IMapTileModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IMapTileModule.cs @@ -27,6 +27,7 @@ using OpenMetaverse; using OpenSim.Framework; +using System.Drawing; namespace OpenSim.Region.Framework.Interfaces { @@ -36,5 +37,6 @@ namespace OpenSim.Region.Framework.Interfaces /// Upload a new maptile /// void UploadMapTile(IScene scene); + void UploadMapTile(IScene scene, Bitmap mapTile); } }