move to using a hash table for builtin number -> builtin lookup so sparse

ranges can be used efficiently. move the auto-allocated builtins to
0x10000000-0x7fffffff. should be more than enough :)

use static builtin tables ("nul" terminated) instead of a series of
function calls to add builtins to a vm. should be more memory efficient.
This commit is contained in:
Bill Currie 2004-01-06 05:51:09 +00:00
parent a87fc16d12
commit acd54afff7
23 changed files with 620 additions and 526 deletions

View File

@ -210,8 +210,9 @@ const char *PR_GlobalStringNoContents (progs_t *pr, int ofs, etype_t type);
pr_type_t *GetEdictFieldValue(progs_t *pr, edict_t *ed, const char *field);
void PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num);
void PR_RegisterBuiltins (progs_t *pr, builtin_t *builtins);
builtin_t *PR_FindBuiltin (progs_t *pr, const char *name);
builtin_t *PR_FindBuiltinNum (progs_t *pr, int num);
int PR_RelocateBuiltins (progs_t *pr);
int PR_ResolveGlobals (progs_t *pr);
@ -313,6 +314,9 @@ struct progs_s {
int zone_size;
struct hashtab_s *builtin_hash;
struct hashtab_s *builtin_num_hash;
unsigned bi_next;
struct hashtab_s *function_hash;
struct hashtab_s *global_hash;
struct hashtab_s *field_hash;
@ -378,9 +382,6 @@ struct progs_s {
void *(*allocate_progs_mem)(progs_t *pr, int size);
void (*free_progs_mem)(progs_t *pr, void *mem);
builtin_t **builtins;
int numbuiltins;
pr_resource_t *resources;
struct hashtab_s *resource_hash;

View File

@ -414,6 +414,28 @@ menu_load_file (progs_t *pr, const char *path)
return QFS_LoadFile (path, 0);
}
static builtin_t builtins[] = {
{"Menu_Begin", bi_Menu_Begin, -1},
{"Menu_FadeScreen", bi_Menu_FadeScreen, -1},
{"Menu_Draw", bi_Menu_Draw, -1},
{"Menu_EnterHook", bi_Menu_EnterHook, -1},
{"Menu_LeaveHook", bi_Menu_LeaveHook, -1},
{"Menu_Pic", bi_Menu_Pic, -1},
{"Menu_SubPic", bi_Menu_SubPic, -1},
{"Menu_CenterPic", bi_Menu_CenterPic, -1},
{"Menu_CenterSubPic", bi_Menu_CenterSubPic, -1},
{"Menu_Item", bi_Menu_Item, -1},
{"Menu_Cursor", bi_Menu_Cursor, -1},
{"Menu_KeyEvent", bi_Menu_KeyEvent, -1},
{"Menu_End", bi_Menu_End, -1},
{"Menu_TopMenu", bi_Menu_TopMenu, -1},
{"Menu_SelectMenu", bi_Menu_SelectMenu, -1},
{"Menu_SetQuit", bi_Menu_SetQuit, -1},
{"Menu_Quit", bi_Menu_Quit, -1},
{"Menu_GetIndex", bi_Menu_GetIndex, -1},
{0},
};
void
Menu_Init (void)
{
@ -426,24 +448,7 @@ Menu_Init (void)
menu_hash = Hash_NewTable (61, menu_get_key, menu_free, 0);
PR_AddBuiltin (&menu_pr_state, "Menu_Begin", bi_Menu_Begin, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_FadeScreen", bi_Menu_FadeScreen, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Draw", bi_Menu_Draw, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_EnterHook", bi_Menu_EnterHook, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_LeaveHook", bi_Menu_LeaveHook, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Pic", bi_Menu_Pic, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_SubPic", bi_Menu_SubPic, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_CenterPic", bi_Menu_CenterPic, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_CenterSubPic", bi_Menu_CenterSubPic, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Item", bi_Menu_Item, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Cursor", bi_Menu_Cursor, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_KeyEvent", bi_Menu_KeyEvent, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_End", bi_Menu_End, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_TopMenu", bi_Menu_TopMenu, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_SelectMenu", bi_Menu_SelectMenu, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_SetQuit", bi_Menu_SetQuit, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Quit", bi_Menu_Quit, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_GetIndex", bi_Menu_GetIndex, -1);
PR_RegisterBuiltins (&menu_pr_state, builtins);
PR_Obj_Progs_Init (&menu_pr_state);

View File

@ -102,16 +102,20 @@ bi_cbuf_clear (progs_t *pr, void *data)
{
}
static builtin_t builtins[] = {
{"Cbuf_AddText", bi_Cbuf_AddText, -1},
{"Cbuf_InsertText", bi_Cbuf_InsertText, -1},
{"Cbuf_Execute", bi_Cbuf_Execute, -1},
{"Cbuf_Execute_Sets", bi_Cbuf_Execute_Sets, -1},
{0}
};
void
Cbuf_Progs_Init (progs_t *pr)
{
cbuf_resources_t *res = calloc (sizeof (cbuf_resources_t), 1);
PR_Resources_Register (pr, "Cbuf", res, bi_cbuf_clear);
PR_AddBuiltin (pr, "Cbuf_AddText", bi_Cbuf_AddText, -1);
PR_AddBuiltin (pr, "Cbuf_InsertText", bi_Cbuf_InsertText, -1);
PR_AddBuiltin (pr, "Cbuf_Execute", bi_Cbuf_Execute, -1);
PR_AddBuiltin (pr, "Cbuf_Execute_Sets", bi_Cbuf_Execute_Sets, -1);
PR_RegisterBuiltins (pr, builtins);
}
void

View File

@ -147,6 +147,14 @@ bi_Cmd_Args (progs_t *pr)
//Cmd_ExecuteString
//Cmd_ForwardToServer
static builtin_t builtins[] = {
{"Cmd_AddCommand", bi_Cmd_AddCommand, -1},
{"Cmd_Argc", bi_Cmd_Argc, -1},
{"Cmd_Argv", bi_Cmd_Argv, -1},
{"Cmd_Args", bi_Cmd_Args, -1},
{0}
};
void
Cmd_Progs_Init (progs_t *pr)
{
@ -157,8 +165,5 @@ Cmd_Progs_Init (progs_t *pr)
bi_cmds = Hash_NewTable (1021, bi_cmd_get_key, bi_cmd_free, 0);
PR_AddBuiltin (pr, "Cmd_AddCommand", bi_Cmd_AddCommand, -1);
PR_AddBuiltin (pr, "Cmd_Argc", bi_Cmd_Argc, -1);
PR_AddBuiltin (pr, "Cmd_Argv", bi_Cmd_Argv, -1);
PR_AddBuiltin (pr, "Cmd_Args", bi_Cmd_Args, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -56,8 +56,13 @@ bi_Cvar_GetCvarString (progs_t *pr)
RETURN_STRING (pr, Cvar_VariableString (varname));
}
static builtin_t builtins[] = {
{"Cvar_GetCvarString", bi_Cvar_GetCvarString, -1},
{0}
};
void
Cvar_Progs_Init (progs_t *pr)
{
PR_AddBuiltin (pr, "Cvar_GetCvarString", bi_Cvar_GetCvarString, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -173,8 +173,13 @@ error:
R_INT (pr) = 0;
}
static builtin_t builtins[] = {
{"File_Open", bi_File_Open, -1},
{0}
};
void
File_Progs_Init (progs_t *pr)
{
PR_AddBuiltin (pr, "File_Open", bi_File_Open, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -176,6 +176,15 @@ bi_GIB_Handle_Get (progs_t *pr)
// R_INT (pr) = 0;
}
static builtin_t builtins[] = {
{"GIB_Builtin_Add", bi_GIB_Builtin_Add, -1},
{"GIB_Return", bi_GIB_Return, -1},
{"GIB_Handle_New", bi_GIB_Handle_New, -1},
{"GIB_Handle_Free", bi_GIB_Handle_Free, -1},
{"GIB_Handle_Get", bi_GIB_Handle_Get, -1},
{0}
};
void
GIB_Progs_Init (progs_t *pr)
{
@ -184,11 +193,8 @@ GIB_Progs_Init (progs_t *pr)
PR_Resources_Register (pr, "GIB", res, bi_gib_builtin_clear);
bi_gib_builtins = Hash_NewTable (1021, bi_gib_builtin_get_key, bi_gib_builtin_free, 0);
bi_gib_builtins = Hash_NewTable (1021, bi_gib_builtin_get_key,
bi_gib_builtin_free, 0);
PR_AddBuiltin (pr, "GIB_Builtin_Add", bi_GIB_Builtin_Add, -1);
PR_AddBuiltin (pr, "GIB_Return", bi_GIB_Return, -1);
PR_AddBuiltin (pr, "GIB_Handle_New", bi_GIB_Handle_New, -1);
PR_AddBuiltin (pr, "GIB_Handle_Free", bi_GIB_Handle_Free, -1);
PR_AddBuiltin (pr, "GIB_Handle_Get", bi_GIB_Handle_Get, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -303,6 +303,27 @@ bi_hash_clear (progs_t *pr, void *data)
res->tabs = 0;
}
static builtin_t builtins[] = {
{"Hash_NewTable", bi_Hash_NewTable, -1},
{"Hash_SetHashCompare", bi_Hash_SetHashCompare, -1},
{"Hash_DelTable", bi_Hash_DelTable, -1},
{"Hash_FlushTable", bi_Hash_FlushTable, -1},
{"Hash_Add", bi_Hash_Add, -1},
{"Hash_AddElement", bi_Hash_AddElement, -1},
{"Hash_Find", bi_Hash_Find, -1},
{"Hash_FindElement", bi_Hash_FindElement, -1},
{"Hash_FindList", bi_Hash_FindList, -1},
{"Hash_FindElementList", bi_Hash_FindElementList, -1},
{"Hash_Del", bi_Hash_Del, -1},
{"Hash_DelElement", bi_Hash_DelElement, -1},
{"Hash_Free", bi_Hash_Free, -1},
{"Hash_String", bi_Hash_String, -1},
{"Hash_Buffer", bi_Hash_Buffer, -1},
{"Hash_GetList", bi_Hash_GetList, -1},
{"Hash_Stats", bi_Hash_Stats, -1},
{0}
};
void
Hash_Progs_Init (progs_t *pr)
{
@ -310,21 +331,5 @@ Hash_Progs_Init (progs_t *pr)
res->tabs = 0;
PR_Resources_Register (pr, "Hash", res, bi_hash_clear);
PR_AddBuiltin (pr, "Hash_NewTable", bi_Hash_NewTable, -1);
PR_AddBuiltin (pr, "Hash_SetHashCompare", bi_Hash_SetHashCompare, -1);
PR_AddBuiltin (pr, "Hash_DelTable", bi_Hash_DelTable, -1);
PR_AddBuiltin (pr, "Hash_FlushTable", bi_Hash_FlushTable, -1);
PR_AddBuiltin (pr, "Hash_Add", bi_Hash_Add, -1);
PR_AddBuiltin (pr, "Hash_AddElement", bi_Hash_AddElement, -1);
PR_AddBuiltin (pr, "Hash_Find", bi_Hash_Find, -1);
PR_AddBuiltin (pr, "Hash_FindElement", bi_Hash_FindElement, -1);
PR_AddBuiltin (pr, "Hash_FindList", bi_Hash_FindList, -1);
PR_AddBuiltin (pr, "Hash_FindElementList", bi_Hash_FindElementList, -1);
PR_AddBuiltin (pr, "Hash_Del", bi_Hash_Del, -1);
PR_AddBuiltin (pr, "Hash_DelElement", bi_Hash_DelElement, -1);
PR_AddBuiltin (pr, "Hash_Free", bi_Hash_Free, -1);
PR_AddBuiltin (pr, "Hash_String", bi_Hash_String, -1);
PR_AddBuiltin (pr, "Hash_Buffer", bi_Hash_Buffer, -1);
PR_AddBuiltin (pr, "Hash_GetList", bi_Hash_GetList, -1);
PR_AddBuiltin (pr, "Hash_Stats", bi_Hash_Stats, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -224,6 +224,19 @@ bi_il_clear (progs_t *pr, void *data)
}
}
static builtin_t builtins[] = {
{"InputLine_Create", bi_InputLine_Create, -1},
{"InputLine_SetUserData", bi_InputLine_SetUserData, -1},
{"InputLine_SetWidth", bi_InputLine_SetWidth, -1},
{"InputLine_SetText", bi_InputLine_SetText, -1},
{"InputLine_GetText", bi_InputLine_GetText, -1},
{"InputLine_Destroy", bi_InputLine_Destroy, -1},
{"InputLine_Clear", bi_InputLine_Clear, -1},
{"InputLine_Process", bi_InputLine_Process, -1},
{"InputLine_Draw", bi_InputLine_Draw, -1},
{0}
};
void
InputLine_Progs_Init (progs_t *pr)
{
@ -232,16 +245,7 @@ InputLine_Progs_Init (progs_t *pr)
res->lines = calloc (sizeof (inputline_t *), res->max_lines);
PR_Resources_Register (pr, "InputLine", res, bi_il_clear);
PR_AddBuiltin (pr, "InputLine_Create", bi_InputLine_Create, -1);
PR_AddBuiltin (pr, "InputLine_SetUserData",
bi_InputLine_SetUserData, -1);
PR_AddBuiltin (pr, "InputLine_SetWidth", bi_InputLine_SetWidth, -1);
PR_AddBuiltin (pr, "InputLine_SetText", bi_InputLine_SetText, -1);
PR_AddBuiltin (pr, "InputLine_GetText", bi_InputLine_GetText, -1);
PR_AddBuiltin (pr, "InputLine_Destroy", bi_InputLine_Destroy, -1);
PR_AddBuiltin (pr, "InputLine_Clear", bi_InputLine_Clear, -1);
PR_AddBuiltin (pr, "InputLine_Process", bi_InputLine_Process, -1);
PR_AddBuiltin (pr, "InputLine_Draw", bi_InputLine_Draw, -1);
PR_RegisterBuiltins (pr, builtins);
}
void

View File

@ -169,6 +169,20 @@ plist_compare (void *k1, void *k2, void *unused)
return k1 == k2;
}
static builtin_t builtins[] = {
{"PL_GetPropertyList", bi_PL_GetPropertyList, -1},
{"PL_ObjectForKey", bi_PL_ObjectForKey, -1},
{"PL_ObjectAtIndex", bi_PL_ObjectAtIndex, -1},
{"PL_D_AddObject", bi_PL_D_AddObject, -1},
{"PL_A_AddObject", bi_PL_A_AddObject, -1},
{"PL_A_InsertObjectAtIndex", bi_PL_A_InsertObjectAtIndex, -1},
{"PL_NewDictionary", bi_PL_NewDictionary, -1},
{"PL_NewArray", bi_PL_NewArray, -1},
// {"PL_NewData", bi_PL_NewData, -1},
{"PL_NewString", bi_PL_NewString, -1},
{0}
};
void
Plist_Progs_Init (progs_t *pr)
{
@ -177,14 +191,5 @@ Plist_Progs_Init (progs_t *pr)
Hash_SetHashCompare (res->items, plist_get_hash, plist_compare);
PR_Resources_Register (pr, "plist", res, bi_plist_clear);
PR_AddBuiltin (pr, "PL_GetPropertyList", bi_PL_GetPropertyList, -1);
PR_AddBuiltin (pr, "PL_ObjectForKey", bi_PL_ObjectForKey, -1);
PR_AddBuiltin (pr, "PL_ObjectAtIndex", bi_PL_ObjectAtIndex, -1);
PR_AddBuiltin (pr, "PL_D_AddObject", bi_PL_D_AddObject, -1);
PR_AddBuiltin (pr, "PL_A_AddObject", bi_PL_A_AddObject, -1);
PR_AddBuiltin (pr, "PL_A_InsertObjectAtIndex", bi_PL_A_InsertObjectAtIndex, -1);
PR_AddBuiltin (pr, "PL_NewDictionary", bi_PL_NewDictionary, -1);
PR_AddBuiltin (pr, "PL_NewArray", bi_PL_NewArray, -1);
//PR_AddBuiltin (pr, "PL_NewData", bi_PL_NewData, -1);
PR_AddBuiltin (pr, "PL_NewString", bi_PL_NewString, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -268,6 +268,37 @@ bi_Qfilesize (progs_t *pr)
R_INT (pr) = Qfilesize (*h);
}
static builtin_t secure_builtins[] = {
{"Qrename", secured, -1},
{"Qremove", secured, -1},
{"Qopen", secured, -1},
{0}
};
static builtin_t insecure_builtins[] = {
{"Qrename", bi_Qrename, -1},
{"Qremove", bi_Qremove, -1},
{"Qopen", bi_Qopen, -1},
{0}
};
static builtin_t builtins[] = {
{"Qclose", bi_Qclose, -1},
{"Qgetline", bi_Qgetline, -1},
{"Qread", bi_Qread, -1},
{"Qwrite", bi_Qwrite, -1},
{"Qputs", bi_Qputs, -1},
// {"Qgets", bi_Qgets, -1},
{"Qgetc", bi_Qgetc, -1},
{"Qputc", bi_Qputc, -1},
{"Qseek", bi_Qseek, -1},
{"Qtell", bi_Qtell, -1},
{"Qflush", bi_Qflush, -1},
{"Qeof", bi_Qeof, -1},
{"Qfilesize", bi_Qfilesize, -1},
{0}
};
void
QFile_Progs_Init (progs_t *pr, int secure)
{
@ -275,25 +306,9 @@ QFile_Progs_Init (progs_t *pr, int secure)
PR_Resources_Register (pr, "QFile", res, bi_qfile_clear);
if (secure) {
PR_AddBuiltin (pr, "Qrename", secured, -1);
PR_AddBuiltin (pr, "Qremove", secured, -1);
PR_AddBuiltin (pr, "Qopen", secured, -1);
PR_RegisterBuiltins (pr, secure_builtins);
} else {
PR_AddBuiltin (pr, "Qrename", bi_Qrename, -1);
PR_AddBuiltin (pr, "Qremove", bi_Qremove, -1);
PR_AddBuiltin (pr, "Qopen", bi_Qopen, -1);
PR_RegisterBuiltins (pr, insecure_builtins);
}
PR_AddBuiltin (pr, "Qclose", bi_Qclose, -1);
PR_AddBuiltin (pr, "Qgetline", bi_Qgetline, -1);
PR_AddBuiltin (pr, "Qread", bi_Qread, -1);
PR_AddBuiltin (pr, "Qwrite", bi_Qwrite, -1);
PR_AddBuiltin (pr, "Qputs", bi_Qputs, -1);
// PR_AddBuiltin (pr, "Qgets", bi_Qgets, -1);
PR_AddBuiltin (pr, "Qgetc", bi_Qgetc, -1);
PR_AddBuiltin (pr, "Qputc", bi_Qputc, -1);
PR_AddBuiltin (pr, "Qseek", bi_Qseek, -1);
PR_AddBuiltin (pr, "Qtell", bi_Qtell, -1);
PR_AddBuiltin (pr, "Qflush", bi_Qflush, -1);
PR_AddBuiltin (pr, "Qeof", bi_Qeof, -1);
PR_AddBuiltin (pr, "Qfilesize", bi_Qfilesize, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -116,11 +116,16 @@ bi_QFS_WriteFile (progs_t *pr)
QFS_WriteFile (va ("%s/%s", qfs_gamedir->dir.def, filename), buf, count);
}
static builtin_t builtins[] = {
{"QFS_Rename", bi_QFS_Rename, -1},
{"QFS_LoadFile", bi_QFS_LoadFile, -1},
{"QFS_OpenFile", bi_QFS_OpenFile, -1},
{"QFS_WriteFile", bi_QFS_WriteFile, -1},
{0}
};
void
QFS_Progs_Init (progs_t *pr)
{
PR_AddBuiltin (pr, "QFS_Rename", bi_QFS_Rename, -1);
PR_AddBuiltin (pr, "QFS_LoadFile", bi_QFS_LoadFile, -1);
PR_AddBuiltin (pr, "QFS_OpenFile", bi_QFS_OpenFile, -1);
PR_AddBuiltin (pr, "QFS_WriteFile", bi_QFS_WriteFile, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -626,16 +626,11 @@ static builtin_t builtins[] = {
{"stoi", PF_stoi, 113},
{"stov", PF_stov, 114},
{"gametype", PR_gametype, 115},
{0}
};
void
PR_Cmds_Init (progs_t *pr)
{
int i;
builtin_t *bi;
for (i = 0; i < sizeof (builtins) / sizeof (builtins[0]); i++) {
bi = builtins + i;
PR_AddBuiltin (pr, bi->name, bi->proc, bi->binum);
}
};
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -54,52 +54,82 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "compat.h"
/*
Builtins are arranged into groups of 65536 to allow for diffent expantion
sets. eg, stock id is 0x0000xxxx, quakeforge is 0x000fxxxx. predefined
groups go up to 0x0fffxxxx allowing 4096 different groups. Builtins
0x10000000 to 0x7fffffff are reserved for auto-allocation. The range
0x8000000 to 0xffffffff is unavailable due to the builtin number being
a negative statement address.
*/
#define PR_AUTOBUILTIN 0x10000000
static const char *
builtin_get_key (void *_bi, void *unused)
{
builtin_t *bi = (builtin_t *)_bi;
return bi->name;
}
#define PR_AUTOBUILTIN 120
void
PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num)
static unsigned long
builtin_get_hash (void *_bi, void *unused)
{
int i;
builtin_t *bi = (builtin_t *)_bi;
if (!pr->builtin_hash)
return bi->binum;
}
static int
builtin_compare (void *_bia, void *_bib, void *unused)
{
builtin_t *bia = (builtin_t *)_bia;
builtin_t *bib = (builtin_t *)_bib;
return bia->binum == bib->binum;
}
static int
builtin_next (progs_t *pr)
{
if (!pr->bi_next)
pr->bi_next = PR_AUTOBUILTIN;
if (pr->bi_next == 0x80000000)
PR_Error (pr, "too many auto-allocated builtins");
return pr->bi_next++;
}
void
PR_RegisterBuiltins (progs_t *pr, builtin_t *builtins)
{
builtin_t *bi;
if (!pr->builtin_hash) {
pr->builtin_hash = Hash_NewTable (1021, builtin_get_key, 0, pr);
if (pr->numbuiltins == 0) {
pr->builtins = calloc (PR_AUTOBUILTIN, sizeof (builtin_t*));
pr->numbuiltins = PR_AUTOBUILTIN;
if (!pr->builtins)
PR_Error (pr, "PR_AddBuiltin: memory allocation error!");
pr->builtin_num_hash = Hash_NewTable (1021, 0, 0, pr);
Hash_SetHashCompare (pr->builtin_num_hash, builtin_get_hash,
builtin_compare);
}
if (num < 0) {
for (i = PR_AUTOBUILTIN;
i < pr->numbuiltins && pr->builtins[i]; i++)
;
if (i >= pr->numbuiltins) {
pr->numbuiltins++;
pr->builtins = realloc (pr->builtins,
pr->numbuiltins * sizeof (builtin_t*));
if (!pr->builtins)
PR_Error (pr, "PR_AddBuiltin: memory allocation error!");
}
} else {
if (num >= PR_AUTOBUILTIN || num == 0)
PR_Error (pr, "PR_AddBuiltin: invalid builtin number.");
if (pr->builtins[num])
PR_Error (pr, "PR_AddBuiltin: builtin number already exists.");
i = num;
while (builtins->name) {
if (builtins->binum == 0 || builtins->binum >= PR_AUTOBUILTIN)
PR_Error (pr, "bad builtin number: %s = #%d", builtins->name,
builtins->binum);
if (builtins->binum < 0)
builtins->binum = builtin_next (pr);
if ((bi = Hash_Find (pr->builtin_hash, builtins->name))
|| (bi = Hash_FindElement (pr->builtin_num_hash, builtins)))
PR_Error (pr, "builtin %s = #%d already defined (%s = #%d)",
builtins->name, builtins->binum,
bi->name, bi->binum);
Hash_Add (pr->builtin_hash, builtins);
Hash_AddElement (pr->builtin_num_hash, builtins);
builtins++;
}
pr->builtins[i] = malloc (sizeof (builtin_t));
pr->builtins[i]->proc = builtin;
pr->builtins[i]->name = name;
pr->builtins[i]->binum = i;
Hash_Add (pr->builtin_hash, pr->builtins[i]);
}
builtin_t *
@ -108,6 +138,15 @@ PR_FindBuiltin (progs_t *pr, const char *name)
return (builtin_t *) Hash_Find (pr->builtin_hash, name);
}
builtin_t *
PR_FindBuiltinNum (progs_t *pr, int num)
{
builtin_t bi;
bi.binum = num;
return (builtin_t *) Hash_FindElement (pr->builtin_num_hash, &bi);
}
static void
bi_no_function (progs_t *pr)
{
@ -150,9 +189,8 @@ PR_RelocateBuiltins (progs_t *pr)
func->first_statement = -bi->binum;
}
ind = -func->first_statement;
if (ind >= pr->numbuiltins || !(bi = pr->builtins[ind])
|| !(proc = bi->proc)) {
bi = PR_FindBuiltinNum (pr, -func->first_statement);
if (!bi || !(proc = bi->proc)) {
Sys_DPrintf ("WARNING: Bad builtin call number: %s = #%d\n",
bi_name, ind);
proc = bi_no_function;

View File

@ -53,21 +53,16 @@ static __attribute__ ((unused)) const char rcsid[] =
static void
call_function (progs_t *pr, func_t func)
{
dfunction_t *newf;
dfunction_t *f;
if (!func)
PR_RunError (pr, "NULL function");
newf = pr->pr_functions + func;
if (newf->first_statement < 0) {
f = pr->pr_functions + func;
if (f->first_statement < 0) {
// negative statements are built in functions
int i = -newf->first_statement;
if (i >= pr->numbuiltins || !pr->builtins[i]
|| !pr->builtins[i]->proc)
PR_RunError (pr, "Bad builtin call number");
pr->builtins[i]->proc (pr);
((bfunction_t *) f)->func (pr);
} else {
PR_EnterFunction (pr, newf);
PR_EnterFunction (pr, f);
}
}
@ -919,79 +914,73 @@ pr__c_Object__conformsToProtocol_ (progs_t *pr)
//====================================================================
static struct {
const char *name;
void (*func)(progs_t *pr);
} obj_methods [] = {
{"__obj_exec_class", pr___obj_exec_class},
static builtin_t obj_methods [] = {
{"__obj_exec_class", pr___obj_exec_class, -1},
{"obj_error", pr_obj_error},
{"obj_verror", pr_obj_verror},
{"obj_set_error_handler", pr_obj_set_error_handler},
{"obj_msg_lookup", pr_obj_msg_lookup},
{"obj_msg_lookup_super", pr_obj_msg_lookup_super},
{"obj_msg_sendv", pr_obj_msg_sendv},
{"obj_malloc", pr_obj_malloc},
{"obj_atomic_malloc", pr_obj_atomic_malloc},
{"obj_valloc", pr_obj_valloc},
{"obj_realloc", pr_obj_realloc},
{"obj_calloc", pr_obj_calloc},
{"obj_free", pr_obj_free},
{"obj_get_uninstalled_dtable", pr_obj_get_uninstalled_dtable},
{"obj_msgSend", pr_obj_msgSend},
{"obj_msgSend_super", pr_obj_msgSend_super},
{"obj_error", pr_obj_error, -1},
{"obj_verror", pr_obj_verror, -1},
{"obj_set_error_handler", pr_obj_set_error_handler, -1},
{"obj_msg_lookup", pr_obj_msg_lookup, -1},
{"obj_msg_lookup_super", pr_obj_msg_lookup_super, -1},
{"obj_msg_sendv", pr_obj_msg_sendv, -1},
{"obj_malloc", pr_obj_malloc, -1},
{"obj_atomic_malloc", pr_obj_atomic_malloc, -1},
{"obj_valloc", pr_obj_valloc, -1},
{"obj_realloc", pr_obj_realloc, -1},
{"obj_calloc", pr_obj_calloc, -1},
{"obj_free", pr_obj_free, -1},
{"obj_get_uninstalled_dtable", pr_obj_get_uninstalled_dtable, -1},
{"obj_msgSend", pr_obj_msgSend, -1},
{"obj_msgSend_super", pr_obj_msgSend_super, -1},
{"obj_get_class", pr_obj_get_class, -1},
{"obj_lookup_class", pr_obj_lookup_class, -1},
{"obj_next_class", pr_obj_next_class, -1},
{"obj_get_class", pr_obj_get_class},
{"obj_lookup_class", pr_obj_lookup_class},
{"obj_next_class", pr_obj_next_class},
{"sel_get_name", pr_sel_get_name, -1},
{"sel_get_type", pr_sel_get_type, -1},
{"sel_get_uid", pr_sel_get_uid, -1},
{"sel_register_name", pr_sel_register_name, -1},
{"sel_is_mapped", pr_sel_is_mapped, -1},
{"sel_get_name", pr_sel_get_name},
{"sel_get_type", pr_sel_get_type},
{"sel_get_uid", pr_sel_get_uid},
{"sel_register_name", pr_sel_register_name},
{"sel_is_mapped", pr_sel_is_mapped},
{"class_get_class_method", pr_class_get_class_method, -1},
{"class_get_instance_method", pr_class_get_instance_method, -1},
{"class_pose_as", pr_class_pose_as, -1},
{"class_create_instance", pr_class_create_instance, -1},
{"class_get_class_name", pr_class_get_class_name, -1},
{"class_get_instance_size", pr_class_get_instance_size, -1},
{"class_get_meta_class", pr_class_get_meta_class, -1},
{"class_get_super_class", pr_class_get_super_class, -1},
{"class_get_version", pr_class_get_version, -1},
{"class_is_class", pr_class_is_class, -1},
{"class_is_meta_class", pr_class_is_meta_class, -1},
{"class_set_version", pr_class_set_version, -1},
{"class_get_gc_object_type", pr_class_get_gc_object_type, -1},
{"class_ivar_set_gcinvisible", pr_class_ivar_set_gcinvisible, -1},
{"class_get_class_method", pr_class_get_class_method},
{"class_get_instance_method", pr_class_get_instance_method},
{"class_pose_as", pr_class_pose_as},
{"class_create_instance", pr_class_create_instance},
{"class_get_class_name", pr_class_get_class_name},
{"class_get_instance_size", pr_class_get_instance_size},
{"class_get_meta_class", pr_class_get_meta_class},
{"class_get_super_class", pr_class_get_super_class},
{"class_get_version", pr_class_get_version},
{"class_is_class", pr_class_is_class},
{"class_is_meta_class", pr_class_is_meta_class},
{"class_set_version", pr_class_set_version},
{"class_get_gc_object_type", pr_class_get_gc_object_type},
{"class_ivar_set_gcinvisible", pr_class_ivar_set_gcinvisible},
{"method_get_imp", pr_method_get_imp, -1},
{"get_imp", pr_get_imp, -1},
{"method_get_imp", pr_method_get_imp},
{"get_imp", pr_get_imp},
{"object_copy", pr_object_copy, -1},
{"object_dispose", pr_object_dispose, -1},
{"object_get_class", pr_object_get_class, -1},
{"object_get_class_name", pr_object_get_class_name, -1},
{"object_get_meta_class", pr_object_get_meta_class, -1},
{"object_get_super_class", pr_object_get_super_class, -1},
{"object_is_class", pr_object_is_class, -1},
{"object_is_instance", pr_object_is_instance, -1},
{"object_is_meta_class", pr_object_is_meta_class, -1},
{"object_copy", pr_object_copy},
{"object_dispose", pr_object_dispose},
{"object_get_class", pr_object_get_class},
{"object_get_class_name", pr_object_get_class_name},
{"object_get_meta_class", pr_object_get_meta_class},
{"object_get_super_class", pr_object_get_super_class},
{"object_is_class", pr_object_is_class},
{"object_is_instance", pr_object_is_instance},
{"object_is_meta_class", pr_object_is_meta_class},
{"_i_Object__hash", pr__i_Object__hash},
{"_i_Object_error_error_", pr__i_Object_error_error_},
{"_c_Object__conformsToProtocol_", pr__c_Object__conformsToProtocol_},
{"_i_Object__hash", pr__i_Object__hash, -1},
{"_i_Object_error_error_", pr__i_Object_error_error_, -1},
{"_c_Object__conformsToProtocol_", pr__c_Object__conformsToProtocol_, -1},
{0}
};
void
PR_Obj_Progs_Init (progs_t *pr)
{
size_t i;
for (i = 0; i < sizeof (obj_methods) / sizeof (obj_methods[0]); i++) {
PR_AddBuiltin (pr, obj_methods[i].name, obj_methods[i].func, -1);
}
PR_RegisterBuiltins (pr, obj_methods);
}
int

View File

@ -221,6 +221,19 @@ bi_draw_clear (progs_t *pr, void *data)
Hash_FlushTable (res->pic_hash);
}
static builtin_t builtins[] = {
{"Draw_CachePic", bi_Draw_CachePic, -1},
{"Draw_Pic", bi_Draw_Pic, -1},
{"Draw_SubPic", bi_Draw_SubPic, -1},
{"Draw_CenterPic", bi_Draw_CenterPic, -1},
{"Draw_Character", bi_Draw_Character, -1},
{"Draw_String", bi_Draw_String, -1},
{"Draw_nString", bi_Draw_nString, -1},
{"Draw_AltString", bi_Draw_AltString, -1},
{"Draw_Fill", bi_Draw_Fill, -1},
{0}
};
void
R_Progs_Init (progs_t *pr)
{
@ -228,13 +241,5 @@ R_Progs_Init (progs_t *pr)
res->pic_hash = Hash_NewTable (61, bi_draw_get_key, bi_draw_free, 0);
PR_Resources_Register (pr, "Draw", res, bi_draw_clear);
PR_AddBuiltin (pr, "Draw_CachePic", bi_Draw_CachePic, -1);
PR_AddBuiltin (pr, "Draw_Pic", bi_Draw_Pic, -1);
PR_AddBuiltin (pr, "Draw_SubPic", bi_Draw_SubPic, -1);
PR_AddBuiltin (pr, "Draw_CenterPic", bi_Draw_CenterPic, -1);
PR_AddBuiltin (pr, "Draw_Character", bi_Draw_Character, -1);
PR_AddBuiltin (pr, "Draw_String", bi_Draw_String, -1);
PR_AddBuiltin (pr, "Draw_nString", bi_Draw_nString, -1);
PR_AddBuiltin (pr, "Draw_AltString", bi_Draw_AltString, -1);
PR_AddBuiltin (pr, "Draw_Fill", bi_Draw_Fill, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -130,13 +130,17 @@ bi_Key_KeynumToString (progs_t *pr)
RETURN_STRING (pr, Key_KeynumToString (keynum));
};
static builtin_t builtins[] = {
{"Key_SetBinding", bi_Key_SetBinding, -1},
{"Key_LookupBinding", bi_Key_LookupBinding, -1},
{"Key_CountBinding", bi_Key_CountBinding, -1},
{"Key_KeynumToString", bi_Key_KeynumToString, -1},
// NEED THIS ?// {"Key_StringToKeynum", bi_Key_KeynumToString, -1},
{0}
};
void
Key_Progs_Init (progs_t *pr)
{
PR_AddBuiltin (pr, "Key_SetBinding", bi_Key_SetBinding, -1);
PR_AddBuiltin (pr, "Key_LookupBinding", bi_Key_LookupBinding, -1);
PR_AddBuiltin (pr, "Key_CountBinding", bi_Key_CountBinding, -1);
PR_AddBuiltin (pr, "Key_KeynumToString", bi_Key_KeynumToString, -1);
// NEED THIS ?// PR_AddBuiltin (pr, "Key_StringToKeynum", bi_Key_KeynumToString, -1);
PR_RegisterBuiltins (pr, builtins);
}

View File

@ -63,6 +63,7 @@ static __attribute__ ((unused)) const char rcsid[] =
Dumps self.
error (value)
// void (string e) error
*/
void
PF_error (progs_t *pr)
@ -86,6 +87,7 @@ PF_error (progs_t *pr)
removed, but the level can continue.
objerror (value)
// void (string e) objerror
*/
void
PF_objerror (progs_t *pr)
@ -107,7 +109,7 @@ PF_objerror (progs_t *pr)
PF_makevectors
Writes new values for v_forward, v_up, and v_right based on angles
makevectors (vector)
void (entity e) makevectors
*/
void
PF_makevectors (progs_t *pr)
@ -126,6 +128,7 @@ PF_makevectors (progs_t *pr)
teleported.
setorigin (entity, origin)
// void (entity e, vector o) setorigin
*/
void
PF_setorigin (progs_t *pr)
@ -215,6 +218,7 @@ SetMinMaxSize (progs_t *pr, edict_t *e, const vec3_t min, const vec3_t max,
the size box is rotated by the current angle
setsize (entity, minvector, maxvector)
// void (entity e, vector min, vector max) setsize
*/
void
PF_setsize (progs_t *pr)
@ -232,6 +236,7 @@ PF_setsize (progs_t *pr)
PF_setmodel
setmodel (entity, model)
// void (entity e, string m) setmodel
*/
void
PF_setmodel (progs_t *pr)
@ -269,6 +274,7 @@ PF_setmodel (progs_t *pr)
broadcast print to everyone on server
bprint (value)
// void (string s) bprint
*/
void
PF_bprint (progs_t *pr)
@ -285,6 +291,7 @@ PF_bprint (progs_t *pr)
single print to a specific client
sprint (clientent, value)
// void (entity client, string s) sprint
*/
void
PF_sprint (progs_t *pr)
@ -313,6 +320,7 @@ PF_sprint (progs_t *pr)
single print to a specific client
centerprint (clientent, value)
// void (...) centerprint
*/
void
PF_centerprint (progs_t *pr)
@ -335,6 +343,7 @@ PF_centerprint (progs_t *pr)
MSG_WriteString (&cl->message, s);
}
// void (vector o, vector d, float color, float count) particle
void
PF_particle (progs_t *pr)
{
@ -351,6 +360,7 @@ PF_particle (progs_t *pr)
/*
PF_ambientsound
// void (vector pos, string samp, float vol, float atten) ambientsound
*/
void
PF_ambientsound (progs_t *pr)
@ -396,6 +406,7 @@ PF_ambientsound (progs_t *pr)
An attenuation of 0 will play full volume everywhere in the level.
Larger attenuations will drop off.
// void (entity e, float chan, string samp) sound
*/
void
PF_sound (progs_t *pr)
@ -429,6 +440,7 @@ PF_sound (progs_t *pr)
entities if the tryents flag is set.
traceline (vector1, vector2, tryents)
// float (vector v1, vector v2, float tryents) traceline
*/
void
PF_traceline (progs_t *pr)
@ -538,6 +550,7 @@ int c_invis, c_notvis;
it is not returned at all.
name checkclient ()
// entity () clientlist
*/
void
PF_checkclient (progs_t *pr)
@ -579,6 +592,7 @@ PF_checkclient (progs_t *pr)
Sends text over to the client's execution buffer
stuffcmd (clientent, value)
// void (entity client, string s) stuffcmd
*/
void
PF_stuffcmd (progs_t *pr)
@ -604,6 +618,7 @@ PF_stuffcmd (progs_t *pr)
Inserts text into the server console's execution buffer
localcmd (string)
// void (string s) localcmd
*/
void
PF_localcmd (progs_t *pr)
@ -620,6 +635,7 @@ PF_localcmd (progs_t *pr)
Returns a chain of entities that have origins within a spherical area
findradius (origin, radius)
// entity (vector org, float rad) findradius
*/
void
PF_findradius (progs_t *pr)
@ -657,6 +673,7 @@ PF_findradius (progs_t *pr)
RETURN_EDICT (pr, chain);
}
// entity () spawn
void
PF_Spawn (progs_t *pr)
{
@ -666,6 +683,7 @@ PF_Spawn (progs_t *pr)
RETURN_EDICT (pr, ed);
}
// void (entity e) remove
void
PF_Remove (progs_t *pr)
{
@ -682,6 +700,8 @@ PR_CheckEmptyString (progs_t *pr, const char *s)
PR_RunError (pr, "Bad string");
}
// string (string s) precache_file
// string (string s) precache_file2
void
PF_precache_file (progs_t *pr)
{
@ -689,6 +709,8 @@ PF_precache_file (progs_t *pr)
R_INT (pr) = P_INT (pr, 0);
}
// void (string s) precache_sound
// string (string s) precache_sound2
void
PF_precache_sound (progs_t *pr)
{
@ -714,6 +736,8 @@ PF_precache_sound (progs_t *pr)
PR_RunError (pr, "PF_precache_sound: overflow");
}
// void (string s) precache_model
// string (string s) precache_model2
void
PF_precache_model (progs_t *pr)
{
@ -744,6 +768,7 @@ PF_precache_model (progs_t *pr)
PF_walkmove
float (float yaw, float dist) walkmove
// float (float yaw, float dist) walkmove
*/
void
PF_walkmove (progs_t *pr)
@ -784,6 +809,7 @@ PF_walkmove (progs_t *pr)
PF_droptofloor
void () droptofloor
// float () droptofloor
*/
void
PF_droptofloor (progs_t *pr)
@ -815,6 +841,7 @@ PF_droptofloor (progs_t *pr)
PF_lightstyle
void (float style, string value) lightstyle
// void (float style, string value) lightstyle
*/
void
PF_lightstyle (progs_t *pr)
@ -841,6 +868,7 @@ PF_lightstyle (progs_t *pr)
}
}
// float (entity e) checkbottom
void
PF_checkbottom (progs_t *pr)
{
@ -851,6 +879,7 @@ PF_checkbottom (progs_t *pr)
R_FLOAT (pr) = SV_CheckBottom (ent);
}
// float (vector v) pointcontents
void
PF_pointcontents (progs_t *pr)
{
@ -868,6 +897,7 @@ cvar_t *sv_aim;
Pick a vector for the player to shoot along
vector aim (entity, missilespeed)
// vector (entity e, float speed) aim
*/
void
PF_aim (progs_t *pr)
@ -945,6 +975,7 @@ PF_aim (progs_t *pr)
PF_changeyaw
This was a major timewaster in progs, so it was converted to C
// void () ChangeYaw
*/
void
PF_changeyaw (progs_t *pr)
@ -1018,48 +1049,56 @@ WriteDest (progs_t *pr)
return NULL;
}
// void (float to, float f) WriteByte
void
PF_WriteByte (progs_t *pr)
{
MSG_WriteByte (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteChar
void
PF_WriteChar (progs_t *pr)
{
MSG_WriteByte (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteShort
void
PF_WriteShort (progs_t *pr)
{
MSG_WriteShort (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteLong
void
PF_WriteLong (progs_t *pr)
{
MSG_WriteLong (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteAngle
void
PF_WriteAngle (progs_t *pr)
{
MSG_WriteAngle (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteCoord
void
PF_WriteCoord (progs_t *pr)
{
MSG_WriteCoord (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, string s) WriteString
void
PF_WriteString (progs_t *pr)
{
MSG_WriteString (WriteDest (pr), P_GSTRING (pr, 1));
}
// void (float to, entity s) WriteEntity
void
PF_WriteEntity (progs_t *pr)
{
@ -1068,6 +1107,7 @@ PF_WriteEntity (progs_t *pr)
// ============================================================================
// void (entity e) makestatic
void
PF_makestatic (progs_t *pr)
{
@ -1092,6 +1132,7 @@ PF_makestatic (progs_t *pr)
ED_Free (pr, ent);
}
// void (entity e) setspawnparms
void
PF_setspawnparms (progs_t *pr)
{
@ -1111,6 +1152,7 @@ PF_setspawnparms (progs_t *pr)
sv_globals.parms[i] = client->spawn_parms[i];
}
// void (string s) changelevel
void
PF_changelevel (progs_t *pr)
{
@ -1129,6 +1171,7 @@ PF_changelevel (progs_t *pr)
#define MAX_PF_HULLS 64 // FIXME make dynamic?
clip_hull_t *pf_hull_list[MAX_PF_HULLS];
// integer (entity ent, vector point) hullpointcontents
static void
PF_hullpointcontents (progs_t *pr)
{
@ -1144,6 +1187,7 @@ PF_hullpointcontents (progs_t *pr)
R_INT (pr) = SV_HullPointContents (hull, 0, offset);
}
// vector (integer hull, integer max) getboxbounds
static void
PF_getboxbounds (progs_t *pr)
{
@ -1160,6 +1204,7 @@ PF_getboxbounds (progs_t *pr)
}
}
// integer () getboxhull
static void
PF_getboxhull (progs_t *pr)
{
@ -1184,6 +1229,7 @@ PF_getboxhull (progs_t *pr)
}
}
// void (integer hull) freeboxhull
static void
PF_freeboxhull (progs_t *pr)
{
@ -1213,6 +1259,7 @@ calc_dist (vec3_t p, vec3_t n, vec3_t *offsets)
return DotProduct (v, n);
}
// void (integer hull, vector right, vector forward, vector up, vector mins, vector maxs) rotate_bbox
static void
PF_rotate_bbox (progs_t *pr)
{
@ -1297,134 +1344,75 @@ PF_Fixme (progs_t *pr)
PR_RunError (pr, "unimplemented bulitin function called");
}
// float () checkextension
static void
PF_checkextension (progs_t *pr)
{
R_FLOAT (pr) = 0; // FIXME: make this function actually useful
}
static builtin_t builtins[] = {
{"makevectors", PF_makevectors, 1},
{"setorigin", PF_setorigin, 2},
{"setmodel", PF_setmodel, 3},
{"setsize", PF_setsize, 4},
{"fixme", PF_Fixme, 5},
{"sound", PF_sound, 8},
{"error", PF_error, 10},
{"objerror", PF_objerror, 11},
{"spawn", PF_Spawn, 14},
{"remove", PF_Remove, 15},
{"traceline", PF_traceline, 16},
{"checkclient", PF_checkclient, 17},
{"precache_sound", PF_precache_sound, 19},
{"precache_model", PF_precache_model, 20},
{"stuffcmd", PF_stuffcmd, 21},
{"findradius", PF_findradius, 22},
{"bprint", PF_bprint, 23},
{"sprint", PF_sprint, 24},
{"walkmove", PF_walkmove, 32},
{"droptofloor", PF_droptofloor, 34},
{"lightstyle", PF_lightstyle, 35},
{"checkbottom", PF_checkbottom, 40},
{"pointcontents", PF_pointcontents, 41},
{"aim", PF_aim, 44},
{"localcmd", PF_localcmd, 46},
{"particle", PF_particle, 48},
{"changeyaw", PF_changeyaw, 49},
{"writebyte", PF_WriteByte, 52},
{"writechar", PF_WriteChar, 53},
{"writeshort", PF_WriteShort, 54},
{"writelong", PF_WriteLong, 55},
{"writecoord", PF_WriteCoord, 56},
{"writeangle", PF_WriteAngle, 57},
{"writestring", PF_WriteString, 58},
{"writeentity", PF_WriteEntity, 59},
{"movetogoal", SV_MoveToGoal, 67},
{"precache_file", PF_precache_file, 68},
{"makestatic", PF_makestatic, 69},
{"changelevel", PF_changelevel, 70},
{"centerprint", PF_centerprint, 73},
{"ambientsound", PF_ambientsound, 74},
{"precache_model2", PF_precache_model, 75},
{"precache_sound2", PF_precache_sound, 76},
{"precache_file2", PF_precache_file, 77},
{"setspawnparms", PF_setspawnparms, 78},
{"hullpointcontents", PF_hullpointcontents, 93},
{"getboxbounds", PF_getboxbounds, 94},
{"getboxhull", PF_getboxhull, 95},
{"freeboxhull", PF_freeboxhull, 96},
{"rotate_bbox", PF_rotate_bbox, 97},
{"checkextension", PF_checkextension, 99},
{0}
};
void
SV_PR_Cmds_Init ()
{
PR_Cmds_Init (&sv_pr_state);
PR_Obj_Progs_Init (&sv_pr_state);
// void (entity e) makevectors
PR_AddBuiltin (&sv_pr_state, "makevectors", PF_makevectors, 1);
// void (entity e, vector o) setorigin
PR_AddBuiltin (&sv_pr_state, "setorigin", PF_setorigin, 2);
// void (entity e, string m) setmodel
PR_AddBuiltin (&sv_pr_state, "setmodel", PF_setmodel, 3);
// void (entity e, vector min, vector max) setsize
PR_AddBuiltin (&sv_pr_state, "setsize", PF_setsize, 4);
// void (entity e, vector min, vector max) setabssize
PR_AddBuiltin (&sv_pr_state, "fixme", PF_Fixme, 5);
// void (entity e, float chan, string samp) sound
PR_AddBuiltin (&sv_pr_state, "sound", PF_sound, 8);
// void (string e) error
PR_AddBuiltin (&sv_pr_state, "error", PF_error, 10);
// void (string e) objerror
PR_AddBuiltin (&sv_pr_state, "objerror", PF_objerror, 11);
// entity () spawn
PR_AddBuiltin (&sv_pr_state, "spawn", PF_Spawn, 14);
// void (entity e) remove
PR_AddBuiltin (&sv_pr_state, "remove", PF_Remove, 15);
// float (vector v1, vector v2, float tryents) traceline
PR_AddBuiltin (&sv_pr_state, "traceline", PF_traceline, 16);
// entity () clientlist
PR_AddBuiltin (&sv_pr_state, "checkclient", PF_checkclient, 17);
// void (string s) precache_sound
PR_AddBuiltin (&sv_pr_state, "precache_sound", PF_precache_sound, 19);
// void (string s) precache_model
PR_AddBuiltin (&sv_pr_state, "precache_model", PF_precache_model, 20);
// void (entity client, string s) stuffcmd
PR_AddBuiltin (&sv_pr_state, "stuffcmd", PF_stuffcmd, 21);
// entity (vector org, float rad) findradius
PR_AddBuiltin (&sv_pr_state, "findradius", PF_findradius, 22);
// void (string s) bprint
PR_AddBuiltin (&sv_pr_state, "bprint", PF_bprint, 23);
// void (entity client, string s) sprint
PR_AddBuiltin (&sv_pr_state, "sprint", PF_sprint, 24);
// float (float yaw, float dist) walkmove
PR_AddBuiltin (&sv_pr_state, "walkmove", PF_walkmove, 32);
// float () droptofloor
PR_AddBuiltin (&sv_pr_state, "droptofloor", PF_droptofloor, 34);
// void (float style, string value) lightstyle
PR_AddBuiltin (&sv_pr_state, "lightstyle", PF_lightstyle, 35);
// float (entity e) checkbottom
PR_AddBuiltin (&sv_pr_state, "checkbottom", PF_checkbottom, 40);
// float (vector v) pointcontents
PR_AddBuiltin (&sv_pr_state, "pointcontents", PF_pointcontents, 41);
// vector (entity e, float speed) aim
PR_AddBuiltin (&sv_pr_state, "aim", PF_aim, 44);
// void (string s) localcmd
PR_AddBuiltin (&sv_pr_state, "localcmd", PF_localcmd, 46);
// void (vector o, vector d, float color, float count) particle
PR_AddBuiltin (&sv_pr_state, "particle", PF_particle, 48);
// void () ChangeYaw
PR_AddBuiltin (&sv_pr_state, "changeyaw", PF_changeyaw, 49);
// void (float to, float f) WriteByte
PR_AddBuiltin (&sv_pr_state, "writebyte", PF_WriteByte, 52);
// void (float to, float f) WriteChar
PR_AddBuiltin (&sv_pr_state, "writechar", PF_WriteChar, 53);
// void (float to, float f) WriteShort
PR_AddBuiltin (&sv_pr_state, "writeshort", PF_WriteShort, 54);
// void (float to, float f) WriteLong
PR_AddBuiltin (&sv_pr_state, "writelong", PF_WriteLong, 55);
// void (float to, float f) WriteCoord
PR_AddBuiltin (&sv_pr_state, "writecoord", PF_WriteCoord, 56);
// void (float to, float f) WriteAngle
PR_AddBuiltin (&sv_pr_state, "writeangle", PF_WriteAngle, 57);
// void (float to, string s) WriteString
PR_AddBuiltin (&sv_pr_state, "writestring", PF_WriteString, 58);
// void (float to, entity s) WriteEntity
PR_AddBuiltin (&sv_pr_state, "writeentity", PF_WriteEntity, 59);
// void (float step) movetogoal
PR_AddBuiltin (&sv_pr_state, "movetogoal", SV_MoveToGoal, 67);
// string (string s) precache_file
PR_AddBuiltin (&sv_pr_state, "precache_file", PF_precache_file, 68);
// void (entity e) makestatic
PR_AddBuiltin (&sv_pr_state, "makestatic", PF_makestatic, 69);
// void (string s) changelevel
PR_AddBuiltin (&sv_pr_state, "changelevel", PF_changelevel, 70);
// void (...) centerprint
PR_AddBuiltin (&sv_pr_state, "centerprint", PF_centerprint, 73);
// void (vector pos, string samp, float vol, float atten) ambientsound
PR_AddBuiltin (&sv_pr_state, "ambientsound", PF_ambientsound, 74);
// string (string s) precache_model2
PR_AddBuiltin (&sv_pr_state, "precache_model2", PF_precache_model, 75);
// string (string s) precache_sound2
PR_AddBuiltin (&sv_pr_state, "precache_sound2", PF_precache_sound, 76);
// string (string s) precache_file2
PR_AddBuiltin (&sv_pr_state, "precache_file2", PF_precache_file, 77);
// void (entity e) setspawnparms
PR_AddBuiltin (&sv_pr_state, "setspawnparms", PF_setspawnparms, 78);
// integer (entity ent, vector point) hullpointcontents
PR_AddBuiltin (&sv_pr_state, "hullpointcontents", PF_hullpointcontents,
93);
// vector (integer hull, integer max) getboxbounds
PR_AddBuiltin (&sv_pr_state, "getboxbounds", PF_getboxbounds, 94);
// integer () getboxhull
PR_AddBuiltin (&sv_pr_state, "getboxhull", PF_getboxhull, 95);
// void (integer hull) freeboxhull
PR_AddBuiltin (&sv_pr_state, "freeboxhull", PF_freeboxhull, 96);
// void (integer hull, vector right, vector forward, vector up, vector mins, vector maxs) rotate_bbox
PR_AddBuiltin (&sv_pr_state, "rotate_bbox", PF_rotate_bbox, 97);
// float () checkextension
PR_AddBuiltin (&sv_pr_state, "checkextension", PF_checkextension, 99);
PR_RegisterBuiltins (&sv_pr_state, builtins);
}
// void (entity e, vector min, vector max) setabssize
// void (float step) movetogoal

View File

@ -340,8 +340,6 @@ SV_Progs_Init (void)
sv_pr_state.time = &sv.time;
sv_pr_state.reserved_edicts = &svs.maxclients;
sv_pr_state.unlink = SV_UnlinkEdict;
sv_pr_state.builtins = 0;
sv_pr_state.numbuiltins = 0;
sv_pr_state.parse_field = parse_field;
sv_pr_state.prune_edict = prune_edict;

View File

@ -66,6 +66,7 @@ static __attribute__ ((unused)) const char rcsid[] =
Dumps self.
error (value)
// void (string e) error
*/
void
PF_error (progs_t *pr)
@ -89,6 +90,7 @@ PF_error (progs_t *pr)
removed, but the level can continue.
objerror (value)
// void (string e) objerror
*/
void
PF_objerror (progs_t *pr)
@ -111,6 +113,7 @@ PF_objerror (progs_t *pr)
Writes new values for v_forward, v_up, and v_right based on angles
makevectors (vector)
// void (entity e) makevectors
*/
void
PF_makevectors (progs_t *pr)
@ -129,6 +132,7 @@ PF_makevectors (progs_t *pr)
teleported.
setorigin (entity, origin)
// void (entity e, vector o) setorigin
*/
void
PF_setorigin (progs_t *pr)
@ -148,6 +152,7 @@ PF_setorigin (progs_t *pr)
the size box is rotated by the current angle
setsize (entity, minvector, maxvector)
// void (entity e, vector min, vector max) setsize
*/
void
PF_setsize (progs_t *pr)
@ -168,6 +173,7 @@ PF_setsize (progs_t *pr)
PF_setmodel
setmodel(entity, model)
// void (entity e, string m) setmodel
Also sets size, mins, and maxs for inline bmodels
*/
void
@ -208,6 +214,7 @@ PF_setmodel (progs_t *pr)
broadcast print to everyone on server
bprint (value)
// void (string s) bprint
*/
void
PF_bprint (progs_t *pr)
@ -227,6 +234,7 @@ PF_bprint (progs_t *pr)
single print to a specific client
sprint (clientent, value)
// void (entity client, string s) sprint
*/
void
PF_sprint (progs_t *pr)
@ -255,6 +263,7 @@ PF_sprint (progs_t *pr)
/*
PF_centerprint
// void (...) centerprint
single print to a specific client
@ -293,6 +302,7 @@ PF_centerprint (progs_t *pr)
/*
PF_ambientsound
// void (vector pos, string samp, float vol, float atten) ambientsound
*/
void
PF_ambientsound (progs_t *pr)
@ -329,6 +339,7 @@ PF_ambientsound (progs_t *pr)
/*
PF_sound
// void (entity e, float chan, string samp) sound
Each entity can have eight independant sound sources, like voice,
weapon, feet, etc.
@ -364,6 +375,7 @@ PF_sound (progs_t *pr)
entities if the tryents flag is set.
traceline (vector1, vector2, tryents)
// float (vector v1, vector v2, float tryents) traceline
*/
void
PF_traceline (progs_t *pr)
@ -395,10 +407,11 @@ PF_traceline (progs_t *pr)
}
/*
PF_checkmove
PF_checkmove
// void (vector start, vector mins, vector maxs, vector end, float type, entity passent) checkmove
Wrapper around SV_Move, this makes PF_movetoground and PF_traceline
redundant.
Wrapper around SV_Move, this makes PF_movetoground and PF_traceline
redundant.
*/
static void
PF_checkmove (progs_t *pr)
@ -500,6 +513,7 @@ int c_invis, c_notvis;
/*
PF_checkclient
// entity () clientlist
Returns a client (or object that has a client enemy) that would be a
valid target.
@ -549,6 +563,7 @@ PF_checkclient (progs_t *pr)
Sends text over to the client's execution buffer
stuffcmd (clientent, value)
// void (entity client, string s) stuffcmd
*/
void
PF_stuffcmd (progs_t *pr)
@ -600,6 +615,7 @@ PF_stuffcmd (progs_t *pr)
/*
PF_localcmd
// void (string s) localcmd
Inserts text into the server console's execution buffer
@ -620,6 +636,7 @@ PF_localcmd (progs_t *pr)
Returns a chain of entities that have origins within a spherical area
findradius (origin, radius)
// entity (vector org, float rad) findradius
*/
void
PF_findradius (progs_t *pr)
@ -657,6 +674,7 @@ PF_findradius (progs_t *pr)
RETURN_EDICT (pr, chain);
}
// entity () spawn
void
PF_Spawn (progs_t *pr)
{
@ -668,6 +686,7 @@ PF_Spawn (progs_t *pr)
cvar_t *pr_double_remove;
// void (entity e) remove
void
PF_Remove (progs_t *pr)
{
@ -725,6 +744,8 @@ do_precache (progs_t *pr, const char **cache, int max, const char *name,
PR_RunError (pr, "%s: overflow", func);
}
// string (string s) precache_file
// string (string s) precache_file2
void
PF_precache_file (progs_t *pr)
{ // precache_file is only used to copy
@ -732,6 +753,8 @@ PF_precache_file (progs_t *pr)
R_INT (pr) = P_INT (pr, 0);
}
// void (string s) precache_sound
// string (string s) precache_sound2
void
PF_precache_sound (progs_t *pr)
{
@ -740,6 +763,8 @@ PF_precache_sound (progs_t *pr)
R_INT (pr) = P_INT (pr, 0);
}
// void (string s) precache_model
// string (string s) precache_model2
void
PF_precache_model (progs_t *pr)
{
@ -753,6 +778,7 @@ PF_precache_model (progs_t *pr)
PF_walkmove
float (float yaw, float dist) walkmove
// float (float yaw, float dist) walkmove
*/
void
PF_walkmove (progs_t *pr)
@ -793,6 +819,7 @@ PF_walkmove (progs_t *pr)
PF_droptofloor
void () droptofloor
// float () droptofloor
*/
void
PF_droptofloor (progs_t *pr)
@ -824,6 +851,7 @@ PF_droptofloor (progs_t *pr)
PF_lightstyle
void (float style, string value) lightstyle
// void (float style, string value) lightstyle
*/
void
PF_lightstyle (progs_t *pr)
@ -857,6 +885,7 @@ PF_lightstyle (progs_t *pr)
}
}
// float (entity e) checkbottom
void
PF_checkbottom (progs_t *pr)
{
@ -867,6 +896,7 @@ PF_checkbottom (progs_t *pr)
R_FLOAT (pr) = SV_CheckBottom (ent);
}
// float (vector v) pointcontents
void
PF_pointcontents (progs_t *pr)
{
@ -881,6 +911,7 @@ cvar_t *sv_aim;
/*
PF_aim
// vector (entity e, float speed) aim
Pick a vector for the player to shoot along
vector aim (entity, missilespeed)
@ -975,6 +1006,7 @@ PF_aim (progs_t *pr)
/*
PF_changeyaw
// void () ChangeYaw
This was a major timewaster in progs, so it was converted to C
*/
@ -1064,6 +1096,7 @@ Write_GetClient (progs_t *pr)
return &svs.clients[entnum - 1];
}
// void (float to, ...) WriteBytes
void
PF_WriteBytes (progs_t *pr)
{
@ -1092,6 +1125,7 @@ PF_WriteBytes (progs_t *pr)
}
}
// void (float to, float f) WriteByte
void
PF_WriteByte (progs_t *pr)
{
@ -1110,6 +1144,7 @@ PF_WriteByte (progs_t *pr)
MSG_WriteByte (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteChar
void
PF_WriteChar (progs_t *pr)
{
@ -1128,6 +1163,7 @@ PF_WriteChar (progs_t *pr)
MSG_WriteByte (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteShort
void
PF_WriteShort (progs_t *pr)
{
@ -1146,6 +1182,7 @@ PF_WriteShort (progs_t *pr)
MSG_WriteShort (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteLong
void
PF_WriteLong (progs_t *pr)
{
@ -1164,6 +1201,7 @@ PF_WriteLong (progs_t *pr)
MSG_WriteLong (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteAngle
void
PF_WriteAngle (progs_t *pr)
{
@ -1182,6 +1220,7 @@ PF_WriteAngle (progs_t *pr)
MSG_WriteAngle (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, float f) WriteCoord
void
PF_WriteCoord (progs_t *pr)
{
@ -1200,6 +1239,7 @@ PF_WriteCoord (progs_t *pr)
MSG_WriteCoord (WriteDest (pr), P_FLOAT (pr, 1));
}
// void (float to, vector v) WriteAngleV
void
PF_WriteAngleV (progs_t *pr)
{
@ -1220,6 +1260,7 @@ PF_WriteAngleV (progs_t *pr)
MSG_WriteAngleV (WriteDest (pr), ang);
}
// void (float to, vector v) WriteCoordV
void
PF_WriteCoordV (progs_t *pr)
{
@ -1240,6 +1281,7 @@ PF_WriteCoordV (progs_t *pr)
MSG_WriteCoordV (WriteDest (pr), coord);
}
// void (float to, string s) WriteString
void
PF_WriteString (progs_t *pr)
{
@ -1259,6 +1301,7 @@ PF_WriteString (progs_t *pr)
MSG_WriteString (WriteDest (pr), P_GSTRING (pr, 1));
}
// void (float to, entity s) WriteEntity
void
PF_WriteEntity (progs_t *pr)
{
@ -1277,6 +1320,7 @@ PF_WriteEntity (progs_t *pr)
MSG_WriteShort (WriteDest (pr), P_EDICTNUM (pr, 1));
}
// void (entity e) makestatic
void
PF_makestatic (progs_t *pr)
{
@ -1304,6 +1348,7 @@ PF_makestatic (progs_t *pr)
ED_Free (pr, ent);
}
// void (entity e) setspawnparms
void
PF_setspawnparms (progs_t *pr)
{
@ -1326,6 +1371,7 @@ PF_setspawnparms (progs_t *pr)
sv_globals.parms[i] = client->spawn_parms[i];
}
// void (string s) changelevel
void
PF_changelevel (progs_t *pr)
{
@ -1345,6 +1391,7 @@ PF_changelevel (progs_t *pr)
PF_logfrag
logfrag (killer, killee)
// void (entity killer, entity killee) logfrag
*/
void
PF_logfrag (progs_t *pr)
@ -1406,6 +1453,7 @@ PF_logfrag (progs_t *pr)
PF_infokey
string (entity e, string key) infokey
// string (entity e, string key) infokey
*/
void
PF_infokey (progs_t *pr)
@ -1449,6 +1497,7 @@ PF_infokey (progs_t *pr)
PF_multicast
void (vector where, float set) multicast
// void (vector where, float set) multicast
*/
void
PF_multicast (progs_t *pr)
@ -1466,6 +1515,7 @@ PF_multicast (progs_t *pr)
PF_cfopen
float (string path, string mode) cfopen
// float (string path, string mode) cfopen
*/
static void
PF_cfopen (progs_t *pr)
@ -1477,6 +1527,7 @@ PF_cfopen (progs_t *pr)
PF_cfclose
void (float desc) cfclose
// void (float desc) cfclose
*/
static void
PF_cfclose (progs_t *pr)
@ -1488,6 +1539,7 @@ PF_cfclose (progs_t *pr)
PF_cfread
string (float desc) cfread
// string (float desc) cfread
*/
static void
PF_cfread (progs_t *pr)
@ -1499,6 +1551,7 @@ PF_cfread (progs_t *pr)
PF_cfwrite
float (float desc, string buf) cfwrite
// float (float desc, string buf) cfwrite
*/
static void
PF_cfwrite (progs_t *pr)
@ -1510,6 +1563,7 @@ PF_cfwrite (progs_t *pr)
PF_cfeof
float () cfeof
// float (float desc) cfeof
*/
static void
PF_cfeof (progs_t *pr)
@ -1521,6 +1575,7 @@ PF_cfeof (progs_t *pr)
PF_cfquota
float () cfquota
// float () cfquota
*/
static void
PF_cfquota (progs_t *pr)
@ -1528,6 +1583,7 @@ PF_cfquota (progs_t *pr)
R_FLOAT (pr) = CF_Quota ();
}
// void (entity ent, string key, string value) setinfokey
static void
PF_setinfokey (progs_t *pr)
{
@ -1543,6 +1599,7 @@ PF_setinfokey (progs_t *pr)
}
}
// entity (entity ent) testentitypos
static void
PF_testentitypos (progs_t *pr)
{
@ -1554,6 +1611,7 @@ PF_testentitypos (progs_t *pr)
#define MAX_PF_HULLS 64 // FIXME make dynamic?
clip_hull_t *pf_hull_list[MAX_PF_HULLS];
// integer (entity ent, vector point) hullpointcontents
static void
PF_hullpointcontents (progs_t *pr)
{
@ -1569,6 +1627,7 @@ PF_hullpointcontents (progs_t *pr)
R_INT (pr) = SV_HullPointContents (hull, 0, offset);
}
// vector (integer hull, integer max) getboxbounds
static void
PF_getboxbounds (progs_t *pr)
{
@ -1585,6 +1644,7 @@ PF_getboxbounds (progs_t *pr)
}
}
// integer () getboxhull
static void
PF_getboxhull (progs_t *pr)
{
@ -1609,6 +1669,7 @@ PF_getboxhull (progs_t *pr)
}
}
// void (integer hull) freeboxhull
static void
PF_freeboxhull (progs_t *pr)
{
@ -1638,6 +1699,7 @@ calc_dist (vec3_t p, vec3_t n, vec3_t *offsets)
return DotProduct (v, n);
}
// void (integer hull, vector right, vector forward, vector up, vector mins, vector maxs) rotate_bbox
static void
PF_rotate_bbox (progs_t *pr)
{
@ -1716,12 +1778,14 @@ PF_rotate_bbox (progs_t *pr)
}
}
// void (entity e, vector min, vector max) setabssize
void
PF_Fixme (progs_t *pr)
{
PR_RunError (pr, "Unimplemented builtin function called");
}
// float () checkextension
static void
PF_checkextension (progs_t *pr)
{
@ -1743,6 +1807,7 @@ PF_sv_cvar (progs_t *pr)
}
}
// entity () SV_AllocClient
static void
PF_SV_AllocClient (progs_t *pr)
{
@ -1760,6 +1825,7 @@ PF_SV_AllocClient (progs_t *pr)
RETURN_EDICT (pr, cl->edict);
}
// void (entity cl) SV_FreeClient
static void
PF_SV_FreeClient (progs_t *pr)
{
@ -1780,6 +1846,7 @@ PF_SV_FreeClient (progs_t *pr)
// "server");
}
// void (entity cl, string userinfo) SV_SetUserinfo
static void
PF_SV_SetUserinfo (progs_t *pr)
{
@ -1795,6 +1862,7 @@ PF_SV_SetUserinfo (progs_t *pr)
SV_ExtractFromUserinfo (cl);
}
// void (entity cl, integer ping) SV_SetPing
static void
PR_SV_SetPing (progs_t *pr)
{
@ -1806,6 +1874,7 @@ PR_SV_SetPing (progs_t *pr)
cl->ping = P_INT (pr, 1);
}
// void (entity cl, float secs, vector angles, vector move, integer buttons, integer impulse) SV_UserCmd
static void
PR_SV_UserCmd (progs_t *pr)
{
@ -1830,6 +1899,7 @@ PR_SV_UserCmd (progs_t *pr)
cl->lastcmd.buttons = 0; // avoid multiple fires on lag
}
// void (entity cl) SV_Spawn
static void
PR_SV_Spawn (progs_t *pr)
{
@ -1842,172 +1912,106 @@ PR_SV_Spawn (progs_t *pr)
SV_Spawn (cl);
}
static builtin_t builtins[] = {
{"makevectors", PF_makevectors, 1},
{"setorigin", PF_setorigin, 2},
{"setmodel", PF_setmodel, 3},
{"setsize", PF_setsize, 4},
{"sound", PF_sound, 8},
{"error", PF_error, 10},
{"objerror", PF_objerror, 11},
{"spawn", PF_Spawn, 14},
{"remove", PF_Remove, 15},
{"traceline", PF_traceline, 16},
{"checkclient", PF_checkclient, 17},
{"precache_sound", PF_precache_sound, 19},
{"precache_model", PF_precache_model, 20},
{"stuffcmd", PF_stuffcmd, 21},
{"findradius", PF_findradius, 22},
{"bprint", PF_bprint, 23},
{"sprint", PF_sprint, 24},
{"walkmove", PF_walkmove, 32},
{"droptofloor", PF_droptofloor, 34},
{"lightstyle", PF_lightstyle, 35},
{"checkbottom", PF_checkbottom, 40},
{"pointcontents", PF_pointcontents, 41},
{"aim", PF_aim, 44},
{"localcmd", PF_localcmd, 46},
{"changeyaw", PF_changeyaw, 49},
{"writebyte", PF_WriteByte, 52},
{"WriteBytes", PF_WriteBytes, -1},
{"writechar", PF_WriteChar, 53},
{"writeshort", PF_WriteShort, 54},
{"writelong", PF_WriteLong, 55},
{"writecoord", PF_WriteCoord, 56},
{"writeangle", PF_WriteAngle, 57},
{"WriteCoordV", PF_WriteCoordV, -1},
{"WriteAngleV", PF_WriteAngleV, -1},
{"writestring", PF_WriteString, 58},
{"writeentity", PF_WriteEntity, 59},
{"movetogoal", SV_MoveToGoal, 67},
{"precache_file", PF_precache_file, 68},
{"makestatic", PF_makestatic, 69},
{"changelevel", PF_changelevel, 70},
{"centerprint", PF_centerprint, 73},
{"ambientsound", PF_ambientsound, 74},
{"precache_model2", PF_precache_model, 75},
{"precache_sound2", PF_precache_sound, 76},
{"precache_file2", PF_precache_file, 77},
{"setspawnparms", PF_setspawnparms, 78},
{"logfrag", PF_logfrag, 79},
{"infokey", PF_infokey, 80},
{"multicast", PF_multicast, 82},
{"testentitypos", PF_testentitypos, 92},
{"hullpointcontents", PF_hullpointcontents, 93},
{"getboxbounds", PF_getboxbounds, 94},
{"getboxhull", PF_getboxhull, 95},
{"freeboxhull", PF_freeboxhull, 96},
{"rotate_bbox", PF_rotate_bbox, 97},
{"checkmove", PF_checkmove, 98},
{"checkextension", PF_checkextension, 99},
{"setinfokey", PF_setinfokey, 102},
{"cfopen", PF_cfopen, 103},
{"cfclose", PF_cfclose, 104},
{"cfread", PF_cfread, 105},
{"cfwrite", PF_cfwrite, 106},
{"cfeof", PF_cfeof, 107},
{"cfquota", PF_cfquota, 108},
{"SV_AllocClient", PF_SV_AllocClient, -1},
{"SV_FreeClient", PF_SV_FreeClient, -1},
{"SV_SetUserinfo", PF_SV_SetUserinfo, -1},
{"SV_SetPing", PR_SV_SetPing, -1},
{"SV_UserCmd", PR_SV_UserCmd, -1},
{"SV_Spawn", PR_SV_Spawn, -1},
{0}
};
void
SV_PR_Cmds_Init ()
{
builtin_t *bi;
PR_Cmds_Init (&sv_pr_state);
PR_Obj_Progs_Init (&sv_pr_state);
// (override standard builtin)
sv_pr_state.builtins[45] = 0;
// float (string s) cvar
PR_AddBuiltin (&sv_pr_state, "cvar", PF_sv_cvar, 45);
bi = PR_FindBuiltin (&sv_pr_state, "cvar");
bi->proc = PF_sv_cvar;
// void (entity e) makevectors
PR_AddBuiltin (&sv_pr_state, "makevectors", PF_makevectors, 1);
// void (entity e, vector o) setorigin
PR_AddBuiltin (&sv_pr_state, "setorigin", PF_setorigin, 2);
// void (entity e, string m) setmodel
PR_AddBuiltin (&sv_pr_state, "setmodel", PF_setmodel, 3);
// void (entity e, vector min, vector max) setsize
PR_AddBuiltin (&sv_pr_state, "setsize", PF_setsize, 4);
// void (entity e, vector min, vector max) setabssize
PR_AddBuiltin (&sv_pr_state, "fixme", PF_Fixme, 5);
// void (entity e, float chan, string samp) sound
PR_AddBuiltin (&sv_pr_state, "sound", PF_sound, 8);
// void (string e) error
PR_AddBuiltin (&sv_pr_state, "error", PF_error, 10);
// void (string e) objerror
PR_AddBuiltin (&sv_pr_state, "objerror", PF_objerror, 11);
// entity () spawn
PR_AddBuiltin (&sv_pr_state, "spawn", PF_Spawn, 14);
// void (entity e) remove
PR_AddBuiltin (&sv_pr_state, "remove", PF_Remove, 15);
// float (vector v1, vector v2, float tryents) traceline
PR_AddBuiltin (&sv_pr_state, "traceline", PF_traceline, 16);
// entity () clientlist
PR_AddBuiltin (&sv_pr_state, "checkclient", PF_checkclient, 17);
// void (string s) precache_sound
PR_AddBuiltin (&sv_pr_state, "precache_sound", PF_precache_sound, 19);
// void (string s) precache_model
PR_AddBuiltin (&sv_pr_state, "precache_model", PF_precache_model, 20);
// void (entity client, string s) stuffcmd
PR_AddBuiltin (&sv_pr_state, "stuffcmd", PF_stuffcmd, 21);
// entity (vector org, float rad) findradius
PR_AddBuiltin (&sv_pr_state, "findradius", PF_findradius, 22);
// void (string s) bprint
PR_AddBuiltin (&sv_pr_state, "bprint", PF_bprint, 23);
// void (entity client, string s) sprint
PR_AddBuiltin (&sv_pr_state, "sprint", PF_sprint, 24);
// float (float yaw, float dist) walkmove
PR_AddBuiltin (&sv_pr_state, "walkmove", PF_walkmove, 32);
// float () droptofloor
PR_AddBuiltin (&sv_pr_state, "droptofloor", PF_droptofloor, 34);
// void (float style, string value) lightstyle
PR_AddBuiltin (&sv_pr_state, "lightstyle", PF_lightstyle, 35);
// float (entity e) checkbottom
PR_AddBuiltin (&sv_pr_state, "checkbottom", PF_checkbottom, 40);
// float (vector v) pointcontents
PR_AddBuiltin (&sv_pr_state, "pointcontents", PF_pointcontents, 41);
// vector (entity e, float speed) aim
PR_AddBuiltin (&sv_pr_state, "aim", PF_aim, 44);
// void (string s) localcmd
PR_AddBuiltin (&sv_pr_state, "localcmd", PF_localcmd, 46);
// void () ChangeYaw
PR_AddBuiltin (&sv_pr_state, "changeyaw", PF_changeyaw, 49);
// void (float to, float f) WriteByte
PR_AddBuiltin (&sv_pr_state, "writebyte", PF_WriteByte, 52);
// void (float to, ...) WriteBytes
PR_AddBuiltin (&sv_pr_state, "WriteBytes", PF_WriteBytes, -1);
// void (float to, float f) WriteChar
PR_AddBuiltin (&sv_pr_state, "writechar", PF_WriteChar, 53);
// void (float to, float f) WriteShort
PR_AddBuiltin (&sv_pr_state, "writeshort", PF_WriteShort, 54);
// void (float to, float f) WriteLong
PR_AddBuiltin (&sv_pr_state, "writelong", PF_WriteLong, 55);
// void (float to, float f) WriteCoord
PR_AddBuiltin (&sv_pr_state, "writecoord", PF_WriteCoord, 56);
// void (float to, float f) WriteAngle
PR_AddBuiltin (&sv_pr_state, "writeangle", PF_WriteAngle, 57);
// void (float to, vector v) WriteCoordV
PR_AddBuiltin (&sv_pr_state, "WriteCoordV", PF_WriteCoordV, -1);
// void (float to, vector v) WriteAngleV
PR_AddBuiltin (&sv_pr_state, "WriteAngleV", PF_WriteAngleV, -1);
// void (float to, string s) WriteString
PR_AddBuiltin (&sv_pr_state, "writestring", PF_WriteString, 58);
// void (float to, entity s) WriteEntity
PR_AddBuiltin (&sv_pr_state, "writeentity", PF_WriteEntity, 59);
// void (float step) movetogoal
PR_AddBuiltin (&sv_pr_state, "movetogoal", SV_MoveToGoal, 67);
// string (string s) precache_file
PR_AddBuiltin (&sv_pr_state, "precache_file", PF_precache_file, 68);
// void (entity e) makestatic
PR_AddBuiltin (&sv_pr_state, "makestatic", PF_makestatic, 69);
// void (string s) changelevel
PR_AddBuiltin (&sv_pr_state, "changelevel", PF_changelevel, 70);
// void (...) centerprint
PR_AddBuiltin (&sv_pr_state, "centerprint", PF_centerprint, 73);
// void (vector pos, string samp, float vol, float atten) ambientsound
PR_AddBuiltin (&sv_pr_state, "ambientsound", PF_ambientsound, 74);
// string (string s) precache_model2
PR_AddBuiltin (&sv_pr_state, "precache_model2", PF_precache_model, 75);
// string (string s) precache_sound2
PR_AddBuiltin (&sv_pr_state, "precache_sound2", PF_precache_sound, 76);
// string (string s) precache_file2
PR_AddBuiltin (&sv_pr_state, "precache_file2", PF_precache_file, 77);
// void (entity e) setspawnparms
PR_AddBuiltin (&sv_pr_state, "setspawnparms", PF_setspawnparms, 78);
// void (entity killer, entity killee) logfrag
PR_AddBuiltin (&sv_pr_state, "logfrag", PF_logfrag, 79);
// string (entity e, string key) infokey
PR_AddBuiltin (&sv_pr_state, "infokey", PF_infokey, 80);
// void (vector where, float set) multicast
PR_AddBuiltin (&sv_pr_state, "multicast", PF_multicast, 82);
// entity (entity ent) testentitypos
PR_AddBuiltin (&sv_pr_state, "testentitypos", PF_testentitypos, 92);
// integer (entity ent, vector point) hullpointcontents
PR_AddBuiltin (&sv_pr_state, "hullpointcontents", PF_hullpointcontents,
93);
// vector (integer hull, integer max) getboxbounds
PR_AddBuiltin (&sv_pr_state, "getboxbounds", PF_getboxbounds, 94);
// integer () getboxhull
PR_AddBuiltin (&sv_pr_state, "getboxhull", PF_getboxhull, 95);
// void (integer hull) freeboxhull
PR_AddBuiltin (&sv_pr_state, "freeboxhull", PF_freeboxhull, 96);
// void (integer hull, vector right, vector forward, vector up, vector mins, vector maxs) rotate_bbox
PR_AddBuiltin (&sv_pr_state, "rotate_bbox", PF_rotate_bbox, 97);
// void (vector start, vector mins, vector maxs, vector end, float type, entity passent) checkmove
PR_AddBuiltin (&sv_pr_state, "checkmove", PF_checkmove, 98);
// float () checkextension
PR_AddBuiltin (&sv_pr_state, "checkextension", PF_checkextension, 99);
// void (entity ent, string key, string value) setinfokey
PR_AddBuiltin (&sv_pr_state, "setinfokey", PF_setinfokey, 102);
// float (string path, string mode) cfopen
PR_AddBuiltin (&sv_pr_state, "cfopen", PF_cfopen, 103);
// void (float desc) cfclose
PR_AddBuiltin (&sv_pr_state, "cfclose", PF_cfclose, 104);
// string (float desc) cfread
PR_AddBuiltin (&sv_pr_state, "cfread", PF_cfread, 105);
// float (float desc, string buf) cfwrite
PR_AddBuiltin (&sv_pr_state, "cfwrite", PF_cfwrite, 106);
// float (float desc) cfeof
PR_AddBuiltin (&sv_pr_state, "cfeof", PF_cfeof, 107);
// float () cfquota
PR_AddBuiltin (&sv_pr_state, "cfquota", PF_cfquota, 108);
// entity () SV_AllocClient
PR_AddBuiltin (&sv_pr_state, "SV_AllocClient", PF_SV_AllocClient, -1);
// void (entity cl) SV_FreeClient
PR_AddBuiltin (&sv_pr_state, "SV_FreeClient", PF_SV_FreeClient, -1);
// void (entity cl, string userinfo) SV_SetUserinfo
PR_AddBuiltin (&sv_pr_state, "SV_SetUserinfo", PF_SV_SetUserinfo, -1);
// void (entity cl, integer ping) SV_SetPing
PR_AddBuiltin (&sv_pr_state, "SV_SetPing", PR_SV_SetPing, -1);
// void (entity cl, float secs, vector angles, vector move, integer buttons, integer impulse) SV_UserCmd
PR_AddBuiltin (&sv_pr_state, "SV_UserCmd", PR_SV_UserCmd, -1);
// void (entity cl) SV_Spawn
PR_AddBuiltin (&sv_pr_state, "SV_Spawn", PR_SV_Spawn, -1);
PR_RegisterBuiltins (&sv_pr_state, builtins);
};
// void (float step) movetogoal

View File

@ -348,8 +348,6 @@ SV_Progs_Init (void)
sv_pr_state.reserved_edicts = &reserved_edicts;
sv_pr_state.unlink = SV_UnlinkEdict;
sv_pr_state.flush = SV_FlushSignon;
sv_pr_state.builtins = 0;
sv_pr_state.numbuiltins = 0;
sv_pr_state.parse_field = parse_field;
sv_pr_state.prune_edict = prune_edict;
sv_pr_state.free_edict = free_edict; // eww, I hate the need for this :(

View File

@ -1892,12 +1892,17 @@ SV_ExecuteClientMessage (client_t *cl)
}
}
static builtin_t builtins[] = {
{"SV_AddUserCommand", PF_AddUserCommand, -1},
{0}
};
void
SV_UserInit (void)
{
ucmd_table = Hash_NewTable (251, ucmds_getkey, ucmds_free, 0);
Hash_SetHashCompare (ucmd_table, ucmd_get_hash, ucmd_compare);
PR_AddBuiltin (&sv_pr_state, "SV_AddUserCommand", PF_AddUserCommand, -1);
PR_RegisterBuiltins (&sv_pr_state, builtins);
cl_rollspeed = Cvar_Get ("cl_rollspeed", "200", CVAR_NONE, NULL,
"How quickly a player straightens out after "
"strafing");

View File

@ -149,18 +149,23 @@ bi_printf (progs_t *pr)
dstring_delete (dstr);
}
static builtin_t builtins[] = {
{"print", bi_print, 1},
{"errno", bi_errno, 3},
{"strerror", bi_strerror, 4},
{"open", bi_open, 5},
{"close", bi_close, 6},
{"read", bi_read, 7},
{"write", bi_write, 8},
{"seek", bi_seek, 9},
{"traceon", bi_traceon, 10},
{"traceoff", bi_traceoff, 11},
{"printf", bi_printf, 12},
{0}
};
void
BI_Init (progs_t *pr)
{
PR_AddBuiltin (pr, "print", bi_print, 1);
PR_AddBuiltin (pr, "errno", bi_errno, 3);
PR_AddBuiltin (pr, "strerror", bi_strerror, 4);
PR_AddBuiltin (pr, "open", bi_open, 5);
PR_AddBuiltin (pr, "close", bi_close, 6);
PR_AddBuiltin (pr, "read", bi_read, 7);
PR_AddBuiltin (pr, "write", bi_write, 8);
PR_AddBuiltin (pr, "seek", bi_seek, 9);
PR_AddBuiltin (pr, "traceon", bi_traceon, 10);
PR_AddBuiltin (pr, "traceoff", bi_traceoff, 11);
PR_AddBuiltin (pr, "printf", bi_printf, 12);
PR_RegisterBuiltins (pr, builtins);
}