]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Handle impulse command in client code TimePath/client_impulse
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 1 Apr 2018 06:09:30 +0000 (16:09 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 1 Apr 2018 06:09:30 +0000 (16:09 +1000)
qcsrc/client/commands/_mod.inc
qcsrc/client/commands/_mod.qh
qcsrc/client/commands/cl_cmd.qc
qcsrc/client/commands/impulse.qc [new file with mode: 0644]
qcsrc/client/commands/impulse.qh [new file with mode: 0644]
qcsrc/client/view.qc

index dcfc6ecea56e94103c08ae21a99997bf815dff72..86929ebcc5e1053bb0f66c4917e8274fc2fea2ad 100644 (file)
@@ -2,3 +2,4 @@
 #ifdef CSQC
     #include <client/commands/cl_cmd.qc>
 #endif
+#include <client/commands/impulse.qc>
index 7829965a2350f0bb075fd0431447aabe030f7d57..4b038d5df9dd5f720205390cddb6232d8ae96e73 100644 (file)
@@ -2,3 +2,4 @@
 #ifdef CSQC
     #include <client/commands/cl_cmd.qh>
 #endif
+#include <client/commands/impulse.qh>
index 8faf0f387b6ccd33103cbfd825dec2692a7ac760..e0ea3e53478d3f41974fdd705784c4817a50910c 100644 (file)
@@ -5,7 +5,7 @@
 // ==============================================
 
 #include <common/command/_mod.qh>
-#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 (file)
index 0000000..f081835
--- /dev/null
@@ -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 (file)
index 0000000..bd41cf5
--- /dev/null
@@ -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();
index dd184bee9bbeb7d8dfcf3f5eb75abf7337d330b5..530d8fe023be82ecfbfd55f4810e066fdb49a815 100644 (file)
@@ -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