diff options
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r-- | OpenSim/Region/Environment/Modules/TextureDownloadModule.cs | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs index 813be8d..6d5d5e8 100644 --- a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs +++ b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs | |||
@@ -47,7 +47,7 @@ namespace OpenSim.Region.Environment.Modules | |||
47 | private Scene m_scene; | 47 | private Scene m_scene; |
48 | private List<Scene> m_scenes = new List<Scene>(); | 48 | private List<Scene> m_scenes = new List<Scene>(); |
49 | 49 | ||
50 | private BlockingQueue<TextureSender> QueueSenders = new BlockingQueue<TextureSender>(); | 50 | private readonly BlockingQueue<TextureSender> m_queueSenders = new BlockingQueue<TextureSender>(); |
51 | 51 | ||
52 | private Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = | 52 | private Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = |
53 | new Dictionary<LLUUID, UserTextureDownloadService>(); | 53 | new Dictionary<LLUUID, UserTextureDownloadService>(); |
@@ -108,7 +108,7 @@ namespace OpenSim.Region.Environment.Modules | |||
108 | return true; | 108 | return true; |
109 | } | 109 | } |
110 | 110 | ||
111 | textureService = new UserTextureDownloadService(m_scene, QueueSenders); | 111 | textureService = new UserTextureDownloadService(m_scene, m_queueSenders); |
112 | m_userTextureServices.Add(userID, textureService); | 112 | m_userTextureServices.Add(userID, textureService); |
113 | return true; | 113 | return true; |
114 | } | 114 | } |
@@ -128,7 +128,7 @@ namespace OpenSim.Region.Environment.Modules | |||
128 | { | 128 | { |
129 | while (true) | 129 | while (true) |
130 | { | 130 | { |
131 | TextureSender sender = QueueSenders.Dequeue(); | 131 | TextureSender sender = m_queueSenders.Dequeue(); |
132 | if (sender.Cancel) | 132 | if (sender.Cancel) |
133 | { | 133 | { |
134 | TextureSent(sender); | 134 | TextureSent(sender); |
@@ -142,7 +142,7 @@ namespace OpenSim.Region.Environment.Modules | |||
142 | } | 142 | } |
143 | else | 143 | else |
144 | { | 144 | { |
145 | QueueSenders.Enqueue(sender); | 145 | m_queueSenders.Enqueue(sender); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | } | 148 | } |
@@ -155,11 +155,9 @@ namespace OpenSim.Region.Environment.Modules | |||
155 | 155 | ||
156 | public class UserTextureDownloadService | 156 | public class UserTextureDownloadService |
157 | { | 157 | { |
158 | private Dictionary<LLUUID, TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender>(); | 158 | private readonly Dictionary<LLUUID, TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender>(); |
159 | 159 | private readonly BlockingQueue<TextureSender> m_sharedSendersQueue; | |
160 | private BlockingQueue<TextureSender> m_sharedSendersQueue; | 160 | private readonly Scene m_scene; |
161 | |||
162 | private Scene m_scene; | ||
163 | 161 | ||
164 | public UserTextureDownloadService(Scene scene, BlockingQueue<TextureSender> sharedQueue) | 162 | public UserTextureDownloadService(Scene scene, BlockingQueue<TextureSender> sharedQueue) |
165 | { | 163 | { |
@@ -169,38 +167,45 @@ namespace OpenSim.Region.Environment.Modules | |||
169 | 167 | ||
170 | public void HandleTextureRequest(IClientAPI client, TextureRequestArgs e) | 168 | public void HandleTextureRequest(IClientAPI client, TextureRequestArgs e) |
171 | { | 169 | { |
170 | TextureSender textureSender; | ||
171 | |||
172 | //TODO: should be working out the data size/ number of packets to be sent for each discard level | 172 | //TODO: should be working out the data size/ number of packets to be sent for each discard level |
173 | if ((e.DiscardLevel >= 0) || (e.Priority != 0)) | 173 | if ((e.DiscardLevel >= 0) || (e.Priority != 0)) |
174 | { | 174 | { |
175 | lock (m_textureSenders) | 175 | lock (m_textureSenders) |
176 | { | 176 | { |
177 | if (!m_textureSenders.ContainsKey(e.RequestedAssetID)) | 177 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) |
178 | { | ||
179 | textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); | ||
180 | textureSender.counter = 0; | ||
181 | |||
182 | if ((textureSender.ImageLoaded) && | ||
183 | (textureSender.Sending == false)) | ||
184 | { | ||
185 | textureSender.Sending = true; | ||
186 | |||
187 | if (!m_sharedSendersQueue.Contains(textureSender)) | ||
188 | { | ||
189 | m_sharedSendersQueue.Enqueue(textureSender); | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | else | ||
178 | { | 194 | { |
179 | TextureSender requestHandler = | 195 | TextureSender requestHandler = |
180 | new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber); | 196 | new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber); |
181 | m_textureSenders.Add(e.RequestedAssetID, requestHandler); | 197 | m_textureSenders.Add(e.RequestedAssetID, requestHandler); |
182 | m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback); | 198 | m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback); |
183 | } | 199 | } |
184 | else | ||
185 | { | ||
186 | m_textureSenders[e.RequestedAssetID].UpdateRequest(e.DiscardLevel, e.PacketNumber); | ||
187 | m_textureSenders[e.RequestedAssetID].counter = 0; | ||
188 | if ((m_textureSenders[e.RequestedAssetID].ImageLoaded) && | ||
189 | (m_textureSenders[e.RequestedAssetID].Sending == false)) | ||
190 | { | ||
191 | m_textureSenders[e.RequestedAssetID].Sending = true; | ||
192 | m_sharedSendersQueue.Enqueue(m_textureSenders[e.RequestedAssetID]); | ||
193 | } | ||
194 | } | ||
195 | } | 200 | } |
196 | } | 201 | } |
197 | else | 202 | else |
198 | { | 203 | { |
199 | lock (m_textureSenders) | 204 | lock (m_textureSenders) |
200 | { | 205 | { |
201 | if (m_textureSenders.ContainsKey(e.RequestedAssetID)) | 206 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) |
202 | { | 207 | { |
203 | m_textureSenders[e.RequestedAssetID].Cancel = true; | 208 | textureSender.Cancel = true; |
204 | } | 209 | } |
205 | } | 210 | } |
206 | } | 211 | } |
@@ -210,19 +215,25 @@ namespace OpenSim.Region.Environment.Modules | |||
210 | { | 215 | { |
211 | lock (m_textureSenders) | 216 | lock (m_textureSenders) |
212 | { | 217 | { |
213 | if (m_textureSenders.ContainsKey(textureID)) | 218 | TextureSender textureSender; |
219 | |||
220 | if (m_textureSenders.TryGetValue(textureID, out textureSender)) | ||
214 | { | 221 | { |
215 | if (!m_textureSenders[textureID].ImageLoaded) | 222 | if (!textureSender.ImageLoaded) |
216 | { | 223 | { |
217 | m_textureSenders[textureID].TextureReceived(asset); | 224 | textureSender.TextureReceived(asset); |
218 | m_textureSenders[textureID].Sending = true; | 225 | textureSender.Sending = true; |
219 | m_textureSenders[textureID].counter = 0; | 226 | textureSender.counter = 0; |
220 | m_sharedSendersQueue.Enqueue(m_textureSenders[textureID]); | 227 | |
228 | if (!m_sharedSendersQueue.Contains(textureSender)) | ||
229 | { | ||
230 | m_sharedSendersQueue.Enqueue(textureSender); | ||
231 | } | ||
221 | } | 232 | } |
222 | } | 233 | } |
223 | else | 234 | else |
224 | { | 235 | { |
225 | // Got a texture with no sender object to handle it, this shouldn't happen | 236 | throw new Exception("Got a texture with no sender object to handle it, this shouldn't happen"); |
226 | } | 237 | } |
227 | } | 238 | } |
228 | } | 239 | } |
@@ -329,9 +340,9 @@ namespace OpenSim.Region.Environment.Modules | |||
329 | } | 340 | } |
330 | catch (ArgumentOutOfRangeException) | 341 | catch (ArgumentOutOfRangeException) |
331 | { | 342 | { |
332 | MainLog.Instance.Warn("TEXTURE", | 343 | MainLog.Instance.Error("TEXTURE", |
333 | "Unable to separate texture into multiple packets: Array bounds failure on asset:" + | 344 | "Unable to separate texture into multiple packets: Array bounds failure on asset:" + |
334 | m_asset.FullID.ToString() + "- TextureDownloadModule.cs. line:328"); | 345 | m_asset.FullID.ToString() ); |
335 | return; | 346 | return; |
336 | } | 347 | } |
337 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | 348 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); |