From 98b9d996f8c012b5d48eb7213c81d812c92535d0 Mon Sep 17 00:00:00 2001 From: Samual Date: Tue, 8 Nov 2011 14:23:07 -0500 Subject: [PATCH] Much more work with CSQC gamecommand.qc, plus other fixes/tweaks elsewhere --- qcsrc/client/Main.qc | 3 + qcsrc/client/gamecommand.qc | 322 +++++++++++++++++--------------- qcsrc/server/cl_weaponsystem.qc | 2 - qcsrc/server/clientcommands.qc | 12 +- 4 files changed, 176 insertions(+), 163 deletions(-) diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index a4f118371..aa511f377 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -21,6 +21,7 @@ float __engine_check; string forcefog; void WaypointSprite_Load(); +void ConsoleCommand_macro_init(); void CSQC_Init(void) { prvm_language = cvar_string("prvm_language"); @@ -63,6 +64,8 @@ void CSQC_Init(void) //registercmd("hud_configure"); //registercmd("hud_save"); //registercmd("menu_action"); + + ConsoleCommand_macro_init(); registercvar("hud_usecsqc", "1"); registercvar("scoreboard_columns", "default", CVAR_SAVE); diff --git a/qcsrc/client/gamecommand.qc b/qcsrc/client/gamecommand.qc index 4b23fe2f3..15fb2f3c4 100644 --- a/qcsrc/client/gamecommand.qc +++ b/qcsrc/client/gamecommand.qc @@ -1,6 +1,21 @@ -// -------------------------------------------------------------------------- -// BEGIN REQUIRED CSQC FUNCTIONS -//include "main.qh" +// ============================================== +// CSQC client commands code, written by Samual +// Last updated: November 8th, 2011 +// ============================================== + +#define GC_REQUEST_COMMAND 1 +#define GC_REQUEST_USAGE 2 + +void Cmd_HUD_SetFields(float); +void Cmd_HUD_Help(float); + +.vector view_ofs; +entity debug_shotorg; + + +// ============================ +// Misc. Supporting Functions +// ============================ void cvar_clientsettemp(string cv, string val) { @@ -12,7 +27,7 @@ void cvar_clientsettemp(string cv, string val) e.classname = "saved_cvar_value"; e.netname = strzone(cv); e.message = strzone(cvar_string(cv)); -:saved + :saved cvar_set(cv, val); } @@ -22,9 +37,6 @@ void cvar_clientsettemp_restore() for(e = world; (e = find(e, classname, "saved_cvar_value")); ) cvar_set(e.netname, e.message); } - -.vector view_ofs; -entity debug_shotorg; void ShotOrg_Draw() { self.origin = view_origin + view_forward * self.view_ofs_x + view_right * self.view_ofs_y + view_up * self.view_ofs_z; @@ -88,170 +100,170 @@ void DrawDebugModel() self.drawmask = MASK_NORMAL; } } -void Cmd_HUD_SetFields(float); -void Cmd_HUD_Help(float); -void GameCommand(string msg) -{ - string s; - float argc; - entity e; - argc = tokenize_console(msg); - if(argv(0) == "help" || argc == 0) - { - print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n")); - print(_(" settemp cvar value\n")); - print(_(" scoreboard_columns_set ...\n")); - print(_(" scoreboard_columns_help\n")); - GameCommand_Generic("help"); - return; - } - if(GameCommand_Generic(msg)) - return; +// ======================= +// Command Sub-Functions +// ======================= - if(strCmd == "hud_configure") { // config hud - cvar_set("_hud_configure", ftos(!autocvar__hud_configure)); - return true; - } else if(strCmd == "hud_save") { // save hud config - if(argv(1) == "" || argv(2)) { - print(_("Usage:\n")); - print(_("hud_save configname (saves to hud_skinname_configname.cfg)\n")); +void GameCommand_blurtest(float request) +{ + // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now... + // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command. + + #ifdef BLURTEST + switch(request) + { + case GC_REQUEST_COMMAND: + { + blurtest_time0 = time; + blurtest_time1 = time + stof(argv(1)); + blurtest_radius = stof(argv(2)); + blurtest_power = stof(argv(3)); + print("Enabled blurtest\n"); + return; + } + + default: + case GC_REQUEST_USAGE: + { + print("\nUsage:^3 cl_cmd blurtest\n"); + print(" No arguments required.\n"); + return; } - else - HUD_Panel_ExportCfg(argv(1)); - return true; - - string cmd; - cmd = argv(0); - if(cmd == "mv_download") { - Cmd_MapVote_MapDownload(argc); } - else if(cmd == "hud_panel_radar_maximized") + #else + if(request) { - if(argc == 1) - hud_panel_radar_maximized = !hud_panel_radar_maximized; - else - hud_panel_radar_maximized = (stof(argv(1)) != 0); - } - else if(cmd == "settemp") { - cvar_clientsettemp(argv(1), argv(2)); - } - else if(cmd == "scoreboard_columns_set") { - Cmd_HUD_SetFields(argc); - } - else if(cmd == "scoreboard_columns_help") { - Cmd_HUD_Help(argc); - } -#ifdef BLURTEST - else if(cmd == "blurtest") { - blurtest_time0 = time; - blurtest_time1 = time + stof(argv(1)); - blurtest_radius = stof(argv(2)); - blurtest_power = stof(argv(3)); - } -#endif - else if(cmd == "shotorg_move") { - if(!debug_shotorg) - ShotOrg_Spawn(); - else - debug_shotorg.view_ofs = debug_shotorg.view_ofs + stov(argv(1)); - localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n"); - } - else if(cmd == "shotorg_movez") { - if(!debug_shotorg) - ShotOrg_Spawn(); - else - debug_shotorg.view_ofs = debug_shotorg.view_ofs + stof(argv(1)) * (debug_shotorg.view_ofs * (1 / debug_shotorg.view_ofs_x)); // closer/farther, same xy pos - localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n"); - } - else if(cmd == "shotorg_set") { - if(!debug_shotorg) - ShotOrg_Spawn(); - else - debug_shotorg.view_ofs = stov(argv(1)); - localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n"); - } - else if(cmd == "shotorg_setz") { - if(!debug_shotorg) - ShotOrg_Spawn(); - else - debug_shotorg.view_ofs = debug_shotorg.view_ofs * (stof(argv(1)) / debug_shotorg.view_ofs_x); // closer/farther, same xy pos - localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n"); + print("Blurtest is not enabled on this client.\n"); + return; } - else if(cmd == "shotorg_toggle_hide") { - if(debug_shotorg) + #endif +} + +void GameCommand_hud(float request, float argc) +{ + switch(request) + { + case GC_REQUEST_COMMAND: { - debug_shotorg.cnt = !debug_shotorg.cnt; + + return; } - } - else if(cmd == "shotorg_end") { - if(debug_shotorg) + + default: + case GC_REQUEST_USAGE: { - print(vtos(debug_shotorg.view_ofs), "\n"); - remove(debug_shotorg); - debug_shotorg = world; + print("\nUsage:^3 cl_cmd hud TODO\n"); + print(" No arguments required.\n"); + return; } - localcmd("sv_cmd debug_shotorg\n"); - } - else if(cmd == "sendcvar") { - // W_FixWeaponOrder will trash argv, so save what we need. - string thiscvar; - thiscvar = strzone(argv(1)); - s = cvar_string(thiscvar); - if(thiscvar == "cl_weaponpriority") - s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1); - else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18) - s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0); - localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n"); - strunzone(thiscvar); } - else if(cmd == "spawn") { - s = argv(1); - e = spawn(); - precache_model(s); - setmodel(e, s); - setorigin(e, view_origin); - e.angles = view_angles; - e.draw = DrawDebugModel; - e.classname = "debugmodel"; - } - else if(cmd == "vyes") - { - if(uid2name_dialog) - { - vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos) - vote_prev = 0; - localcmd("setreport cl_allow_uid2name 1\n"); - vote_change = -9999; - uid2name_dialog = 0; - } - else - { - localcmd("cmd vote yes\n"); - } - } - else if(cmd == "vno") - { - if(uid2name_dialog) - { - vote_active = 0; - vote_prev = 0; - localcmd("setreport cl_allow_uid2name 0\n"); - vote_change = -9999; - uid2name_dialog = 0; - } - else - { - localcmd("cmd vote no\n"); - } - } +} - else +/* use this when creating a new command, making sure to place it in alphabetical order. +void GameCommand_(float request) +{ + switch(request) { - print("Invalid command. For a list of supported commands, try cl_cmd help.\n"); + case GC_REQUEST_COMMAND: + { + + return; + } + + default: + case GC_REQUEST_USAGE: + { + print("\nUsage:^3 cl_cmd \n"); + print(" No arguments required.\n"); + return; + } } +} +*/ + + +// ================================== +// Macro system for client commands +// ================================== + +// Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) +#define CLIENT_COMMANDS(request,arguments) \ + CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \ + CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \ + /* nothing */ + +void GameCommand_macro_help() +{ + #define CLIENT_COMMAND(name,function,description) \ + { print(" ^2", name, "^7: ", description, "\n"); } + + CLIENT_COMMANDS(0, 0) + #undef CLIENT_COMMAND + + return; +} + +float GameCommand_macro_command(float argc) +{ + #define CLIENT_COMMAND(name,function,description) \ + { if(name == strtolower(argv(0))) { function; return TRUE; } } + + CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc) + #undef CLIENT_COMMAND + + return FALSE; +} + +float GameCommand_macro_usage(float argc) +{ + #define CLIENT_COMMAND(name,function,description) \ + { if(name == strtolower(argv(1))) { function; return TRUE; } } + + CLIENT_COMMANDS(GC_REQUEST_USAGE, argc) + #undef CLIENT_COMMAND + + return FALSE; +} + + +// ========================================= +// Main Function Called By Engine (cl_cmd) +// ========================================= +// If this function exists, client code handles gamecommand instead of the engine code. + +void GameCommand(string command) +{ + float argc = tokenize_console(command); + if(strtolower(argv(0)) == "help") + { + if(argc == 1) + { + print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n"); + GameCommand_macro_help(); + GameCommand_Generic("help"); + print("For help about specific commands, type cl_cmd help COMMAND\n"); + return; + } + else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it + { + return; + } + } + else if(GameCommand_Generic(command)) + { + return; // handled by common/gamecommand.qc + } + else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands + { + return; // handled by one of the above GameCommand_* functions + } + + // nothing above caught the command, must be invalid + print("Invalid command. For a list of supported commands, try cl_cmd help.\n"); + return; } diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index 4acb8da89..7ce62e5b8 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -185,8 +185,6 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m vecs = ent.weaponentity.movedir; else vecs = '0 0 0'; - if(debug_shotorg != '0 0 0') - vecs = debug_shotorg; dv = v_right * -vecs_y + v_up * vecs_z; w_shotorg = ent.origin + ent.view_ofs + dv; diff --git a/qcsrc/server/clientcommands.qc b/qcsrc/server/clientcommands.qc index f0e582688..74b501eb5 100644 --- a/qcsrc/server/clientcommands.qc +++ b/qcsrc/server/clientcommands.qc @@ -1,7 +1,7 @@ -// ======================================================= -// Server side client commands code, reworked by Samual +// ========================================================= +// Server side networked commands code, reworked by Samual // Last updated: November 8th, 2011 -// ======================================================= +// ========================================================= #define CC_REQUEST_COMMAND 1 #define CC_REQUEST_USAGE 2 @@ -838,9 +838,9 @@ void ClientCommand_(float request) */ -// =========================== -// Macro system for commands -// =========================== +// ===================================== +// Macro system for networked commands +// ===================================== // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) #define CLIENT_COMMANDS(request,arguments,command) \ -- 2.39.2