adapt frame rate based on whether events are happening

This commit is contained in:
Colin McMillen 2023-08-26 12:55:06 -04:00
parent 393369773b
commit 6478f1ee95

View File

@ -418,14 +418,27 @@ public class Game : GameWindow {
Shader shader = new(); Shader shader = new();
Matrix4 projection; Matrix4 projection;
float zoomLevel = 0f; float zoomLevel = 0f;
double timeSinceEvent = 0;
protected override void OnUpdateFrame(FrameEventArgs e) { protected override void OnUpdateFrame(FrameEventArgs e) {
base.OnUpdateFrame(e); base.OnUpdateFrame(e);
toast.Update(e.Time); toast.Update(e.Time);
Photo previousPhoto = photos[photoIndex];
KeyboardState input = KeyboardState; KeyboardState input = KeyboardState;
if (input.IsAnyKeyDown || MouseState.IsAnyButtonDown || MouseState.Delta != Vector2i.Zero) {
timeSinceEvent = 0;
} else {
timeSinceEvent += e.Time;
}
if (IsFocused && timeSinceEvent < 1) {
RenderFrequency = 30;
UpdateFrequency = 30;
} else {
RenderFrequency = 2;
UpdateFrequency = 2;
}
Photo previousPhoto = photos[photoIndex];
bool shiftIsDown = input.IsKeyDown(Keys.LeftShift) || input.IsKeyDown(Keys.RightShift); bool shiftIsDown = input.IsKeyDown(Keys.LeftShift) || input.IsKeyDown(Keys.RightShift);
bool altIsDown = input.IsKeyDown(Keys.LeftAlt) || input.IsKeyDown(Keys.RightAlt); bool altIsDown = input.IsKeyDown(Keys.LeftAlt) || input.IsKeyDown(Keys.RightAlt);
@ -664,8 +677,8 @@ public class Game : GameWindow {
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\07\31"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\07\31");
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // 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\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++) { for (int i = 0; i < files.Count(); i++) {
string file = files[i]; string file = files[i];