Added loop funcionality
This commit is contained in:
30
examples/01.cs
Normal file
30
examples/01.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user