From: terencehill Date: Sat, 1 Jun 2024 22:23:03 +0000 (+0200) Subject: Change order of some operations so that gmqcc can apply constant folding X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6a355760a793801038e280a779a628bfecd09494;p=xonotic%2Fxonotic-data.pk3dir.git Change order of some operations so that gmqcc can apply constant folding --- diff --git a/qcsrc/client/draw.qc b/qcsrc/client/draw.qc index 5540ae4fb..5f39196d8 100644 --- a/qcsrc/client/draw.qc +++ b/qcsrc/client/draw.qc @@ -217,8 +217,8 @@ void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector return; // Complete rectangle, nothing more needed. } - float co = cos(f * 2 * M_PI); - float si = sin(f * 2 * M_PI); + float co = cos(f * (2 * M_PI)); + float si = sin(f * (2 * M_PI)); float q = fabs(co) + fabs(si); co /= q; si /= q; diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index b892d6291..057c2aadf 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -1271,7 +1271,7 @@ bool StrafeHUD_drawTextIndicator(string text, float height, vector color, float if((height <= 0) || (lasttime <= 0) || (fadetime <= 0) || ((time - lasttime) >= fadetime)) return false; - float alpha = cos(((time - lasttime) / fadetime) * 90 * DEG2RAD); // fade non-linear like the physics panel does + float alpha = cos(((time - lasttime) / fadetime) * M_PI_2); // fade non-linear like the physics panel does vector size = panel_size; size.y = height; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 5173a1645..5c67a2115 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -524,20 +524,20 @@ vector GetCurrentFov(float fov) velocityzoom = 1; float frustumx, frustumy, fovx, fovy; - frustumy = tan(fov * M_PI / 360.0) * 0.75 * current_viewzoom * velocityzoom; + frustumy = tan(fov * (M_PI / 360)) * 0.75 * current_viewzoom * velocityzoom; frustumx = frustumy * vid_width / vid_height / vid_pixelheight; - fovx = atan2(frustumx, 1) / M_PI * 360.0; - fovy = atan2(frustumy, 1) / M_PI * 360.0; + fovx = atan2(frustumx, 1) * (360 / M_PI); + fovy = atan2(frustumy, 1) * (360 / M_PI); return '1 0 0' * fovx + '0 1 0' * fovy; } vector GetViewLocationFOV(float fov) { - float frustumy = tan(fov * M_PI / 360.0) * 0.75; + float frustumy = tan(fov * (M_PI / 360)) * 0.75; float frustumx = frustumy * vid_width / vid_height / vid_pixelheight; - float fovx = atan2(frustumx, 1) / M_PI * 360.0; - float fovy = atan2(frustumy, 1) / M_PI * 360.0; + float fovx = atan2(frustumx, 1) * (360 / M_PI); + float fovy = atan2(frustumy, 1) * (360 / M_PI); return '1 0 0' * fovx + '0 1 0' * fovy; } diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc index b285d17f4..827aa0f5c 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc @@ -1588,7 +1588,7 @@ bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effe for(i = 0; i < 16; ++i) { iteration_scale -= i / 16; - theta = random() * 2 * M_PI; + theta = random() * (2 * M_PI); loc_y = sin(theta); loc_x = cos(theta); loc_z = 0; diff --git a/qcsrc/common/minigames/minigame/pong.qc b/qcsrc/common/minigames/minigame/pong.qc index b6c0988c7..af655c2c2 100644 --- a/qcsrc/common/minigames/minigame/pong.qc +++ b/qcsrc/common/minigames/minigame/pong.qc @@ -45,7 +45,7 @@ void pong_ball_throw(entity ball) { float angle; do - angle = random()*M_PI*2; + angle = random() * (2 * M_PI); while ( fabs(sin(angle)) < 0.17 || fabs(cos(angle)) < 0.17 ); ball.velocity_x = cos(angle)*autocvar_sv_minigames_pong_ball_speed; ball.velocity_y = sin(angle)*autocvar_sv_minigames_pong_ball_speed; diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index d44e649f2..b071d0180 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -451,7 +451,7 @@ void nade_ice_think(entity this) randomr = random(); randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius; float randomw; - randomw = random() * M_PI * 2; + randomw = random() * (2 * M_PI); vector randomp; randomp.x = randomr * cos(randomw); randomp.y = randomr * sin(randomw); @@ -829,7 +829,7 @@ void nade_darkness_think(entity this) randomr = random(); randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius; float randomw; - randomw = random() * M_PI * 2; + randomw = random() * (2 * M_PI); vector randomp; randomp.x = randomr * cos(randomw); randomp.y = randomr * sin(randomw); diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index ca120d295..76cedfd1e 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -457,8 +457,8 @@ vector decompressShortVector(int data) } else { - q = .19634954084936207740 * q; - p = .19634954084936207740 * p - 1.57079632679489661922; + q = M_PI / 16 * q; + p = M_PI / 16 * p - M_PI_2; out.x = cos(q) * cos(p); out.y = sin(q) * cos(p); out.z = -sin(p); @@ -484,7 +484,7 @@ float compressShortVector(vector vec) error("BOGUS vectoangles"); //print("angles: ", vtos(ang), "\n"); - p = floor(0.5 + (ang.x + 90) * 16 / 180) & 15; // -90..90 to 0..14 + p = floor(0.5 + (ang.x + 90) * (16 / 180)) & 15; // -90..90 to 0..14 if(p == 0) { if(vec.z < 0) @@ -493,7 +493,7 @@ float compressShortVector(vector vec) y = 30; } else - y = floor(0.5 + ang.y * 32 / 360) & 31; // 0..360 to 0..32 + y = floor(0.5 + ang.y * (32 / 360)) & 31; // 0..360 to 0..32 len = invertLengthLog(vlen(vec)); //print("compressed: p:", ftos(p)); print(" y:", ftos(y)); print(" len:", ftos(len), "\n"); diff --git a/qcsrc/lib/random.qc b/qcsrc/lib/random.qc index a5ff69356..de78f4027 100644 --- a/qcsrc/lib/random.qc +++ b/qcsrc/lib/random.qc @@ -85,7 +85,7 @@ float gsl_ran_gaussian(float sigma) } else { - float a = random() * 2 * M_PI; + float a = random() * (2 * M_PI); float b = sqrt(-2 * log(random())); gsl_ran_gaussian_lastvalue = cos(a) * b; gsl_ran_gaussian_lastvalue_set = 1; diff --git a/qcsrc/server/anticheat.qc b/qcsrc/server/anticheat.qc index a818df3eb..1539e72e5 100644 --- a/qcsrc/server/anticheat.qc +++ b/qcsrc/server/anticheat.qc @@ -60,7 +60,7 @@ float movement_oddity(vector m0, vector m1) float cosangle = normalize(m0) * normalize(m1); if(cosangle >= 0) return 0; - return 0.5 - 0.5 * cos(cosangle * cosangle * 4 * M_PI); + return 0.5 - 0.5 * cos(cosangle * cosangle * (4 * M_PI)); // returns 0 for: -1, -sqrt(0.5), 0 (angles that commonly happen with kbd) } diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 2a557c5f0..2c60fd432 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -245,7 +245,7 @@ vector waypoint_getSymmetricalPoint(vector org, int ctf_flags) if (autocvar_g_waypointeditor_symmetrical == -1) map_center = autocvar_g_waypointeditor_symmetrical_origin; - new_org = Rotate(org - map_center, 360 * DEG2RAD / ctf_flags) + map_center; + new_org = Rotate(org - map_center, 2 * M_PI / ctf_flags) + map_center; } else if (fabs(autocvar_g_waypointeditor_symmetrical) == 2) {