Time static class

This commit is contained in:
Matt Thorson 2020-05-04 21:04:29 -07:00
parent 0519afb158
commit 35c29f3f74
4 changed files with 29 additions and 24 deletions

View File

@ -12,9 +12,6 @@ namespace Strawberry
public class Game : SDLApp
{
public List<VirtualInput> 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<VirtualInput>();
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()

View File

@ -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

View File

@ -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

9
src/Time.bf Normal file
View File

@ -0,0 +1,9 @@
namespace Strawberry
{
static public class Time
{
static public float Elapsed;
static public float PreviousElapsed;
static public float Delta = 1 / 60f;
}
}