mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-27 06:02:18 +00:00
Static event handlers can create/register/unregister other static event handlers.
This commit is contained in:
parent
e8a0eda476
commit
c7e3ff2356
2 changed files with 46 additions and 1 deletions
|
@ -289,7 +289,30 @@ DEFINE_ACTION_FUNCTION(DEventHandler, CreateOnce)
|
||||||
// check if there are already registered handlers of this type.
|
// check if there are already registered handlers of this type.
|
||||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||||
if (handler->GetClass() == t) // check precise class
|
if (handler->GetClass() == t) // check precise class
|
||||||
ACTION_RETURN_OBJECT(nullptr);
|
ACTION_RETURN_OBJECT(handler);
|
||||||
|
// generate a new object of this type.
|
||||||
|
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.
|
// generate a new object of this type.
|
||||||
ACTION_RETURN_OBJECT(t->CreateNew());
|
ACTION_RETURN_OBJECT(t->CreateNew());
|
||||||
}
|
}
|
||||||
|
@ -320,6 +343,20 @@ DEFINE_ACTION_FUNCTION(DEventHandler, Unregister)
|
||||||
ACTION_RETURN_BOOL(E_UnregisterHandler(handler));
|
ACTION_RETURN_BOOL(E_UnregisterHandler(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(DStaticEventHandler, Register)
|
||||||
|
{
|
||||||
|
PARAM_PROLOGUE;
|
||||||
|
PARAM_OBJECT(handler, DStaticEventHandler);
|
||||||
|
ACTION_RETURN_BOOL(E_RegisterHandler(handler));
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(DStaticEventHandler, Unregister)
|
||||||
|
{
|
||||||
|
PARAM_PROLOGUE;
|
||||||
|
PARAM_OBJECT(handler, DStaticEventHandler);
|
||||||
|
ACTION_RETURN_BOOL(E_UnregisterHandler(handler));
|
||||||
|
}
|
||||||
|
|
||||||
#define DEFINE_EVENT_HANDLER(cls, funcname, args) DEFINE_ACTION_FUNCTION(cls, funcname) \
|
#define DEFINE_EVENT_HANDLER(cls, funcname, args) DEFINE_ACTION_FUNCTION(cls, funcname) \
|
||||||
{ \
|
{ \
|
||||||
PARAM_SELF_PROLOGUE(cls); \
|
PARAM_SELF_PROLOGUE(cls); \
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
class StaticEventHandler : Object native
|
class StaticEventHandler : Object native
|
||||||
{
|
{
|
||||||
|
// static event handlers CAN register other static event handlers.
|
||||||
|
// unlike EventHandler.Create that will not create them.
|
||||||
|
protected static native StaticEventHandler Create(class<StaticEventHandler> type);
|
||||||
|
protected static native StaticEventHandler CreateOnce(class<StaticEventHandler> type);
|
||||||
|
|
||||||
|
protected static native bool Register(StaticEventHandler handler);
|
||||||
|
protected static native bool Unregister(StaticEventHandler handler);
|
||||||
|
|
||||||
virtual native void WorldLoaded();
|
virtual native void WorldLoaded();
|
||||||
virtual native void WorldUnloaded();
|
virtual native void WorldUnloaded();
|
||||||
virtual native void WorldThingSpawned();
|
virtual native void WorldThingSpawned();
|
||||||
|
|
Loading…
Reference in a new issue