]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make physics hook common, move multijump stuff into multijump file
authorMario <mario@smbclan.net>
Mon, 23 Nov 2015 10:53:15 +0000 (20:53 +1000)
committerMario <mario@smbclan.net>
Mon, 23 Nov 2015 10:53:15 +0000 (20:53 +1000)
qcsrc/client/mutators/events.qh
qcsrc/common/mutators/events.qh
qcsrc/common/mutators/mutator/multijump/multijump.qc
qcsrc/common/physics.qc
qcsrc/common/physics.qh
qcsrc/server/mutators/events.qh

index baaba14aef2a0f6d5607f688f1d79192486f4d0c..937e3170b56e8368181906ab2851994b23786f59 100644 (file)
@@ -88,17 +88,6 @@ MUTATOR_HOOKABLE(ClearModelParams, EV_NO_ARGS);
 string checkmodel_input, checkmodel_command;
 MUTATOR_HOOKABLE(GetModelParams, EV_GetModelParams);
 
-/** called when a player presses the jump key */
-#define EV_PlayerJump(i, o) \
-       /**/ i(float, player_multijump) \
-       /**/ i(float, player_jumpheight) \
-       /**/ o(float, player_multijump) \
-       /**/ o(float, player_jumpheight) \
-       /**/
-float player_multijump;
-float player_jumpheight;
-MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
-
 /** Called checking if 3rd person mode should be forced on */
 #define EV_WantEventchase(i, o) \
        /** entity id */ i(entity, __self) \
index 82898237c53f38e6a212b62ff4f7089ff348bc5b..05f567d761c136079415f1decdaf2f0cf87e6557 100644 (file)
@@ -61,4 +61,21 @@ MUTATOR_HOOKABLE(IsFlying, EV_IsFlying);
     /**/
 MUTATOR_HOOKABLE(WP_Format, EV_WP_Format);
 
+/**
+ * called before any player physics, may adjust variables for movement,
+ * is run AFTER bot code and idle checking on the server
+ */
+MUTATOR_HOOKABLE(PlayerPhysics, EV_NO_ARGS);
+
+/** called when a player presses the jump key */
+#define EV_PlayerJump(i, o) \
+    /**/ i(float, player_multijump) \
+    /**/ i(float, player_jumpheight) \
+    /**/ o(float, player_multijump) \
+    /**/ o(float, player_jumpheight) \
+    /**/
+float player_multijump;
+float player_jumpheight;
+MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
+
 #endif
index 00e22af7234a24cf7a915dfb1e02151bf070be50..10214591e5e62d8a796d25309b3f245df3a99616 100644 (file)
@@ -4,6 +4,22 @@
 #endif
 #include "../../../physics.qh"
 
+
+#if defined(SVQC)
+void multijump_AddStats();
+
+REGISTER_MUTATOR(multijump, cvar("g_multijump"))
+{
+       MUTATOR_ONADD
+       {
+               multijump_AddStats();
+       }
+       return false;
+}
+#elif defined(CSQC)
+REGISTER_MUTATOR(multijump, true);
+#endif
+
 .int multijump_count;
 .bool multijump_ready;
 .bool cvar_cl_multijump;
@@ -36,13 +52,13 @@ float autocvar_g_multijump_dodging = 1;
 .float stat_multijump_maxspeed;
 .float stat_multijump_dodging;
 
