From: TimePath Date: Sun, 1 Apr 2018 06:09:30 +0000 (+1000) Subject: Handle impulse command in client code X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f4480adff6b6b4411a75226fb36417bcd5de1b57;p=xonotic%2Fxonotic-data.pk3dir.git Handle impulse command in client code --- diff --git a/qcsrc/client/commands/_mod.inc b/qcsrc/client/commands/_mod.inc index dcfc6ecea..86929ebcc 100644 --- a/qcsrc/client/commands/_mod.inc +++ b/qcsrc/client/commands/_mod.inc @@ -2,3 +2,4 @@ #ifdef CSQC #include #endif +#include diff --git a/qcsrc/client/commands/_mod.qh b/qcsrc/client/commands/_mod.qh index 7829965a2..4b038d5df 100644 --- a/qcsrc/client/commands/_mod.qh +++ b/qcsrc/client/commands/_mod.qh @@ -2,3 +2,4 @@ #ifdef CSQC #include #endif +#include diff --git a/qcsrc/client/commands/cl_cmd.qc b/qcsrc/client/commands/cl_cmd.qc index 8faf0f387..e0ea3e534 100644 --- a/qcsrc/client/commands/cl_cmd.qc +++ b/qcsrc/client/commands/cl_cmd.qc @@ -5,7 +5,7 @@ // ============================================== #include -#include "cl_cmd.qh" +#include "impulse.qh" #include "../autocvars.qh" #include "../defs.qh" @@ -655,6 +655,9 @@ bool CSQC_ConsoleCommand(string command) { int argc = tokenize_console(command); string s = strtolower(argv(0)); + if (s == "impulse" && impulse_handle(argv(1))) { + return true; + } // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it. return ConsoleCommand_macro_normal(s, argc) || ConsoleCommand_macro_movement(s, argc) diff --git a/qcsrc/client/commands/impulse.qc b/qcsrc/client/commands/impulse.qc new file mode 100644 index 000000000..f08183561 --- /dev/null +++ b/qcsrc/client/commands/impulse.qc @@ -0,0 +1,34 @@ +#include "impulse.qh" + +STATIC_INIT(impulse) { + registercommand("impulse"); +} + +string impulse_sentinel = "!"; + +bool impulse_handle(string arg) +{ + // taking advantage of atoi's behaviour in the engine to ignore non-digits to prevent re-entry + if (endsWith(arg, impulse_sentinel)) { + // pass to engine + return false; + } + int req = stoi(arg); + switch (req) { + default: { + impulse_var = req; + break; + } + } + return true; +} + +void impulse_set(int value) +{ + localcmd(sprintf("impulse %d%s\n", value, impulse_sentinel)); +} + +void impulse_frame_end() +{ + impulse_set(impulse_var); +} diff --git a/qcsrc/client/commands/impulse.qh b/qcsrc/client/commands/impulse.qh new file mode 100644 index 000000000..bd41cf55f --- /dev/null +++ b/qcsrc/client/commands/impulse.qh @@ -0,0 +1,10 @@ +#pragma once + +/** impulse is an extra byte sent in input packets */ +int impulse_var; + +bool impulse_handle(string arg); + +void impulse_set(int value); + +void impulse_frame_end(); diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index dd184bee9..530d8fe02 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1,11 +1,12 @@ #include "view.qh" -#include "autocvars.qh" -#include "miscfunctions.qh" #include "announcer.qh" -#include "hud/_mod.qh" +#include "autocvars.qh" #include "mapvoting.qh" +#include "miscfunctions.qh" #include "shownames.qh" +#include "commands/impulse.qh" +#include "hud/_mod.qh" #include "hud/panel/scoreboard.qh" #include "hud/panel/quickmenu.qh" @@ -2438,6 +2439,7 @@ void CSQC_UpdateView(entity this, float w, float h) cl_notice_run(); unpause_update(); + impulse_frame_end(); Net_Flush(); // let's reset the view back to normal for the end