aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/SimianGrid
diff options
context:
space:
mode:
authorMic Bowman2014-02-05 21:26:39 -0800
committerMic Bowman2014-02-05 21:26:39 -0800
commit1913ab5ad55f93f5b009df80cb016ac214c1a6e3 (patch)
tree808c31ed5199ebc06922856a203738326cd471b7 /OpenSim/Services/Connectors/SimianGrid
parentRemove the added whitespace, test concluded (diff)
downloadopensim-SC_OLD-1913ab5ad55f93f5b009df80cb016ac214c1a6e3.zip
opensim-SC_OLD-1913ab5ad55f93f5b009df80cb016ac214c1a6e3.tar.gz
opensim-SC_OLD-1913ab5ad55f93f5b009df80cb016ac214c1a6e3.tar.bz2
opensim-SC_OLD-1913ab5ad55f93f5b009df80cb016ac214c1a6e3.tar.xz
Update the SimianMaptile uploader to accommodate varregions.
Diffstat (limited to 'OpenSim/Services/Connectors/SimianGrid')
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs133
1 files changed, 59 insertions, 74 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs
index b999509..8375c95 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs
@@ -181,7 +181,6 @@ namespace OpenSim.Services.Connectors.SimianGrid
181 m_log.DebugFormat("[SIMIAN MAPTILE]: upload maptile for {0}",scene.RegionInfo.RegionName); 181 m_log.DebugFormat("[SIMIAN MAPTILE]: upload maptile for {0}",scene.RegionInfo.RegionName);
182 182
183 // Create a PNG map tile and upload it to the AddMapTile API 183 // Create a PNG map tile and upload it to the AddMapTile API
184 byte[] pngData = Utils.EmptyBytes;
185 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); 184 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
186 if (tileGenerator == null) 185 if (tileGenerator == null)
187 { 186 {
@@ -189,93 +188,79 @@ namespace OpenSim.Services.Connectors.SimianGrid
189 return; 188 return;
190 } 189 }
191 190
192 using (Image mapTile = tileGenerator.CreateMapTile()) 191 using (Bitmap mapTile = tileGenerator.CreateMapTile())
193 { 192 {
194 using (MemoryStream stream = new MemoryStream()) 193 if (mapTile != null)
194 {
195 // If the region/maptile is legacy sized, just upload the one tile like it has always been done
196 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
197 {
198 ConvertAndUploadMaptile(mapTile, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY);
199 }
200 else
201 {
202 // For larger regions (varregion) we must cut the region image into legacy sized
203 // pieces since that is how the maptile system works.
204 // Note the assumption that varregions are always a multiple of legacy size.
205 for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
206 {
207 for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
208 {
209 // Images are addressed from the upper left corner so have to do funny
210 // math to pick out the sub-tile since regions are numbered from
211 // the lower left.
212 Rectangle rect = new Rectangle(
213 (int)xx,
214 mapTile.Height - (int)yy - (int)Constants.RegionSize,
215 (int)Constants.RegionSize, (int)Constants.RegionSize);
216
217 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
218 {
219 uint locX = scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize);
220 uint locY = scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize);
221
222 ConvertAndUploadMaptile(subMapTile, locX, locY);
223 }
224 }
225 }
226 }
227 }
228 else
195 { 229 {
196 mapTile.Save(stream, ImageFormat.Png); 230 m_log.WarnFormat("[SIMIAN MAPTILE] Tile image generation failed");
197 pngData = stream.ToArray();
198 } 231 }
199 } 232 }
200 233
234 }
235
236 ///<summary>
237 ///
238 ///</summary>
239 private void ConvertAndUploadMaptile(Image mapTile, uint locX, uint locY)
240 {
241 //m_log.DebugFormat("[SIMIAN MAPTILE]: upload maptile for location {0}, {1}", locX, locY);
242
243 byte[] pngData = Utils.EmptyBytes;
244 using (MemoryStream stream = new MemoryStream())
245 {
246 mapTile.Save(stream, ImageFormat.Png);
247 pngData = stream.ToArray();
248 }
249
201 NameValueCollection requestArgs = new NameValueCollection 250 NameValueCollection requestArgs = new NameValueCollection
202 { 251 {
203 { "RequestMethod", "xAddMapTile" }, 252 { "RequestMethod", "xAddMapTile" },
204 { "X", scene.RegionInfo.RegionLocX.ToString() }, 253 { "X", locX.ToString() },
205 { "Y", scene.RegionInfo.RegionLocY.ToString() }, 254 { "Y", locY.ToString() },
206 { "ContentType", "image/png" }, 255 { "ContentType", "image/png" },
207 { "EncodedData", System.Convert.ToBase64String(pngData) } 256 { "EncodedData", System.Convert.ToBase64String(pngData) }
208 }; 257 };
209 258
210 OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs); 259 OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
211 if (! response["Success"].AsBoolean()) 260 if (! response["Success"].AsBoolean())
212 { 261 {
213 m_log.WarnFormat("[SIMIAN MAPTILE] failed to store map tile; {0}",response["Message"].AsString()); 262 m_log.WarnFormat("[SIMIAN MAPTILE] failed to store map tile; {0}",response["Message"].AsString());
214 return;
215 } 263 }
216
217 // List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
218 // {
219 // new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
220 // new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
221 // new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
222 // };
223
224 // string errorMessage = null;
225 // int tickstart = Util.EnvironmentTickCount();
226
227 // // Make the remote storage request
228 // try
229 // {
230 // HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
231 // request.Timeout = 20000;
232 // request.ReadWriteTimeout = 5000;
233
234 // using (HttpWebResponse response = MultipartForm.Post(request, postParameters))
235 // {
236 // using (Stream responseStream = response.GetResponseStream())
237 // {
238 // string responseStr = responseStream.GetStreamString();
239 // OSD responseOSD = OSDParser.Deserialize(responseStr);
240 // if (responseOSD.Type == OSDType.Map)
241 // {
242 // OSDMap responseMap = (OSDMap)responseOSD;
243 // if (responseMap["Success"].AsBoolean())
244 // return;
245
246 // errorMessage = "Upload failed: " + responseMap["Message"].AsString();
247 // }
248 // else
249 // {
250 // errorMessage = "Response format was invalid:\n" + responseStr;
251 // }
252 // }
253 // }
254 // }
255 // catch (WebException we)
256 // {
257 // errorMessage = we.Message;
258 // if (we.Status == WebExceptionStatus.ProtocolError)
259 // {
260 // HttpWebResponse webResponse = (HttpWebResponse)we.Response;
261 // errorMessage = String.Format("[{0}] {1}",
262 // webResponse.StatusCode,webResponse.StatusDescription);
263 // }
264 // }
265 // catch (Exception ex)
266 // {
267 // errorMessage = ex.Message;
268 // }
269 // finally
270 // {
271 // // This just dumps a warning for any operation that takes more than 100 ms
272 // int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
273 // m_log.DebugFormat("[SIMIAN MAPTILE]: map tile uploaded in {0}ms",tickdiff);
274 // }
275
276 // m_log.WarnFormat("[SIMIAN MAPTILE]: Failed to store {0} byte tile for {1}: {2}",
277 // pngData.Length, scene.RegionInfo.RegionName, errorMessage);
278
279 } 264 }
280 } 265 }
281} \ No newline at end of file 266} \ No newline at end of file