From 8156eda70020503ae78d74449f5a852e21f8a5b4 Mon Sep 17 00:00:00 2001 From: Spoike Date: Wed, 4 Aug 2021 21:17:52 +0000 Subject: [PATCH] Add anglesub builtin, requested by Shpuld. Returns angle difference within rotations +/- 180. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6004 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/pr_csqc.c | 1 + engine/common/pr_bgcmd.c | 11 +++++++++++ engine/common/pr_common.h | 1 + engine/server/pr_cmds.c | 1 + 4 files changed, 14 insertions(+) diff --git a/engine/client/pr_csqc.c b/engine/client/pr_csqc.c index a8268a393..690ce88bb 100644 --- a/engine/client/pr_csqc.c +++ b/engine/client/pr_csqc.c @@ -6945,6 +6945,7 @@ static struct { {"checkextension", PF_checkextension, 99}, // #99 float(string extname) checkextension (EXT_CSQC) {"checkbuiltin", PF_checkbuiltin, 0}, {"anglemod", PF_anglemod, 102}, + {"anglesub", PF_anglesub, 0}, //110 {"fopen", PF_fopen, 110}, // #110 float(string strname, float accessmode) fopen (FRIK_FILE) diff --git a/engine/common/pr_bgcmd.c b/engine/common/pr_bgcmd.c index fb12cdf44..a2423ec5c 100644 --- a/engine/common/pr_bgcmd.c +++ b/engine/common/pr_bgcmd.c @@ -6112,6 +6112,17 @@ void QCBUILTIN PF_anglemod (pubprogfuncs_t *prinst, struct globalvars_s *pr_glob G_FLOAT(OFS_RETURN) = v; } +void QCBUILTIN PF_anglesub (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals) +{ + float v = G_FLOAT(OFS_PARM0) - G_FLOAT(OFS_PARM1); + + while (v > 180) + v = v - 360; + while (v < -180) + v = v + 360; + + G_FLOAT(OFS_RETURN) = v; +} //void(vector dir) vectorvectors //Writes new values for v_forward, v_up, and v_right based on the given forward vector diff --git a/engine/common/pr_common.h b/engine/common/pr_common.h index a87278142..2a19941fb 100644 --- a/engine/common/pr_common.h +++ b/engine/common/pr_common.h @@ -121,6 +121,7 @@ void QCBUILTIN PF_rint (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals) void QCBUILTIN PF_floor (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals); void QCBUILTIN PF_ceil (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals); void QCBUILTIN PF_anglemod (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals); +void QCBUILTIN PF_anglesub (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals); void QCBUILTIN PF_vectorvectors (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals); void QCBUILTIN PF_crossproduct (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals); void QCBUILTIN PF_Tokenize (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals); diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 2d101fee2..9744e8ced 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -11085,6 +11085,7 @@ static BuiltinList_t BuiltinList[] = { //nq qw h2 ebfs {"checkbuiltin", PF_checkbuiltin, 0, 0, 0, 0, D("float(__variant funcref)", "Checks to see if the specified builtin is supported/mapped. This is intended as a way to check for #0 functions, allowing for simple single-builtin functions. Warning, if two different engines map different builtins to the same number, then this function will not tell you which will be called, only that it won't crash (the exception being #0, which are remapped as available).")}, {"builtin_find", PF_builtinsupported,100, 100, 0, 100, D("float(string builtinname)", "Looks to see if the named builtin is valid, and returns the builtin number it exists at.")}, // #100 //per builtin system. {"anglemod", PF_anglemod, 0, 0, 0, 102, "float(float value)"}, + {"anglesub", PF_anglesub, 0, 0, 0, 0, D("float(float newangle, float oldangle)","Returns newangle-oldangle, except returning the shortest route around a circle so yields a result between -180 and +180.")}, {"qsg_cvar_string", PF_cvar_string, 0, 0, 0, 103, D("DEP string(string cvarname)","An old/legacy equivelent of more recent/common builtins in order to read a cvar's string value."), true}, //TEI_SHOWLMP2