From 5da99790241a38d63d7b4f765bb8ad4b4b024546 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 22 Aug 2015 16:35:49 +0100 Subject: Warp3D map now seems to work --- .../MapImage/MapImageServiceModule.cs | 13 +++--- .../CoreModules/World/WorldMap/WorldMapModule.cs | 51 ++++++++++++++++++---- .../Region/Framework/Interfaces/IMapTileModule.cs | 2 + 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs index da74f30..8484809 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 31b1c35..9a6ee99 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); + + // v2/3 (MapImageServiceModule) + m_mapImageServiceModule.UploadMapTile(m_scene, mapbmp); + } + } + + private void GenerateMaptile(Bitmap mapbmp) + { + byte[] data; - byte[] data = terrain.WriteJpeg2000Image(); - if (data == null) + 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 4d64236..857d923 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); } } -- cgit v1.1