]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move PM_walk landing event to ecs
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 23 Jun 2016 23:30:27 +0000 (09:30 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 23 Jun 2016 23:30:27 +0000 (09:30 +1000)
qcsrc/common/physics/player.qc
qcsrc/ecs/README.md
qcsrc/ecs/_lib.inc
qcsrc/ecs/events/_mod.inc
qcsrc/ecs/events/_mod.qh
qcsrc/ecs/events/physics.qc [new file with mode: 0644]
qcsrc/ecs/events/physics.qh [new file with mode: 0644]
qcsrc/ecs/systems/physics.qc
qcsrc/ecs/systems/sv_physics.qc

index f5ff4c4fa55dab13f06e6006588fbcb25cbda7c8..13a4bcd7a018b517011dfd5a56b66f68896208d0 100644 (file)
@@ -1042,21 +1042,6 @@ void PM_jetpack(entity this, float maxspd_mod)
 
 void PM_walk(entity this, float maxspd_mod)
 {
-       if (!WAS_ONGROUND(this))
-       {
-#ifdef SVQC
-               if (autocvar_speedmeter)
-                       LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
-#endif
-               if (this.lastground < time - 0.3)
-                       this.velocity *= (1 - PHYS_FRICTION_ONLAND(this));
-#ifdef SVQC
-               if (this.jumppadcount > 1)
-                       LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
-               this.jumppadcount = 0;
-#endif
-       }
-
        // walking
        makevectors(this.v_angle.y * '0 1 0');
        const vector wishvel = v_forward * this.movement.x
index 9fd6ad6948ac5e7b2501d338ea2b0f338743759c..d49094f7b48c68019752dd871f46ee360bd7478e 100644 (file)
@@ -44,5 +44,4 @@
 ### listening
 
     entity listener = new_pure(someListener);
-    listener.evt_$event = void(entity this) { code; };
-    subscribe(listener, $event);
+    subscribe(listener, $event, void(entity this) { code; });
index 32db1f3d3e6cb1f1b0a4f7672dfc1a058d522f07..ef8e67c58a907020961cde32d164e49472df35f3 100644 (file)
@@ -13,8 +13,9 @@
        FOREACH_ENTITY_FLOAT_ORDERED(evt_##T##_listener, true, it.evt_##T(__VA_ARGS__)); \
        MACRO_END
 
-#define subscribe(listener, T) \
+#define subscribe(listener, T, fn) \
        MACRO_BEGIN \
+       listener.evt_##T = (fn); \
        listener.evt_##T##_listener = true; \
        MACRO_END
 
index 98fb4815c1ce28cc699a429537ea75c2643b4487..c139d72b51ed4738fb396b3407fd335324cd921a 100644 (file)
@@ -1 +1,2 @@
 // generated file; do not modify
+#include <ecs/events/physics.qc>
index 98fb4815c1ce28cc699a429537ea75c2643b4487..1e8c791ce9b403aafc843acd2e95b6aebff0e082 100644 (file)
@@ -1 +1,2 @@
 // generated file; do not modify
+#include <ecs/events/physics.qh>
diff --git a/qcsrc/ecs/events/physics.qc b/qcsrc/ecs/events/physics.qc
new file mode 100644 (file)
index 0000000..909f45c
--- /dev/null
@@ -0,0 +1 @@
+#include "physics.qh"
diff --git a/qcsrc/ecs/events/physics.qh b/qcsrc/ecs/events/physics.qh
new file mode 100644 (file)
index 0000000..df32c55
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+EVENT(phys_land, (entity this));
index c38e891ccd0f9361be5e5ffb50229df35129b2b2..c299079ef634d97b27d0809ebf501234d6897274 100644 (file)
@@ -105,6 +105,12 @@ void sys_phys_update(entity this, float dt)
        } else if (ITEMS_STAT(this) & IT_USING_JETPACK) {
                PM_jetpack(this, maxspeed_mod);
        } else if (IS_ONGROUND(this)) {
+               if (!WAS_ONGROUND(this)) {
+                       emit(phys_land, this);
+                       if (this.lastground < time - 0.3) {
+                               this.velocity *= (1 - PHYS_FRICTION_ONLAND(this));
+                       }
+               }
                PM_walk(this, maxspeed_mod);
        } else {
                PM_air(this, buttons_prev, maxspeed_mod);
index 5c480fe78438c1471bf9253bd02fc5e036d55a9f..0df3411c1d37be4b62ae0ca2aa4db0ad6b0ba3f0 100644 (file)
@@ -9,8 +9,8 @@ void sys_phys_fix(entity this, float dt)
 bool sys_phys_override(entity this)
 {
        int buttons = PHYS_INPUT_BUTTON_MASK(this);
-       if (PM_check_specialcommand(this, buttons)) return true;
-       if (this.PlayerPhysplug && this.PlayerPhysplug(this)) return true;
+       if (PM_check_specialcommand(this, buttons)) { return true; }
+       if (this.PlayerPhysplug && this.PlayerPhysplug(this)) { return true; }
        return false;
 }
 
@@ -21,7 +21,7 @@ void sys_phys_monitor(entity this)
        if (sv_maxidle > 0) {
                if (buttons != this.buttons_old
                    || this.movement != this.movement_old
-                   || this.v_angle != this.v_angle_old) this.parm_idlesince = time;
+                   || this.v_angle != this.v_angle_old) { this.parm_idlesince = time; }
        }
        PM_check_nickspam(this);
        PM_check_punch(this);
@@ -29,21 +29,21 @@ void sys_phys_monitor(entity this)
 
 void sys_phys_ai(entity this)
 {
-       if (!IS_BOT_CLIENT(this)) return;
-       if (playerdemo_read(this)) return;
+       if (!IS_BOT_CLIENT(this)) { return; }
+       if (playerdemo_read(this)) { return; }
        bot_think(this);
 }
 
 void sys_phys_pregame_hold(entity this)
 {
-       if (!IS_PLAYER(this)) return;
+       if (!IS_PLAYER(this)) { return; }
        const bool allowed_to_move = (time >= game_starttime);
        if (!allowed_to_move) {
                this.velocity = '0 0 0';
                this.movetype = MOVETYPE_NONE;
                this.disableclientprediction = 2;
        } else if (this.disableclientprediction == 2) {
-               if (this.movetype == MOVETYPE_NONE) this.movetype = MOVETYPE_WALK;
+               if (this.movetype == MOVETYPE_NONE) { this.movetype = MOVETYPE_WALK; }
                this.disableclientprediction = 0;
        }
 }
@@ -51,7 +51,7 @@ void sys_phys_pregame_hold(entity this)
 void sys_phys_spectator_control(entity this)
 {
        float maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
-       if (!this.spectatorspeed) this.spectatorspeed = maxspeed_mod;
+       if (!this.spectatorspeed) { this.spectatorspeed = maxspeed_mod; }
        if ((this.impulse >= 1 && this.impulse <= 19)
            || (this.impulse >= 200 && this.impulse <= 209)
            || (this.impulse >= 220 && this.impulse <= 229)
@@ -61,14 +61,17 @@ void sys_phys_spectator_control(entity this)
                            || this.impulse == 15
                            || this.impulse == 18
                            || (this.impulse >= 200 && this.impulse <= 209)
-                          ) this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
-                       else if (this.impulse == 11) this.spectatorspeed = maxspeed_mod;
-                       else if (this.impulse == 12
+                          ) { this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5); } else if (this.impulse == 11) {
+                               this.spectatorspeed = maxspeed_mod;
+                       else if (this.impulse == 12
                            || this.impulse == 16
                            || this.impulse == 19
                            || (this.impulse >= 220 && this.impulse <= 229)
-                               ) this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
-                       else if (this.impulse >= 1 && this.impulse <= 9) this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
+                                 ) {
+                               this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
+                       } else if (this.impulse >= 1 && this.impulse <= 9) {
+                               this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
+                       }
                }  // otherwise just clear
                this.impulse = 0;
        }
@@ -95,3 +98,20 @@ void sys_phys_fixspeed(entity this, float maxspeed_mod)
                stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
        }
 }
+
+void sys_phys_land(entity this)
+{
+       if (autocvar_speedmeter) {
+               LOG_TRACEF("landing velocity: %v (abs: %f)", this.velocity, vlen(this.velocity));
+       }
+       if (this.jumppadcount > 1) {
+               LOG_TRACEF("%dx jumppad combo", this.jumppadcount);
+       }
+       this.jumppadcount = 0;
+}
+
+STATIC_INIT(sys_phys)
+{
+       entity listener = new_pure(sys_phys);
+       subscribe(listener, phys_land, sys_phys_land);
+}