From 50e4a45b5e0505e74a51b2fa7aa2486ba65045ad Mon Sep 17 00:00:00 2001 From: xx-TheDoctor-xx Date: Mon, 3 Aug 2020 20:39:31 +0100 Subject: [PATCH] Added loop funcionality --- examples/01.cs | 30 ++++++++++++++++++++++++++++++ src/TickManager.cs | 18 +++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 examples/01.cs diff --git a/examples/01.cs b/examples/01.cs new file mode 100644 index 0000000..dc87c50 --- /dev/null +++ b/examples/01.cs @@ -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); + } + } +} diff --git a/src/TickManager.cs b/src/TickManager.cs index 72e3698..f255cf1 100644 --- a/src/TickManager.cs +++ b/src/TickManager.cs @@ -4,6 +4,8 @@ using System.Text; namespace TickManager { + public delegate void Tick(); + /// /// Handles ticking for an application /// @@ -24,6 +26,20 @@ namespace TickManager /// internal TickClock tc = new TickClock(); + /// + /// Event that gets called every time it ticks + /// + public event Tick OnTick; + + /// + /// Used to run in a loop. Invokes the OnTick event + /// + public void Tick() + { + if (CanTick()) + OnTick?.Invoke(); + } + /// /// The frequency your application will tick /// @@ -55,7 +71,7 @@ namespace TickManager /// Checks if the application can process the same tick relative to the frequency set /// /// Whether the application should process the next tick or not - public bool CanTick() + internal bool CanTick() { double tickTime = tc.Tick(); bool canTick = tickTime > msptInternal;