From 00cf2725823ace6efc2040b71841cfab52a132e1 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 15 Jan 2012 18:10:06 +0100 Subject: [PATCH] add a gamecommand "nextframe" to help automate map screenshots --- commands.cfg | 3 ++- qcsrc/client/Main.qc | 3 ++- qcsrc/client/View.qc | 2 ++ qcsrc/client/command/cl_cmd.qc | 2 +- qcsrc/common/command/generic.qc | 21 +++++++++++++++++++++ qcsrc/common/command/generic.qh | 2 +- qcsrc/common/util.qc | 20 ++++++++++++++++++++ qcsrc/common/util.qh | 4 ++++ qcsrc/menu/menu.qc | 2 ++ qcsrc/server/sv_main.qc | 2 ++ 10 files changed, 57 insertions(+), 4 deletions(-) diff --git a/commands.cfg b/commands.cfg index 1f7e68458..b23a1e847 100644 --- a/commands.cfg +++ b/commands.cfg @@ -53,6 +53,7 @@ alias who "qc_cmd_svcmd who ${* ?}" // Displa alias addtolist "qc_cmd_svmenu addtolist ${* ?}" // Add a string to a cvar alias dumpcommands "qc_cmd_svmenu dumpcommands ${* ?}" // Dump all commands on the program to *_cmd_dump.txt alias maplist "qc_cmd_svmenu maplist ${* ?}" // Automatic control of maplist +alias nextframe "qc_cmd_svmenu nextframe ${* ?}" // do something next frame alias removefromlist "qc_cmd_svmenu removefromlist ${* ?}" // Remove a string from a cvar alias rpn "qc_cmd_svmenu rpn ${* ?}" // RPN calculator //alias settemp "qc_cmd_svmenu settemp ${* ?}" // Temporarily set a value to a cvar which is restored later @@ -289,4 +290,4 @@ alias vdoend "vdo endmatch" // rcon server commands // ====================== rcon_secure 1 -set rcon_restricted_commands "restart fraglimit chmap gotomap endmatch reducematchtime extendmatchtime allready kick kickban \"sv_cmd bans\" \"sv_cmd unban *\" status \"sv_cmd teamstatus\" movetoauto movetored movetoblue movetoyellow movetopink" \ No newline at end of file +set rcon_restricted_commands "restart fraglimit chmap gotomap endmatch reducematchtime extendmatchtime allready kick kickban \"sv_cmd bans\" \"sv_cmd unban *\" status \"sv_cmd teamstatus\" movetoauto movetored movetoblue movetoyellow movetopink" diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index 8facbf500..81c1369a0 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -787,7 +787,8 @@ void Gamemode_Init() { if not(isdemo()) { - localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n"); + if(!(calledhooks & HOOK_START)) + localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n"); calledhooks |= HOOK_START; } } diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index 5ab52d5f1..afccaf45d 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -372,6 +372,8 @@ void CSQC_UpdateView(float w, float h) vector vf_size, vf_min; float a; + execute_next_frame(); + ++framecount; hud = getstati(STAT_HUD); diff --git a/qcsrc/client/command/cl_cmd.qc b/qcsrc/client/command/cl_cmd.qc index 95032dce7..638b7f996 100644 --- a/qcsrc/client/command/cl_cmd.qc +++ b/qcsrc/client/command/cl_cmd.qc @@ -524,4 +524,4 @@ float CSQC_ConsoleCommand(string command) // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it. return FALSE; -} \ No newline at end of file +} diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 8cf7f5aa5..01660ba62 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -208,6 +208,26 @@ void GenericCommand_maplist(float request, float argc) } } +void GenericCommand_nextframe(float request, float arguments, string command) +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + queue_to_execute_next_frame(substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); + return; + } + + default: + case CMD_REQUEST_USAGE: + { + print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " command...")); + print(" Where command will be executed next frame of this VM\n"); + return; + } + } +} + void GenericCommand_removefromlist(float request, float argc) { switch(request) @@ -334,6 +354,7 @@ void GenericCommand_(float request) GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "Add a string to a cvar") \ GENERIC_COMMAND("dumpcommands", GenericCommand_dumpcommands(request), "Dump all commands on the program to *_cmd_dump.txt") \ GENERIC_COMMAND("maplist", GenericCommand_maplist(request, arguments), "Automatic control of maplist") \ + GENERIC_COMMAND("nextframe", GenericCommand_nextframe(request, arguments, command), "Execute the given command next frame of this VM") \ GENERIC_COMMAND("removefromlist", GenericCommand_removefromlist(request, arguments), "Remove a string from a cvar") \ GENERIC_COMMAND("rpn", GenericCommand_rpn(request, arguments, command), "RPN calculator") \ GENERIC_COMMAND("settemp", GenericCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \ diff --git a/qcsrc/common/command/generic.qh b/qcsrc/common/command/generic.qh index 3078a0f05..6fa7d3822 100644 --- a/qcsrc/common/command/generic.qh +++ b/qcsrc/common/command/generic.qh @@ -14,4 +14,4 @@ string GetProgramCommandPrefix(void); // used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file #define CMD_Write(s) fputs(fh, s) #define CMD_Write_Alias(execute,command,description) CMD_Write(sprintf("alias %-20s \"%-13s %-20s ${* ?}\" // %s\n", command, execute, command, description)) -void GenericCommand_macro_write_aliases(float fh); \ No newline at end of file +void GenericCommand_macro_write_aliases(float fh); diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 57e653113..09a58c099 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2212,3 +2212,23 @@ float ReadApproxPastTime() return servertime - dt; } #endif + +string to_execute_next_frame; +void execute_next_frame() +{ + if(to_execute_next_frame) + { + localcmd("\n", to_execute_next_frame, "\n"); + strunzone(to_execute_next_frame); + to_execute_next_frame = string_null; + } +} +void queue_to_execute_next_frame(string s) +{ + if(to_execute_next_frame) + { + s = strcat(s, "\n", to_execute_next_frame); + strunzone(to_execute_next_frame); + } + to_execute_next_frame = strzone(s); +} diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 4b0526815..485e190b9 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -297,3 +297,7 @@ void WriteApproxPastTime(float dst, float t); #ifdef CSQC float ReadApproxPastTime(); #endif + +// execute-stuff-next-frame subsystem +void execute_next_frame(); +void queue_to_execute_next_frame(string s); diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 536295fc2..c097f99b9 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -616,6 +616,8 @@ void m_draw() float t; float realFrametime; + execute_next_frame(); + menuMouseMode = cvar("menu_mouse_absolute"); if (anim) diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index 73c444afe..66579bc9c 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -151,6 +151,8 @@ float RedirectionThink(); entity SelectSpawnPoint (float anypoint); void StartFrame (void) { + execute_next_frame(); + remove = remove_unsafely; // not during spawning! serverprevtime = servertime; servertime = time; -- 2.39.2