From 636d822da78faa1fb62c11ccc70ec083ab7d457e Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Sun, 9 Feb 2020 12:47:58 -0600 Subject: [PATCH] Replaced SPF_VIEW with A_SetView. --- src/playsim/actor.h | 4 + src/playsim/p_actionfunctions.cpp | 70 +++++++++++++ src/playsim/p_local.h | 1 - src/playsim/p_mobj.cpp | 142 +++++++++++++++----------- wadsrc/static/zscript/actors/actor.zs | 3 + wadsrc/static/zscript/constants.zs | 1 - 6 files changed, 158 insertions(+), 63 deletions(-) diff --git a/src/playsim/actor.h b/src/playsim/actor.h index c78d14f3b..cb808e2b1 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -841,9 +841,13 @@ public: } // These also set CF_INTERPVIEW for players. + DAngle ClampPitch(DAngle p); void SetPitch(DAngle p, int fflags); void SetAngle(DAngle ang, int fflags); void SetRoll(DAngle roll, int fflags); + void SetViewPitch(DAngle p, int fflags); + void SetViewAngle(DAngle ang, int fflags); + void SetViewRoll(DAngle roll, int fflags); PClassActor *GetBloodType(int type = 0) const; diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index fec9a4d25..fa757ba63 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -2855,6 +2855,76 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetRoll) return 0; } +//=========================================================================== +// +// A_SetViewAngle +// +// Set actor's viewangle (in degrees). +// +//=========================================================================== + +DEFINE_ACTION_FUNCTION(AActor, A_SetViewAngle) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(angle); + PARAM_INT(flags); + PARAM_INT(ptr); + + AActor *ref = COPY_AAPTR(self, ptr); + if (ref != NULL) + { + ref->SetViewAngle(angle, flags); + } + return 0; +} + +//=========================================================================== +// +// A_SetViewPitch +// +// Set actor's viewpitch (in degrees). +// +//=========================================================================== + +DEFINE_ACTION_FUNCTION(AActor, A_SetViewPitch) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(pitch); + PARAM_INT(flags); + PARAM_INT(ptr); + + AActor *ref = COPY_AAPTR(self, ptr); + + if (ref != NULL) + { + ref->SetViewPitch(pitch, flags); + } + return 0; +} + +//=========================================================================== +// +// [MC] A_SetViewRoll +// +// Set actor's viewroll (in degrees). +// +//=========================================================================== + +DEFINE_ACTION_FUNCTION(AActor, A_SetViewRoll) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(roll); + PARAM_INT(flags); + PARAM_INT(ptr); + AActor *ref = COPY_AAPTR(self, ptr); + + if (ref != NULL) + { + ref->SetViewRoll(roll, flags); + } + return 0; +} + //=========================================================================== // // A_SetUserVar diff --git a/src/playsim/p_local.h b/src/playsim/p_local.h index 16a6f2643..2eafe7e2f 100644 --- a/src/playsim/p_local.h +++ b/src/playsim/p_local.h @@ -221,7 +221,6 @@ enum SPF { SPF_FORCECLAMP = 1, // players always clamp SPF_INTERPOLATE = 2, - SPF_VIEW = 4, }; enum PCM diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index a55ffd1b0..40ea4e62f 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -3350,89 +3350,109 @@ DEFINE_ACTION_FUNCTION(AActor, SetShade) return 0; } +// [MC] Helper function for Set(View)Pitch. +DAngle AActor::ClampPitch(DAngle p) +{ + // clamp the pitch we set + DAngle min, max; + + if (player != nullptr) + { + min = player->MinPitch; + max = player->MaxPitch; + } + else + { + min = -89.; + max = 89.; + } + p = clamp(p, min, max); + return p; +} + void AActor::SetPitch(DAngle p, int fflags) { - if (player != NULL || fflags & SPF_FORCECLAMP) - { // clamp the pitch we set - DAngle min, max; - - if (player != NULL) - { - min = player->MinPitch; - max = player->MaxPitch; - } - else - { - min = -89.; - max = 89.; - } - p = clamp(p, min, max); - } - - bool view = (fflags & SPF_VIEW); - bool changed = false; - if (view) + if (player != nullptr || (fflags & SPF_FORCECLAMP)) { - if (p != ViewAngles.Pitch) - { - ViewAngles.Pitch = p; - changed = true; - } + p = ClampPitch(p); } - else if (p != Angles.Pitch) + + if (p != Angles.Pitch) { Angles.Pitch = p; - changed = true; - } - if (changed && player != nullptr && (fflags & SPF_INTERPOLATE)) - { - player->cheats |= CF_INTERPVIEW; + if (player != nullptr && (fflags & SPF_INTERPOLATE)) + { + player->cheats |= CF_INTERPVIEW; + } } + } void AActor::SetAngle(DAngle ang, int fflags) { - bool view = (fflags & SPF_VIEW); - bool changed = false; - if (view) - { - if (ang != ViewAngles.Yaw) - { - ViewAngles.Yaw = ang; - changed = true; - } - } - else if (ang != Angles.Yaw) + if (ang != Angles.Yaw) { Angles.Yaw = ang; - changed = true; - } - if (changed && player != nullptr && (fflags & SPF_INTERPOLATE)) - { - player->cheats |= CF_INTERPVIEW; + if (player != nullptr && (fflags & SPF_INTERPOLATE)) + { + player->cheats |= CF_INTERPVIEW; + } } + } void AActor::SetRoll(DAngle r, int fflags) { - bool view = (fflags & SPF_VIEW); - bool changed = false; - if (view) - { - if (r != ViewAngles.Roll) - { - ViewAngles.Roll = r; - changed = true; - } - } - else if (r != Angles.Roll) + if (r != Angles.Roll) { Angles.Roll = r; - changed = true; + if (player != nullptr && (fflags & SPF_INTERPOLATE)) + { + player->cheats |= CF_INTERPVIEW; + } } - if (changed && player != nullptr && (fflags & SPF_INTERPOLATE)) +} + +void AActor::SetViewPitch(DAngle p, int fflags) +{ + if (player != NULL || (fflags & SPF_FORCECLAMP)) { - player->cheats |= CF_INTERPVIEW; + p = ClampPitch(p); + } + + if (p != ViewAngles.Pitch) + { + ViewAngles.Pitch = p; + if (player != nullptr && (fflags & SPF_INTERPOLATE)) + { + player->cheats |= CF_INTERPVIEW; + } + } + +} + +void AActor::SetViewAngle(DAngle ang, int fflags) +{ + if (ang != ViewAngles.Yaw) + { + ViewAngles.Yaw = ang; + if (player != nullptr && (fflags & SPF_INTERPOLATE)) + { + player->cheats |= CF_INTERPVIEW; + } + } + +} + +void AActor::SetViewRoll(DAngle r, int fflags) +{ + if (r != ViewAngles.Roll) + { + ViewAngles.Roll = r; + if (player != nullptr && (fflags & SPF_INTERPOLATE)) + { + player->cheats |= CF_INTERPVIEW; + } } } diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index ab02640e6..5d70aa6c8 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1120,6 +1120,9 @@ class Actor : Thinker native native void A_SetAngle(double angle = 0, int flags = 0, int ptr = AAPTR_DEFAULT); native void A_SetPitch(double pitch, int flags = 0, int ptr = AAPTR_DEFAULT); native void A_SetRoll(double roll, int flags = 0, int ptr = AAPTR_DEFAULT); + native void A_SetViewAngle(double angle = 0, int flags = 0, int ptr = AAPTR_DEFAULT); + native void A_SetViewPitch(double pitch, int flags = 0, int ptr = AAPTR_DEFAULT); + native void A_SetViewRoll(double roll, int flags = 0, int ptr = AAPTR_DEFAULT); deprecated("2.3") native void A_SetUserVar(name varname, int value); deprecated("2.3") native void A_SetUserArray(name varname, int index, int value); deprecated("2.3") native void A_SetUserVarFloat(name varname, double value); diff --git a/wadsrc/static/zscript/constants.zs b/wadsrc/static/zscript/constants.zs index 27d4c8fc0..02e6d4fce 100644 --- a/wadsrc/static/zscript/constants.zs +++ b/wadsrc/static/zscript/constants.zs @@ -547,7 +547,6 @@ enum EAngleFlags { SPF_FORCECLAMP = 1, SPF_INTERPOLATE = 2, - SPF_VIEW = 4, }; // flags for A_CheckLOF