From f671ff556dc561fd81bc6f31039a5c37333a948b Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Thu, 23 Jan 2025 04:18:10 +1000 Subject: [PATCH] Match Q3 wishspeed and wishdir calculations This is equivalent to the relevant change in 0e542a1e3052b8bfe744b6ab34fe62de005b379d and produces the same pipeline hash (ie the same hash as given by reverting bec7b1df67bdb738bd65cdb261fe4e6a30890073). It's written `wishvel * (1 / wishspeed)` because that's how Q3 does it. The difference in the result is insignificant for normal gametypes but might be significant for Q3 DeFRaG compatibility in extreme cases. See https://gitlab.com/xonotic/xonotic-data.pk3dir/-/merge_requests/1438 for discussion. --- .gitlab-ci.yml | 2 +- qcsrc/ecs/systems/physics.qc | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 037245249..c94fcbfe5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,7 +45,7 @@ test_compilation_units: test_sv_game: stage: test script: - - export EXPECT=5a343412b4fa7772695453d4dd0d03a7 + - export EXPECT=601b58ab0baed5060eb18c8fc084e072 - qcsrc/tools/sv_game-hashtest.sh - exit $? diff --git a/qcsrc/ecs/systems/physics.qc b/qcsrc/ecs/systems/physics.qc index cfa927b8e..da2000c21 100644 --- a/qcsrc/ecs/systems/physics.qc +++ b/qcsrc/ecs/systems/physics.qc @@ -266,8 +266,11 @@ void sys_phys_simulate(entity this, float dt) } // acceleration - const vector wishdir = normalize(wishvel); - float wishspeed = min(vlen(wishvel), this.com_phys_vel_max); + float wishspeed = vlen(wishvel); + // Mathematically equivalent to normalize(wishvel) but more closely matches Q3 + // which uses the same single-precision optimisation to save one sqrt() + const vector wishdir = wishspeed ? wishvel * (1 / wishspeed) : '0 0 0'; + wishspeed = min(wishspeed, this.com_phys_vel_max); if (this.com_phys_air) { if (!(this.flags & FL_WATERJUMP)) { -- 2.39.5