diff --git a/codemp/botlib/be_interface.cpp b/codemp/botlib/be_interface.cpp index 6d61da92a3..a243de073a 100644 --- a/codemp/botlib/be_interface.cpp +++ b/codemp/botlib/be_interface.cpp @@ -910,5 +910,7 @@ botlib_export_t *GetBotLibAPI(int apiVersion, botlib_import_t *import) { be_botlib_export.BotLibUpdateEntity = Export_BotLibUpdateEntity; be_botlib_export.Test = BotExportTest; + PC_Init(); + return &be_botlib_export; } diff --git a/codemp/botlib/botlib.h b/codemp/botlib/botlib.h index 0345e758b1..a3ecd5f1d3 100644 --- a/codemp/botlib/botlib.h +++ b/codemp/botlib/botlib.h @@ -426,7 +426,7 @@ typedef struct botlib_export_s int (*BotLibVarGet)(char *var_name, char *value, int size); //sets a C-like define returns BLERR_ - int (*PC_AddGlobalDefine)(char *string); + int (*PC_AddGlobalDefine)(const char *string); int (*PC_LoadSourceHandle)(const char *filename); int (*PC_FreeSourceHandle)(int handle); int (*PC_ReadTokenHandle)(int handle, pc_token_t *pc_token); diff --git a/codemp/botlib/l_precomp.cpp b/codemp/botlib/l_precomp.cpp index 8089a56c0a..526bad2b2b 100644 --- a/codemp/botlib/l_precomp.cpp +++ b/codemp/botlib/l_precomp.cpp @@ -176,6 +176,17 @@ void QDECL SourceWarning(source_t *source, char *str, ...) Log_Print("warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text); #endif //BSPC } //end of the function ScriptWarning + +void PC_Init(void) { + // PC_InitTokenHeap(); + +#if DEFINEHASHING + if (!globaldefines) { + globaldefines = (struct define_s **)GetClearedMemory(DEFINEHASHSIZE * sizeof(define_t *)); + } +#endif +} + //============================================================================ // // Parameter: - @@ -1130,7 +1141,9 @@ int PC_Directive_undef(source_t *source) { token_t token; define_t *define, *lastdefine; +#if DEFINEHASHING int hash; +#endif if (source->skip > 0) return qtrue; // @@ -1341,12 +1354,15 @@ int PC_Directive_define(source_t *source) // Returns: - // Changes Globals: - //============================================================================ -define_t *PC_DefineFromString(char *string) +define_t *PC_DefineFromString(const char *string) { script_t *script; source_t src; token_t *t; - int res, i; + int res; +#if DEFINEHASHING + int i; +#endif // DEFINEHASHING define_t *def; PC_InitTokenHeap(); @@ -1367,7 +1383,7 @@ define_t *PC_DefineFromString(char *string) src.tokens = src.tokens->next; PC_FreeToken(t); } //end for -#ifdef DEFINEHASHING +#if DEFINEHASHING def = NULL; for (i = 0; i < DEFINEHASHSIZE; i++) { @@ -1399,7 +1415,7 @@ define_t *PC_DefineFromString(char *string) // Returns: - // Changes Globals: - //============================================================================ -int PC_AddDefine(source_t *source, char *string) +int PC_AddDefine(source_t *source, const char *string) { define_t *define; @@ -1425,9 +1441,19 @@ int PC_AddDefine(source_t *source, char *string) // Returns: - // Changes Globals: - //============================================================================ -int PC_AddGlobalDefine(char *string) +int PC_AddGlobalDefine(const char *string) { -#if !DEFINEHASHING +#if DEFINEHASHING + define_t *define = PC_DefineFromString(string); + if (!define) { + return qfalse; + } + + qboolean savedAGD = addGlobalDefine; + addGlobalDefine = qtrue; + PC_AddDefineToHash(define, NULL); + addGlobalDefine = savedAGD; +#else define_t *define; define = PC_DefineFromString(string); @@ -1446,7 +1472,22 @@ int PC_AddGlobalDefine(char *string) //============================================================================ int PC_RemoveGlobalDefine(char *name) { -#if !DEFINEHASHING +#if DEFINEHASHING + if (globaldefines) { + int i; + for (i = 0; i < DEFINEHASHSIZE; i++) { + define_t *define; + for (define = globaldefines[i]; define; define = define->globalnext) { + if (strcmp(define->name, name)) { + globaldefines[i] = define->globalnext; + PC_FreeDefine(define); + return qtrue; + } + } + } + } + return qfalse; +#else define_t *define; define = PC_FindDefine(globaldefines, name); @@ -3143,8 +3184,10 @@ void FreeSource(source_t *source) token_t *token; define_t *define; indent_t *indent; +#if DEFINEHASHING define_t *nextdefine; int i; +#endif //PC_PrintDefineHashTable(source->definehash); //free all the scripts diff --git a/codemp/botlib/l_precomp.h b/codemp/botlib/l_precomp.h index b1731c11f6..ca8f029ec5 100644 --- a/codemp/botlib/l_precomp.h +++ b/codemp/botlib/l_precomp.h @@ -115,7 +115,8 @@ typedef struct source_s token_t token; //last read token } source_t; - +// initialise the precompiler +void PC_Init(void); //read a token from the source int PC_ReadToken(source_t *source, token_t *token); //expect a certain token @@ -139,9 +140,9 @@ int PC_ReadLine(source_t *source, token_t *token); //returns true if there was a white space in front of the token int PC_WhiteSpaceBeforeToken(token_t *token); //add a define to the source -int PC_AddDefine(source_t *source, char *string); +int PC_AddDefine(source_t *source, const char *string); //add a globals define that will be added to all opened sources -int PC_AddGlobalDefine(char *string); +int PC_AddGlobalDefine(const char *string); //remove the given global define int PC_RemoveGlobalDefine(char *name); //remove all globals defines diff --git a/codemp/botlib/l_script.cpp b/codemp/botlib/l_script.cpp index ab49c8c62b..28fc771171 100644 --- a/codemp/botlib/l_script.cpp +++ b/codemp/botlib/l_script.cpp @@ -1399,7 +1399,7 @@ script_t *LoadScriptFile(const char *filename) // Returns: - // Changes Globals: - //============================================================================ -script_t *LoadScriptMemory(char *ptr, int length, char *name) +script_t *LoadScriptMemory(const char *ptr, int length, char *name) { void *buffer; script_t *script; diff --git a/codemp/botlib/l_script.h b/codemp/botlib/l_script.h index 574732a711..e438469f13 100644 --- a/codemp/botlib/l_script.h +++ b/codemp/botlib/l_script.h @@ -242,7 +242,7 @@ const char *PunctuationFromNum(script_t *script, int num); //load a script from the given file at the given offset with the given length script_t *LoadScriptFile(const char *filename); //load a script from the given memory with the given length -script_t *LoadScriptMemory(char *ptr, int length, char *name); +script_t *LoadScriptMemory(const char *ptr, int length, char *name); //free a script void FreeScript(script_t *script); //set the base folder to load files from diff --git a/codemp/cgame/cg_public.h b/codemp/cgame/cg_public.h index 801aa1be6a..b044089cd1 100644 --- a/codemp/cgame/cg_public.h +++ b/codemp/cgame/cg_public.h @@ -614,7 +614,7 @@ typedef struct cgameImport_s { void (*Key_SetCatcher) ( int catcher ); // preprocessor (botlib_export->PC_***) - int (*PC_AddGlobalDefine) ( char *string ); + int (*PC_AddGlobalDefine) ( const char *string ); int (*PC_FreeSource) ( int handle ); int (*PC_LoadGlobalDefines) ( const char *filename ); int (*PC_LoadSource) ( const char *filename ); diff --git a/codemp/cgame/cg_syscalls.c b/codemp/cgame/cg_syscalls.c index 2c905d67fd..56e2890f4b 100644 --- a/codemp/cgame/cg_syscalls.c +++ b/codemp/cgame/cg_syscalls.c @@ -386,7 +386,7 @@ void trap_Key_SetCatcher( int catcher ) { int trap_Key_GetKey( const char *binding ) { return Q_syscall( CG_KEY_GETKEY, binding ); } -int trap_PC_AddGlobalDefine( char *define ) { +int trap_PC_AddGlobalDefine( const char *define ) { return Q_syscall( CG_PC_ADD_GLOBAL_DEFINE, define ); } int trap_PC_LoadSource( const char *filename ) { diff --git a/codemp/client/cl_cgameapi.cpp b/codemp/client/cl_cgameapi.cpp index 15267443a6..51465e27e5 100644 --- a/codemp/client/cl_cgameapi.cpp +++ b/codemp/client/cl_cgameapi.cpp @@ -1262,7 +1262,7 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) { return Key_GetKey( (const char *)VMA(1) ); case CG_PC_ADD_GLOBAL_DEFINE: - return botlib_export->PC_AddGlobalDefine( (char *)VMA(1) ); + return botlib_export->PC_AddGlobalDefine( (const char *)VMA(1) ); case CG_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle( (const char *)VMA(1) ); diff --git a/codemp/client/cl_uiapi.cpp b/codemp/client/cl_uiapi.cpp index 4ed911798b..687267cae2 100644 --- a/codemp/client/cl_uiapi.cpp +++ b/codemp/client/cl_uiapi.cpp @@ -1071,7 +1071,7 @@ intptr_t CL_UISystemCalls( intptr_t *args ) { return re->AnyLanguage_ReadCharFromString( (const char *)VMA(1), (int *) VMA(2), (qboolean *) VMA(3) ); case UI_PC_ADD_GLOBAL_DEFINE: - return botlib_export->PC_AddGlobalDefine( (char *)VMA(1) ); + return botlib_export->PC_AddGlobalDefine( (const char *)VMA(1) ); case UI_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle( (const char *)VMA(1) ); diff --git a/codemp/game/g_public.h b/codemp/game/g_public.h index d90e350978..173a4b43d5 100644 --- a/codemp/game/g_public.h +++ b/codemp/game/g_public.h @@ -971,7 +971,7 @@ typedef struct gameImport_s { int (*BotLibShutdown) ( void ); int (*BotLibVarSet) ( char *var_name, char *value ); int (*BotLibVarGet) ( char *var_name, char *value, int size ); - int (*BotLibDefine) ( char *string ); + int (*BotLibDefine) ( const char *string ); int (*BotLibStartFrame) ( float time ); int (*BotLibLoadMap) ( const char *mapname ); int (*BotLibUpdateEntity) ( int ent, void *bue ); diff --git a/codemp/game/g_syscalls.c b/codemp/game/g_syscalls.c index 3e49935e17..c9600c036b 100644 --- a/codemp/game/g_syscalls.c +++ b/codemp/game/g_syscalls.c @@ -421,7 +421,7 @@ int trap_BotLibVarSet(char *var_name, char *value) { int trap_BotLibVarGet(char *var_name, char *value, int size) { return Q_syscall( BOTLIB_LIBVAR_GET, var_name, value, size ); } -int trap_BotLibDefine(char *string) { +int trap_BotLibDefine(const char *string) { return Q_syscall( BOTLIB_PC_ADD_GLOBAL_DEFINE, string ); } int trap_BotLibStartFrame(float time) { diff --git a/codemp/server/sv_gameapi.cpp b/codemp/server/sv_gameapi.cpp index d216669abf..05b4d58b88 100644 --- a/codemp/server/sv_gameapi.cpp +++ b/codemp/server/sv_gameapi.cpp @@ -1211,7 +1211,7 @@ static int SV_BotLibVarGet( char *var_name, char *value, int size ) { return botlib_export->BotLibVarGet( var_name, value, size ); } -static int SV_BotLibDefine( char *string ) { +static int SV_BotLibDefine( const char *string ) { return botlib_export->PC_AddGlobalDefine( string ); } @@ -2226,7 +2226,7 @@ intptr_t SV_GameSystemCalls( intptr_t *args ) { return botlib_export->BotLibVarGet( (char *)VMA(1), (char *)VMA(2), args[3] ); case BOTLIB_PC_ADD_GLOBAL_DEFINE: - return botlib_export->PC_AddGlobalDefine( (char *)VMA(1) ); + return botlib_export->PC_AddGlobalDefine( (const char *)VMA(1) ); case BOTLIB_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle( (const char *)VMA(1) ); case BOTLIB_PC_FREE_SOURCE: diff --git a/codemp/ui/ui_public.h b/codemp/ui/ui_public.h index 9cb29cca55..8bee9b32df 100644 --- a/codemp/ui/ui_public.h +++ b/codemp/ui/ui_public.h @@ -269,7 +269,7 @@ typedef struct uiImport_s { void (*Key_SetCatcher) ( int catcher ); void (*Key_SetOverstrikeMode) ( qboolean state ); - int (*PC_AddGlobalDefine) ( char *define ); + int (*PC_AddGlobalDefine) ( const char *define ); int (*PC_FreeSource) ( int handle ); int (*PC_LoadGlobalDefines) ( const char* filename ); int (*PC_LoadSource) ( const char *filename ); diff --git a/codemp/ui/ui_syscalls.c b/codemp/ui/ui_syscalls.c index a2e4d8fd9c..02cd5c0a9a 100644 --- a/codemp/ui/ui_syscalls.c +++ b/codemp/ui/ui_syscalls.c @@ -286,7 +286,7 @@ int trap_LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s int trap_MemoryRemaining( void ) { return Q_syscall( UI_MEMORY_REMAINING ); } -int trap_PC_AddGlobalDefine( char *define ) { +int trap_PC_AddGlobalDefine( const char *define ) { return Q_syscall( UI_PC_ADD_GLOBAL_DEFINE, define ); } int trap_PC_LoadSource( const char *filename ) {