From b84db27f83ab825eefe254757c3e5fd96601272c Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Sat, 11 Feb 2023 22:20:23 +0100 Subject: [PATCH] Add OnClose event. Reboot shortcut resets steps to 0 --- Capy64/Eventing/EventEmitter.cs | 9 +++++++++ Capy64/Runtime/EventEmitter.cs | 2 +- Capy64/Runtime/RuntimeManager.cs | 10 +++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Capy64/Eventing/EventEmitter.cs b/Capy64/Eventing/EventEmitter.cs index 8047111..f07d0df 100644 --- a/Capy64/Eventing/EventEmitter.cs +++ b/Capy64/Eventing/EventEmitter.cs @@ -21,6 +21,7 @@ public class EventEmitter // Functional events public event EventHandler OnTick; public event EventHandler OnInit; + public event EventHandler OnClose; public event EventHandler OnScreenSizeChange; public event EventHandler OnOverlay; @@ -100,6 +101,14 @@ public class EventEmitter } } + public void RaiseClose() + { + if (OnClose is not null) + { + OnClose(this, EventArgs.Empty); + } + } + public void RaiseScreenSizeChange() { if (OnScreenSizeChange is not null) diff --git a/Capy64/Runtime/EventEmitter.cs b/Capy64/Runtime/EventEmitter.cs index 918e7bf..b072677 100644 --- a/Capy64/Runtime/EventEmitter.cs +++ b/Capy64/Runtime/EventEmitter.cs @@ -71,7 +71,7 @@ internal class EventEmitter { heldReboot = 0; RuntimeManager.ResetPanic(); - RuntimeManager.Reboot(); + RuntimeManager.Reset(); } } diff --git a/Capy64/Runtime/RuntimeManager.cs b/Capy64/Runtime/RuntimeManager.cs index dc09c5b..f944f2f 100644 --- a/Capy64/Runtime/RuntimeManager.cs +++ b/Capy64/Runtime/RuntimeManager.cs @@ -5,6 +5,7 @@ using KeraLua; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.Tracing; using System.IO; using System.Linq; using System.Text; @@ -17,8 +18,8 @@ internal class RuntimeManager : IPlugin { private LuaState luaState; private EventEmitter emitter; - private int step = 0; + private static int step = 0; private static bool close = false; private static bool inPanic = false; @@ -65,6 +66,7 @@ internal class RuntimeManager : IPlugin { if (close || !luaState.ProcessQueue()) { + _game.EventEmitter.RaiseClose(); Start(); } } @@ -143,6 +145,12 @@ internal class RuntimeManager : IPlugin } } + public static void Reset() + { + close = true; + step = 0; + } + public static void Reboot() { close = true;