]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move PM_ladder to ecs
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 23 Jun 2016 23:11:38 +0000 (09:11 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 23 Jun 2016 23:11:38 +0000 (09:11 +1000)
qcsrc/common/physics/player.qc
qcsrc/ecs/components/physics.qh
qcsrc/ecs/systems/physics.qc

index 38c6fed9e0e079b68641b5178ffa12ee1329a762..f5ff4c4fa55dab13f06e6006588fbcb25cbda7c8 100644 (file)
@@ -917,58 +917,6 @@ void PM_swim(entity this, float maxspd_mod)
 }
 
 .vector oldmovement;
-void PM_ladder(entity this, float maxspd_mod)
-{
-       // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
-       UNSET_ONGROUND(this);
-
-       float g;
-       g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
-       if (PHYS_ENTGRAVITY(this))
-               g *= PHYS_ENTGRAVITY(this);
-       if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
-       {
-               g *= 0.5;
-               this.velocity_z += g;
-       }
-
-       this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
-       makevectors(this.v_angle);
-       //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
-       vector wishvel = v_forward * this.movement_x
-                                       + v_right * this.movement_y
-                                       + '0 0 1' * this.movement_z;
-       if(this.viewloc)
-               wishvel.z = this.oldmovement.x;
-       this.velocity_z += g;
-       if (this.ladder_entity.classname == "func_water")
-       {
-               float f = vlen(wishvel);
-               if (f > this.ladder_entity.speed)
-                       wishvel *= (this.ladder_entity.speed / f);
-
-               this.watertype = this.ladder_entity.skin;
-               f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
-               if ((this.origin_z + this.view_ofs_z) < f)
-                       this.waterlevel = WATERLEVEL_SUBMERGED;
-               else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f)
-                       this.waterlevel = WATERLEVEL_SWIMMING;
-               else if ((this.origin_z + this.mins_z + 1) < f)
-                       this.waterlevel = WATERLEVEL_WETFEET;
-               else
-               {
-                       this.waterlevel = WATERLEVEL_NONE;
-                       this.watertype = CONTENT_EMPTY;
-               }
-       }
-       // acceleration
-       vector wishdir = normalize(wishvel);
-       float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
-       if(time >= PHYS_TELEPORT_TIME(this))
-               // water acceleration
-               PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
-       PM_ClientMovement_Move(this);
-}
 
 void PM_jetpack(entity this, float maxspd_mod)
 {
index 7457cb29c73bfbe296d2b7a51c42c2e0162a7102..f3af010413d7755bf870766bd7376350675a892d 100644 (file)
@@ -8,3 +8,7 @@ COMPONENT(phys);
 .vector com_phys_acc;
 .float com_phys_acc_rate;
 .float com_phys_friction;
+
+.vector com_phys_gravity;
+// TODO: remove
+.bool com_phys_ladder;
index 27b3689c90f6355ce5b6a9dfe8d75120fbf7c965..c38e891ccd0f9361be5e5ffb50229df35129b2b2 100644 (file)
@@ -93,7 +93,15 @@ void sys_phys_update(entity this, float dt)
        } else if (this.waterlevel >= WATERLEVEL_SWIMMING) {
                PM_swim(this, maxspeed_mod);
        } else if (time < this.ladder_time) {
-               PM_ladder(this, maxspeed_mod);
+               this.com_phys_friction = PHYS_FRICTION(this);
+               this.com_phys_vel_max = PHYS_MAXSPEED(this) * maxspeed_mod;
+               this.com_phys_acc_rate = PHYS_ACCELERATE(this) * maxspeed_mod;
+               this.com_phys_gravity = '0 0 -1' * PHYS_GRAVITY(this) * dt;
+               if (PHYS_ENTGRAVITY(this)) { this.com_phys_gravity *= PHYS_ENTGRAVITY(this); }
+               this.com_phys_ladder = true;
+               sys_phys_simulate(this, dt);
+               this.com_phys_ladder = false;
+               this.com_phys_gravity = '0 0 0';
        } else if (ITEMS_STAT(this) & IT_USING_JETPACK) {
                PM_jetpack(this, maxspeed_mod);
        } else if (IS_ONGROUND(this)) {
@@ -113,15 +121,49 @@ void sys_phys_update(entity this, float dt)
 
 void sys_phys_simulate(entity this, float dt)
 {
-       // noclipping or flying
+       // noclipping
+       // flying
+       // on a spawnfunc_func_ladder
+       // swimming in spawnfunc_func_water
        UNSET_ONGROUND(this);
 
+       float g = -this.com_phys_gravity.z;
+       if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) {
+               g *= 0.5;
+               this.velocity_z += g;
+       }
        this.velocity = this.velocity * (1 - dt * this.com_phys_friction);
+       this.velocity_z += g;
+
        makevectors(this.v_angle);
        // wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
        vector wishvel = v_forward * this.movement.x
            + v_right * this.movement.y
            + '0 0 1' * this.movement.z;
+       if (this.com_phys_ladder) {
+               if (this.viewloc) {
+                       wishvel.z = this.oldmovement.x;
+               }
+               if (this.ladder_entity.classname == "func_water") {
+                       float f = vlen(wishvel);
+                       if (f > this.ladder_entity.speed) {
+                               wishvel *= (this.ladder_entity.speed / f);
+                       }
+
+                       this.watertype = this.ladder_entity.skin;
+                       f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
+                       if ((this.origin_z + this.view_ofs_z) < f) {
+                               this.waterlevel = WATERLEVEL_SUBMERGED;
+                       } else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f) {
+                               this.waterlevel = WATERLEVEL_SWIMMING;
+                       } else if ((this.origin_z + this.mins_z + 1) < f) {
+                               this.waterlevel = WATERLEVEL_WETFEET;
+                       } else {
+                               this.waterlevel = WATERLEVEL_NONE;
+                               this.watertype = CONTENT_EMPTY;
+                       }
+               }
+       }
        // acceleration
        vector wishdir = normalize(wishvel);
        float wishspeed = min(vlen(wishvel), this.com_phys_vel_max);