mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-02-18 11:38:28 +08:00
Time static class
This commit is contained in:
parent
0519afb158
commit
35c29f3f74
@ -12,9 +12,6 @@ namespace Strawberry
|
|||||||
public class Game : SDLApp
|
public class Game : SDLApp
|
||||||
{
|
{
|
||||||
public List<VirtualInput> VirtualInputs;
|
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 scene;
|
||||||
private Scene switchToScene;
|
private Scene switchToScene;
|
||||||
@ -26,7 +23,6 @@ namespace Strawberry
|
|||||||
{
|
{
|
||||||
Game = this;
|
Game = this;
|
||||||
VirtualInputs = new List<VirtualInput>();
|
VirtualInputs = new List<VirtualInput>();
|
||||||
DeltaTime = 1 / 60f;
|
|
||||||
|
|
||||||
mTitle.Set(windowTitle);
|
mTitle.Set(windowTitle);
|
||||||
mWidth = width;
|
mWidth = width;
|
||||||
@ -72,8 +68,8 @@ namespace Strawberry
|
|||||||
if (scene != null)
|
if (scene != null)
|
||||||
scene.Update();
|
scene.Update();
|
||||||
|
|
||||||
PreviousTime = Time;
|
Time.PreviousElapsed = Time.Elapsed;
|
||||||
Time += DeltaTime;
|
Time.Elapsed += Time.Delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
|
@ -56,16 +56,16 @@ namespace Strawberry
|
|||||||
|
|
||||||
//Press
|
//Press
|
||||||
if (last != IntValue && IntValue != 0)
|
if (last != IntValue && IntValue != 0)
|
||||||
lastPress = Game.Time;
|
lastPress = Time.Elapsed;
|
||||||
Pressed = IntValue != 0 && lastPress > lastPressClear && Game.Time - lastPress <= pressBuffer;
|
Pressed = IntValue != 0 && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer;
|
||||||
|
|
||||||
//Repeat
|
//Repeat
|
||||||
if (IntValue != 0 && repeatStart > 0 && Game.Time - lastPress >= repeatStart)
|
if (IntValue != 0 && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart)
|
||||||
{
|
{
|
||||||
Repeating = true;
|
Repeating = true;
|
||||||
|
|
||||||
int a = (int)((Game.PreviousTime - lastPress) / repeatInterval);
|
int a = (int)((Time.PreviousElapsed - lastPress) / repeatInterval);
|
||||||
int b = (int)((Game.Time - lastPress) / repeatInterval);
|
int b = (int)((Time.Elapsed - lastPress) / repeatInterval);
|
||||||
if (a != b)
|
if (a != b)
|
||||||
Pressed = true;
|
Pressed = true;
|
||||||
}
|
}
|
||||||
@ -74,18 +74,18 @@ namespace Strawberry
|
|||||||
|
|
||||||
//Release
|
//Release
|
||||||
if (last != 0 && IntValue == 0)
|
if (last != 0 && IntValue == 0)
|
||||||
lastRelease = Game.Time;
|
lastRelease = Time.Elapsed;
|
||||||
Released = IntValue == 0 && lastRelease > lastReleaseClear && Game.Time - lastRelease <= releaseBuffer;
|
Released = IntValue == 0 && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearPressBuffer()
|
public void ClearPressBuffer()
|
||||||
{
|
{
|
||||||
lastPressClear = Game.Time;
|
lastPressClear = Time.Elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearReleaseBuffer()
|
public void ClearReleaseBuffer()
|
||||||
{
|
{
|
||||||
lastReleaseClear = Game.Time;
|
lastReleaseClear = Time.Elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Calls
|
// Setup Calls
|
||||||
|
@ -50,16 +50,16 @@ namespace Strawberry
|
|||||||
|
|
||||||
//Press
|
//Press
|
||||||
if (!last && Check)
|
if (!last && Check)
|
||||||
lastPress = Game.Time;
|
lastPress = Time.Elapsed;
|
||||||
Pressed = Check && lastPress > lastPressClear && Game.Time - lastPress <= pressBuffer;
|
Pressed = Check && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer;
|
||||||
|
|
||||||
//Repeat
|
//Repeat
|
||||||
if (Check && repeatStart > 0 && Game.Time - lastPress >= repeatStart)
|
if (Check && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart)
|
||||||
{
|
{
|
||||||
Repeating = true;
|
Repeating = true;
|
||||||
|
|
||||||
int a = (int)((Game.PreviousTime - lastPress) / repeatInterval);
|
int a = (int)((Time.PreviousElapsed - lastPress) / repeatInterval);
|
||||||
int b = (int)((Game.Time - lastPress) / repeatInterval);
|
int b = (int)((Time.Elapsed - lastPress) / repeatInterval);
|
||||||
if (a != b)
|
if (a != b)
|
||||||
Pressed = true;
|
Pressed = true;
|
||||||
}
|
}
|
||||||
@ -68,18 +68,18 @@ namespace Strawberry
|
|||||||
|
|
||||||
//Release
|
//Release
|
||||||
if (last && !Check)
|
if (last && !Check)
|
||||||
lastRelease = Game.Time;
|
lastRelease = Time.Elapsed;
|
||||||
Released = !Check && lastRelease > lastReleaseClear && Game.Time - lastRelease <= releaseBuffer;
|
Released = !Check && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearPressBuffer()
|
public void ClearPressBuffer()
|
||||||
{
|
{
|
||||||
lastPressClear = Game.Time;
|
lastPressClear = Time.Elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearReleaseBuffer()
|
public void ClearReleaseBuffer()
|
||||||
{
|
{
|
||||||
lastReleaseClear = Game.Time;
|
lastReleaseClear = Time.Elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Calls
|
// Setup Calls
|
||||||
|
9
src/Time.bf
Normal file
9
src/Time.bf
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user