From cf39af0642be5d32c0978d04d87cd14f2b49d482 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 13 Jan 2017 01:06:37 +0100 Subject: [PATCH] - consolidated the sector action classes. This can be done with a lot less overhead by using one of the object's properties to store the activation flag, so that all the nearly redundant trigger methods can be folded into one. --- src/g_shared/a_sectoraction.cpp | 208 +----------------- src/r_defs.h | 2 +- src/s_advsound.cpp | 2 +- wadsrc/static/zscript/shared/sectoraction.txt | 88 ++++++-- 4 files changed, 80 insertions(+), 220 deletions(-) diff --git a/src/g_shared/a_sectoraction.cpp b/src/g_shared/a_sectoraction.cpp index e19abade0..308527b65 100644 --- a/src/g_shared/a_sectoraction.cpp +++ b/src/g_shared/a_sectoraction.cpp @@ -108,10 +108,12 @@ bool ASectorAction::TriggerAction(AActor *triggerer, int activationType) bool ASectorAction::DoTriggerAction (AActor *triggerer, int activationType) { + bool didit = (activationType & health) ? CheckTrigger(triggerer) : false; + if (tracer != NULL) - return barrier_cast(tracer)->DoTriggerAction (triggerer, activationType); + return didit | barrier_cast(tracer)->DoTriggerAction (triggerer, activationType); else - return false; + return didit; } bool ASectorAction::CanTrigger (AActor *triggerer) const @@ -133,205 +135,3 @@ bool ASectorAction::CheckTrigger (AActor *triggerer) const return false; } -// Triggered when entering sector ------------------------------------------- - -class ASecActEnter : public ASectorAction -{ - DECLARE_CLASS (ASecActEnter, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActEnter, false, false) - - -bool ASecActEnter::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_Enter) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when leaving sector -------------------------------------------- - -class ASecActExit : public ASectorAction -{ - DECLARE_CLASS (ASecActExit, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActExit, false, false) - - -bool ASecActExit::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_Exit) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when hitting sector's floor ------------------------------------ - -class ASecActHitFloor : public ASectorAction -{ - DECLARE_CLASS (ASecActHitFloor, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -// Skull Tag uses 9999 for a special that is triggered whenever -// the player is on the sector's floor. I think this is more useful. - -IMPLEMENT_CLASS(ASecActHitFloor, false, false) - - -bool ASecActHitFloor::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_HitFloor) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when hitting sector's ceiling ---------------------------------- - -class ASecActHitCeil : public ASectorAction -{ - DECLARE_CLASS (ASecActHitCeil, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActHitCeil, false, false) - - -bool ASecActHitCeil::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_HitCeiling) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when using inside sector --------------------------------------- - -class ASecActUse : public ASectorAction -{ - DECLARE_CLASS (ASecActUse, ASectorAction) -public: - ASecActUse() : ASectorAction (true) {} - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActUse, false, false) - - -bool ASecActUse::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_Use) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when using a sector's wall ------------------------------------- - -class ASecActUseWall : public ASectorAction -{ - DECLARE_CLASS (ASecActUseWall, ASectorAction) -public: - ASecActUseWall() : ASectorAction (true) {} - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActUseWall, false, false) - - -bool ASecActUseWall::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_UseWall) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when eyes go below fake floor ---------------------------------- - -class ASecActEyesDive : public ASectorAction -{ - DECLARE_CLASS (ASecActEyesDive, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActEyesDive, false, false) - - -bool ASecActEyesDive::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_EyesDive) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when eyes go above fake floor ---------------------------------- - -class ASecActEyesSurface : public ASectorAction -{ - DECLARE_CLASS (ASecActEyesSurface, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActEyesSurface, false, false) - - -bool ASecActEyesSurface::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_EyesSurface) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when eyes go below fake floor ---------------------------------- - -class ASecActEyesBelowC : public ASectorAction -{ - DECLARE_CLASS (ASecActEyesBelowC, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActEyesBelowC, false, false) - - -bool ASecActEyesBelowC::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_EyesBelowC) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when eyes go above fake floor ---------------------------------- - -class ASecActEyesAboveC : public ASectorAction -{ - DECLARE_CLASS (ASecActEyesAboveC, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActEyesAboveC, false, false) - - -bool ASecActEyesAboveC::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_EyesAboveC) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} - -// Triggered when eyes go below fake floor ---------------------------------- - -class ASecActHitFakeFloor : public ASectorAction -{ - DECLARE_CLASS (ASecActHitFakeFloor, ASectorAction) -public: - bool DoTriggerAction (AActor *triggerer, int activationType); -}; - -IMPLEMENT_CLASS(ASecActHitFakeFloor, false, false) - - -bool ASecActHitFakeFloor::DoTriggerAction (AActor *triggerer, int activationType) -{ - bool didit = (activationType & SECSPAC_HitFakeFloor) ? CheckTrigger (triggerer) : false; - return didit | Super::DoTriggerAction (triggerer, activationType); -} diff --git a/src/r_defs.h b/src/r_defs.h index cea9078d2..9f6291852 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -290,8 +290,8 @@ public: bool TriggerAction(AActor *triggerer, int activationType); bool CanTrigger (AActor *triggerer) const; bool IsActivatedByUse() const; -protected: virtual bool DoTriggerAction(AActor *triggerer, int activationType); +protected: bool CheckTrigger(AActor *triggerer) const; private: bool ActivatedByUse; diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index d2c40109a..b374483b5 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -2483,7 +2483,7 @@ bool AMusicChanger::DoTriggerAction (AActor *triggerer, int activationType) triggerer->player->MUSINFOtics = 30; } } - return Super::DoTriggerAction (triggerer, activationType); + return tracer == nullptr? false : barrier_cast(tracer)->DoTriggerAction(triggerer, activationType); } void AMusicChanger::PostBeginPlay() diff --git a/wadsrc/static/zscript/shared/sectoraction.txt b/wadsrc/static/zscript/shared/sectoraction.txt index 03278f2d3..b1d41a69f 100644 --- a/wadsrc/static/zscript/shared/sectoraction.txt +++ b/wadsrc/static/zscript/shared/sectoraction.txt @@ -1,6 +1,22 @@ class SectorAction : Actor native { + // this class uses health to define the activation type. + enum EActivation + { + SECSPAC_Enter = 1, + SECSPAC_Exit = 2, + SECSPAC_HitFloor = 4, + SECSPAC_HitCeiling = 8, + SECSPAC_Use = 16, + SECSPAC_UseWall = 32, + SECSPAC_EyesDive = 64, + SECSPAC_EyesSurface = 128, + SECSPAC_EyesBelowC = 256, + SECSPAC_EyesAboveC = 512, + SECSPAC_HitFakeFloor= 1024, + }; + default { +NOBLOCKMAP @@ -12,68 +28,112 @@ class SectorAction : Actor native // Triggered when entering sector ------------------------------------------- -class SecActEnter : SectorAction native +class SecActEnter : SectorAction { + Default + { + Health SECSPAC_Enter; + } } // Triggered when leaving sector -------------------------------------------- -class SecActExit : SectorAction native +class SecActExit : SectorAction { + Default + { + Health SECSPAC_Exit; + } } // Triggered when hitting sector's floor ------------------------------------ -class SecActHitFloor : SectorAction native +class SecActHitFloor : SectorAction { + Default + { + Health SECSPAC_HitFloor; + } } // Triggered when hitting sector's ceiling ---------------------------------- -class SecActHitCeil : SectorAction native +class SecActHitCeil : SectorAction { + Default + { + Health SECSPAC_HitCeiling; + } } // Triggered when using inside sector --------------------------------------- -class SecActUse : SectorAction native +class SecActUse : SectorAction { + Default + { + Health SECSPAC_Use; + } } // Triggered when using a sector's wall ------------------------------------- -class SecActUseWall : SectorAction native +class SecActUseWall : SectorAction { + Default + { + Health SECSPAC_UseWall; + } } // Triggered when eyes go below fake floor ---------------------------------- -class SecActEyesDive : SectorAction native +class SecActEyesDive : SectorAction { + Default + { + Health SECSPAC_EyesDive; + } } // Triggered when eyes go above fake floor ---------------------------------- -class SecActEyesSurface : SectorAction native +class SecActEyesSurface : SectorAction { + Default + { + Health SECSPAC_EyesSurface; + } } -// Triggered when eyes go below fake floor ---------------------------------- +// Triggered when eyes go below fake ceiling ---------------------------------- -class SecActEyesBelowC : SectorAction native +class SecActEyesBelowC : SectorAction { + Default + { + Health SECSPAC_EyesBelowC; + } } -// Triggered when eyes go above fake floor ---------------------------------- +// Triggered when eyes go above fake ceiling ---------------------------------- -class SecActEyesAboveC : SectorAction native +class SecActEyesAboveC : SectorAction { + Default + { + Health SECSPAC_EyesAboveC; + } } -// Triggered when eyes go below fake floor ---------------------------------- +// Triggered when hitting fake floor ---------------------------------- -class SecActHitFakeFloor : SectorAction native +class SecActHitFakeFloor : SectorAction { + Default + { + Health SECSPAC_HitFakeFloor; + } } // Music changer ----------------------------------