From 71933b34971b8adae8ff7d8e35b12d8a398a6dd9 Mon Sep 17 00:00:00 2001 From: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com> Date: Fri, 17 Apr 2026 02:46:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20EventManager.hx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funkin/backend/scripting/EventManager.hx | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/source/funkin/backend/scripting/EventManager.hx b/source/funkin/backend/scripting/EventManager.hx index 162d72fa6d..349d704f67 100644 --- a/source/funkin/backend/scripting/EventManager.hx +++ b/source/funkin/backend/scripting/EventManager.hx @@ -4,29 +4,40 @@ import flixel.FlxState; import funkin.backend.scripting.events.*; final class EventManager { - // map doesn't work for that - public static var eventValues:Array = []; - public static var eventKeys:Array> = []; + public static var eventCache:Map = []; - public static function get(cl:Class):T { - var c:Class = cast cl; + #if cpp + public static var cppEventCache:haxe.ds.ObjectMap = new haxe.ds.ObjectMap(); - var index = eventKeys.indexOf(c); - if (index < 0) { - eventKeys.push(c); - var ret; - eventValues.push(ret = Type.createInstance(c, [])); - return cast ret; + public static inline function get(cl:Class):T { + var event:CancellableEvent = cppEventCache.get(cl); + if (event == null) { + event = Type.createInstance(cl, []); + cppEventCache.set(cl, event); } - - return cast eventValues[index]; + return cast event; + } + #else + public static inline function get(cl:Class):T { + var className = Type.getClassName(cl); + var event = eventCache.get(className); + if (event == null) { + event = Type.createInstance(cl, []); + eventCache.set(className, event); + } + return cast event; } + #end public static function reset() { - for(v in eventValues) - v.destroy(); - eventValues = []; - eventKeys = []; + #if cpp + cppEventCache = new haxe.ds.ObjectMap(); + #else + for (event in eventCache) { + event.destroy(); + } + eventCache = []; + #end } public static function init() { @@ -35,4 +46,4 @@ final class EventManager { private static inline function onStateSwitch(newState:FlxState) reset(); -} \ No newline at end of file +} From 20b0567dd9e1096e55363ab28b2b39bb1c3a21dd Mon Sep 17 00:00:00 2001 From: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com> Date: Fri, 17 Apr 2026 02:53:53 +0800 Subject: [PATCH 2/2] I don't know why it has to be this way either. --- source/funkin/backend/utils/DiscordUtil.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/funkin/backend/utils/DiscordUtil.hx b/source/funkin/backend/utils/DiscordUtil.hx index 282e5b2b9e..84791be2e2 100644 --- a/source/funkin/backend/utils/DiscordUtil.hx +++ b/source/funkin/backend/utils/DiscordUtil.hx @@ -5,7 +5,7 @@ import flixel.sound.FlxSound; import flixel.util.typeLimit.OneOfTwo; import funkin.backend.scripting.*; // lazy import funkin.backend.scripting.events.CancellableEvent; -import funkin.backend.scripting.events.discord.*; +import funkin.backend.scripting.events.discord.DiscordPresenceUpdateEvent; import funkin.backend.system.macros.Utils; import haxe.Json; import openfl.display.BitmapData;