From a83ae23c65eeb30e861f0fddc9f26bae911498e0 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Tue, 24 Mar 2015 15:36:12 +0100 Subject: [PATCH] Kill dotproduct() function as it's built-in in QC; move cross() to warpzonelib so warpzonelib can use it and stay standalone. --- qcsrc/common/util.qc | 13 ------------- qcsrc/common/util.qh | 3 --- qcsrc/common/weapons/w_shockwave.qc | 4 +--- qcsrc/server/command/cmd.qc | 9 +++++++++ qcsrc/server/mutators/gamemode_ctf.qc | 4 +--- qcsrc/warpzonelib/mathlib.qc | 8 ++++++++ qcsrc/warpzonelib/mathlib.qh | 4 ++++ qcsrc/warpzonelib/server.qc | 4 +--- 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 99fecda0b..49d707f07 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -500,19 +500,6 @@ string ScoreString(int pFlags, float pValue) return valstr; } -float dotproduct(vector a, vector b) -{ - return a.x * b.x + a.y * b.y + a.z * b.z; -} - -vector cross(vector a, vector b) -{ - return - '1 0 0' * (a.y * b.z - a.z * b.y) - + '0 1 0' * (a.z * b.x - a.x * b.z) - + '0 0 1' * (a.x * b.y - a.y * b.x); -} - // compressed vector format: // like MD3, just even shorter // 4 bit pitch (16 angles), 0 is -90, 8 is 0, 16 would be 90 diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 4de610f26..b2cdf8dca 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -109,9 +109,6 @@ const float TIME_FACTOR = 100; string ScoreString(float vflags, float value); -float dotproduct(vector a, vector b); -vector cross(vector a, vector b); - void compressShortVector_init(); vector decompressShortVector(float data); float compressShortVector(vector vec); diff --git a/qcsrc/common/weapons/w_shockwave.qc b/qcsrc/common/weapons/w_shockwave.qc index 24b8634b9..3f40c5397 100644 --- a/qcsrc/common/weapons/w_shockwave.qc +++ b/qcsrc/common/weapons/w_shockwave.qc @@ -553,13 +553,11 @@ void W_Shockwave_Attack(void) center = CENTER_OR_VIEWOFS(head); // find the closest point on the enemy to the center of the attack - float ang; // angle between shotdir and h float h; // hypotenuse, which is the distance between attacker to head float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin h = vlen(center - self.origin); - ang = acos(dotproduct(normalize(center - self.origin), w_shotdir)); - a = h * cos(ang); + a = h * (normalize(center - self.origin) * w_shotdir); // WEAPONTODO: replace with simpler method vector nearest_on_line = (w_shotorg + a * w_shotdir); diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index 4a8b59eba..14e0f201c 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -825,6 +825,15 @@ void ClientCommand_macro_write_aliases(float fh) void SV_ParseClientCommand(string command) { + // If invalid UTF-8, don't even parse it + string command2 = ""; + float len = strlen(command); + float i; + for (i = 0; i < len; ++i) + command2 = strcat(command2, chr2str(str2chr(command, i))); + if (command != command2) + return; + // if we're banned, don't even parse the command if(Ban_MaybeEnforceBanOnce(self)) return; diff --git a/qcsrc/server/mutators/gamemode_ctf.qc b/qcsrc/server/mutators/gamemode_ctf.qc index 2e6eb4ff7..5ea2924cc 100644 --- a/qcsrc/server/mutators/gamemode_ctf.qc +++ b/qcsrc/server/mutators/gamemode_ctf.qc @@ -89,13 +89,11 @@ float ctf_CheckPassDirection(vector head_center, vector passer_center, vector pa makevectors(passer_angle); // find the closest point on the enemy to the center of the attack - float ang; // angle between shotdir and h float h; // hypotenuse, which is the distance between attacker to head float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin h = vlen(head_center - passer_center); - ang = acos(dotproduct(normalize(head_center - passer_center), v_forward)); - a = h * cos(ang); + a = h * (normalize(head_center - passer_center) * v_forward); vector nearest_on_line = (passer_center + a * v_forward); float distance_from_line = vlen(nearest_to_passer - nearest_on_line); diff --git a/qcsrc/warpzonelib/mathlib.qc b/qcsrc/warpzonelib/mathlib.qc index d86af8a00..c9cde9072 100644 --- a/qcsrc/warpzonelib/mathlib.qc +++ b/qcsrc/warpzonelib/mathlib.qc @@ -290,3 +290,11 @@ int isunordered(float x, float y) { return !(x < y || x == y || x > y); } + +vector cross(vector a, vector b) +{ + return + '1 0 0' * (a.y * b.z - a.z * b.y) + + '0 1 0' * (a.z * b.x - a.x * b.z) + + '0 0 1' * (a.x * b.y - a.y * b.x); +} diff --git a/qcsrc/warpzonelib/mathlib.qh b/qcsrc/warpzonelib/mathlib.qh index a37ba63de..ddd494de5 100644 --- a/qcsrc/warpzonelib/mathlib.qh +++ b/qcsrc/warpzonelib/mathlib.qh @@ -112,4 +112,8 @@ const float M_2_PI = 0.63661977236758134308; /* 2/pi */ const float M_2_SQRTPI = 1.12837916709551257390; /* 2/sqrt(pi) */ const float M_SQRT2 = 1.41421356237309504880; /* sqrt(2) */ const float M_SQRT1_2 = 0.70710678118654752440; /* 1/sqrt(2) */ + +// Non- stuff follows here. +vector cross(vector a, vector b); + #endif diff --git a/qcsrc/warpzonelib/server.qc b/qcsrc/warpzonelib/server.qc index 5d529c12e..d5a3f4e92 100644 --- a/qcsrc/warpzonelib/server.qc +++ b/qcsrc/warpzonelib/server.qc @@ -563,9 +563,7 @@ void WarpZone_InitStep_UpdateTransform() c = getsurfacepoint(self, i_s, tri.z); p = b - a; q = c - a; - n = '1 0 0' * (q.y * p.z - q.z * p.y) - + '0 1 0' * (q.z * p.x - q.x * p.z) - + '0 0 1' * (q.x * p.y - q.y * p.x); + n = cross(q, p); area = area + vlen(n); norm = norm + n; point = point + vlen(n) * (a + b + c); -- 2.39.2