diff --git a/source/funkin/backend/scripting/EventManager.hx b/source/funkin/backend/scripting/EventManager.hx index 162d72fa6..349d704f6 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 +} diff --git a/source/funkin/backend/utils/DiscordUtil.hx b/source/funkin/backend/utils/DiscordUtil.hx index 282e5b2b9..84791be2e 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;