cvar_cmd_list.txt
来自「quake1 dos源代码最新版本」· 文本 代码 · 共 142 行
TXT
142 行
================================================================
Title : Tutorial: Implementing CMDLIST and CVARLIST commands into the Quake engine
Date : 2000-09-18
Filename : CVAR_CMD_LIST.TXT
Author : Matthias "Maddes" Buecher
Email Address : maddes@go.to
Homepage : Quake Info Pool
http://www.quake-info-pool.net/
Quake Standards Group (short QSG)
http://www.quakesource.org/
Complexity : Low
================================================================
Introduction
============
You all know the commands "cmdlist" and "cvarlist" from Quake II and Quake 3
Arena, which are lacking in Classic Quake. This tutorial will show you how to
add them.
How to implement CMDLIST and CVARLIST commands
==============================================
For "cmdlist" we need a new function in CMD.C, which you should add before all
other functions. It is based on the existing functions Cmd_Exists() and
Cmd_CompleteCommand(), it loops through the linked list of all commands. If a
parameter is stated, it also compares the beginning of the command with it, so
"cmdlist cl" displays only client variables.
You shouldn't have any problems to understand as there's no special logic in it.
// 2000-01-09 CmdList command by Maddes start
/*
========
Cmd_List
========
*/
void Cmd_List_f (void)
{
cmd_function_t *cmd;
int i;
char *partial;
int len;
int count;
if (Cmd_Argc() > 1)
{
partial = Cmd_Argv (1);
len = strlen(partial);
}
else
{
partial = NULL;
len = 0;
}
count=0;
for (cmd=cmd_functions, i=0 ; cmd ; cmd=cmd->next, i++)
{
if (partial && Q_strncasecmp (partial, cmd->name, len))
{
continue;
}
Con_Printf ("%s\n", cmd->name);
count++;
}
Con_Printf ("------------\n");
if (partial)
{
Con_Printf ("%i beginning with \"%s\" out of ", count, partial);
}
Con_Printf ("%i commands\n", i);
}
// 2000-01-09 CmdList command by Maddes end
At last you have to give the function a corresponding command, here "cmdlist".
Add the following line at the end of Cmd_Init() and "cmdlist" is fully implemented.
Cmd_AddCommand ("cmdlist", Cmd_List_f); // 2000-01-09 CmdList command by Maddes
Nearly the same is done for "cvarlist", just add the following function to CVAR.C.
It works the same way as it does for "cmdlist".
// 2000-01-09 CvarList command by Maddes start
/*
=========
Cvar_List_f
=========
*/
void Cvar_List_f (void)
{
cvar_t *var;
int i;
char *partial;
int len;
int count;
if (Cmd_Argc() > 1)
{
partial = Cmd_Argv (1);
len = strlen(partial);
}
else
{
partial = NULL;
len = 0;
}
count=0;
for (var=cvar_vars, i=0 ; var ; var=var->next, i++)
{
if (partial && Q_strncasecmp (partial, var->name, len))
{
continue;
}
Con_Printf ("\"%s\" is \"%s\"\n", var->name, var->string);
count++;
}
Con_Printf ("------------\n");
if (partial)
{
Con_Printf ("%i beginning with \"%s\" out of ", count, partial);
}
Con_Printf ("%i variables\n", i);
}
// 2000-01-09 CvarList command by Maddes end
Add the following line at the end of Cmd_Init() in CMD.C.
Cmd_AddCommand ("cvarlist", Cvar_List_f); // 2000-01-09 CvarList command by Maddes
The only difference to "cmdlist" is that this function is defined in CVAR.C and
referenced in CMD.C, so we have to declare it in CVAR.H.
(What a lovely example for the difference between definition and declaration, isn't it? :)
void Cvar_List_f (void); // 2000-01-09 CvarList command by Maddes
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?