diff --git a/src/events.cpp b/src/events.cpp index f296144d96..30a699ee24 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -294,29 +294,6 @@ DEFINE_ACTION_FUNCTION(DEventHandler, CreateOnce) ACTION_RETURN_OBJECT(t->CreateNew()); } -// for static -DEFINE_ACTION_FUNCTION(DStaticEventHandler, Create) -{ - PARAM_PROLOGUE; - PARAM_CLASS(t, DStaticEventHandler); - // static handlers can create any type of object. - // generate a new object of this type. - ACTION_RETURN_OBJECT(t->CreateNew()); -} - -DEFINE_ACTION_FUNCTION(DStaticEventHandler, CreateOnce) -{ - PARAM_PROLOGUE; - PARAM_CLASS(t, DStaticEventHandler); - // static handlers can create any type of object. - // check if there are already registered handlers of this type. - for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) - if (handler->GetClass() == t) // check precise class - ACTION_RETURN_OBJECT(handler); - // generate a new object of this type. - ACTION_RETURN_OBJECT(t->CreateNew()); -} - DEFINE_ACTION_FUNCTION(DEventHandler, Find) { PARAM_PROLOGUE; @@ -343,6 +320,40 @@ DEFINE_ACTION_FUNCTION(DEventHandler, Unregister) ACTION_RETURN_BOOL(E_UnregisterHandler(handler)); } +// for static +DEFINE_ACTION_FUNCTION(DStaticEventHandler, Create) +{ + PARAM_PROLOGUE; + PARAM_CLASS(t, DStaticEventHandler); + // static handlers can create any type of object. + // generate a new object of this type. + ACTION_RETURN_OBJECT(t->CreateNew()); +} + +DEFINE_ACTION_FUNCTION(DStaticEventHandler, CreateOnce) +{ + PARAM_PROLOGUE; + PARAM_CLASS(t, DStaticEventHandler); + // static handlers can create any type of object. + // check if there are already registered handlers of this type. + for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) + if (handler->GetClass() == t) // check precise class + ACTION_RETURN_OBJECT(handler); + // generate a new object of this type. + ACTION_RETURN_OBJECT(t->CreateNew()); +} + +// we might later want to change this +DEFINE_ACTION_FUNCTION(DStaticEventHandler, Find) +{ + PARAM_PROLOGUE; + PARAM_CLASS(t, DStaticEventHandler); + for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) + if (handler->GetClass() == t) // check precise class + ACTION_RETURN_OBJECT(handler); + ACTION_RETURN_OBJECT(nullptr); +} + DEFINE_ACTION_FUNCTION(DStaticEventHandler, Register) { PARAM_PROLOGUE; diff --git a/wadsrc/static/zscript/events.txt b/wadsrc/static/zscript/events.txt index 85a662e3ad..e5b878603d 100755 --- a/wadsrc/static/zscript/events.txt +++ b/wadsrc/static/zscript/events.txt @@ -4,6 +4,7 @@ class StaticEventHandler : Object native // unlike EventHandler.Create that will not create them. protected static native StaticEventHandler Create(class type); protected static native StaticEventHandler CreateOnce(class type); + protected static native StaticEventHandler Find(Class type); // just for convenience. who knows. protected static native bool Register(StaticEventHandler handler); protected static native bool Unregister(StaticEventHandler handler);