29 using System.Collections.Generic;
 
   30 using System.Collections.Specialized;
 
   31 using System.Reflection;
 
   36 using System.Drawing.Imaging;
 
   41 using OpenSim.Framework;
 
   42 using OpenSim.Region.Framework.Interfaces;
 
   43 using OpenSim.Region.Framework.Scenes;
 
   45 using OpenMetaverse.StructuredData;
 
   48 namespace OpenSim.Services.Connectors.SimianGrid
 
   55     [Extension(Path = 
"/OpenSim/RegionModules", NodeName = 
"RegionModule", Id = 
"SimianGridMaptile")]
 
   58         private static readonly ILog m_log =
 
   59             LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
   61         private bool m_enabled = 
false;
 
   62         private string m_serverUrl = String.Empty;
 
   63         private Dictionary<UUID, Scene> m_scenes = 
new Dictionary<UUID, Scene>();
 
   65         private int m_refreshtime = 0;
 
   66         private int m_lastrefresh = 0;
 
   67         private System.Timers.Timer m_refreshTimer = 
new System.Timers.Timer();
 
   69         #region ISharedRegionModule 
   71         public Type ReplaceableInterface { 
get { 
return null; } }
 
   72         public string Name { 
get { 
return "SimianGridMaptile"; } }        
 
   81             IConfig config = source.Configs[
"SimianGridMaptiles"];
 
   85             if (! config.GetBoolean(
"Enabled", 
false))
 
   88             m_serverUrl = config.GetString(
"MaptileURL");
 
   89             if (
String.IsNullOrEmpty(m_serverUrl))
 
   92             int refreshseconds = Convert.ToInt32(config.GetString(
"RefreshTime"));
 
   93             if (refreshseconds <= 0)
 
   96             m_refreshtime = refreshseconds * 1000; 
 
   97             m_log.InfoFormat(
"[SIMIAN MAPTILE] enabled with refresh timeout {0} and URL {1}",
 
   98                              m_refreshtime,m_serverUrl);
 
  110                 m_refreshTimer.Enabled = 
true;
 
  111                 m_refreshTimer.AutoReset = 
true;
 
  112                 m_refreshTimer.Interval = 5 * 60 * 1000; 
 
  113                 m_refreshTimer.Elapsed += 
new ElapsedEventHandler(HandleMaptileRefresh);
 
  129                 m_scenes[scene.RegionInfo.RegionID] = scene;
 
  141                 m_scenes.Remove(scene.RegionInfo.RegionID);
 
  144         #endregion ISharedRegionModule 
  149         private void HandleMaptileRefresh(
object sender, EventArgs ea)
 
  154             if (m_lastrefresh > 0 && Util.EnvironmentTickCountSubtract(m_lastrefresh) < m_refreshtime)
 
  157             m_log.DebugFormat(
"[SIMIAN MAPTILE] map refresh fired");
 
  160                 foreach (
IScene scene 
in m_scenes.Values)
 
  164                         UploadMapTile(scene);
 
  168                         m_log.WarnFormat(
"[SIMIAN MAPTILE] something bad happened {0}",ex.Message);
 
  173             m_lastrefresh = Util.EnvironmentTickCount();
 
  179         private void UploadMapTile(
IScene scene)
 
  181             m_log.DebugFormat(
"[SIMIAN MAPTILE]: upload maptile for {0}",scene.RegionInfo.RegionName);
 
  185             if (tileGenerator == null)
 
  187                 m_log.Warn(
"[SIMIAN MAPTILE]: Cannot upload PNG map tile without an ImageGenerator");
 
  191             using (Bitmap mapTile = tileGenerator.CreateMapTile())
 
  205                         for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
 
  207                             for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
 
  217                                 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
 
  219                                     uint locX = scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize);
 
  220                                     uint locY = scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize);
 
  222                                     ConvertAndUploadMaptile(subMapTile, locX, locY);
 
  230                     m_log.WarnFormat(
"[SIMIAN MAPTILE] Tile image generation failed");
 
  239         private void ConvertAndUploadMaptile(Image mapTile, uint locX, uint locY)
 
  243             byte[] pngData = Utils.EmptyBytes;
 
  244             using (MemoryStream stream = 
new MemoryStream())
 
  246                 mapTile.Save(stream, ImageFormat.Png);
 
  247                 pngData = stream.ToArray();
 
  250             NameValueCollection requestArgs = 
new NameValueCollection
 
  252                     { 
"RequestMethod", 
"xAddMapTile" },
 
  253                     { 
"X", locX.ToString() },
 
  254                     { 
"Y", locY.ToString() },
 
  255                     { 
"ContentType", 
"image/png" },
 
  256                     { 
"EncodedData", System.Convert.ToBase64String(pngData) }
 
  259             OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
 
  260             if (! response[
"Success"].AsBoolean())
 
  262                 m_log.WarnFormat(
"[SIMIAN MAPTILE] failed to store map tile; {0}",response[
"Message"].AsString());
 
OpenMetaverse.StructuredData.OSDMap OSDMap
 
void Initialise(IConfigSource source)
 
void RemoveRegion(Scene scene)
 
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
 
uint RegionLocY
The y co-ordinate of this region in map tiles (e.g. 1000). Coordinate is scaled as world coordinates ...
 
void AddRegion(Scene scene)
 
uint RegionLocX
The x co-ordinate of this region in map tiles (e.g. 1000). Coordinate is scaled as world coordinates ...