cache images by string (filename) rather than index; disable unloading for now
This commit is contained in:
parent
3c1e2c8dad
commit
dc909a80f4
19
Program.cs
19
Program.cs
@ -565,7 +565,7 @@ public class Game : GameWindow {
|
||||
int VertexArrayObject;
|
||||
List<Photo> allPhotos = new();
|
||||
List<Photo> photos = new();
|
||||
HashSet<int> loadedImages = new();
|
||||
HashSet<string> loadedImages = new();
|
||||
int photoIndex = 0;
|
||||
int ribbonIndex = 0;
|
||||
Shader shader = new();
|
||||
@ -710,6 +710,8 @@ public class Game : GameWindow {
|
||||
|
||||
void FilterByRating(int rating) {
|
||||
Console.WriteLine("filter to " + rating);
|
||||
photos = allPhotos.Where(p => p.Rating >= rating).ToList();
|
||||
photoIndex = 0;
|
||||
}
|
||||
|
||||
protected override void OnLoad() {
|
||||
@ -750,11 +752,11 @@ public class Game : GameWindow {
|
||||
|
||||
// Load photos from a directory.
|
||||
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\");
|
||||
// string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\");
|
||||
string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\");
|
||||
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\");
|
||||
// string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23");
|
||||
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
|
||||
string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
|
||||
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
|
||||
|
||||
for (int i = 0; i < files.Count(); i++) {
|
||||
string file = files[i];
|
||||
@ -789,8 +791,9 @@ 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.
|
||||
// FIXME: maybe use an LRU cache for evicting images?
|
||||
// FIXME: keep around thumbnail-sized textures?
|
||||
// FIXME: turn unloading back on, using an LRU cache for evicting images.
|
||||
/*
|
||||
foreach (int i in loadedImages) {
|
||||
if (i < minUnloadedImage || i > maxUnloadedImage) {
|
||||
// Console.WriteLine("unloading " + i);
|
||||
@ -798,12 +801,12 @@ public class Game : GameWindow {
|
||||
photos[i].UnloadAsync();
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
// Then, start loading any images that aren't in our window.
|
||||
for (int i = minLoadedImage; i <= maxLoadedImage; i++) {
|
||||
if (!loadedImages.Contains(i)) {
|
||||
if (!loadedImages.Contains(photos[i].Filename)) {
|
||||
// Console.WriteLine("loading " + i);
|
||||
loadedImages.Add(i);
|
||||
loadedImages.Add(photos[i].Filename);
|
||||
await Task.Run( () => { photos[i].LoadAsync(); });
|
||||
}
|
||||
}
|
||||
@ -816,7 +819,7 @@ public class Game : GameWindow {
|
||||
LoadAndUnloadImagesAsync();
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject); HashSet<int> loadedImages = new();
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
||||
GL.ActiveTexture(TextureUnit.Texture0);
|
||||
|
||||
Photo activePhoto = photos[photoIndex];
|
||||
|
Loading…
Reference in New Issue
Block a user