Generalized event handler definition; removed excessive VM calls when we don't have override defined.

This commit is contained in:
ZZYZX 2017-01-22 06:23:44 +02:00
parent 2aadd1e13c
commit 5bfd484ae2

View file

@ -109,33 +109,26 @@ DEFINE_ACTION_FUNCTION(DEventHandler, Unregister)
return 0;
}
DEFINE_ACTION_FUNCTION(DEventHandler, MapLoaded)
{
PARAM_SELF_PROLOGUE(DEventHandler);
// do nothing
return 0;
#define DEFINE_EVENT_HANDLER(cls, funcname) DEFINE_ACTION_FUNCTION(cls, funcname) \
{ \
PARAM_SELF_PROLOGUE(cls); \
return 0; \
} \
void cls::funcname() \
{ \
IFVIRTUAL(cls, funcname) \
{ \
if (func == cls##_##funcname##_VMPtr) \
return; \
VMValue params[1] = { (cls*)this }; \
GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr); \
} \
}
DEFINE_ACTION_FUNCTION(DEventHandler, MapUnloading)
{
PARAM_SELF_PROLOGUE(DEventHandler);
// do nothing
return 0;
}
DEFINE_ACTION_FUNCTION(DEventHandler, RenderFrame)
{
PARAM_SELF_PROLOGUE(DEventHandler);
// do nothing
return 0;
}
DEFINE_ACTION_FUNCTION(DEventHandler, RenderCamera)
{
PARAM_SELF_PROLOGUE(DEventHandler);
// do nothing
return 0;
}
DEFINE_EVENT_HANDLER(DEventHandler, MapLoaded)
DEFINE_EVENT_HANDLER(DEventHandler, MapUnloading)
DEFINE_EVENT_HANDLER(DEventHandler, RenderFrame)
DEFINE_EVENT_HANDLER(DEventHandler, RenderCamera)
//
void DEventHandler::OnDestroy()
@ -144,46 +137,6 @@ void DEventHandler::OnDestroy()
DObject::OnDestroy();
}
void DEventHandler::MapLoaded()
{
IFVIRTUAL(DEventHandler, MapLoaded)
{
// Without the type cast this picks the 'void *' assignment...
VMValue params[1] = { (DEventHandler*)this };
GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr);
}
}
void DEventHandler::MapUnloading()
{
IFVIRTUAL(DEventHandler, MapUnloading)
{
// Without the type cast this picks the 'void *' assignment...
VMValue params[1] = { (DEventHandler*)this };
GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr);
}
}
void DEventHandler::RenderFrame()
{
IFVIRTUAL(DEventHandler, RenderFrame)
{
// Without the type cast this picks the 'void *' assignment...
VMValue params[1] = { (DEventHandler*)this };
GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr);
}
}
void DEventHandler::RenderCamera()
{
IFVIRTUAL(DEventHandler, RenderCamera)
{
// Without the type cast this picks the 'void *' assignment...
VMValue params[1] = { (DEventHandler*)this };
GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr);
}
}
void DRenderEventHandler::Setup()
{
ViewPos = ::ViewPos;