varregion: split up generated maptile images for storage in map. This
makes maps for varregions show up properly.varregion
parent
cc5cffc212
commit
60de0bc3c2
|
@ -57,6 +57,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
|
|||
{
|
||||
private static readonly ILog m_log =
|
||||
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private static string LogHeader = "[MAP IMAGE SERVICE MODULE]";
|
||||
|
||||
private bool m_enabled = false;
|
||||
private IMapImageService m_MapService;
|
||||
|
@ -192,42 +193,87 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
|
|||
///</summary>
|
||||
private void UploadMapTile(IScene scene)
|
||||
{
|
||||
m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: upload maptile for {0}", scene.RegionInfo.RegionName);
|
||||
m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.RegionInfo.RegionName);
|
||||
string regionName = scene.RegionInfo.RegionName;
|
||||
|
||||
// Create a JPG map tile and upload it to the AddMapTile API
|
||||
byte[] jpgData = Utils.EmptyBytes;
|
||||
IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
|
||||
if (tileGenerator == null)
|
||||
{
|
||||
m_log.Warn("[MAP IMAGE SERVICE MODULE]: Cannot upload PNG map tile without an ImageGenerator");
|
||||
m_log.WarnFormat("{0} Cannot upload map tile without an ImageGenerator", LogHeader);
|
||||
return;
|
||||
}
|
||||
|
||||
using (Image mapTile = tileGenerator.CreateMapTile())
|
||||
using (Bitmap mapTile = tileGenerator.CreateMapTile())
|
||||
{
|
||||
// XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there
|
||||
// is no static map tile.
|
||||
if (mapTile == null)
|
||||
return;
|
||||
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
if (mapTile != null)
|
||||
{
|
||||
mapTile.Save(stream, ImageFormat.Jpeg);
|
||||
jpgData = stream.ToArray();
|
||||
mapTile.Save( // DEBUG DEBUG
|
||||
String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY),
|
||||
ImageFormat.Jpeg);
|
||||
// If the region/maptile is legacy sized, just upload the one tile like it has always been done
|
||||
if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
|
||||
{
|
||||
ConvertAndUploadMaptile(mapTile,
|
||||
scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
|
||||
scene.RegionInfo.RegionName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For larger regions (varregion) we must cut the region image into legacy sized
|
||||
// pieces since that is how the maptile system works.
|
||||
// Note the assumption that varregions are always a multiple of legacy size.
|
||||
for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
|
||||
{
|
||||
for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
|
||||
{
|
||||
// Images are addressed from the upper left corner so have to do funny
|
||||
// math to pick out the sub-tile since regions are numbered from
|
||||
// the lower left.
|
||||
Rectangle rect = new Rectangle(
|
||||
(int)xx,
|
||||
mapTile.Height - (int)yy - (int)Constants.RegionSize,
|
||||
(int)Constants.RegionSize, (int)Constants.RegionSize);
|
||||
using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
|
||||
{
|
||||
m_log.DebugFormat("{0} ConvertAndUploadMaptile: {1}: rect={2}, xx,yy=<{3},{4}>",
|
||||
LogHeader, regionName, rect, xx, yy);
|
||||
ConvertAndUploadMaptile(subMapTile,
|
||||
scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
|
||||
scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize),
|
||||
regionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat("{0} Tile image generation failed", LogHeader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jpgData == Utils.EmptyBytes)
|
||||
private void ConvertAndUploadMaptile(Image tileImage, uint locX, uint locY, string regionName)
|
||||
{
|
||||
byte[] jpgData = Utils.EmptyBytes;
|
||||
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Tile image generation failed");
|
||||
return;
|
||||
tileImage.Save(stream, ImageFormat.Jpeg);
|
||||
jpgData = stream.ToArray();
|
||||
}
|
||||
|
||||
string reason = string.Empty;
|
||||
if (!m_MapService.AddMapTile((int)scene.RegionInfo.RegionLocX, (int)scene.RegionInfo.RegionLocY, jpgData, out reason))
|
||||
if (jpgData != Utils.EmptyBytes)
|
||||
{
|
||||
m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: Unable to upload tile image for {0} at {1}-{2}: {3}",
|
||||
scene.RegionInfo.RegionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, reason);
|
||||
string reason = string.Empty;
|
||||
if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, out reason))
|
||||
{
|
||||
m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader,
|
||||
regionName, locX, locY, reason);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, regionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -406,7 +406,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
|
|||
}
|
||||
uint xstart = 0;
|
||||
uint ystart = 0;
|
||||
Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);
|
||||
Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);
|
||||
if (itemtype == 6) // Service 6 right now (MAP_ITEM_AGENTS_LOCATION; green dots)
|
||||
{
|
||||
if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle)
|
||||
|
|
Loading…
Reference in New Issue