aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorRobert Adams2015-03-29 17:21:19 -0700
committerRobert Adams2015-03-29 17:21:19 -0700
commitc0ad5ee81da3d24153bfc9769759ac1981d604ea (patch)
treed053941a4c005a8a653640428e9668ff874fef27 /OpenSim
parentvarregion: update MapImageModule and ShadedMapTimeRenderer for variable sized... (diff)
downloadopensim-SC_OLD-c0ad5ee81da3d24153bfc9769759ac1981d604ea.zip
opensim-SC_OLD-c0ad5ee81da3d24153bfc9769759ac1981d604ea.tar.gz
opensim-SC_OLD-c0ad5ee81da3d24153bfc9769759ac1981d604ea.tar.bz2
opensim-SC_OLD-c0ad5ee81da3d24153bfc9769759ac1981d604ea.tar.xz
varregion: update MapImageServiceModule to upload multiple map tiles for large regions.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs82
1 files changed, 65 insertions, 17 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
index 96182cd..da74f30 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
@@ -57,6 +57,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
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);
60 private static string LogHeader = "[MAP IMAGE SERVICE MODULE]";
60 61
61 private bool m_enabled = false; 62 private bool m_enabled = false;
62 private IMapImageService m_MapService; 63 private IMapImageService m_MapService;
@@ -192,47 +193,94 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
192 m_lastrefresh = Util.EnvironmentTickCount(); 193 m_lastrefresh = Util.EnvironmentTickCount();
193 } 194 }
194 195
196 public void UploadMapTile(IScene scene, Bitmap mapTile)
197 {
198 m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.Name);
199
200 // mapTile.Save( // DEBUG DEBUG
201 // String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY),
202 // ImageFormat.Jpeg);
203 // If the region/maptile is legacy sized, just upload the one tile like it has always been done
204 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
205 {
206 ConvertAndUploadMaptile(mapTile, scene,
207 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY);
208 }
209 else
210 {
211 // For larger regions (varregion) we must cut the region image into legacy sized
212 // pieces since that is how the maptile system works.
213 // Note the assumption that varregions are always a multiple of legacy size.
214 for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
215 {
216 for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
217 {
218 // Images are addressed from the upper left corner so have to do funny
219 // math to pick out the sub-tile since regions are numbered from
220 // the lower left.
221 Rectangle rect = new Rectangle(
222 (int)xx,
223 mapTile.Height - (int)yy - (int)Constants.RegionSize,
224 (int)Constants.RegionSize, (int)Constants.RegionSize);
225 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
226 {
227 ConvertAndUploadMaptile(subMapTile, scene,
228 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
229 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize)
230 );
231 }
232 }
233 }
234 }
235 }
236
195 ///<summary> 237 ///<summary>
196 /// 238 ///
197 ///</summary> 239 ///</summary>
198 public void UploadMapTile(IScene scene) 240 public void UploadMapTile(IScene scene)
199 { 241 {
200 m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: upload maptile for {0}", scene.RegionInfo.RegionName); 242 m_log.DebugFormat("{0}: upload maptile for {1}", LogHeader, scene.RegionInfo.RegionName);
201 243
202 // Create a JPG map tile and upload it to the AddMapTile API 244 // Create a JPG map tile and upload it to the AddMapTile API
203 byte[] jpgData = Utils.EmptyBytes;
204 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); 245 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
205 if (tileGenerator == null) 246 if (tileGenerator == null)
206 { 247 {
207 m_log.Warn("[MAP IMAGE SERVICE MODULE]: Cannot upload PNG map tile without an ImageGenerator"); 248 m_log.WarnFormat("{0} Cannot upload map tile without an ImageGenerator", LogHeader);
208 return; 249 return;
209 } 250 }
210 251
211 using (Image mapTile = tileGenerator.CreateMapTile()) 252 using (Bitmap mapTile = tileGenerator.CreateMapTile())
212 { 253 {
213 // XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there 254 // XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there
214 // is no static map tile. 255 // is no static map tile.
215 if (mapTile == null) 256 if (mapTile == null)
216 return; 257 return;
217 258
218 using (MemoryStream stream = new MemoryStream()) 259 UploadMapTile(scene, mapTile);
219 {
220 mapTile.Save(stream, ImageFormat.Jpeg);
221 jpgData = stream.ToArray();
222 }
223 } 260 }
261 }
262
263 private void ConvertAndUploadMaptile(Image tileImage, IScene scene, uint locX, uint locY)
264 {
265 byte[] jpgData = Utils.EmptyBytes;
224 266
225 if (jpgData == Utils.EmptyBytes) 267 using (MemoryStream stream = new MemoryStream())
226 { 268 {
227 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Tile image generation failed"); 269 tileImage.Save(stream, ImageFormat.Jpeg);
228 return; 270 jpgData = stream.ToArray();
229 } 271 }
230 272 if (jpgData != Utils.EmptyBytes)
231 string reason = string.Empty; 273 {
232 if (!m_MapService.AddMapTile((int)scene.RegionInfo.RegionLocX, (int)scene.RegionInfo.RegionLocY, jpgData, scene.RegionInfo.ScopeID, out reason)) 274 string reason = string.Empty;
275 if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, scene.RegionInfo.ScopeID, out reason))
276 {
277 m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader,
278 scene.RegionInfo.RegionName, locX, locY, reason);
279 }
280 }
281 else
233 { 282 {
234 m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: Unable to upload tile image for {0} at {1}-{2}: {3}", 283 m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, scene.RegionInfo.RegionName);
235 scene.RegionInfo.RegionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, reason);
236 } 284 }
237 } 285 }
238 } 286 }