From 6478f1ee9554b4fb705c28a6680451dee21941b2 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Sat, 26 Aug 2023 12:55:06 -0400 Subject: [PATCH] adapt frame rate based on whether events are happening --- Program.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index 13a0362..35d7381 100644 --- a/Program.cs +++ b/Program.cs @@ -418,14 +418,27 @@ public class Game : GameWindow { Shader shader = new(); Matrix4 projection; float zoomLevel = 0f; + double timeSinceEvent = 0; protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); toast.Update(e.Time); - Photo previousPhoto = photos[photoIndex]; - 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 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\import"); // 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\Germany all\104D7000"); + string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\"); for (int i = 0; i < files.Count(); i++) { string file = files[i];