mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Timing helpers
This commit is contained in:
parent
35c29f3f74
commit
654398a137
34
src/Scene.bf
34
src/Scene.bf
|
@ -5,6 +5,8 @@ namespace Strawberry
|
|||
{
|
||||
public class Scene
|
||||
{
|
||||
public float TimeStarted { get; private set; }
|
||||
|
||||
private List<Entity> entities;
|
||||
private HashSet<Entity> toRemove;
|
||||
private HashSet<Entity> toAdd;
|
||||
|
@ -33,7 +35,7 @@ namespace Strawberry
|
|||
|
||||
public virtual void Started()
|
||||
{
|
||||
|
||||
TimeStarted = Time.Elapsed;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
|
@ -95,6 +97,36 @@ namespace Strawberry
|
|||
}
|
||||
}
|
||||
|
||||
// Time
|
||||
|
||||
public float TimeElapsed
|
||||
{
|
||||
[Inline]
|
||||
get
|
||||
{
|
||||
return Time.Elapsed - TimeStarted;
|
||||
}
|
||||
}
|
||||
|
||||
public float PreviousTimeElapsed
|
||||
{
|
||||
[Inline]
|
||||
get
|
||||
{
|
||||
return Time.PreviousElapsed - TimeStarted;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TimeOnInterval(float interval, float offset = 0)
|
||||
{
|
||||
return (int)((TimeElapsed - offset) / interval) != (int)((PreviousTimeElapsed - offset) / interval);
|
||||
}
|
||||
|
||||
public bool TimeBetweenInterval(float interval, float offset = 0)
|
||||
{
|
||||
return (TimeElapsed - offset) % (interval * 2) >= interval;
|
||||
}
|
||||
|
||||
// Finding Entities
|
||||
|
||||
public T First<T>() where T : Entity
|
||||
|
|
10
src/Time.bf
10
src/Time.bf
|
@ -5,5 +5,15 @@ namespace Strawberry
|
|||
static public float Elapsed;
|
||||
static public float PreviousElapsed;
|
||||
static public float Delta = 1 / 60f;
|
||||
|
||||
static public bool OnInterval(float interval, float offset = 0)
|
||||
{
|
||||
return (int)((Elapsed - offset) / interval) != (int)((PreviousElapsed - offset) / interval);
|
||||
}
|
||||
|
||||
static public bool BetweenInterval(float interval, float offset = 0)
|
||||
{
|
||||
return (Elapsed - offset) % (interval * 2) >= interval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user