From: Mario Date: Mon, 23 Nov 2015 10:53:15 +0000 (+1000) Subject: Make physics hook common, move multijump stuff into multijump file X-Git-Tag: xonotic-v0.8.2~1634 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=de98b80015b25011f5ff98a62cf8756f514330f1;p=xonotic%2Fxonotic-data.pk3dir.git Make physics hook common, move multijump stuff into multijump file --- diff --git a/qcsrc/client/mutators/events.qh b/qcsrc/client/mutators/events.qh index baaba14ae..937e3170b 100644 --- a/qcsrc/client/mutators/events.qh +++ b/qcsrc/client/mutators/events.qh @@ -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) \ diff --git a/qcsrc/common/mutators/events.qh b/qcsrc/common/mutators/events.qh index 82898237c..05f567d76 100644 --- a/qcsrc/common/mutators/events.qh +++ b/qcsrc/common/mutators/events.qh @@ -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 diff --git a/qcsrc/common/mutators/mutator/multijump/multijump.qc b/qcsrc/common/mutators/mutator/multijump/multijump.qc index 00e22af72..10214591e 100644 --- a/qcsrc/common/mutators/mutator/multijump/multijump.qc +++ b/qcsrc/common/mutators/mutator/multijump/multijump.qc @@ -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"); diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index 63e7ae7e9..9e3a16d55 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -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) { diff --git a/qcsrc/common/physics.qh b/qcsrc/common/physics.qh index 639776593..070f07ebc 100644 --- a/qcsrc/common/physics.qh +++ b/qcsrc/common/physics.qh @@ -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; diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 5c7c2311b..be95bd1a4 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -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) \