diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs')
-rw-r--r-- | OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs | 118 |
1 files changed, 61 insertions, 57 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs index 93fdae3..8375c95 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Collections.Specialized; | ||
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using System.Net; | 32 | using System.Net; |
32 | using System.IO; | 33 | using System.IO; |
@@ -43,7 +44,8 @@ using OpenSim.Region.Framework.Scenes; | |||
43 | using OpenMetaverse; | 44 | using OpenMetaverse; |
44 | using OpenMetaverse.StructuredData; | 45 | using OpenMetaverse.StructuredData; |
45 | 46 | ||
46 | namespace OpenSim.Region.OptionalModules.Simian | 47 | //namespace OpenSim.Region.OptionalModules.Simian |
48 | namespace OpenSim.Services.Connectors.SimianGrid | ||
47 | { | 49 | { |
48 | /// <summary> | 50 | /// <summary> |
49 | /// </summary> | 51 | /// </summary> |
@@ -179,7 +181,6 @@ namespace OpenSim.Region.OptionalModules.Simian | |||
179 | 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); |
180 | 182 | ||
181 | // 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 |
182 | byte[] pngData = Utils.EmptyBytes; | ||
183 | IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); | 184 | IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); |
184 | if (tileGenerator == null) | 185 | if (tileGenerator == null) |
185 | { | 186 | { |
@@ -187,76 +188,79 @@ namespace OpenSim.Region.OptionalModules.Simian | |||
187 | return; | 188 | return; |
188 | } | 189 | } |
189 | 190 | ||
190 | using (Image mapTile = tileGenerator.CreateMapTile()) | 191 | using (Bitmap mapTile = tileGenerator.CreateMapTile()) |
191 | { | ||
192 | using (MemoryStream stream = new MemoryStream()) | ||
193 | { | ||
194 | mapTile.Save(stream, ImageFormat.Png); | ||
195 | pngData = stream.ToArray(); | ||
196 | } | ||
197 | } | ||
198 | |||
199 | List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>() | ||
200 | { | ||
201 | new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()), | ||
202 | new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()), | ||
203 | new MultipartForm.File("Tile", "tile.png", "image/png", pngData) | ||
204 | }; | ||
205 | |||
206 | string errorMessage = null; | ||
207 | int tickstart = Util.EnvironmentTickCount(); | ||
208 | |||
209 | // Make the remote storage request | ||
210 | try | ||
211 | { | 192 | { |
212 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl); | 193 | if (mapTile != null) |
213 | request.Timeout = 20000; | ||
214 | request.ReadWriteTimeout = 5000; | ||
215 | |||
216 | using (HttpWebResponse response = MultipartForm.Post(request, postParameters)) | ||
217 | { | 194 | { |
218 | using (Stream responseStream = response.GetResponseStream()) | 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) | ||
219 | { | 197 | { |
220 | string responseStr = responseStream.GetStreamString(); | 198 | ConvertAndUploadMaptile(mapTile, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY); |
221 | OSD responseOSD = OSDParser.Deserialize(responseStr); | 199 | } |
222 | if (responseOSD.Type == OSDType.Map) | 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) | ||
223 | { | 206 | { |
224 | OSDMap responseMap = (OSDMap)responseOSD; | 207 | for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize) |
225 | if (responseMap["Success"].AsBoolean()) | 208 | { |
226 | return; | 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); | ||
227 | 216 | ||
228 | errorMessage = "Upload failed: " + responseMap["Message"].AsString(); | 217 | using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat)) |
229 | } | 218 | { |
230 | else | 219 | uint locX = scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize); |
231 | { | 220 | uint locY = scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize); |
232 | errorMessage = "Response format was invalid:\n" + responseStr; | 221 | |
222 | ConvertAndUploadMaptile(subMapTile, locX, locY); | ||
223 | } | ||
224 | } | ||
233 | } | 225 | } |
234 | } | 226 | } |
235 | } | 227 | } |
236 | } | 228 | else |
237 | catch (WebException we) | ||
238 | { | ||
239 | errorMessage = we.Message; | ||
240 | if (we.Status == WebExceptionStatus.ProtocolError) | ||
241 | { | 229 | { |
242 | HttpWebResponse webResponse = (HttpWebResponse)we.Response; | 230 | m_log.WarnFormat("[SIMIAN MAPTILE] Tile image generation failed"); |
243 | errorMessage = String.Format("[{0}] {1}", | ||
244 | webResponse.StatusCode,webResponse.StatusDescription); | ||
245 | } | 231 | } |
246 | } | 232 | } |
247 | catch (Exception ex) | 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()) | ||
248 | { | 245 | { |
249 | errorMessage = ex.Message; | 246 | mapTile.Save(stream, ImageFormat.Png); |
247 | pngData = stream.ToArray(); | ||
250 | } | 248 | } |
251 | finally | 249 | |
250 | NameValueCollection requestArgs = new NameValueCollection | ||
251 | { | ||
252 | { "RequestMethod", "xAddMapTile" }, | ||
253 | { "X", locX.ToString() }, | ||
254 | { "Y", locY.ToString() }, | ||
255 | { "ContentType", "image/png" }, | ||
256 | { "EncodedData", System.Convert.ToBase64String(pngData) } | ||
257 | }; | ||
258 | |||
259 | OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs); | ||
260 | if (! response["Success"].AsBoolean()) | ||
252 | { | 261 | { |
253 | // This just dumps a warning for any operation that takes more than 100 ms | 262 | m_log.WarnFormat("[SIMIAN MAPTILE] failed to store map tile; {0}",response["Message"].AsString()); |
254 | int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); | ||
255 | m_log.DebugFormat("[SIMIAN MAPTILE]: map tile uploaded in {0}ms",tickdiff); | ||
256 | } | 263 | } |
257 | |||
258 | m_log.WarnFormat("[SIMIAN MAPTILE]: Failed to store {0} byte tile for {1}: {2}", | ||
259 | pngData.Length, scene.RegionInfo.RegionName, errorMessage); | ||
260 | } | 264 | } |
261 | } | 265 | } |
262 | } \ No newline at end of file | 266 | } \ No newline at end of file |