ebfs.txt
来自「quake1 dos源代码最新版本」· 文本 代码 · 共 895 行 · 第 1/3 页
TXT
895 行
i = -newf->first_statement;
if (i >= pr_numbuiltins)
PR_RunError ("Bad builtin call number");
pr_builtins[i] ();
break;
}
... into ...
if (newf->first_statement < 0)
{ // negative statements are built in functions
i = -newf->first_statement;
// 2001-09-14 Enhanced BuiltIn Function System (EBFS) by Maddes start
if ( (i >= pr_numbuiltins)
|| (pr_builtins[i] == pr_ebfs_builtins[0].function) )
{
funcname = pr_strings + newf->s_name;
if (pr_builtin_remap.value)
{
remaphint = NULL;
}
else
{
remaphint = "Try \"builtin remapping\" by setting PR_BUILTIN_REMAP to 1\n";
}
PR_RunError ("Bad builtin call number %i for %s\nPlease contact the PROGS.DAT author\nUse BUILTINLIST to see all assigned builtin functions\n%s", i, funcname, remaphint);
}
// 2001-09-14 Enhanced BuiltIn Function System (EBFS) by Maddes end
pr_builtins[i] ();
break;
}
A nice addition is the new command "builtinlist", which lists all builtin functions
with their numbers and names.
In PR_EDICT.C before PR_Init() add the following function...
// 2001-09-14 Enhanced BuiltIn Function System (EBFS) by Maddes start
/*
=============
PR_BuiltInList_f
For debugging, prints all builtin functions with assigned and default number
=============
*/
void PR_BuiltInList_f (void)
{
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 (i=1; i < pr_ebfs_numbuiltins; i++)
{
if (partial && Q_strncasecmp (partial, pr_ebfs_builtins[i].funcname, len))
{
continue;
}
count++;
Con_Printf ("%i(%i): %s\n", pr_ebfs_builtins[i].funcno, pr_ebfs_builtins[i].default_funcno, pr_ebfs_builtins[i].funcname);
}
Con_Printf ("------------\n");
if (partial)
{
Con_Printf ("%i beginning with \"%s\" out of ", count, partial);
}
Con_Printf ("%i builtin functions\n", i);
}
// 2001-09-14 Enhanced BuiltIn Function System (EBFS) by Maddes end
Then add this function as a command in PR_Init() with the following line...
Cmd_AddCommand ("builtinlist", PR_BuiltInList_f); // 2001-09-14 Enhanced BuiltIn Function System (EBFS) by Maddes
Now recompile the engine.
Last but not least, do not forget to document the EBFS in your readme and add
the file "How_to_use_EBFS_in_QuakeC.txt" to your engine documentation. This way
QuakeC coders will know how to use EBFS with your engine.
Download the textfile here. (Bram: place download link from above here again)
Part III - Rules for registering new builtin functions to the QSG list
======================================================================
If you want to implement a new builtin function it is highly recommended to
check out the existing builtin functions on the QSG homepage before. If the
functionality you are going to create is not listed, then start coding and give
it a dummy function number of 9999 (and counting downwards for others).
If you are done and have tested thoroughly, create a short tutorial for this
function (similar to part IV) and register your function on the QSG homepage.
Please include your name, email address (for questions), a description and the
short tutorial. When your function is registered you will get it's real function
number.
Part IV - Four examples of implementing new builtin functions with EBFS
========================================================================
a) The function is called "cmd_find" and it checks if an engine command is
available. The return value is 1 if the command exists, otherwise it is 0.
In PR_CMDS.C add the following code anywhere before the builtin variables...
// 2001-09-16 New BuiltIn Function: cmd_find() by Maddes start
/*
=================
PF_cmd_find
float cmd_find (string)
=================
*/
void PF_cmd_find (void)
{
char *cmdname;
float result;
cmdname = G_STRING(OFS_PARM0);
result = Cmd_Exists (cmdname);
G_FLOAT(OFS_RETURN) = result;
}
// 2001-09-16 New BuiltIn Function: cmd_find() by Maddes end
... and to the EBFS data array add ...
{ 101, "cmd_find", PF_cmd_find }, // 2001-09-16 New BuiltIn Function: cmd_find() by Maddes
Done.
b) The function is called "cvar_find" and checks if a console variable is
available. The return value is 1 if the cvar exists, otherwise it is 0.
In PR_CMDS.C add the following code anywhere before the builtin variables...
// 2001-09-16 New BuiltIn Function: cvar_find() by Maddes start
/*
=================
PF_cvar_find
float cvar_find (string)
=================
*/
void PF_cvar_find (void)
{
char *varname;
float result;
varname = G_STRING(OFS_PARM0);
result = 0;
if (Cvar_FindVar (varname))
{
result = 1;
}
G_FLOAT(OFS_RETURN) = result;
}
// 2001-09-16 New BuiltIn Function: cvar_find() by Maddes end
... and to the EBFS data array add ...
{ 102, "cvar_find", PF_cvar_find }, // 2001-09-16 New BuiltIn Function: cvar_find() by Maddes
Done.
c) The function is called "cvar_string" and returns the string of a console
variable.
In PR_CMDS.C add the following code anywhere before the builtin variables...
// 2001-09-16 New BuiltIn Function: cvar_string() by Maddes start
/*
=================
PF_cvar_string
string cvar_string (string)
=================
*/
void PF_cvar_string (void)
{
char *varname;
cvar_t *var;
varname = G_STRING(OFS_PARM0);
var = Cvar_FindVar (varname);
if (!var)
{
Con_DPrintf ("Cvar_String: variable \"%s\" not found\n", varname); // 2001-09-09 Made 'Cvar not found' a developer message by Maddes
G_INT(OFS_RETURN) = OFS_NULL;
}
else
{
G_INT(OFS_RETURN) = var->string - pr_strings;
}
}
// 2001-09-16 New BuiltIn Function: cvar_string() by Maddes end
... and to the EBFS data array add ...
{ 103, "cvar_string", PF_cvar_string }, // 2001-09-16 New BuiltIn Function: cvar_string() by Maddes
Done.
d) The function is called "WriteFloat" and is the missing Write function.
In PR_CMDS.C add the following code anywhere before the builtin variables...
// 2001-09-16 New BuiltIn Function: WriteFloat() by Maddes start
/*
PF_WriteFloat
void (float to, float f) WriteFloat
*/
void PF_WriteFloat (void)
{
MSG_WriteFloat (WriteDest(), G_FLOAT(OFS_PARM1));
}
// 2001-09-16 New BuiltIn Function: WriteFloat() by Maddes end
... and to the EBFS data array add ...
{ 107, "WriteFloat", PF_WriteFloat }, // 2001-09-16 New BuiltIn Function: WriteFloat() by Maddes
Done.
You see it it is very easy to add your own builtin functions to the system.
If you do have new builtin functions then check out the previous part how to
submit them to the QSG.
Part V - Activating some useful builtin functions of the preliminary Quake 2 code
===================================================================================
There are some simple but useful builtin functions done for the preliminary
Quake 2 code: sin, cos, sqrt and etos.
First you have to activate the code for Classic Quake.
Remove the "#ifdef QUAKE2" before and the "#endif" behind PF_etos().
Before PF_sin() place the following line...
#endif // 2001-09-16 Quake 2 builtin functions: sin, cos, sqrt, etos by id/Maddes
... and remove the "#endif" behind PF_sqrt().
At last replace the following in the EBFS data array...
#ifdef QUAKE2
{ 60, "sin", PF_sin },
{ 61, "cos", PF_cos },
{ 62, "sqrt", PF_sqrt },
{ 63, "changepitch", PF_changepitch },
{ 64, "TraceToss", PF_TraceToss },
{ 65, "etos", PF_etos },
{ 66, "WaterMove", PF_WaterMove },
#endif
... with ...
// 2001-09-16 Quake 2 builtin functions: sin, cos, sqrt, etos by id/Maddes start
{ 60, "sin", PF_sin },
{ 61, "cos", PF_cos },
{ 62, "sqrt", PF_sqrt },
#ifdef QUAKE2
{ 63, "changepitch", PF_changepitch },
{ 64, "TraceToss", PF_TraceToss },
#endif
{ 65, "etos", PF_etos },
#ifdef QUAKE2
{ 66, "WaterMove", PF_WaterMove },
#endif
// 2001-09-16 Quake 2 builtin functions: sin, cos, sqrt, etos by id/Maddes end
Done.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?