Browse Source

Photo.Unload() is now async

main
Colin McMillen 12 months ago
parent
commit
32cb03ab15
  1. 17
      Program.cs

17
Program.cs

@ -187,9 +187,10 @@ public class Photo {
image = tmp;
}
public void Unload() {
public async void UnloadAsync() {
Loaded = false;
if (texture != placeholder) {
texture.Dispose();
await Task.Run( () => { texture.Dispose(); });
texture = placeholder;
}
}
@ -703,19 +704,15 @@ public class Game : GameWindow {
int maxLoadedImage = Math.Min(photoIndex + 20, photos.Count - 1);
// First, unload images that are far outside our window.
// FIXME: also cancel any in-progress loading tasks that have moved outside our window.
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// FIXME: maybe use an LRU cache for evicting images?
// FIXME: keep around thumbnail-sized textures?
foreach (int i in loadedImages) {
if (i < minUnloadedImage || i > maxUnloadedImage) {
loadedImages.Remove(i);
photos[i].Unload();
// Console.WriteLine("unloading " + i);
loadedImages.Remove(i);
photos[i].UnloadAsync();
}
}
stopwatch.Stop();
if (stopwatch.Elapsed.TotalMilliseconds > 1) {
Console.WriteLine(stopwatch.Elapsed.TotalMilliseconds);
}
// Then, start loading any images that aren't in our window.
for (int i = minLoadedImage; i <= maxLoadedImage; i++) {

Loading…
Cancel
Save