-void multijump_UpdateStats()
-{SELFPARAM();
-       self.stat_multijump = PHYS_MULTIJUMP;
-       self.stat_multijump_speed = PHYS_MULTIJUMP_SPEED;
-       self.stat_multijump_add = PHYS_MULTIJUMP_ADD;
-       self.stat_multijump_maxspeed = PHYS_MULTIJUMP_MAXSPEED;
-       self.stat_multijump_dodging = PHYS_MULTIJUMP_DODGING;
+void multijump_UpdateStats(entity this)
+{
+       this.stat_multijump = PHYS_MULTIJUMP;
+       this.stat_multijump_speed = PHYS_MULTIJUMP_SPEED;
+       this.stat_multijump_add = PHYS_MULTIJUMP_ADD;
+       this.stat_multijump_maxspeed = PHYS_MULTIJUMP_MAXSPEED;
+       this.stat_multijump_dodging = PHYS_MULTIJUMP_DODGING;
 }
 
 void multijump_AddStats()
@@ -56,22 +72,20 @@ void multijump_AddStats()
 
 #endif
 
-void PM_multijump()
-{SELFPARAM();
+void PM_multijump(entity this)
+{
        if(!PHYS_MULTIJUMP) { return; }
 
-       if(IS_ONGROUND(self))
-       {
-               self.multijump_count = 0;
-       }
+       if(IS_ONGROUND(this))
+               this.multijump_count = 0;
 }
 
-bool PM_multijump_checkjump()
-{SELFPARAM();
+bool PM_multijump_checkjump(entity this)
+{
        if(!PHYS_MULTIJUMP) { return false; }
 
 #ifdef SVQC
-       bool client_multijump = self.cvar_cl_multijump;
+       bool client_multijump = this.cvar_cl_multijump;
 #elif defined(CSQC)
        bool client_multijump = cvar("cl_multijump");
 
@@ -79,10 +93,10 @@ bool PM_multijump_checkjump()
                return false; // nope
 #endif
 
-       if (!IS_JUMP_HELD(self) && !IS_ONGROUND(self) && client_multijump) // jump button pressed this frame and we are in midair
-               self.multijump_ready = true;  // this is necessary to check that we released the jump button and pressed it again
+       if (!IS_JUMP_HELD(this) && !IS_ONGROUND(this) && client_multijump) // jump button pressed this frame and we are in midair
+               this.multijump_ready = true;  // this is necessary to check that we released the jump button and pressed it again
        else
-               self.multijump_ready = false;
+               this.multijump_ready = false;
 
        int phys_multijump = PHYS_MULTIJUMP;
 
@@ -90,16 +104,16 @@ bool PM_multijump_checkjump()
        phys_multijump = (PHYS_MULTIJUMP) ? -1 : 0;
 #endif
 
-       if(!player_multijump && self.multijump_ready && (self.multijump_count < phys_multijump || phys_multijump == -1) && self.velocity_z > PHYS_MULTIJUMP_SPEED && (!PHYS_MULTIJUMP_MAXSPEED || vlen(self.velocity) <= PHYS_MULTIJUMP_MAXSPEED))
+       if(!player_multijump && this.multijump_ready && (this.multijump_count < phys_multijump || phys_multijump == -1) && this.velocity_z > PHYS_MULTIJUMP_SPEED && (!PHYS_MULTIJUMP_MAXSPEED || vlen(this.velocity) <= PHYS_MULTIJUMP_MAXSPEED))
        {
                if (PHYS_MULTIJUMP)
                {
                        if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
                        {
-                               if (self.velocity_z < PHYS_JUMPVELOCITY)
+                               if (this.velocity_z < PHYS_JUMPVELOCITY)
                                {
                                        player_multijump = true;
-                                       self.velocity_z = 0;
+                                       this.velocity_z = 0;
                                }
                        }
                        else
@@ -108,63 +122,56 @@ bool PM_multijump_checkjump()
                        if(player_multijump)
                        {
                                if(PHYS_MULTIJUMP_DODGING)
-                               if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
+                               if(this.movement_x != 0 || this.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
                                {
                                        float curspeed;
                                        vector wishvel, wishdir;
 
 /*#ifdef SVQC
                                        curspeed = max(
-                                               vlen(vec2(self.velocity)), // current xy speed
-                                               vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
+                                               vlen(vec2(this.velocity)), // current xy speed
+                                               vlen(vec2(antilag_takebackavgvelocity(this, max(this.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
                                        );
 #elif defined(CSQC)*/
-                                       curspeed = vlen(vec2(self.velocity));
+                                       curspeed = vlen(vec2(this.velocity));
 //#endif
 
-                                       makevectors(self.v_angle_y * '0 1 0');
-                                       wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+                                       makevectors(this.v_angle_y * '0 1 0');
+                                       wishvel = v_forward * this.movement_x + v_right * this.movement_y;
                                        wishdir = normalize(wishvel);
 
-                                       self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
-                                       self.velocity_y = wishdir_y * curspeed;
+                                       this.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
+                                       this.velocity_y = wishdir_y * curspeed;
                                        // keep velocity_z unchanged!
                                }
                                if (PHYS_MULTIJUMP > 0)
                                {
-                                       self.multijump_count += 1;
+                                       this.multijump_count += 1;
                                }
                        }
                }
-               self.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
+               this.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
        }
 
        return false;
 }
 
-#ifdef SVQC
-REGISTER_MUTATOR(multijump, cvar("g_multijump"))
-{
-       MUTATOR_ONADD
-       {
-               multijump_AddStats();
-       }
-       return false;
-}
-
 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
 {
-       multijump_UpdateStats();
-       PM_multijump();
-
+#ifdef SVQC
+       multijump_UpdateStats(self);
+#endif
+       PM_multijump(self);
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
 {
-       return PM_multijump_checkjump();
+       return PM_multijump_checkjump(self);
 }
 
+#ifdef SVQC
+
 MUTATOR_HOOKFUNCTION(multijump, GetCvars)
 {
        GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump");
index 63e7ae7e91dae4ee1caa28bf8d66ea993c1c2454..9e3a16d5518b57741eeaa004b874327df592e7f5 100644 (file)
@@ -547,11 +547,8 @@ bool PlayerJump ()
        player_jumpheight = mjumpheight;
 #endif
 
-       if (MUTATOR_CALLHOOK(PlayerJump, doublejump, mjumpheight)
-#ifdef CSQC
-               || PM_multijump_checkjump()
-#endif
-               ) { return true; }
+       if (MUTATOR_CALLHOOK(PlayerJump, doublejump, mjumpheight))
+               return true;
 
        doublejump = player_multijump;
        mjumpheight = player_jumpheight;
@@ -1688,12 +1685,7 @@ void PM_Main(entity this)
        if (this.conveyor.state)
                this.velocity -= this.conveyor.movedir;
 
-#ifdef SVQC
        MUTATOR_CALLHOOK(PlayerPhysics);
-#endif
-#ifdef CSQC
-       PM_multijump();
-#endif
 
 //     float forcedodge = 1;
 //     if(forcedodge) {
index 639776593c1cece2ed3bc6ba1ec07af3588785c8..070f07ebc4d8cf5ed6f22bf8f217bb92248d4a11 100644 (file)
@@ -29,9 +29,6 @@ bool IsFlying(entity a);
        const int FL_WATERJUMP = 2048;  // player jumping out of water
        const int FL_JUMPRELEASED = 4096;       // for jump debouncing
 
-       float PM_multijump_checkjump();
-       void PM_multijump();
-
        .float watertype;
        .float waterlevel;
        .int items;
index 5c7c2311b2bfbb3a60bee91274f63c664ac13a3d..be95bd1a49a3d5e35660ffe1e1b14ab96a086ecb 100644 (file)
@@ -93,17 +93,6 @@ string item_model;
 string item_model_output;
 MUTATOR_HOOKABLE(ItemModel, EV_ItemModel);
 
-/** called when a player presses the jump key */
-#define EV_PlayerJump(i, o) \
-    /**/ i(float, player_multijump) \
-    /**/ i(float, player_jumpheight) \
-    /**/ o(float, player_multijump) \
-    /**/ o(float, player_jumpheight) \
-    /**/
-float player_multijump;
-float player_jumpheight;
-MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
-
 /** called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill */
 #define EV_GiveFragsForKill(i, o) \
     /**/ i(entity, __self) \
@@ -219,12 +208,6 @@ MUTATOR_HOOKABLE(PlayerPreThink, EV_NO_ARGS);
 /** TODO change this into a general PlayerPostThink hook? */
 MUTATOR_HOOKABLE(GetPressedKeys, EV_NO_ARGS);
 
-/**
- * called before any player physics, may adjust variables for movement,
- * is run AFTER bot code and idle checking
- */
-MUTATOR_HOOKABLE(PlayerPhysics, EV_NO_ARGS);
-
 /** is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client */
 #define EV_GetCvars(i, o) \
     /**/ i(float, get_cvars_f) \