From 7842605a13c376c986ffddd20d66eb39cb3abec8 Mon Sep 17 00:00:00 2001 From: braxi Date: Thu, 12 Sep 2024 12:14:46 +0200 Subject: [PATCH] smoll edits here and there --- src/common/shared.h | 6 + src/engine/client/cgame/cg_entities.c | 2 +- src/engine/client/cgame/progdefs_client.h | 8 +- src/engine/client/ui/ui_load.c | 2 +- src/engine/model_cache.c | 2 +- src/engine/pragma.c | 4 +- src/engine/pragma_dedsv.vcxproj | 11 +- src/engine/pragma_dedsv.vcxproj.filters | 13 +- src/engine/pragma_engine.vcxproj | 10 +- src/engine/pragma_engine.vcxproj.filters | 22 ++-- src/engine/script/progdefs_server.h | 13 +- src/engine/script/progdefs_ui.h | 19 ++- .../script/{scr_debug.c => qcvm_debug.c} | 26 ++-- src/engine/script/{scr_exec.c => qcvm_exec.c} | 10 +- src/engine/script/{scr_main.c => qcvm_main.c} | 37 +++--- .../{script_internals.h => qcvm_private.h} | 35 ++++-- .../script/{scr_utils.c => qcvm_utils.c} | 21 +--- src/engine/script/scr_builtins_math.c | 2 +- src/engine/script/scr_builtins_shared.c | 2 +- src/engine/script/scriptvm.h | 119 ++++++++++-------- src/engine/server/sv_gentity.c | 2 +- src/engine/server/sv_main.c | 2 +- src/tools/tools_shared.cpp | 5 +- 23 files changed, 203 insertions(+), 170 deletions(-) rename src/engine/script/{scr_debug.c => qcvm_debug.c} (88%) rename src/engine/script/{scr_exec.c => qcvm_exec.c} (98%) rename src/engine/script/{scr_main.c => qcvm_main.c} (94%) rename src/engine/script/{script_internals.h => qcvm_private.h} (83%) rename src/engine/script/{scr_utils.c => qcvm_utils.c} (89%) diff --git a/src/common/shared.h b/src/common/shared.h index e5308f3b..ee56ecbe 100644 --- a/src/common/shared.h +++ b/src/common/shared.h @@ -9,6 +9,10 @@ See the attached GNU General Public License v2 for more details. */ // shared.h -- included first by ALL program modules + +#ifndef _PRAGMA_SHARED_H_ +#define _PRAGMA_SHARED_H_ + #pragma once #include "../engine/pragma_config.h" @@ -691,5 +695,7 @@ typedef struct short stats[MAX_STATS]; // fast status bar updates } player_state_t; +#endif /*_PRAGMA_SHARED_H_*/ + diff --git a/src/engine/client/cgame/cg_entities.c b/src/engine/client/cgame/cg_entities.c index e5006e6a..b1e940a1 100644 --- a/src/engine/client/cgame/cg_entities.c +++ b/src/engine/client/cgame/cg_entities.c @@ -10,7 +10,7 @@ See the attached GNU General Public License v2 for more details. #include "../client.h" #include "cg_local.h" -#include "../../script/script_internals.h" // for ddef_t +#include "../../script/qcvm_private.h" // for ddef_t extern ddef_t* Scr_FindEntityField(char* name); // scr_main.c extern qboolean Scr_ParseEpair(void* base, ddef_t* key, char* s, int memtag); // scr_main.c diff --git a/src/engine/client/cgame/progdefs_client.h b/src/engine/client/cgame/progdefs_client.h index a7da574a..eb6947a0 100644 --- a/src/engine/client/cgame/progdefs_client.h +++ b/src/engine/client/cgame/progdefs_client.h @@ -8,6 +8,10 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ +#ifndef _PRAGMA_PROGDEFS_CLIENT_H_ +#define _PRAGMA_PROGDEFS_CLIENT_H_ + +#pragma once #ifndef scr_func_t typedef int32_t scr_func_t; @@ -82,4 +86,6 @@ typedef struct cl_entvars_s vec3_t color; float fullbright; -} cl_entvars_t; \ No newline at end of file +} cl_entvars_t; + +#endif /*_PRAGMA_PROGDEFS_CLIENT_H_*/ \ No newline at end of file diff --git a/src/engine/client/ui/ui_load.c b/src/engine/client/ui/ui_load.c index afc6473e..4233d0ed 100644 --- a/src/engine/client/ui/ui_load.c +++ b/src/engine/client/ui/ui_load.c @@ -13,7 +13,7 @@ See the attached GNU General Public License v2 for more details. #pragma once #include "../client.h" -#include "../../script/script_internals.h" +#include "../../script/qcvm_private.h" #include "../../script/scriptvm.h" #include "ui_local.h" diff --git a/src/engine/model_cache.c b/src/engine/model_cache.c index ae302e51..7236ab0f 100644 --- a/src/engine/model_cache.c +++ b/src/engine/model_cache.c @@ -803,7 +803,7 @@ void Com_LoadAliasModel(cached_model_t* mod, void* buffer, const int filelen) _strlwr(surf->name); // strip off a trailing _1 or _2 - j = strlen(surf->name); + j = (int)strlen(surf->name); if (j > 2 && surf->name[j - 2] == '_') { surf->name[j - 2] = 0; diff --git a/src/engine/pragma.c b/src/engine/pragma.c index 0eda450e..91cacd9f 100644 --- a/src/engine/pragma.c +++ b/src/engine/pragma.c @@ -1197,8 +1197,8 @@ void Qcommon_Init (int argc, char **argv) printf("\n\n"); - printf("running %i ticks per second\n", SERVER_FPS); - printf("protocol version is %i\n\n", PROTOCOL_VERSION); + printf("Server runs game at %i ticks per second.\n", SERVER_FPS); + printf("Protocol version is: %i.\n\n", PROTOCOL_VERSION); #endif if (setjmp (abortframe) ) diff --git a/src/engine/pragma_dedsv.vcxproj b/src/engine/pragma_dedsv.vcxproj index 0bb4d415..40b04837 100644 --- a/src/engine/pragma_dedsv.vcxproj +++ b/src/engine/pragma_dedsv.vcxproj @@ -28,6 +28,7 @@ + @@ -46,7 +47,7 @@ - + @@ -74,10 +75,10 @@ - - - - + + + + diff --git a/src/engine/pragma_dedsv.vcxproj.filters b/src/engine/pragma_dedsv.vcxproj.filters index f428addf..86a80072 100644 --- a/src/engine/pragma_dedsv.vcxproj.filters +++ b/src/engine/pragma_dedsv.vcxproj.filters @@ -38,7 +38,7 @@ QCVM - + QCVM @@ -69,6 +69,9 @@ Common + + Common + @@ -80,16 +83,16 @@ QCVM - + QCVM - + QCVM - + QCVM - + QCVM diff --git a/src/engine/pragma_engine.vcxproj b/src/engine/pragma_engine.vcxproj index 1aec022c..dea3ebec 100644 --- a/src/engine/pragma_engine.vcxproj +++ b/src/engine/pragma_engine.vcxproj @@ -63,7 +63,7 @@ - + @@ -125,10 +125,10 @@ - - - - + + + + diff --git a/src/engine/pragma_engine.vcxproj.filters b/src/engine/pragma_engine.vcxproj.filters index 9c0f1183..03f96fda 100644 --- a/src/engine/pragma_engine.vcxproj.filters +++ b/src/engine/pragma_engine.vcxproj.filters @@ -185,16 +185,16 @@ QCVM - + QCVM - + QCVM - + QCVM - + QCVM @@ -282,19 +282,19 @@ Common - QCVM\File Formats + Common\File Formats - QCVM\File Formats + Common\File Formats - QCVM\File Formats + Common\File Formats - QCVM\File Formats + Common\File Formats - QCVM\File Formats + Common\File Formats QCVM @@ -302,7 +302,7 @@ QCVM - + QCVM @@ -355,7 +355,7 @@ {a6d0833b-ce91-4759-8fce-f26ba289128f} - + {87710d39-a80c-4ea4-ad15-187203329dd9} diff --git a/src/engine/script/progdefs_server.h b/src/engine/script/progdefs_server.h index f38ebd5e..23f3baa6 100644 --- a/src/engine/script/progdefs_server.h +++ b/src/engine/script/progdefs_server.h @@ -8,13 +8,10 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ +#ifndef _PRAGMA_PROGDEFS_SERVER_H_ +#define _PRAGMA_PROGDEFS_SERVER_H_ -#ifndef scr_func_t - typedef int32_t scr_func_t; - typedef int32_t scr_entity_t; - typedef int32_t scr_string_t; -#endif - +#pragma once // prog globals typedef struct sv_globalvars_s @@ -155,4 +152,6 @@ typedef struct sv_entvars_s int32_t pm_gravity; vec3_t pm_delta_angles; // add to command angles to get view direction // changed by spawns, rotating objects, and teleporters -} sv_entvars_t; \ No newline at end of file +} sv_entvars_t; + +#endif \ No newline at end of file diff --git a/src/engine/script/progdefs_ui.h b/src/engine/script/progdefs_ui.h index 369723f4..1bcfb6e1 100644 --- a/src/engine/script/progdefs_ui.h +++ b/src/engine/script/progdefs_ui.h @@ -8,12 +8,17 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ +#ifndef _PRAGMA_PROGDEFS_GUI_H_ +#define _PRAGMA_PROGDEFS_GUI_H_ + +#pragma once + #ifndef scr_func_t -typedef int32_t scr_func_t; -typedef int32_t scr_int_t; -// typedef vec3_t scr_vec_t; -typedef int32_t scr_entity_t; -typedef int32_t scr_string_t; + typedef int32_t scr_func_t; + typedef int32_t scr_int_t; + // typedef vec3_t scr_vec_t; + typedef int32_t scr_entity_t; + typedef int32_t scr_string_t; #endif typedef struct ui_globalvars_s @@ -56,4 +61,6 @@ typedef struct ui_itemvars_s // also "rgba" vec3_t color; float alpha; -} ui_itemvars_t; \ No newline at end of file +} ui_itemvars_t; + +#endif /*_PRAGMA_PROGDEFS_GUI_H_*/ \ No newline at end of file diff --git a/src/engine/script/scr_debug.c b/src/engine/script/qcvm_debug.c similarity index 88% rename from src/engine/script/scr_debug.c rename to src/engine/script/qcvm_debug.c index ba28d871..62ef0cdc 100644 --- a/src/engine/script/scr_debug.c +++ b/src/engine/script/qcvm_debug.c @@ -11,7 +11,7 @@ See the attached GNU General Public License v2 for more details. // scr_debug.c #include "../pragma.h" -#include "script_internals.h" +#include "qcvm_private.h" static int type_size[9] = @@ -73,18 +73,18 @@ char* Scr_ValueString(etype_t type, eval_t* val) switch (type) { case ev_string: - sprintf(line, "%s", ScrInternal_String(val->string)); + sprintf(line, "%s", Scr_GetString(val->string)); break; case ev_entity: sprintf(line, "entity %i", (int)NUM_FOR_ENT(VM_TO_ENT(val->edict))); break; case ev_function: f = active_qcvm->functions + val->function; - sprintf(line, "%s()", ScrInternal_String(f->s_name)); + sprintf(line, "%s()", Scr_GetString(f->s_name)); break; case ev_field: def = ScrInternal_FieldAtOfs(val->_int); - sprintf(line, ".%s", ScrInternal_String(def->s_name)); + sprintf(line, ".%s", Scr_GetString(def->s_name)); break; case ev_void: sprintf(line, "*void*"); @@ -130,18 +130,18 @@ char* Scr_ValueStringDeveloper(etype_t type, eval_t* val) switch (type) { case ev_string: - sprintf(line, "'%s' [string]", ScrInternal_String(val->string)); + sprintf(line, "'%s' [string]", Scr_GetString(val->string)); break; case ev_entity: sprintf(line, "%i [entity]", (int)NUM_FOR_ENT(VM_TO_ENT(val->edict))); break; case ev_function: f = active_qcvm->functions + val->function; - sprintf(line, "%s [function]", ScrInternal_String(f->s_name)); + sprintf(line, "%s [function]", Scr_GetString(f->s_name)); break; case ev_field: def = ScrInternal_FieldAtOfs(val->_int); - sprintf(line, "%s [field]", ScrInternal_String(def->s_name)); + sprintf(line, "%s [field]", Scr_GetString(def->s_name)); break; case ev_void: sprintf(line, "*void*"); @@ -184,18 +184,18 @@ char* Scr_UglyValueString(etype_t type, eval_t* val) switch (type) { case ev_string: - sprintf(line, "%s", ScrInternal_String(val->string)); + sprintf(line, "%s", Scr_GetString(val->string)); break; case ev_entity: //sprintf(line, "%i", NUM_FOR_EDICT(PROG_TO_GENT(val->edict))); // braxi -- fixme break; case ev_function: f = active_qcvm->functions + val->function; - sprintf(line, "%s", ScrInternal_String(f->s_name)); + sprintf(line, "%s", Scr_GetString(f->s_name)); break; case ev_field: def = ScrInternal_FieldAtOfs(val->_int); - sprintf(line, "%s", ScrInternal_String(def->s_name)); + sprintf(line, "%s", Scr_GetString(def->s_name)); break; case ev_void: sprintf(line, "void"); @@ -245,7 +245,7 @@ char* Scr_GlobalString(int ofs) else { s = Scr_ValueString(def->type, val); - sprintf(line, "%i(%s)%s", ofs, ScrInternal_String(def->s_name), s); + sprintf(line, "%i(%s)%s", ofs, Scr_GetString(def->s_name), s); } i = (int)strlen(line); @@ -267,7 +267,7 @@ char* Scr_GlobalStringNoContents(int ofs) if (!def) sprintf(line, "%i(???)", ofs); else - sprintf(line, "%i(%s)", ofs, ScrInternal_String(def->s_name)); + sprintf(line, "%i(%s)", ofs, Scr_GetString(def->s_name)); i = (int)strlen(line); for (; i < 20; i++) @@ -356,7 +356,7 @@ void Scr_StackTrace() Com_Printf("%i: \n", i); } else - Com_Printf("%i: %s : %s\n", i, ScrInternal_String(f->s_file), ScrInternal_String(f->s_name)); + Com_Printf("%i: %s : %s\n", i, Scr_GetString(f->s_file), Scr_GetString(f->s_name)); } } diff --git a/src/engine/script/scr_exec.c b/src/engine/script/qcvm_exec.c similarity index 98% rename from src/engine/script/scr_exec.c rename to src/engine/script/qcvm_exec.c index 3a39fec8..e65d9986 100644 --- a/src/engine/script/scr_exec.c +++ b/src/engine/script/qcvm_exec.c @@ -11,7 +11,7 @@ See the attached GNU General Public License v2 for more details. // scr_execution.c #include "../pragma.h" -#include "script_internals.h" +#include "qcvm_private.h" extern ddef_t* ScrInternal_GlobalAtOfs(int ofs); extern ddef_t* Scr_FindEntityField(char* name); @@ -282,7 +282,7 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName) if (!--vm->runawayCounter) { - Scr_RunError("runaway loop error in function %s (%s)", ScrInternal_String(f->s_name), vmDefs[vm->progsType].filename); + Scr_RunError("runaway loop error in function %s (%s)", Scr_GetString(f->s_name), vmDefs[vm->progsType].filename); } vm->xfunction->profile++; @@ -625,8 +625,8 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName) break; case OP_EQ_S: // == string - char * ta = ScrInternal_String(a->string); - char * tb = ScrInternal_String(b->string); + char * ta = Scr_GetString(a->string); + char * tb = Scr_GetString(b->string); c->_float = !strcmp(ta, tb); break; @@ -649,7 +649,7 @@ void Scr_Execute(vmType_t vmtype, scr_func_t fnum, char* callFromFuncName) break; case OP_NE_S: // not equal string - c->_float = strcmp(ScrInternal_String(a->string), ScrInternal_String(b->string)); + c->_float = strcmp(Scr_GetString(a->string), Scr_GetString(b->string)); break; case OP_NE_E: // not equal int diff --git a/src/engine/script/scr_main.c b/src/engine/script/qcvm_main.c similarity index 94% rename from src/engine/script/scr_main.c rename to src/engine/script/qcvm_main.c index 94a034b1..06e45b75 100644 --- a/src/engine/script/scr_main.c +++ b/src/engine/script/qcvm_main.c @@ -7,10 +7,10 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ -// scr_main.c + #include "../pragma.h" -#include "script_internals.h" +#include "qcvm_private.h" cvar_t* vm_runaway; @@ -28,9 +28,6 @@ const qcvmdef_t vmDefs[NUM_SCRIPT_VMS] = {VM_GUI, "progs/gui.dat", 0, "gui"} }; - -#define G_INT(o) (*(int *)&active_qcvm->globals[o]) - void Cmd_PrintVMEntity_f(void); void Cmd_PrintAllVMEntities_f(void); @@ -91,7 +88,6 @@ ddef_t* ScrInternal_FieldAtOfs(int ofs) /* ============ Scr_FindEntityField - Returns ddef for an entity field matching name in active qcvm ============ */ @@ -104,7 +100,7 @@ ddef_t* Scr_FindEntityField(char* name) for (i = 0; i < active_qcvm->progs->numFieldDefs; i++) { def = &active_qcvm->fieldDefs[i]; - if (!strcmp(ScrInternal_String(def->s_name), name)) + if (!strcmp(Scr_GetString(def->s_name), name)) { return def; } @@ -193,7 +189,7 @@ qboolean Scr_ParseEpair(void* base, ddef_t* key, char* s, int memtag) ============ Scr_FindGlobal -Returns ddef for a glibal variable in active qcvm +Returns ddef for a global variable in active qcvm ============ */ ddef_t* Scr_FindGlobal(char* name) @@ -205,7 +201,7 @@ ddef_t* Scr_FindGlobal(char* name) for (i = 0; i < active_qcvm->progs->numGlobalDefs; i++) { def = &active_qcvm->globalDefs[i]; - if (!strcmp(ScrInternal_String(def->s_name), name)) + if (!strcmp(Scr_GetString(def->s_name), name)) return def; } return NULL; @@ -228,7 +224,7 @@ dfunction_t* ScrInternal_FindFunction(char* name) for (i = 0; i < active_qcvm->progs->numFunctions; i++) { func = &active_qcvm->functions[i]; - if (!strcmp(ScrInternal_String(func->s_name), name)) + if (!strcmp(Scr_GetString(func->s_name), name)) return func; } return NULL; @@ -296,16 +292,16 @@ void Scr_LoadProgram(qcvm_t *vm, char* filename) byte *raw; if (!vm) - Com_Error(ERR_FATAL, "%s: called but the vm is NULL\n", __FUNCTION__); + Com_Error(ERR_FATAL, "%s with NULL QCVM.\n", __FUNCTION__); if(vm->progs) - Com_Error(ERR_FATAL, "%s: tried to load second instance of %s script\n", __FUNCTION__, Scr_VMName(vm->progsType)); + Com_Error(ERR_FATAL, "Tried to load second instance of %s QCVM.\n", __FUNCTION__, Scr_VMName(vm->progsType)); // load file len = FS_LoadFile(filename, (void**)&raw); if (!len || len == -1) { - Com_Error(ERR_FATAL, "%s: couldn't load \"%s\"\n", __FUNCTION__, filename); + Com_Error(ERR_FATAL, "Could not load \"%s\".\n", filename); return; } @@ -341,7 +337,11 @@ void Scr_LoadProgram(qcvm_t *vm, char* filename) // cast the data from progs vm->functions = (dfunction_t*)((byte*)vm->progs + vm->progs->ofs_functions); + vm->strings = (char*)vm->progs + vm->progs->ofs_strings; + if ((vm->progs->ofs_strings + vm->progs->numstrings) >= len) + Com_Error(ERR_FATAL, "Strings in %s program are corrupt.\n", filename); + vm->globalDefs = (ddef_t*)((byte*)vm->progs + vm->progs->ofs_globaldefs); vm->fieldDefs = (ddef_t*)((byte*)vm->progs + vm->progs->ofs_fielddefs); vm->statements = (dstatement_t*)((byte*)vm->progs + vm->progs->ofs_statements); @@ -447,8 +447,8 @@ void Scr_CreateScriptVM(vmType_t vmType, unsigned int numEntities, size_t entity vm->progsType = vmType; vm->num_entities = numEntities; - vm->offsetToEntVars = entvarOfs; - vm->entity_size = entitySize; // invaild now, will be set properly in loadprogs + vm->offsetToEntVars = (int)entvarOfs; + vm->entity_size = (int)entitySize; // invaild now, will be set properly in loadprogs // load progs from file Scr_LoadProgram(vm, vmDefs[vmType].filename); @@ -590,7 +590,7 @@ Scr_GetEntitySize int Scr_GetEntitySize() { CheckScriptVM(__FUNCTION__); - return (int)active_qcvm->entity_size; + return active_qcvm->entity_size; } /* @@ -624,7 +624,7 @@ Scr_GetEntityFieldsSize int Scr_GetEntityFieldsSize() { CheckScriptVM(__FUNCTION__); - return (active_qcvm->progs->entityfields * 4); + return (active_qcvm->progs->entityfields * sizeof(int32_t)); } /* @@ -665,6 +665,7 @@ void Scr_PreInitVMs() qcvm[type] = NULL; scr_numBuiltins = 0; + Scr_InitSharedBuiltins(); CG_InitScriptBuiltins(); UI_InitScriptBuiltins(); @@ -675,7 +676,6 @@ void Scr_PreInitVMs() // add developer comands Cmd_AddCommand("vm_printent", Cmd_PrintVMEntity_f); Cmd_AddCommand("vm_printents", Cmd_PrintAllVMEntities_f); -// Cmd_AddCommand("vm_reload", cmd_vm_reload_f); Cmd_AddCommand("vm_generatedefs", Cmd_VM_GenerateDefs_f); } @@ -692,6 +692,7 @@ void Scr_Shutdown() Cmd_RemoveCommand("vm_printent"); Cmd_RemoveCommand("vm_printents"); + Cmd_RemoveCommand("vm_generatedefs"); if (scr_builtins) { diff --git a/src/engine/script/script_internals.h b/src/engine/script/qcvm_private.h similarity index 83% rename from src/engine/script/script_internals.h rename to src/engine/script/qcvm_private.h index ade3c2f0..1608822a 100644 --- a/src/engine/script/script_internals.h +++ b/src/engine/script/qcvm_private.h @@ -8,8 +8,13 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ +#ifndef _PRAGMA_QCVM_PRIVATE_H_ +#define _PRAGMA_QCVM_PRIVATE_H_ + #pragma once +#include "scriptvm.h" // in case.. + typedef enum { // vanilla progs @@ -50,6 +55,8 @@ etype_t; #define OFS_PARM7 25 #define RESERVED_OFS 28 +#define MAX_PARMS 8 + #define DEF_SAVEGLOBAL (1<<15) enum @@ -59,7 +66,7 @@ enum // ============================================================= -#define MAX_PARMS 8 + typedef struct { @@ -74,20 +81,12 @@ typedef struct } dfunction_t; - typedef struct statement_s { uint16_t op; int16_t a, b, c; } dstatement_t; -typedef struct -{ - uint16_t type; // if DEF_SAVEGLOBGAL bit is set the variable needs to be saved in savegames - uint16_t ofs; - int32_t s_name; -} ddef_t; - typedef struct { @@ -155,8 +154,8 @@ typedef struct qcvm_s // sv_globalvars_t *globals_struct; unsigned int num_entities; // number of allocated entities vm_entity_t *entities; - unsigned int entity_size; // size of single entity - unsigned int offsetToEntVars; // *ptr + ofs = ent->v + int entity_size; // size of single entity + int offsetToEntVars; // *ptr + ofs = ent->v void *globals_struct; // sv_globalvars_t @@ -200,6 +199,16 @@ extern int scr_numBuiltins; extern qcvm_t *active_qcvm; extern const qcvmdef_t vmDefs[NUM_SCRIPT_VMS]; -extern char* ScrInternal_String(int str); extern void Scr_InitSharedBuiltins(); -extern void CheckScriptVM(const char* func); \ No newline at end of file +extern void CheckScriptVM(const char* func); + + +#define G_INT(o) (*(int32_t *)&active_qcvm->globals[o]) +#define G_ENTITY(o) ((vm_entity_t *)((byte *)active_qcvm->entities + *(int32_t *)&active_qcvm->globals[o])) +#define G_FLOAT(o) (active_qcvm->globals[o]) +#define G_STRING(o) (active_qcvm->strings + *(scr_string_t *)&active_qcvm->globals[o]) +#define G_VECTOR(o) (&active_qcvm->globals[o]) +#define RETURN_EDICT(e) (((int32_t *)active_qcvm->globals)[OFS_RETURN] = ENT_TO_VM(e)) + + +#endif /*_PRAGMA_QCVM_PRIVATE_H_*/ \ No newline at end of file diff --git a/src/engine/script/scr_utils.c b/src/engine/script/qcvm_utils.c similarity index 89% rename from src/engine/script/scr_utils.c rename to src/engine/script/qcvm_utils.c index 57d9bb0d..c55b14cb 100644 --- a/src/engine/script/scr_utils.c +++ b/src/engine/script/qcvm_utils.c @@ -10,14 +10,9 @@ See the attached GNU General Public License v2 for more details. // scr_utils.c #include "../server/server.h" -#include "script_internals.h" +#include "qcvm_private.h" + -#define G_INT(o) (*(int32_t *)&active_qcvm->globals[o]) -#define G_ENTITY(o) ((vm_entity_t *)((byte *)active_qcvm->entities + *(int32_t *)&active_qcvm->globals[o])) -#define G_FLOAT(o) (active_qcvm->globals[o]) -#define G_STRING(o) (active_qcvm->strings + *(scr_string_t *)&active_qcvm->globals[o]) -#define G_VECTOR(o) (&active_qcvm->globals[o]) -#define RETURN_EDICT(e) (((int32_t *)active_qcvm->globals)[OFS_RETURN] = ENT_TO_VM(e)) /* @@ -69,18 +64,6 @@ scr_func_t Scr_FindFunction(char* funcname) return -1; } -/* -============ -ScrInternal_String - -Returns string from script -============ -*/ -char* ScrInternal_String(int str) -{ - return active_qcvm->strings + str; -} - /* ============ Scr_GetString diff --git a/src/engine/script/scr_builtins_math.c b/src/engine/script/scr_builtins_math.c index 13c03b14..175fa275 100644 --- a/src/engine/script/scr_builtins_math.c +++ b/src/engine/script/scr_builtins_math.c @@ -8,7 +8,7 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ #include "../pragma.h" -#include "script_internals.h" +#include "qcvm_private.h" #define scr_random() ( ( rand() & 0x7fff ) / ( (float)0x7fff ) ) #define scr_crandom() ( 2.0 * ( scr_random() - 0.5 ) ) diff --git a/src/engine/script/scr_builtins_shared.c b/src/engine/script/scr_builtins_shared.c index cf196598..9f798ab3 100644 --- a/src/engine/script/scr_builtins_shared.c +++ b/src/engine/script/scr_builtins_shared.c @@ -8,7 +8,7 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ #include "../pragma.h" -#include "script_internals.h" +#include "qcvm_private.h" extern void Scr_InitMathBuiltins(); diff --git a/src/engine/script/scriptvm.h b/src/engine/script/scriptvm.h index 320f9e39..5589f6f2 100644 --- a/src/engine/script/scriptvm.h +++ b/src/engine/script/scriptvm.h @@ -7,6 +7,10 @@ Copyright (C) 1997-2001 Id Software, Inc. See the attached GNU General Public License v2 for more details. */ + +#ifndef _PRAGMA_QCVM_H_ +#define _PRAGMA_QCVM_H_ + #pragma once #define VM_DEFAULT_RUNAWAY 500000 // number of instructions a single program can execute before it throws infinite loop error @@ -22,15 +26,14 @@ extern cvar_t* vm_runaway; typedef byte vm_entity_t; -// FIXME -- move server and client stuff out of here -//typedef struct gentity_s gentity_t; -#include "progdefs_server.h" -//typedef struct rentity_s rentity_t; +typedef int32_t scr_func_t; +typedef int32_t scr_entity_t; +typedef int32_t scr_string_t; + #include "../client/cgame/progdefs_client.h" -//typedef struct rentity_s rentity_t; +#include "progdefs_server.h" #include "progdefs_ui.h" - // used to define in which VM a builtin can be used // THESE MUST MATCH vmType_t typedef enum @@ -61,19 +64,26 @@ typedef union eval_s scr_entity_t edict; } eval_t; +typedef struct +{ + uint16_t type; // if DEF_SAVEGLOBGAL bit is set the variable needs to be saved in savegames + uint16_t ofs; + int32_t s_name; +} ddef_t; + -extern void Scr_CreateScriptVM(vmType_t vmType, unsigned int numEntities, size_t entitySize, size_t entvarOfs); -extern void Scr_FreeScriptVM(vmType_t vmType); -extern qboolean Scr_IsVMLoaded(vmType_t vmtype); -extern void Scr_BindVM(vmType_t vmType); -extern int Scr_GetEntitySize(); -extern vm_entity_t* Scr_GetEntityPtr(); -extern void* Scr_GetGlobals(); -extern int Scr_GetEntityFieldsSize(); -extern unsigned Scr_GetProgsCRC(vmType_t vmType); +void Scr_CreateScriptVM(vmType_t vmType, unsigned int numEntities, size_t entitySize, size_t entvarOfs); +void Scr_FreeScriptVM(vmType_t vmType); +qboolean Scr_IsVMLoaded(vmType_t vmtype); +void Scr_BindVM(vmType_t vmType); +int Scr_GetEntitySize(); +vm_entity_t* Scr_GetEntityPtr(); +void* Scr_GetGlobals(); +int Scr_GetEntityFieldsSize(); +unsigned Scr_GetProgsCRC(vmType_t vmType); -extern void Scr_PreInitVMs(); -extern void Scr_Shutdown(); +void Scr_PreInitVMs(); +void Scr_Shutdown(); // scr_debug.c @@ -81,40 +91,49 @@ void Scr_StackTrace(); // scr_exec.c -extern void Scr_RunError(char* error, ...); -extern void Scr_Execute(vmType_t vm, scr_func_t fnum, char* callFromFuncName); -extern int Scr_NumArgs(); -extern char *Scr_BuiltinFuncName(); -extern eval_t* Scr_GetEntityFieldValue(vm_entity_t* ent, char* field); // FIXME +void Scr_RunError(char* error, ...); + +void Scr_Execute(vmType_t vm, scr_func_t fnum, char* callFromFuncName); + +int Scr_NumArgs(); + +char *Scr_BuiltinFuncName(); + +eval_t* Scr_GetEntityFieldValue(vm_entity_t* ent, char* field); // FIXME // scr_utils.c -extern void Scr_DefineBuiltin(void (*function)(void), pb_t type, char* fname, char* qcstring); -extern scr_func_t Scr_FindFunction(char* funcname); -extern int Scr_SetString(char* str); -extern char* Scr_GetString(int num); -extern char* Scr_VarString(int first); - -extern vm_entity_t* Scr_GetParmEntity(unsigned int parm); -extern float Scr_GetParmFloat(unsigned int parm); -extern int Scr_GetParmInt(unsigned int parm); -extern char* Scr_GetParmString(unsigned int parm); -extern float* Scr_GetParmVector(unsigned int parm); -extern void Scr_GetParmVector2(unsigned int parm, float* x, float* y, float* z); - -extern float Scr_GetReturnFloat(); - -extern void Scr_ReturnEntity(void *ed); -extern void Scr_ReturnFloat(float val); -extern void Scr_ReturnInt(int val); -extern void Scr_ReturnString(char* str); -extern void Scr_ReturnVector(float* val); - -extern void Scr_AddEntity(unsigned int parm, vm_entity_t* ed); -extern void Scr_AddFloat(unsigned int parm, float val); -extern void Scr_AddInt(unsigned int parm, int val); -extern void Scr_AddString(unsigned int parm, char* str); -extern void Scr_AddVector(unsigned int parm, float* vec); + +void Scr_DefineBuiltin(void (*function)(void), pb_t type, char* fname, char* qcstring); + +scr_func_t Scr_FindFunction(char* funcname); + +int Scr_SetString(char* str); + +char* Scr_GetString(int num); + +char* Scr_VarString(int first); + +vm_entity_t* Scr_GetParmEntity(unsigned int parm); +float Scr_GetParmFloat(unsigned int parm); +int Scr_GetParmInt(unsigned int parm); +char* Scr_GetParmString(unsigned int parm); +float* Scr_GetParmVector(unsigned int parm); +void Scr_GetParmVector2(unsigned int parm, float* x, float* y, float* z); + +float Scr_GetReturnFloat(); + +void Scr_ReturnEntity(void *ed); +void Scr_ReturnFloat(float val); +void Scr_ReturnInt(int val); +void Scr_ReturnString(char* str); +void Scr_ReturnVector(float* val); + +void Scr_AddEntity(unsigned int parm, vm_entity_t* ed); +void Scr_AddFloat(unsigned int parm, float val); +void Scr_AddInt(unsigned int parm, int val); +void Scr_AddString(unsigned int parm, char* str); +void Scr_AddVector(unsigned int parm, float* vec); // @@ -134,4 +153,6 @@ extern void Scr_AddVector(unsigned int parm, float* vec); #define NEXT_ENT(ent) ((vm_entity_t*)ent + Scr_GetEntitySize()) // get entity index -#define NUM_FOR_ENT(ent) ( ((vm_entity_t*)(ent)- Scr_GetEntityPtr()) / Scr_GetEntitySize()) \ No newline at end of file +#define NUM_FOR_ENT(ent) ( ((vm_entity_t*)(ent)- Scr_GetEntityPtr()) / Scr_GetEntitySize()) + +#endif /*_PRAGMA_QCVM_H_*/ \ No newline at end of file diff --git a/src/engine/server/sv_gentity.c b/src/engine/server/sv_gentity.c index 556ee2cc..871001cc 100644 --- a/src/engine/server/sv_gentity.c +++ b/src/engine/server/sv_gentity.c @@ -10,7 +10,7 @@ See the attached GNU General Public License v2 for more details. // sv_gentity.c #include "server.h" -#include "../script/script_internals.h" +#include "../script/qcvm_private.h" // HAAAACK extern ddef_t* Scr_FindEntityField(char* name); //scr_main.c extern qboolean Scr_ParseEpair(void* base, ddef_t* key, char* s, int memtag); //scr_main.c diff --git a/src/engine/server/sv_main.c b/src/engine/server/sv_main.c index 3faa413e..938055f4 100644 --- a/src/engine/server/sv_main.c +++ b/src/engine/server/sv_main.c @@ -795,7 +795,7 @@ void SV_SetConfigString(int index, char *valueString) } if (!valueString || valueString == NULL) - valueString = ""; + valueString = "\0"; // change the string in sv strncpy(sv.configstrings[index], valueString, sizeof(sv.configstrings[index])); diff --git a/src/tools/tools_shared.cpp b/src/tools/tools_shared.cpp index 1cfbfcfb..2e4cd4bf 100644 --- a/src/tools/tools_shared.cpp +++ b/src/tools/tools_shared.cpp @@ -360,10 +360,7 @@ void Com_Tokenize(char* text) { // clear the args from the last string for (int i = 0; i < com_argc; i++) - free(com_argc[i]); - - //cmd_argc = 0; - com_args[0] = 0; + free(com_argv[i]); com_argc = 0;