From 7517b64aeece426cfea50db81749f680ca28b9d3 Mon Sep 17 00:00:00 2001 From: Boondorl <59555366+Boondorl@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:44:26 -0500 Subject: [PATCH] Updated to Interface Event Changed SendConsoleEvent to SendInterfaceEvent to make functionality clearer. Added InterfaceProcess virtual to EventHandlers. Added CCMD for sending interface events. --- src/d_net.cpp | 2 +- src/events.cpp | 82 +++++++++++++++++++++++++-------- src/events.h | 4 +- wadsrc/static/zscript/events.zs | 3 +- 4 files changed, 67 insertions(+), 24 deletions(-) diff --git a/src/d_net.cpp b/src/d_net.cpp index 07cbd4f086..e83b06939b 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2704,7 +2704,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player) for (int i = 0; i < 3; i++) arg[i] = ReadLong(stream); bool manual = !!ReadByte(stream); - primaryLevel->localEventManager->Console(player, s, arg[0], arg[1], arg[2], manual); + primaryLevel->localEventManager->Console(player, s, arg[0], arg[1], arg[2], manual, false); } break; diff --git a/src/events.cpp b/src/events.cpp index e76fb94115..315b2d8b87 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -516,12 +516,12 @@ bool EventManager::Responder(const event_t* ev) return false; } -void EventManager::Console(int player, FString name, int arg1, int arg2, int arg3, bool manual) +void EventManager::Console(int player, FString name, int arg1, int arg2, int arg3, bool manual, bool ui) { - if (ShouldCallStatic(false)) staticEventManager.Console(player, name, arg1, arg2, arg3, manual); + if (ShouldCallStatic(false)) staticEventManager.Console(player, name, arg1, arg2, arg3, manual, ui); for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next) - handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual); + handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual, ui); } void EventManager::RenderOverlay(EHudState state) @@ -686,7 +686,7 @@ DEFINE_ACTION_FUNCTION(DEventHandler, SendNetworkEvent) ACTION_RETURN_BOOL(currentVMLevel->localEventManager->SendNetworkEvent(name, arg1, arg2, arg3, false)); } -DEFINE_ACTION_FUNCTION(DEventHandler, SendConsoleEvent) +DEFINE_ACTION_FUNCTION(DEventHandler, SendInterfaceEvent) { PARAM_PROLOGUE; PARAM_INT(playerNum); @@ -696,7 +696,7 @@ DEFINE_ACTION_FUNCTION(DEventHandler, SendConsoleEvent) PARAM_INT(arg3); if (playerNum == consoleplayer) - primaryLevel->localEventManager->Console(-1, name, arg1, arg2, arg3, false); + primaryLevel->localEventManager->Console(-1, name, arg1, arg2, arg3, false, true); return 0; } @@ -1158,26 +1158,49 @@ void DStaticEventHandler::PostUiTick() } } -void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual) +void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual, bool ui) { if (player < 0) { - IFVIRTUAL(DStaticEventHandler, ConsoleProcess) + if (ui) { - // don't create excessive DObjects if not going to be processed anyway - if (isEmpty(func)) return; - FConsoleEvent e; + IFVIRTUAL(DStaticEventHandler, InterfaceProcess) + { + // don't create excessive DObjects if not going to be processed anyway + if (isEmpty(func)) return; + FConsoleEvent e; - // - e.Player = player; - e.Name = name; - e.Args[0] = arg1; - e.Args[1] = arg2; - e.Args[2] = arg3; - e.IsManual = manual; + // + e.Player = player; + e.Name = name; + e.Args[0] = arg1; + e.Args[1] = arg2; + e.Args[2] = arg3; + e.IsManual = manual; - VMValue params[2] = { (DStaticEventHandler*)this, &e }; - VMCall(func, params, 2, nullptr, 0); + VMValue params[2] = { (DStaticEventHandler*)this, &e }; + VMCall(func, params, 2, nullptr, 0); + } + } + else + { + IFVIRTUAL(DStaticEventHandler, ConsoleProcess) + { + // don't create excessive DObjects if not going to be processed anyway + if (isEmpty(func)) return; + FConsoleEvent e; + + // + e.Player = player; + e.Name = name; + e.Args[0] = arg1; + e.Args[1] = arg2; + e.Args[2] = arg3; + e.IsManual = manual; + + VMValue params[2] = { (DStaticEventHandler*)this, &e }; + VMCall(func, params, 2, nullptr, 0); + } } } else @@ -1253,6 +1276,25 @@ void DStaticEventHandler::OnDestroy() // console stuff // this is kinda like puke, except it distinguishes between local events and playsim events. +CCMD(interfaceevent) +{ + int argc = argv.argc(); + + if (argc < 2 || argc > 5) + { + Printf("Usage: interfaceevent [arg1] [arg2] [arg3]\n"); + } + else + { + int arg[3] = { 0, 0, 0 }; + int argn = min(argc - 2, countof(arg)); + for (int i = 0; i < argn; i++) + arg[i] = atoi(argv[2 + i]); + // call locally + primaryLevel->localEventManager->Console(-1, argv[1], arg[0], arg[1], arg[2], true, true); + } +} + CCMD(event) { int argc = argv.argc(); @@ -1268,7 +1310,7 @@ CCMD(event) for (int i = 0; i < argn; i++) arg[i] = atoi(argv[2 + i]); // call locally - primaryLevel->localEventManager->Console(-1, argv[1], arg[0], arg[1], arg[2], true); + primaryLevel->localEventManager->Console(-1, argv[1], arg[0], arg[1], arg[2], true, false); } } diff --git a/src/events.h b/src/events.h index f5ad75d88e..b6ca6f6a42 100755 --- a/src/events.h +++ b/src/events.h @@ -111,7 +111,7 @@ public: void PostUiTick(); // - void ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual); + void ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual, bool ui); // void CheckReplacement(PClassActor* replacee, PClassActor** replacement, bool* final); @@ -281,7 +281,7 @@ struct EventManager // this executes on events. bool Responder(const event_t* ev); // splits events into InputProcess and UiProcess // this executes on console/net events. - void Console(int player, FString name, int arg1, int arg2, int arg3, bool manual); + void Console(int player, FString name, int arg1, int arg2, int arg3, bool manual, bool ui); // called when looking up the replacement for an actor class bool CheckReplacement(PClassActor* replacee, PClassActor** replacement); diff --git a/wadsrc/static/zscript/events.zs b/wadsrc/static/zscript/events.zs index 658ec06c06..6da39d39fd 100644 --- a/wadsrc/static/zscript/events.zs +++ b/wadsrc/static/zscript/events.zs @@ -124,6 +124,7 @@ class StaticEventHandler : Object native play version("2.4") // virtual ui void ConsoleProcess(ConsoleEvent e) {} + virtual ui void InterfaceProcess(ConsoleEvent e) {} virtual void NetworkProcess(ConsoleEvent e) {} // @@ -148,5 +149,5 @@ class EventHandler : StaticEventHandler native version("2.4") { clearscope static native StaticEventHandler Find(class type); clearscope static native void SendNetworkEvent(String name, int arg1 = 0, int arg2 = 0, int arg3 = 0); - clearscope static native void SendConsoleEvent(int playerNum, string name, int arg1 = 0, int arg2 = 0, int arg3 = 0); + clearscope static native void SendInterfaceEvent(int playerNum, string name, int arg1 = 0, int arg2 = 0, int arg3 = 0); }