From d5634fe916916ac8c4ab0984240ac1bf0547e1b3 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 16 Jul 2017 03:37:37 +1000 Subject: [PATCH] Forward impulses, movement and buttons to ClientState, also port impulse to ClientState --- qcsrc/common/physics/player.qc | 5 ++ qcsrc/common/physics/player.qh | 2 + qcsrc/ecs/systems/sv_physics.qc | 30 ++++---- qcsrc/server/bot/default/havocbot/havocbot.qc | 2 +- qcsrc/server/bot/default/scripting.qc | 2 +- qcsrc/server/cheats.qc | 14 ++-- qcsrc/server/client.qc | 68 +++++++++++++++---- qcsrc/server/client.qh | 31 +++++++++ qcsrc/server/impulse.qc | 4 +- qcsrc/server/mapvoting.qc | 10 +-- qcsrc/server/mutators/mutator/gamemode_ctf.qc | 2 +- 11 files changed, 123 insertions(+), 47 deletions(-) diff --git a/qcsrc/common/physics/player.qc b/qcsrc/common/physics/player.qc index 2f62c409a..2dbc7bbcd 100644 --- a/qcsrc/common/physics/player.qc +++ b/qcsrc/common/physics/player.qc @@ -818,6 +818,11 @@ void SV_PlayerPhysics(entity this) void CSQC_ClientMovement_PlayerMove_Frame(entity this) #endif { +#ifdef SVQC + // needs to be called before physics are run! + PM_UpdateButtons(this); +#endif + sys_phys_update(this, PHYS_INPUT_TIMELENGTH); #ifdef SVQC diff --git a/qcsrc/common/physics/player.qh b/qcsrc/common/physics/player.qh index 4af97abdc..1e94bec57 100644 --- a/qcsrc/common/physics/player.qh +++ b/qcsrc/common/physics/player.qh @@ -244,6 +244,8 @@ STATIC_INIT(PHYS_INPUT_BUTTON_DODGE) void Physics_UpdateStats(entity this, float maxspd_mod); + void PM_UpdateButtons(entity this); + .float stat_sv_airspeedlimit_nonqw = _STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW); .float stat_sv_maxspeed = _STAT(MOVEVARS_MAXSPEED); diff --git a/qcsrc/ecs/systems/sv_physics.qc b/qcsrc/ecs/systems/sv_physics.qc index 20cd53144..fc065b2ad 100644 --- a/qcsrc/ecs/systems/sv_physics.qc +++ b/qcsrc/ecs/systems/sv_physics.qc @@ -57,28 +57,28 @@ void sys_phys_spectator_control(entity this) { float maxspeed_mod = autocvar_sv_spectator_speed_multiplier; 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) + if ((CS(this).impulse >= 1 && CS(this).impulse <= 19) + || (CS(this).impulse >= 200 && CS(this).impulse <= 209) + || (CS(this).impulse >= 220 && CS(this).impulse <= 229) ) { if (this.lastclassname != STR_PLAYER) { - if (this.impulse == 10 - || 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) { + if (CS(this).impulse == 10 + || CS(this).impulse == 15 + || CS(this).impulse == 18 + || (CS(this).impulse >= 200 && CS(this).impulse <= 209) + ) { this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5); } else if (CS(this).impulse == 11) { this.spectatorspeed = maxspeed_mod; - } else if (this.impulse == 12 - || this.impulse == 16 - || this.impulse == 19 - || (this.impulse >= 220 && this.impulse <= 229) + } else if (CS(this).impulse == 12 + || CS(this).impulse == 16 + || CS(this).impulse == 19 + || (CS(this).impulse >= 220 && CS(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); + } else if (CS(this).impulse >= 1 && CS(this).impulse <= 9) { + this.spectatorspeed = 1 + 0.5 * (CS(this).impulse - 1); } } // otherwise just clear - this.impulse = 0; + CS(this).impulse = 0; } } diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 42f51af8c..712157f55 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -180,7 +180,7 @@ void havocbot_ai(entity this) // we are currently holding a weapon that's not fully loaded, reload it if(skill >= 2) // bots can only reload the held weapon on purpose past this skill if(this.(weaponentity).clip_load < this.(weaponentity).clip_size) - this.impulse = IMP_weapon_reload.impulse; // not sure if this is done right + CS(this).impulse = IMP_weapon_reload.impulse; // not sure if this is done right // if we're not reloading a weapon, switch to any weapon in our invnetory that's not fully loaded to reload it next // the code above executes next frame, starting the reloading then diff --git a/qcsrc/server/bot/default/scripting.qc b/qcsrc/server/bot/default/scripting.qc index 7ba7defba..da93d9556 100644 --- a/qcsrc/server/bot/default/scripting.qc +++ b/qcsrc/server/bot/default/scripting.qc @@ -485,7 +485,7 @@ float bot_cmd_cc(entity this) float bot_cmd_impulse(entity this) { - this.impulse = bot_cmd.bot_cmd_parm_float; + CS(this).impulse = bot_cmd.bot_cmd_parm_float; return CMD_STATUS_FINISHED; } diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index ded5e8409..6d78e160c 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -780,21 +780,21 @@ float Drag(entity this, float force_allow_pick, float ischeat) { if(PHYS_INPUT_BUTTON_DRAG(this)) { - if(this.impulse == 10 || this.impulse == 15 || this.impulse == 18) + if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18) { Drag_MoveForward(this); - this.impulse = 0; + CS(this).impulse = 0; } - else if(this.impulse == 12 || this.impulse == 16 || this.impulse == 19) + else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19) { Drag_MoveBackward(this); - this.impulse = 0; + CS(this).impulse = 0; } - else if(this.impulse >= 1 && this.impulse <= 9) + else if(CS(this).impulse >= 1 && CS(this).impulse <= 9) { - Drag_SetSpeed(this, this.impulse - 1); + Drag_SetSpeed(this, CS(this).impulse - 1); } - else if(this.impulse == 14) + else if(CS(this).impulse == 14) { Drag_SetSpeed(this, 9); } diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 196297e52..11833b8c9 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1711,7 +1711,7 @@ void SpectateCopy(entity this, entity spectatee) this.clip_size = spectatee.clip_size; this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance this.health = spectatee.health; - this.impulse = 0; + CS(this).impulse = 0; this.items = spectatee.items; this.last_pickup = spectatee.last_pickup; this.hit_time = spectatee.hit_time; @@ -2108,10 +2108,10 @@ bool joinAllowed(entity this) void ObserverThink(entity this) { - if ( this.impulse ) + if ( CS(this).impulse ) { - MinigameImpulse(this, this.impulse); - this.impulse = 0; + MinigameImpulse(this, CS(this).impulse); + CS(this).impulse = 0; } if (this.flags & FL_JUMPRELEASED) { @@ -2142,15 +2142,15 @@ void ObserverThink(entity this) void SpectatorThink(entity this) { - if ( this.impulse ) + if ( CS(this).impulse ) { - if(MinigameImpulse(this, this.impulse)) - this.impulse = 0; + if(MinigameImpulse(this, CS(this).impulse)) + CS(this).impulse = 0; - if (this.impulse == IMP_weapon_drop.impulse) + if (CS(this).impulse == IMP_weapon_drop.impulse) { STAT(CAMERA_SPECTATOR, this) = (STAT(CAMERA_SPECTATOR, this) + 1) % 3; - this.impulse = 0; + CS(this).impulse = 0; return; } } @@ -2159,7 +2159,7 @@ void SpectatorThink(entity this) if (PHYS_INPUT_BUTTON_JUMP(this) && joinAllowed(this)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; - } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) { + } else if(PHYS_INPUT_BUTTON_ATCK(this) || CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18 || (CS(this).impulse >= 200 && CS(this).impulse <= 209)) { this.flags &= ~FL_JUMPRELEASED; if(SpectateNext(this)) { TRANSMUTE(Spectator, this); @@ -2167,8 +2167,8 @@ void SpectatorThink(entity this) TRANSMUTE(Observer, this); PutClientInServer(this); } - this.impulse = 0; - } else if(this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229)) { + CS(this).impulse = 0; + } else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19 || (CS(this).impulse >= 220 && CS(this).impulse <= 229)) { this.flags &= ~FL_JUMPRELEASED; if(SpectatePrev(this)) { TRANSMUTE(Spectator, this); @@ -2176,7 +2176,7 @@ void SpectatorThink(entity this) TRANSMUTE(Observer, this); PutClientInServer(this); } - this.impulse = 0; + CS(this).impulse = 0; } else if (PHYS_INPUT_BUTTON_ATCK2(this)) { this.flags &= ~FL_JUMPRELEASED; TRANSMUTE(Observer, this); @@ -2408,7 +2408,7 @@ void PlayerPreThink (entity this) if (time > this.respawn_time) { STAT(RESPAWN_TIME, this) = this.respawn_time = time + 1; // only retry once a second respawn(this); - this.impulse = CHIMPULSE_SPEEDRUN.impulse; + CS(this).impulse = CHIMPULSE_SPEEDRUN.impulse; } } else { if (frametime) player_anim(this); @@ -2727,7 +2727,7 @@ void PlayerPostThink (entity this) DrownPlayer(this); CheckRules_Player(this); UpdateChatBubble(this); - if (this.impulse) ImpulseCommands(this); + if (CS(this).impulse) ImpulseCommands(this); if (game_stopped) { CSQCMODEL_AUTOUPDATE(this); @@ -2745,3 +2745,41 @@ void PlayerPostThink (entity this) CSQCMODEL_AUTOUPDATE(this); } + +// hack to copy the button fields from the client entity to the Client State +void PM_UpdateButtons(entity this) +{ + if(this.impulse) + CS(this).impulse = this.impulse; + this.impulse = 0; + + CS(this).button0 = this.button0; + CS(this).button2 = this.button2; + CS(this).button3 = this.button3; + CS(this).button4 = this.button4; + CS(this).button5 = this.button5; + CS(this).button6 = this.button6; + CS(this).button7 = this.button7; + CS(this).button8 = this.button8; + CS(this).button9 = this.button9; + CS(this).button10 = this.button10; + CS(this).button11 = this.button11; + CS(this).button12 = this.button12; + CS(this).button13 = this.button13; + CS(this).button14 = this.button14; + CS(this).button15 = this.button15; + CS(this).button16 = this.button16; + CS(this).buttonuse = this.buttonuse; + CS(this).buttonchat = this.buttonchat; + + CS(this).cursor_active = this.cursor_active; + CS(this).cursor_screen = this.cursor_screen; + CS(this).cursor_trace_start = this.cursor_trace_start; + CS(this).cursor_trace_endpos = this.cursor_trace_endpos; + CS(this).cursor_trace_ent = this.cursor_trace_ent; + + // TODO: ping? + + CS(this).v_angle = this.v_angle; + CS(this).movement = this.movement; +} diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index eb33c89b4..e444f7129 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -29,6 +29,37 @@ CLASS(Client, Object) /** the string "HMAC-SHA256" if signing, and string_null if plaintext */ ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod); + // engine client fields + ATTRIB(Client, impulse, int, this.impulse); + + ATTRIB(Client, button0, int, this.button0); + ATTRIB(Client, button2, int, this.button2); + ATTRIB(Client, button3, int, this.button3); + ATTRIB(Client, button4, int, this.button4); + ATTRIB(Client, button5, int, this.button5); + ATTRIB(Client, button6, int, this.button6); + ATTRIB(Client, button7, int, this.button7); + ATTRIB(Client, button8, int, this.button8); + ATTRIB(Client, button9, int, this.button9); + ATTRIB(Client, button10, int, this.button10); + ATTRIB(Client, button11, int, this.button11); + ATTRIB(Client, button12, int, this.button12); + ATTRIB(Client, button13, int, this.button13); + ATTRIB(Client, button14, int, this.button14); + ATTRIB(Client, button15, int, this.button15); + ATTRIB(Client, button16, int, this.button16); + ATTRIB(Client, buttonuse, int, this.buttonuse); + ATTRIB(Client, buttonchat, int, this.buttonchat); + + ATTRIB(Client, cursor_active, int, this.cursor_active); + ATTRIB(Client, cursor_screen, vector, this.cursor_screen); + ATTRIB(Client, cursor_trace_start, vector, this.cursor_trace_start); + ATTRIB(Client, cursor_trace_endpos, vector, this.cursor_trace_endpos); + ATTRIB(Client, cursor_trace_ent, entity, this.cursor_trace_ent); + + ATTRIB(Client, v_angle, vector, this.v_angle); + ATTRIB(Client, movement, vector, this.movement); + // custom ATTRIB(Client, playerid, int, this.playerid); diff --git a/qcsrc/server/impulse.qc b/qcsrc/server/impulse.qc index c6e3911a1..d9036dea5 100644 --- a/qcsrc/server/impulse.qc +++ b/qcsrc/server/impulse.qc @@ -352,9 +352,9 @@ void ImpulseCommands(entity this) { if (game_stopped) return; - int imp = this.impulse; + int imp = CS(this).impulse; if (!imp) return; - this.impulse = 0; + CS(this).impulse = 0; if (MinigameImpulse(this, imp)) return; diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index 638b40f65..7ccb2a30b 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -599,7 +599,7 @@ void MapVote_Tick() if(it.health != 2342) { it.health = 2342; - it.impulse = 0; + CS(it).impulse = 0; msg_entity = it; WriteByte(MSG_ONE, SVC_FINALE); @@ -610,13 +610,13 @@ void MapVote_Tick() if ( !(mapvote_maps_flags[it.mapvote-1] & GTV_AVAILABLE) ) it.mapvote = 0; // use impulses as new vote - if(it.impulse >= 1 && it.impulse <= mapvote_count) - if( mapvote_maps_flags[it.impulse - 1] & GTV_AVAILABLE ) + if(CS(it).impulse >= 1 && CS(it).impulse <= mapvote_count) + if( mapvote_maps_flags[CS(it).impulse - 1] & GTV_AVAILABLE ) { - it.mapvote = it.impulse; + it.mapvote = CS(it).impulse; MapVote_TouchVotes(it); } - it.impulse = 0; + CS(it).impulse = 0; if(it.mapvote) ++totalvotes; diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index 595671882..253a07e72 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -994,7 +994,7 @@ void ctf_FlagThink(entity this) this.health = 0; ctf_CheckFlagReturn(this, RETURN_SPEEDRUN); - this.owner.impulse = CHIMPULSE_SPEEDRUN.impulse; // move the player back to the waypoint they set + CS(this.owner).impulse = CHIMPULSE_SPEEDRUN.impulse; // move the player back to the waypoint they set ImpulseCommands(this.owner); } if(autocvar_g_ctf_stalemate) -- 2.39.2