From 5bfd484ae2b9e1ec5c57419a71aa55ffebab4176 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Sun, 22 Jan 2017 06:23:44 +0200 Subject: [PATCH] Generalized event handler definition; removed excessive VM calls when we don't have override defined. --- src/events.cpp | 83 +++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 65 deletions(-) diff --git a/src/events.cpp b/src/events.cpp index 93973bd6f..1767ac333 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -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;