diff --git a/src/events.cpp b/src/events.cpp index 8eea680a7..bba4d180d 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -262,6 +262,7 @@ void E_WorldThingDestroyed(AActor* actor) // normal event loopers (non-special, argument-less) DEFINE_EVENT_LOOPER(RenderFrame) DEFINE_EVENT_LOOPER(WorldLightning) +DEFINE_EVENT_LOOPER(WorldTick) // declarations IMPLEMENT_CLASS(DStaticEventHandler, false, false); @@ -400,6 +401,7 @@ DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingSpawned) DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingDied) DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingDestroyed) DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldLightning) +DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldTick) DEFINE_EMPTY_HANDLER(DStaticEventHandler, RenderFrame) // =========================================== @@ -500,6 +502,19 @@ void DStaticEventHandler::WorldLightning() } } +void DStaticEventHandler::WorldTick() +{ + IFVIRTUAL(DStaticEventHandler, WorldTick) + { + // don't create excessive DObjects if not going to be processed anyway + if (func == DStaticEventHandler_WorldTick_VMPtr) + return; + DWorldEvent* e = E_SetupWorldEvent(); + VMValue params[2] = { (DStaticEventHandler*)this, e }; + GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr); + } +} + static DRenderEvent* E_SetupRenderEvent() { static DRenderEvent* e = nullptr; @@ -532,44 +547,3 @@ void DStaticEventHandler::OnDestroy() E_UnregisterHandler(this); Super::OnDestroy(); } -/* -void DStaticRenderEventHandler::Setup() -{ - ViewPos = ::ViewPos; - ViewAngle = ::ViewAngle; - ViewPitch = ::ViewPitch; - ViewRoll = ::ViewRoll; - FracTic = ::r_TicFracF; - Camera = ::camera; -} - -void DStaticRenderEventHandler::RenderFrame() -{ - Setup(); - Super::RenderFrame(); -} - -void DStaticWorldEventHandler::Setup() -{ - IsSaveGame = savegamerestore; - Thing = nullptr; -} - -void DStaticWorldEventHandler::WorldLoaded() -{ - Setup(); - Super::WorldLoaded(); -} - -void DStaticWorldEventHandler::WorldUnloaded() -{ - Setup(); - Super::WorldUnloaded(); -} - -void DStaticWorldEventHandler::WorldThingSpawned(AActor* actor) -{ - Setup(); - Thing = actor; - Super::WorldThingSpawned(actor); -}*/ \ No newline at end of file diff --git a/src/events.h b/src/events.h index 5399443a7..fad159e76 100755 --- a/src/events.h +++ b/src/events.h @@ -33,6 +33,8 @@ void E_WorldThingDied(AActor* actor, AActor* inflictor); void E_WorldThingDestroyed(AActor* actor); // same as ACS SCRIPT_Lightning void E_WorldLightning(); +// this executes on every tick, before everything +void E_WorldTick(); // called on each render frame once. void E_RenderFrame(); @@ -86,6 +88,7 @@ public: virtual void WorldThingDied(AActor*, AActor*); virtual void WorldThingDestroyed(AActor*); virtual void WorldLightning(); + virtual void WorldTick(); virtual void RenderFrame(); }; class DEventHandler : public DStaticEventHandler diff --git a/src/p_tick.cpp b/src/p_tick.cpp index 2f8151425..990cdaf64 100644 --- a/src/p_tick.cpp +++ b/src/p_tick.cpp @@ -36,6 +36,7 @@ #include "r_utility.h" #include "p_spec.h" #include "g_levellocals.h" +#include "events.h" extern gamestate_t wipegamestate; @@ -125,6 +126,8 @@ void P_Ticker (void) /*Added by MC: Freeze mode.*/!(bglobal.freeze && players[i].Bot != NULL)) P_PlayerThink (&players[i]); + // [ZZ] call the WorldTick hook + E_WorldTick(); StatusBar->Tick (); // [RH] moved this here level.Tick (); // [RH] let the level tick DThinker::RunThinkers (); diff --git a/wadsrc/static/zscript/events.txt b/wadsrc/static/zscript/events.txt index 68f77ed9e..179bf8ea6 100755 --- a/wadsrc/static/zscript/events.txt +++ b/wadsrc/static/zscript/events.txt @@ -38,6 +38,7 @@ class StaticEventHandler : Object native virtual native void WorldThingDied(WorldEvent e); virtual native void WorldThingDestroyed(WorldEvent e); virtual native void WorldLightning(WorldEvent e); // for the sake of completeness. + virtual native void WorldTick(WorldEvent e); virtual native void RenderFrame(RenderEvent e); }