aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-09-26 01:02:19 +0100
committerJustin Clark-Casey (justincc)2014-09-26 01:02:19 +0100
commit9fcee7332638a8008140b77641a957ec9268e828 (patch)
tree10f9397ddb6ef8faf35446819284ada20fea65d0 /OpenSim
parentAdd "debug lludp data out" console command for logging outgoing data just bef... (diff)
downloadopensim-SC_OLD-9fcee7332638a8008140b77641a957ec9268e828.zip
opensim-SC_OLD-9fcee7332638a8008140b77641a957ec9268e828.tar.gz
opensim-SC_OLD-9fcee7332638a8008140b77641a957ec9268e828.tar.bz2
opensim-SC_OLD-9fcee7332638a8008140b77641a957ec9268e828.tar.xz
Make "generate map" console command also trigger upload to maptiles as well as asset generation without performing tile generation twice.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs87
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs44
-rw-r--r--OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs37
3 files changed, 118 insertions, 50 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
index cf41754..7dfe53a 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
53 /// </remarks> 53 /// </remarks>
54 54
55 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageServiceModule")] 55 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageServiceModule")]
56 public class MapImageServiceModule : ISharedRegionModule 56 public class MapImageServiceModule : IMapImageUploadModule, ISharedRegionModule
57 { 57 {
58 private static readonly ILog m_log = 58 private static readonly ILog m_log =
59 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 59 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -152,6 +152,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
152 m_scenes[scene.RegionInfo.RegionID] = scene; 152 m_scenes[scene.RegionInfo.RegionID] = scene;
153 153
154 scene.EventManager.OnRegionReadyStatusChange += s => { if (s.Ready) UploadMapTile(s); }; 154 scene.EventManager.OnRegionReadyStatusChange += s => { if (s.Ready) UploadMapTile(s); };
155
156 scene.RegisterModuleInterface<IMapImageUploadModule>(this);
155 } 157 }
156 158
157 ///<summary> 159 ///<summary>
@@ -198,14 +200,53 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
198 m_lastrefresh = Util.EnvironmentTickCount(); 200 m_lastrefresh = Util.EnvironmentTickCount();
199 } 201 }
200 202
203 public void UploadMapTile(IScene scene, Bitmap mapTile)
204 {
205 m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.Name);
206
207 // mapTile.Save( // DEBUG DEBUG
208 // String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY),
209 // ImageFormat.Jpeg);
210 // If the region/maptile is legacy sized, just upload the one tile like it has always been done
211 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
212 {
213 ConvertAndUploadMaptile(mapTile,
214 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
215 scene.RegionInfo.RegionName);
216 }
217 else
218 {
219 // For larger regions (varregion) we must cut the region image into legacy sized
220 // pieces since that is how the maptile system works.
221 // Note the assumption that varregions are always a multiple of legacy size.
222 for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
223 {
224 for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
225 {
226 // Images are addressed from the upper left corner so have to do funny
227 // math to pick out the sub-tile since regions are numbered from
228 // the lower left.
229 Rectangle rect = new Rectangle(
230 (int)xx,
231 mapTile.Height - (int)yy - (int)Constants.RegionSize,
232 (int)Constants.RegionSize, (int)Constants.RegionSize);
233 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
234 {
235 ConvertAndUploadMaptile(subMapTile,
236 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
237 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize),
238 scene.Name);
239 }
240 }
241 }
242 }
243 }
244
201 ///<summary> 245 ///<summary>
202 /// 246 ///
203 ///</summary> 247 ///</summary>
204 private void UploadMapTile(IScene scene) 248 private void UploadMapTile(IScene scene)
205 { 249 {
206 m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.RegionInfo.RegionName);
207 string regionName = scene.RegionInfo.RegionName;
208
209 // Create a JPG map tile and upload it to the AddMapTile API 250 // Create a JPG map tile and upload it to the AddMapTile API
210 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); 251 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
211 if (tileGenerator == null) 252 if (tileGenerator == null)
@@ -213,46 +254,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
213 m_log.WarnFormat("{0} Cannot upload map tile without an ImageGenerator", LogHeader); 254 m_log.WarnFormat("{0} Cannot upload map tile without an ImageGenerator", LogHeader);
214 return; 255 return;
215 } 256 }
257
216 using (Bitmap mapTile = tileGenerator.CreateMapTile()) 258 using (Bitmap mapTile = tileGenerator.CreateMapTile())
217 { 259 {
218 if (mapTile != null) 260 if (mapTile != null)
219 { 261 {
220 // mapTile.Save( // DEBUG DEBUG 262 UploadMapTile(scene, mapTile);
221 // String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY),
222 // ImageFormat.Jpeg);
223 // If the region/maptile is legacy sized, just upload the one tile like it has always been done
224 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
225 {
226 ConvertAndUploadMaptile(mapTile,
227 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
228 scene.RegionInfo.RegionName);
229 }
230 else
231 {
232 // For larger regions (varregion) we must cut the region image into legacy sized
233 // pieces since that is how the maptile system works.
234 // Note the assumption that varregions are always a multiple of legacy size.
235 for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
236 {
237 for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
238 {
239 // Images are addressed from the upper left corner so have to do funny
240 // math to pick out the sub-tile since regions are numbered from
241 // the lower left.
242 Rectangle rect = new Rectangle(
243 (int)xx,
244 mapTile.Height - (int)yy - (int)Constants.RegionSize,
245 (int)Constants.RegionSize, (int)Constants.RegionSize);
246 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
247 {
248 ConvertAndUploadMaptile(subMapTile,
249 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
250 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize),
251 regionName);
252 }
253 }
254 }
255 }
256 } 263 }
257 else 264 else
258 { 265 {
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index 3af8ac4..78fbefe 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -68,6 +68,9 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
68 private static readonly UUID STOP_UUID = UUID.Random(); 68 private static readonly UUID STOP_UUID = UUID.Random();
69 private static readonly string m_mapLayerPath = "0001/"; 69 private static readonly string m_mapLayerPath = "0001/";
70 70
71 private IMapImageGenerator m_mapImageGenerator;
72 private IMapImageUploadModule m_mapImageServiceModule;
73
71 private OpenSim.Framework.BlockingQueue<MapRequestState> requests = new OpenSim.Framework.BlockingQueue<MapRequestState>(); 74 private OpenSim.Framework.BlockingQueue<MapRequestState> requests = new OpenSim.Framework.BlockingQueue<MapRequestState>();
72 75
73 protected Scene m_scene; 76 protected Scene m_scene;
@@ -100,7 +103,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
100 = Util.GetConfigVarFromSections<int>(config, "BlacklistTimeout", configSections, 10 * 60) * 1000; 103 = Util.GetConfigVarFromSections<int>(config, "BlacklistTimeout", configSections, 10 * 60) * 1000;
101 } 104 }
102 105
103 public virtual void AddRegion (Scene scene) 106 public virtual void AddRegion(Scene scene)
104 { 107 {
105 if (!m_Enabled) 108 if (!m_Enabled)
106 return; 109 return;
@@ -144,8 +147,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
144 return; 147 return;
145 148
146 m_ServiceThrottle = scene.RequestModuleInterface<IServiceThrottleModule>(); 149 m_ServiceThrottle = scene.RequestModuleInterface<IServiceThrottleModule>();
147 }
148 150
151 m_mapImageGenerator = m_scene.RequestModuleInterface<IMapImageGenerator>();
152 m_mapImageServiceModule = m_scene.RequestModuleInterface<IMapImageUploadModule>();
153 }
149 154
150 public virtual void Close() 155 public virtual void Close()
151 { 156 {
@@ -1315,7 +1320,17 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1315 if (consoleScene != null && consoleScene != m_scene) 1320 if (consoleScene != null && consoleScene != m_scene)
1316 return; 1321 return;
1317 1322
1318 GenerateMaptile(); 1323 if (m_mapImageGenerator == null)
1324 {
1325 Console.WriteLine("No map image generator available for {0}", m_scene.Name);
1326 return;
1327 }
1328
1329 using (Bitmap mapbmp = m_mapImageGenerator.CreateMapTile())
1330 {
1331 GenerateMaptile(mapbmp);
1332 m_mapImageServiceModule.UploadMapTile(m_scene, mapbmp);
1333 }
1319 } 1334 }
1320 1335
1321 public OSD HandleRemoteMapItemRequest(string path, OSD request, string endpoint) 1336 public OSD HandleRemoteMapItemRequest(string path, OSD request, string endpoint)
@@ -1444,16 +1459,25 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1444 if (m_scene.Heightmap == null) 1459 if (m_scene.Heightmap == null)
1445 return; 1460 return;
1446 1461
1447 //create a texture asset of the terrain 1462 m_log.DebugFormat("[WORLD MAP]: Generating map image for {0}", m_scene.Name);
1448 IMapImageGenerator terrain = m_scene.RequestModuleInterface<IMapImageGenerator>();
1449 if (terrain == null)
1450 return;
1451 1463
1452 m_log.DebugFormat("[WORLD MAP]: Generating map image for {0}", m_scene.RegionInfo.RegionName); 1464 using (Bitmap mapbmp = m_mapImageGenerator.CreateMapTile())
1465 GenerateMaptile(mapbmp);
1466 }
1453 1467
1454 byte[] data = terrain.WriteJpeg2000Image(); 1468 private void GenerateMaptile(Bitmap mapbmp)
1455 if (data == null) 1469 {
1470 byte[] data;
1471
1472 try
1473 {
1474 data = OpenJPEG.EncodeFromImage(mapbmp, true);
1475 }
1476 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
1477 {
1478 m_log.Error("[WORLD MAP]: Failed generating terrain map: " + e);
1456 return; 1479 return;
1480 }
1457 1481
1458 byte[] overlay = GenerateOverlay(); 1482 byte[] overlay = GenerateOverlay();
1459 1483
diff --git a/OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs b/OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs
new file mode 100644
index 0000000..6a7d4a1
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs
@@ -0,0 +1,37 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Drawing;
29using OpenSim.Framework;
30
31namespace OpenSim.Region.Framework.Interfaces
32{
33 public interface IMapImageUploadModule
34 {
35 void UploadMapTile(IScene scene, Bitmap mapTile);
36 }
37} \ No newline at end of file