]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Physics code: calculate wishdir without using normalize and apply other minor math...
authorterencehill <piuntn@gmail.com>
Sat, 30 Nov 2024 10:24:10 +0000 (11:24 +0100)
committerterencehill <piuntn@gmail.com>
Sat, 30 Nov 2024 10:38:20 +0000 (11:38 +0100)
The different wishdir formula causes a hash change despite the meaningless difference in the output

.gitlab-ci.yml
qcsrc/ecs/systems/physics.qc

index 48674649a0124bd09d60271f76a0c413ce26447d..81a98fa726d027248dc8ab60980dab69db86e279 100644 (file)
@@ -36,7 +36,7 @@ test_compilation_units:
 test_sv_game:
   stage: test
   script:
-    - export EXPECT=ee6d65824c57cb6d83cba31481a21822
+    - export EXPECT=f5fbfbd04a22e781397cfd14db367419
     - qcsrc/tools/sv_game-hashtest.sh
     - exit $?
 
index 167b492356195e61f9d63d369b8443470a2a6e8a..adf9067c4659dc6e78968e65589a01857dece25e 100644 (file)
@@ -214,18 +214,19 @@ void sys_phys_simulate(entity this, float dt)
        }
 
        vector forward, right, up;
-       MAKE_VECTORS(vmul(this.v_angle, (this.com_phys_vel_2d ? '0 1 0' : '1 1 1')), forward, right, up);
+       vector v_tmp = (this.com_phys_vel_2d ? vec3(0, this.v_angle.y, 0) : this.v_angle);
+       MAKE_VECTORS(v_tmp, forward, right, up);
        // wishvel = forward * PHYS_CS(this).movement.x + right * PHYS_CS(this).movement.y + up * PHYS_CS(this).movement.z;
        vector wishvel = forward * PHYS_CS(this).movement.x
                + right * PHYS_CS(this).movement.y
-               + '0 0 1' * (PHYS_CS(this).movement.z * (this.com_phys_vel_2d ? 0 : 1));
+               + '0 0 1' * (this.com_phys_vel_2d ? 0 : PHYS_CS(this).movement.z);
        if (this.com_phys_water) {
                if (PHYS_FROZEN(this))
                {
                        if(this.waterlevel >= WATERLEVEL_SUBMERGED && this.velocity.z >= -70) // don't change the speed too abruptally
                                wishvel = '0 0 160'; // resurface
                        else if(this.waterlevel >= WATERLEVEL_SWIMMING && this.velocity.z > 0)
-                               wishvel = eZ * 1.3 * min(this.velocity.z, 160); // resurface a bit more above the surface
+                               wishvel = eZ * (1.3 * min(this.velocity.z, 160)); // resurface a bit more above the surface
                }
                else
                {
@@ -263,9 +264,16 @@ 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 wishvel_len = vlen(wishvel);
+       float wishspeed = min(wishvel_len, this.com_phys_vel_max);
+
+       // same as wishdir = normalize(wishvel); but cheaper
+       const vector wishdir = (wishvel_len ? wishvel / wishvel_len : '0 0 0');
+       vector wishdir2 = normalize(wishvel);
+       if (wishdir2 - wishdir)
+               LOG_INFOF("^x0f8 diff = %v\n", wishdir2 - wishdir);
 
        if (this.com_phys_air) {
                if (!(this.flags & FL_WATERJUMP)) {
@@ -452,22 +460,22 @@ void sys_phys_simulate_simple(entity this, float dt)
                                FOREACH_ENTITY_RADIUS_ORDERED(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin), true, {
                                        if (it.solid != SOLID_TRIGGER || it == this) continue;
                                        if (gettouch(it) && boxesoverlap(it.absmin, it.absmax, this.absmin, this.absmax)) {
-                                           // SV_LinkEdict_TouchAreaGrid_Call
-                                           trace_allsolid = false;
-                                           trace_startsolid = false;
-                                           trace_fraction = 1;
-                                           trace_inwater = false;
-                                           trace_inopen = true;
-                                           trace_endpos = it.origin;
-                                           trace_plane_normal = '0 0 1';
-                                           trace_plane_dist = 0;
-                                           trace_ent = this;
-                                           trace_dpstartcontents = 0;
-                                           trace_dphitcontents = 0;
-                                           trace_dphitq3surfaceflags = 0;
-                                           trace_dphittexturename = string_null;
-                                           gettouch(it)(this, it);
-                                           vel = this.velocity;
+                                               // SV_LinkEdict_TouchAreaGrid_Call
+                                               trace_allsolid = false;
+                                               trace_startsolid = false;
+                                               trace_fraction = 1;
+                                               trace_inwater = false;
+                                               trace_inopen = true;
+                                               trace_endpos = it.origin;
+                                               trace_plane_normal = '0 0 1';
+                                               trace_plane_dist = 0;
+                                               trace_ent = this;
+                                               trace_dpstartcontents = 0;
+                                               trace_dphitcontents = 0;
+                                               trace_dphitq3surfaceflags = 0;
+                                               trace_dphittexturename = string_null;
+                                               gettouch(it)(this, it);
+                                               vel = this.velocity;
                                        }
                                });
                        }