Added loop funcionality

This commit is contained in:
xx-TheDoctor-xx
2020-08-03 20:39:31 +01:00
parent 22ed0539fa
commit 50e4a45b5e
2 changed files with 47 additions and 1 deletions

30
examples/01.cs Normal file
View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace TickManager
{
class _01
{
public TickManager tick_manager = new TickManager();
public void Main()
{
tick_manager.OnTick += Tick_manager_OnTick;
while (true)
{
tick_manager.Tick();
}
}
private void Tick_manager_OnTick()
{
Console.WriteLine("MSPT: ");
Console.Write(tick_manager.MSPT);
Console.WriteLine("TPS: ");
Console.Write(tick_manager.TPS);
}
}
}

View File

@ -4,6 +4,8 @@ using System.Text;
namespace TickManager
{
public delegate void Tick();
/// <summary>
/// Handles ticking for an application
/// </summary>
@ -24,6 +26,20 @@ namespace TickManager
/// </summary>
internal TickClock tc = new TickClock();
/// <summary>
/// Event that gets called every time it ticks
/// </summary>
public event Tick OnTick;
/// <summary>
/// Used to run in a loop. Invokes the OnTick event
/// </summary>
public void Tick()
{
if (CanTick())
OnTick?.Invoke();
}
/// <summary>
/// The frequency your application will tick
/// </summary>
@ -55,7 +71,7 @@ namespace TickManager
/// Checks if the application can process the same tick relative to the frequency set
/// </summary>
/// <returns>Whether the application should process the next tick or not</returns>
public bool CanTick()
internal bool CanTick()
{
double tickTime = tc.Tick();
bool canTick = tickTime > msptInternal;