From 3db1ee9a1ecf530d7873d6cf09b7f2411c30908a Mon Sep 17 00:00:00 2001 From: Boondorl Date: Fri, 24 Jan 2025 16:40:12 -0500 Subject: [PATCH] Improvements for VisualThinkers Added BeginPlay virtual that's called after construction. Added getter for render style in ZScript. --- src/playsim/p_effect.cpp | 23 ++++++++++++++++++++++- src/playsim/p_visualthinker.h | 2 +- wadsrc/static/zscript/visualthinker.zs | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/playsim/p_effect.cpp b/src/playsim/p_effect.cpp index af8514698b..c16d4a9826 100644 --- a/src/playsim/p_effect.cpp +++ b/src/playsim/p_effect.cpp @@ -1052,6 +1052,16 @@ DVisualThinker* DVisualThinker::NewVisualThinker(FLevelLocals* Level, PClass* ty auto zs = static_cast(Level->CreateThinker(type, DVisualThinker::DEFAULT_STAT)); zs->Construct(); + + IFOVERRIDENVIRTUALPTRNAME(zs, NAME_VisualThinker, BeginPlay) + { + VMValue params[] = { zs }; + VMCall(func, params, 1, nullptr, 0); + + if (zs->ObjectFlags & OF_EuthanizeMe) + return nullptr; + } + return zs; } @@ -1269,11 +1279,22 @@ DEFINE_ACTION_FUNCTION_NATIVE(DVisualThinker, SetRenderStyle, SetRenderStyle) return 0; } -int DVisualThinker::GetRenderStyle() +int DVisualThinker::GetRenderStyle() const { return PT.style; } +static int GetRenderStyle(DVisualThinker* self) +{ + return self->GetRenderStyle(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DVisualThinker, GetRenderStyle, GetRenderStyle) +{ + PARAM_SELF_PROLOGUE(DVisualThinker); + ACTION_RETURN_INT(self->GetRenderStyle()); +} + float DVisualThinker::GetOffset(bool y) const // Needed for the renderer. { if (y) diff --git a/src/playsim/p_visualthinker.h b/src/playsim/p_visualthinker.h index 9fb5eae65c..16043effd3 100644 --- a/src/playsim/p_visualthinker.h +++ b/src/playsim/p_visualthinker.h @@ -51,7 +51,7 @@ public: static DVisualThinker* NewVisualThinker(FLevelLocals* Level, PClass* type); void SetTranslation(FName trname); - int GetRenderStyle(); + int GetRenderStyle() const; bool isFrozen(); int GetLightLevel(sector_t *rendersector) const; FVector3 InterpolatedPosition(double ticFrac) const; diff --git a/wadsrc/static/zscript/visualthinker.zs b/wadsrc/static/zscript/visualthinker.zs index 2b6d9a8428..d5dc2253aa 100644 --- a/wadsrc/static/zscript/visualthinker.zs +++ b/wadsrc/static/zscript/visualthinker.zs @@ -26,7 +26,10 @@ Class VisualThinker : Thinker native native Sector CurSector; // can be null! + virtual void BeginPlay() {} + native void SetTranslation(Name trans); + native clearscope ERenderStyle GetRenderStyle() const; native void SetRenderStyle(int mode); // see ERenderStyle native bool IsFrozen();