| 27 |
private Thread MainThread; |
private Thread MainThread; |
| 28 |
// list of current requests in process |
// list of current requests in process |
| 29 |
private Dictionary<UUID, int> CurrentRequests; |
private Dictionary<UUID, int> CurrentRequests; |
| 30 |
|
//private ReaderWriterLockSlim rwCurrentRequests = new ReaderWriterLockSlim(); |
| 31 |
private Queue<UUID> RequestQueue; |
private Queue<UUID> RequestQueue; |
| 32 |
|
//private ReaderWriterLockSlim rwRequestQueue = new ReaderWriterLockSlim(); |
| 33 |
private static AutoResetEvent[] resetEvents; |
private static AutoResetEvent[] resetEvents; |
| 34 |
|
|
| 35 |
private static int[] threadpoolSlots; |
private static int[] threadpoolSlots; |
| 36 |
|
|
| 37 |
// maximum allowed concurrent requests at once |
// maximum allowed concurrent requests at once |
| 38 |
const int MAX_TEXTURE_REQUESTS = 10; |
const int MAX_TEXTURE_REQUESTS = 5; |
| 39 |
|
|
| 40 |
private GridClient gridClient; |
private GridClient gridClient; |
| 41 |
|
|
| 55 |
|
|
| 56 |
gridClient.Throttle.Texture = 440000.0f; |
gridClient.Throttle.Texture = 440000.0f; |
| 57 |
gridClient.Settings.TEXTURE_CACHE_DIR = cachefolderPath; |
gridClient.Settings.TEXTURE_CACHE_DIR = cachefolderPath; |
| 58 |
gridClient.Settings.TEXTURE_CACHE_MAX_SIZE = 70;//Mb |
gridClient.Settings.TEXTURE_CACHE_MAX_SIZE = 700;//Mb |
| 59 |
} |
} |
| 60 |
} |
} |
| 61 |
private static readonly DefaultTexture singleton = new DefaultTexture(); |
private static readonly DefaultTexture singleton = new DefaultTexture(); |
| 62 |
|
|
| 63 |
|
|
| 64 |
public static DefaultTexture SingleTextureManager() |
public static DefaultTexture SingleTextureManager() |
| 65 |
{ |
{ |
| 66 |
return singleton; |
return singleton; |
| 105 |
while (true) |
while (true) |
| 106 |
{ |
{ |
| 107 |
lock (RequestQueue) |
lock (RequestQueue) |
| 108 |
|
//rwRequestQueue.EnterUpgradeableReadLock(); |
| 109 |
{ |
{ |
| 110 |
if (RequestQueue.Count > 0) |
if (RequestQueue.Count > 0) |
| 111 |
{ |
{ |
| 125 |
{ |
{ |
| 126 |
|
|
| 127 |
UUID requestID; |
UUID requestID; |
| 128 |
|
//rwRequestQueue.EnterWriteLock(); |
| 129 |
requestID = RequestQueue.Dequeue(); |
requestID = RequestQueue.Dequeue(); |
| 130 |
|
//rwRequestQueue.ExitWriteLock(); |
| 131 |
|
|
| 132 |
Logger.DebugLog(String.Format("Sending Worker thread new download request {0}", reqNbr)); |
Logger.DebugLog(String.Format("Sending Worker thread new download request {0}", reqNbr)); |
| 133 |
ThreadPool.QueueUserWorkItem(new WaitCallback(textureRequestDoWork), new TaskInfo(requestID, reqNbr)); |
ThreadPool.QueueUserWorkItem(new WaitCallback(textureRequestDoWork), new TaskInfo(requestID, reqNbr)); |
| 134 |
|
|
| 135 |
//gridClient.Assets.RequestImage(requestID, ImageType.Normal); |
//rwRequestQueue.ExitUpgradeableReadLock(); |
| 136 |
|
|
| 137 |
continue; |
continue; |
| 138 |
} |
} |
| 139 |
} |
} |
| 140 |
} |
} |
| 141 |
|
// rwRequestQueue.ExitUpgradeableReadLock(); |
| 142 |
|
|
| 143 |
Thread.Sleep(500); |
Thread.Sleep(500); |
| 144 |
} |
} |
| 149 |
{ |
{ |
| 150 |
TaskInfo ti = (TaskInfo)threadContext; |
TaskInfo ti = (TaskInfo)threadContext; |
| 151 |
|
|
| 152 |
|
//rwCurrentRequests.EnterWriteLock(); |
| 153 |
lock (CurrentRequests) |
lock (CurrentRequests) |
| 154 |
{ |
{ |
| 155 |
if (CurrentRequests.ContainsKey(ti.RequestID)) |
if (CurrentRequests.ContainsKey(ti.RequestID)) |
| 162 |
CurrentRequests.Add(ti.RequestID, ti.RequestNbr); |
CurrentRequests.Add(ti.RequestID, ti.RequestNbr); |
| 163 |
} |
} |
| 164 |
} |
} |
| 165 |
|
//rwCurrentRequests.ExitWriteLock(); |
| 166 |
|
|
| 167 |
Logger.DebugLog(String.Format("Worker {0} Requesting {1}", ti.RequestNbr, ti.RequestID)); |
Logger.DebugLog(String.Format("Worker {0} Requesting {1}", ti.RequestNbr, ti.RequestID)); |
| 168 |
|
|
| 175 |
// Timed out |
// Timed out |
| 176 |
Logger.Log("Worker " + ti.RequestNbr + " Timeout waiting for Texture " + ti.RequestID + " to Download", Helpers.LogLevel.Warning); |
Logger.Log("Worker " + ti.RequestNbr + " Timeout waiting for Texture " + ti.RequestID + " to Download", Helpers.LogLevel.Warning); |
| 177 |
|
|
| 178 |
|
//rwCurrentRequests.EnterWriteLock(); |
| 179 |
lock (CurrentRequests) |
lock (CurrentRequests) |
| 180 |
CurrentRequests.Remove(ti.RequestID); |
CurrentRequests.Remove(ti.RequestID); |
| 181 |
|
//rwCurrentRequests.ExitWriteLock(); |
| 182 |
|
|
| 183 |
|
//rwRequestQueue.EnterWriteLock(); |
| 184 |
lock (RequestQueue) |
lock (RequestQueue) |
| 185 |
RequestQueue.Enqueue(ti.RequestID); |
RequestQueue.Enqueue(ti.RequestID); |
| 186 |
|
//rwRequestQueue.ExitWriteLock(); |
| 187 |
} |
} |
| 188 |
|
|
| 189 |
// free up this download slot |
// free up this download slot |
| 207 |
onDownloadFinished(image.ID, image.Success); |
onDownloadFinished(image.ID, image.Success); |
| 208 |
} |
} |
| 209 |
} |
} |
| 210 |
|
|
| 211 |
ManagedImage managedimg; |
ManagedImage managedimg; |
| 212 |
Image img; Bitmap bitmap; |
Image img; Bitmap bitmap; |
| 213 |
private void SaveTexture2Image(ImageDownload image) |
private void SaveTexture2Image(ImageDownload image) |
| 230 |
} |
} |
| 231 |
else |
else |
| 232 |
{ |
{ |
| 233 |
|
//rwCurrentRequests.EnterReadLock(); |
| 234 |
|
//rwRequestQueue.EnterWriteLock(); |
| 235 |
|
|
| 236 |
lock (RequestQueue) |
lock (RequestQueue) |
| 237 |
{ |
{ |
| 238 |
// Make sure we aren't already downloading the texture |
// Make sure we aren't already downloading the texture |
| 241 |
RequestQueue.Enqueue(textureID); |
RequestQueue.Enqueue(textureID); |
| 242 |
} |
} |
| 243 |
} |
} |
| 244 |
|
|
| 245 |
|
//rwRequestQueue.ExitWriteLock(); |
| 246 |
|
// rwCurrentRequests.ExitReadLock(); |
| 247 |
} |
} |
| 248 |
|
|
| 249 |
return image; |
return image; |
| 251 |
|
|
| 252 |
public void RequestTexture(UUID textureID) |
public void RequestTexture(UUID textureID) |
| 253 |
{ |
{ |
| 254 |
lock (objFileAccess) |
// lock (objFileAccess) |
| 255 |
{ |
{ |
| 256 |
if (File.Exists(Path.Combine(bmpFilePath, textureID.ToString() + ".png")) == true) |
//if (File.Exists(Path.Combine(bmpFilePath, textureID.ToString() + ".png")) == true) |
| 257 |
return; |
// return; |
|
} |
|
| 258 |
|
|
| 259 |
if (gridClient.Assets.Cache.HasImage(textureID) == false) |
if (gridClient.Assets.Cache.HasImage(textureID) == false) |
| 260 |
{ |
{ |
|
bool needdownload = false; |
|
|
lock (CurrentRequests) |
|
|
{ |
|
|
// Make sure we aren't already downloading the texture |
|
|
if (!CurrentRequests.ContainsKey(textureID)) |
|
|
needdownload = true; |
|
|
} |
|
| 261 |
|
|
| 262 |
|
//rwRequestQueue.EnterWriteLock(); |
| 263 |
|
//rwCurrentRequests.EnterReadLock(); |
| 264 |
lock (RequestQueue) |
lock (RequestQueue) |
| 265 |
{ |
{ |
| 266 |
if (needdownload && !RequestQueue.Contains(textureID)) |
// Make sure we aren't already downloading the texture |
| 267 |
{ |
if (!CurrentRequests.ContainsKey(textureID) && !RequestQueue.Contains(textureID)) |
| 268 |
RequestQueue.Enqueue(textureID); |
RequestQueue.Enqueue(textureID); |
| 269 |
} |
} |
| 270 |
|
//rwCurrentRequests.ExitReadLock(); |
| 271 |
|
//rwRequestQueue.ExitWriteLock(); |
| 272 |
} |
} |
| 273 |
} |
} |
|
|
|
|
|
|
| 274 |
} |
} |
| 275 |
|
|
| 276 |
object objFileAccess = new object(); |
object objFileAccess = new object(); |