This was working in div0-stable and was removed in
46acef5491629d06eddb8e78ed01e50b175d2bd8
Due to previous improvements by LH & Cloudwalk, the behaviour is now better:
the new QC command appears in the console in addition to the engine one,
the new command takes priority and what's going on is clearer.
When the CSQC VM shuts down, the registered command is removed.
Also this time we can has documentation.
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
static void VM_CL_registercmd (prvm_prog_t *prog)
{
VM_SAFEPARMCOUNT(1, VM_CL_registercmd);
- if(!Cmd_Exists(cmd_local, PRVM_G_STRING(OFS_PARM0)))
- Cmd_AddCommand(CF_CLIENT, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
+ Cmd_AddCommand(CF_CLIENT, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
}
//#360 float() readbyte (EXT_CSQC)
}
}
-
func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t));
func->flags = flags;
func->name = cmd_name;
func->qcfunc = true; //[515]: csqc
func->next = cmd->userdefined->qc_functions;
+ // bones_was_here: if this QC command overrides an engine command, store its pointer
+ // to avoid doing this search at invocation if QC declines to handle this command.
+ for (cmd_function_t *f = cmd->engine_functions; f; f = f->next)
+ {
+ if (!strcmp(cmd_name, f->name))
+ {
+ Con_DPrintf("Adding QC override of engine command %s\n", cmd_name);
+ func->overridden = f;
+ break;
+ }
+ }
+
// insert it at the right alphanumeric position
for (prev = NULL, current = cmd->userdefined->qc_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next)
;
if(((func->flags & CF_CLIENT) && CL_VM_ConsoleCommand(text)) ||
((func->flags & CF_SERVER) && SV_VM_ConsoleCommand(text)))
return true;
+
+ if (func->overridden) // If this QC command overrides an engine command,
+ func = func->overridden; // fall back to that command.
}
if (func->flags & CF_SERVER_FROM_CLIENT)
{
const char *description;
xcommand_t function;
qbool qcfunc;
+ struct cmd_function_s *overridden; // the engine cmd overriden by this QC cmd, if applicable
qbool autofunc;
qbool initstate; // indicates this command existed at init
} cmd_function_t;
//extension to search_begin (DP_QC_FS_SEARCH), performs a filename search with the specified pattern (for example "maps/*.bsp") and stores the results in a search slot (minimum of 128 supported by any engine with this extension), the other functions take this returned search slot number, be sure to search_free when done (they are also freed on progs reload).
//only searches for files within the specified packfile, which is expected to match the results of whichpack().
-//EXT_CSQC (registercommand for SSQC)
+//EXT_CSQC (registercommand for CSQC, now also available in SVQC)
//idea: probably Spoike
//darkplaces implementation: Cloudwalk
//builtin definitions:
void(string cmdname) registercommand = #352;
+//engine-called QC prototypes:
+//float CSQC_ConsoleCommand(string command);
+//float ConsoleCmd(string command);
//description:
-//the registercommand builtin but the server can use it
+//Adds a new console command which will take priority over a previous command of the same name (including engine commands) and in CSQC is removed when the VM shuts down. This will call CSQC_ConsoleCommand(string command) or ConsoleCmd(string command) in SVQC. Return value should be true if QC handled the command, otherwise return false to have the engine handle it.
+
float(float dividend, float divisor) mod = #245;
static void VM_M_registercommand(prvm_prog_t *prog)
{
VM_SAFEPARMCOUNT(1, VM_M_registercommand);
- if(!Cmd_Exists(cmd_local, PRVM_G_STRING(OFS_PARM0)))
- Cmd_AddCommand(CF_CLIENT, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
+ Cmd_AddCommand(CF_CLIENT, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
}
prvm_builtin_t vm_m_builtins[] = {
static void VM_SV_registercommand (prvm_prog_t *prog)
{
VM_SAFEPARMCOUNT(1, VM_SV_registercmd);
- if(!Cmd_Exists(cmd_local, PRVM_G_STRING(OFS_PARM0)))
- Cmd_AddCommand(CF_SERVER, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
+ Cmd_AddCommand(CF_SERVER, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
}
//PF_setpause, // void(float pause) setpause = #531;