From c3c1e76e8a28f01b1d6e48daced80b546c34499e Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Sun, 31 Dec 2017 19:02:14 -0600 Subject: [PATCH] Added vector diff functions to ZScript LevelLocals class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vec2Diff() and Vec3Diff() work like Actor’s Vec2To() and Vec3To() but use arbitrary points --- src/g_level.cpp | 46 ++++++++++++++++++++++++++++++++++ wadsrc/static/zscript/base.txt | 3 +++ 2 files changed, 49 insertions(+) diff --git a/src/g_level.cpp b/src/g_level.cpp index cb5bc4baf..ce8ff0850 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1954,6 +1954,52 @@ DEFINE_ACTION_FUNCTION(FLevelLocals, SetInterMusic) return 0; } +//========================================================================== +// +// +//========================================================================== + +template +inline T VecDiff(const T& v1, const T& v2) +{ + T result = v2 - v1; + + if (level.subsectors.Size() > 0) + { + const sector_t *const sec1 = P_PointInSector(v1); + const sector_t *const sec2 = P_PointInSector(v2); + + if (nullptr != sec1 && nullptr != sec2) + { + result += Displacements.getOffset(sec2->PortalGroup, sec1->PortalGroup); + } + } + + return result; +} + +DEFINE_ACTION_FUNCTION(FLevelLocals, Vec2Diff) +{ + PARAM_PROLOGUE; + PARAM_FLOAT(x1); + PARAM_FLOAT(y1); + PARAM_FLOAT(x2); + PARAM_FLOAT(y2); + ACTION_RETURN_VEC2(VecDiff(DVector2(x1, y1), DVector2(x2, y2))); +} + +DEFINE_ACTION_FUNCTION(FLevelLocals, Vec3Diff) +{ + PARAM_PROLOGUE; + PARAM_FLOAT(x1); + PARAM_FLOAT(y1); + PARAM_FLOAT(z1); + PARAM_FLOAT(x2); + PARAM_FLOAT(y2); + PARAM_FLOAT(z2); + ACTION_RETURN_VEC3(VecDiff(DVector3(x1, y1, z1), DVector3(x2, y2, z2))); +} + //========================================================================== // // diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 4ffe34dce..01e2af795 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -552,6 +552,9 @@ struct LevelLocals native native bool IsJumpingAllowed() const; native bool IsCrouchingAllowed() const; native bool IsFreelookAllowed() const; + + native static clearscope vector2 Vec2Diff(vector2 v1, vector2 v2); + native static clearscope vector3 Vec3Diff(vector3 v1, vector3 v2); String TimeFormatted(bool totals = false) {