From 35c29f3f74208d63be613c0a1848e5ea7e411abe Mon Sep 17 00:00:00 2001 From: Matt Thorson Date: Mon, 4 May 2020 21:04:29 -0700 Subject: [PATCH] Time static class --- src/Game.bf | 8 ++------ src/Input/VirtualAxis.bf | 18 +++++++++--------- src/Input/VirtualButton.bf | 18 +++++++++--------- src/Time.bf | 9 +++++++++ 4 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 src/Time.bf diff --git a/src/Game.bf b/src/Game.bf index 4c88bdb..e734b33 100644 --- a/src/Game.bf +++ b/src/Game.bf @@ -12,9 +12,6 @@ namespace Strawberry public class Game : SDLApp { public List VirtualInputs; - public float DeltaTime { get; private set; } - public float Time { get; private set; } - public float PreviousTime { get; private set; } private Scene scene; private Scene switchToScene; @@ -26,7 +23,6 @@ namespace Strawberry { Game = this; VirtualInputs = new List(); - DeltaTime = 1 / 60f; mTitle.Set(windowTitle); mWidth = width; @@ -72,8 +68,8 @@ namespace Strawberry if (scene != null) scene.Update(); - PreviousTime = Time; - Time += DeltaTime; + Time.PreviousElapsed = Time.Elapsed; + Time.Elapsed += Time.Delta; } public override void Draw() diff --git a/src/Input/VirtualAxis.bf b/src/Input/VirtualAxis.bf index c49cb3f..8aec2e8 100644 --- a/src/Input/VirtualAxis.bf +++ b/src/Input/VirtualAxis.bf @@ -56,16 +56,16 @@ namespace Strawberry //Press if (last != IntValue && IntValue != 0) - lastPress = Game.Time; - Pressed = IntValue != 0 && lastPress > lastPressClear && Game.Time - lastPress <= pressBuffer; + lastPress = Time.Elapsed; + Pressed = IntValue != 0 && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer; //Repeat - if (IntValue != 0 && repeatStart > 0 && Game.Time - lastPress >= repeatStart) + if (IntValue != 0 && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart) { Repeating = true; - int a = (int)((Game.PreviousTime - lastPress) / repeatInterval); - int b = (int)((Game.Time - lastPress) / repeatInterval); + int a = (int)((Time.PreviousElapsed - lastPress) / repeatInterval); + int b = (int)((Time.Elapsed - lastPress) / repeatInterval); if (a != b) Pressed = true; } @@ -74,18 +74,18 @@ namespace Strawberry //Release if (last != 0 && IntValue == 0) - lastRelease = Game.Time; - Released = IntValue == 0 && lastRelease > lastReleaseClear && Game.Time - lastRelease <= releaseBuffer; + lastRelease = Time.Elapsed; + Released = IntValue == 0 && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer; } public void ClearPressBuffer() { - lastPressClear = Game.Time; + lastPressClear = Time.Elapsed; } public void ClearReleaseBuffer() { - lastReleaseClear = Game.Time; + lastReleaseClear = Time.Elapsed; } // Setup Calls diff --git a/src/Input/VirtualButton.bf b/src/Input/VirtualButton.bf index 5f860bf..fb2f92f 100644 --- a/src/Input/VirtualButton.bf +++ b/src/Input/VirtualButton.bf @@ -50,16 +50,16 @@ namespace Strawberry //Press if (!last && Check) - lastPress = Game.Time; - Pressed = Check && lastPress > lastPressClear && Game.Time - lastPress <= pressBuffer; + lastPress = Time.Elapsed; + Pressed = Check && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer; //Repeat - if (Check && repeatStart > 0 && Game.Time - lastPress >= repeatStart) + if (Check && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart) { Repeating = true; - int a = (int)((Game.PreviousTime - lastPress) / repeatInterval); - int b = (int)((Game.Time - lastPress) / repeatInterval); + int a = (int)((Time.PreviousElapsed - lastPress) / repeatInterval); + int b = (int)((Time.Elapsed - lastPress) / repeatInterval); if (a != b) Pressed = true; } @@ -68,18 +68,18 @@ namespace Strawberry //Release if (last && !Check) - lastRelease = Game.Time; - Released = !Check && lastRelease > lastReleaseClear && Game.Time - lastRelease <= releaseBuffer; + lastRelease = Time.Elapsed; + Released = !Check && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer; } public void ClearPressBuffer() { - lastPressClear = Game.Time; + lastPressClear = Time.Elapsed; } public void ClearReleaseBuffer() { - lastReleaseClear = Game.Time; + lastReleaseClear = Time.Elapsed; } // Setup Calls diff --git a/src/Time.bf b/src/Time.bf new file mode 100644 index 0000000..b86bd2a --- /dev/null +++ b/src/Time.bf @@ -0,0 +1,9 @@ +namespace Strawberry +{ + static public class Time + { + static public float Elapsed; + static public float PreviousElapsed; + static public float Delta = 1 / 60f; + } +}