From fe0f19e1e0f71feaf0e4710ddb9d2132d9816647 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 30 Dec 2016 23:32:43 +0100 Subject: [PATCH] - exported Powerup.InitEffect and EndEffect to scripting. --- src/g_inventory/a_artifacts.cpp | 51 ++++++++++++++++++++--- src/g_inventory/a_artifacts.h | 6 ++- src/g_shared/a_morph.cpp | 4 +- wadsrc/static/zscript/shared/powerups.txt | 3 ++ 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/g_inventory/a_artifacts.cpp b/src/g_inventory/a_artifacts.cpp index 131c161dcb..aac58997e2 100644 --- a/src/g_inventory/a_artifacts.cpp +++ b/src/g_inventory/a_artifacts.cpp @@ -21,6 +21,7 @@ #include "v_palette.h" #include "serializer.h" #include "r_utility.h" +#include "virtual.h" #include "r_data/colormaps.h" @@ -182,6 +183,25 @@ void APowerup::InitEffect () { } +DEFINE_ACTION_FUNCTION(APowerup, InitEffect) +{ + PARAM_SELF_PROLOGUE(APowerup); + self->InitEffect(); + return 0; +} + +void APowerup::CallInitEffect() +{ + IFVIRTUAL(APowerup, InitEffect) + { + VMValue params[1] = { (DObject*)this }; + VMFrameStack stack; + GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr); + } + else InitEffect(); +} + + //=========================================================================== // // APowerup :: DoEffect @@ -230,6 +250,25 @@ void APowerup::EndEffect () } } +DEFINE_ACTION_FUNCTION(APowerup, EndEffect) +{ + PARAM_SELF_PROLOGUE(APowerup); + self->EndEffect(); + return 0; +} + +void APowerup::CallEndEffect() +{ + IFVIRTUAL(APowerup, InitEffect) + { + VMValue params[1] = { (DObject*)this }; + VMFrameStack stack; + GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr); + } + else EndEffect(); +} + + //=========================================================================== // // APowerup :: Destroy @@ -238,7 +277,7 @@ void APowerup::EndEffect () void APowerup::Destroy () { - EndEffect (); + CallEndEffect (); Super::Destroy (); } @@ -325,7 +364,7 @@ AInventory *APowerup::CreateCopy (AActor *other) // properly attached to anything yet. Owner = other; // Actually activate the powerup. - InitEffect (); + CallInitEffect (); // Clear the Owner field, unless it was // changed by the activation, for example, // if this instance is a morph powerup; @@ -599,7 +638,7 @@ void APowerInvisibility::InitEffect () flags5 &= ~(Owner->flags5 & INVISIBILITY_FLAGS5); Owner->flags5 |= flags5 & INVISIBILITY_FLAGS5; - DoEffect(); + CallDoEffect(); } } @@ -1261,7 +1300,7 @@ IMPLEMENT_CLASS(APowerTargeter, false, false) void APowerTargeter::Travelled () { - InitEffect (); + CallInitEffect (); } void APowerTargeter::InitEffect () @@ -1299,14 +1338,14 @@ void APowerTargeter::AttachToOwner(AActor *other) Super::AttachToOwner(other); // Let's actually properly call this for the targeters. - InitEffect(); + CallInitEffect(); } bool APowerTargeter::HandlePickup(AInventory *item) { if (Super::HandlePickup(item)) { - InitEffect(); // reset the HUD sprites + CallInitEffect(); // reset the HUD sprites return true; } return false; diff --git a/src/g_inventory/a_artifacts.h b/src/g_inventory/a_artifacts.h index bb821b5d63..36f4d3443f 100644 --- a/src/g_inventory/a_artifacts.h +++ b/src/g_inventory/a_artifacts.h @@ -26,11 +26,15 @@ public: FNameNoInit Mode; double Strength; -protected: +public: virtual void InitEffect (); virtual void DoEffect () override; virtual void EndEffect (); +protected: + void CallInitEffect(); + void CallEndEffect(); + friend void EndAllPowerupEffects(AInventory *item); friend void InitAllPowerupEffects(AInventory *item); }; diff --git a/src/g_shared/a_morph.cpp b/src/g_shared/a_morph.cpp index 136c096a31..7550ff0da7 100644 --- a/src/g_shared/a_morph.cpp +++ b/src/g_shared/a_morph.cpp @@ -585,7 +585,7 @@ void EndAllPowerupEffects(AInventory *item) { if (item->IsKindOf(RUNTIME_CLASS(APowerup))) { - static_cast(item)->EndEffect(); + static_cast(item)->CallEndEffect(); } item = item->Inventory; } @@ -605,7 +605,7 @@ void InitAllPowerupEffects(AInventory *item) { if (item->IsKindOf(RUNTIME_CLASS(APowerup))) { - static_cast(item)->InitEffect(); + static_cast(item)->CallInitEffect(); } item = item->Inventory; } diff --git a/wadsrc/static/zscript/shared/powerups.txt b/wadsrc/static/zscript/shared/powerups.txt index d28799ff23..43af361f38 100644 --- a/wadsrc/static/zscript/shared/powerups.txt +++ b/wadsrc/static/zscript/shared/powerups.txt @@ -25,6 +25,9 @@ class Powerup : Inventory native // Note, that while this is an inventory flag, it only has meaning on an active powerup. override bool GetNoTeleportFreeze() { return bNoTeleportFreeze; } + + native virtual void InitEffect(); + native virtual void EndEffect(); }