aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/MapImageService/MapImageService.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Services/MapImageService/MapImageService.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Services/MapImageService/MapImageService.cs')
-rw-r--r--OpenSim/Services/MapImageService/MapImageService.cs110
1 files changed, 96 insertions, 14 deletions
diff --git a/OpenSim/Services/MapImageService/MapImageService.cs b/OpenSim/Services/MapImageService/MapImageService.cs
index a85ee70..a816411 100644
--- a/OpenSim/Services/MapImageService/MapImageService.cs
+++ b/OpenSim/Services/MapImageService/MapImageService.cs
@@ -36,6 +36,7 @@ using System.Drawing.Imaging;
36using System.IO; 36using System.IO;
37using System.Net; 37using System.Net;
38using System.Reflection; 38using System.Reflection;
39using System.Threading;
39 40
40using Nini.Config; 41using Nini.Config;
41using log4net; 42using log4net;
@@ -53,6 +54,9 @@ namespace OpenSim.Services.MapImageService
53 private static readonly ILog m_log = 54 private static readonly ILog m_log =
54 LogManager.GetLogger( 55 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType); 56 MethodBase.GetCurrentMethod().DeclaringType);
57#pragma warning disable 414
58 private string LogHeader = "[MAP IMAGE SERVICE]";
59#pragma warning restore 414
56 60
57 private const int ZOOM_LEVELS = 8; 61 private const int ZOOM_LEVELS = 8;
58 private const int IMAGE_WIDTH = 256; 62 private const int IMAGE_WIDTH = 256;
@@ -86,7 +90,7 @@ namespace OpenSim.Services.MapImageService
86 { 90 {
87 Bitmap waterTile = new Bitmap(IMAGE_WIDTH, IMAGE_WIDTH); 91 Bitmap waterTile = new Bitmap(IMAGE_WIDTH, IMAGE_WIDTH);
88 FillImage(waterTile, m_Watercolor); 92 FillImage(waterTile, m_Watercolor);
89 waterTile.Save(m_WaterTileFile); 93 waterTile.Save(m_WaterTileFile, ImageFormat.Jpeg);
90 } 94 }
91 } 95 }
92 } 96 }
@@ -112,28 +116,106 @@ namespace OpenSim.Services.MapImageService
112 reason = e.Message; 116 reason = e.Message;
113 return false; 117 return false;
114 } 118 }
119 }
120
121 return UpdateMultiResolutionFilesAsync(x, y, out reason);
122 }
115 123
116 // Also save in png format? 124 public bool RemoveMapTile(int x, int y, out string reason)
125 {
126 reason = String.Empty;
127 string fileName = GetFileName(1, x, y);
117 128
118 // Stitch seven more aggregate tiles together 129 lock (m_Sync)
119 for (uint zoomLevel = 2; zoomLevel <= ZOOM_LEVELS; zoomLevel++) 130 {
131 try
132 {
133 File.Delete(fileName);
134 }
135 catch (Exception e)
120 { 136 {
121 // Calculate the width (in full resolution tiles) and bottom-left 137 m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to save delete file {0}: {1}", fileName, e);
122 // corner of the current zoom level 138 reason = e.Message;
123 int width = (int)Math.Pow(2, (double)(zoomLevel - 1)); 139 return false;
124 int x1 = x - (x % width); 140 }
125 int y1 = y - (y % width); 141 }
142
143 return UpdateMultiResolutionFilesAsync(x, y, out reason);
144 }
126 145
127 if (!CreateTile(zoomLevel, x1, y1)) 146 // When large varregions start up, they can send piles of new map tiles. This causes
147 // this multi-resolution routine to be called a zillion times an causes much CPU
148 // time to be spent creating multi-resolution tiles that will be replaced when
149 // the next maptile arrives.
150 private class mapToMultiRez
151 {
152 public int xx;
153 public int yy;
154 public mapToMultiRez(int pX, int pY)
155 {
156 xx = pX;
157 yy = pY;
158 }
159 };
160 private Queue<mapToMultiRez> multiRezToBuild = new Queue<mapToMultiRez>();
161 private bool UpdateMultiResolutionFilesAsync(int x, int y, out string reason)
162 {
163 reason = String.Empty;
164 lock (multiRezToBuild)
165 {
166 // m_log.DebugFormat("{0} UpdateMultiResolutionFilesAsync: scheduling update for <{1},{2}>", LogHeader, x, y);
167 multiRezToBuild.Enqueue(new mapToMultiRez(x, y));
168 if (multiRezToBuild.Count == 1)
169 Util.FireAndForget(
170 DoUpdateMultiResolutionFilesAsync, null, "MapImageService.DoUpdateMultiResolutionFilesAsync");
171 }
172
173 return true;
174 }
175
176 private void DoUpdateMultiResolutionFilesAsync(object o)
177 {
178 // This sleep causes the FireAndForget thread to be different than the invocation thread.
179 // It also allows other tiles to be uploaded so the multi-rez images are more likely
180 // to be correct.
181 Thread.Sleep(1 * 1000);
182
183 while (multiRezToBuild.Count > 0)
184 {
185 mapToMultiRez toMultiRez = null;
186 lock (multiRezToBuild)
187 {
188 if (multiRezToBuild.Count > 0)
189 toMultiRez = multiRezToBuild.Dequeue();
190 }
191 if (toMultiRez != null)
192 {
193 int x = toMultiRez.xx;
194 int y = toMultiRez.yy;
195 // m_log.DebugFormat("{0} DoUpdateMultiResolutionFilesAsync: doing build for <{1},{2}>", LogHeader, x, y);
196
197 // Stitch seven more aggregate tiles together
198 for (uint zoomLevel = 2; zoomLevel <= ZOOM_LEVELS; zoomLevel++)
128 { 199 {
129 m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to create tile for {0} at zoom level {1}", fileName, zoomLevel); 200 // Calculate the width (in full resolution tiles) and bottom-left
130 reason = string.Format("Map tile at zoom level {0} failed", zoomLevel); 201 // corner of the current zoom level
131 return false; 202 int width = (int)Math.Pow(2, (double)(zoomLevel - 1));
203 int x1 = x - (x % width);
204 int y1 = y - (y % width);
205
206 lock (m_Sync) // must lock the reading and writing of the maptile files
207 {
208 if (!CreateTile(zoomLevel, x1, y1))
209 {
210 m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to create tile for {0},{1} at zoom level {1}", x, y, zoomLevel);
211 return;
212 }
213 }
132 } 214 }
133 } 215 }
134 } 216 }
135 217
136 return true; 218 return;
137 } 219 }
138 220
139 public byte[] GetMapTile(string fileName, out string format) 221 public byte[] GetMapTile(string fileName, out string format)