X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=prvm_edict.c;h=3c50397e70a4e324c5d4811758f4500418d6fdfe;hp=3ca385a8fac6fec3bfda71ded0787d1630b2998f;hb=c9c011dcf7b2ee062e9493139b89fff99f63ea25;hpb=487018e74a3d4099baf296b57a5a12f0eee00f32 diff --git a/prvm_edict.c b/prvm_edict.c index 3ca385a8..3c50397e 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -29,29 +29,29 @@ int prvm_type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(v prvm_eval_t prvm_badvalue; // used only for error returns -cvar_t prvm_language = {CVAR_CLIENT | CVAR_SERVER | CVAR_SAVE, "prvm_language", "", "when set, loads PROGSFILE.LANGUAGENAME.po and common.LANGUAGENAME.po for string translations; when set to dump, PROGSFILE.pot is written from the strings in the progs"}; +cvar_t prvm_language = {CF_CLIENT | CF_SERVER | CF_ARCHIVE, "prvm_language", "", "when set, loads PROGSFILE.LANGUAGENAME.po and common.LANGUAGENAME.po for string translations; when set to dump, PROGSFILE.pot is written from the strings in the progs"}; // LadyHavoc: prints every opcode as it executes - warning: this is significant spew -cvar_t prvm_traceqc = {CVAR_CLIENT | CVAR_SERVER, "prvm_traceqc", "0", "prints every QuakeC statement as it is executed (only for really thorough debugging!)"}; +cvar_t prvm_traceqc = {CF_CLIENT | CF_SERVER, "prvm_traceqc", "0", "prints every QuakeC statement as it is executed (only for really thorough debugging!)"}; // LadyHavoc: counts usage of each QuakeC statement -cvar_t prvm_statementprofiling = {CVAR_CLIENT | CVAR_SERVER, "prvm_statementprofiling", "0", "counts how many times each QuakeC statement has been executed, these counts are displayed in prvm_printfunction output (if enabled)"}; -cvar_t prvm_timeprofiling = {CVAR_CLIENT | CVAR_SERVER, "prvm_timeprofiling", "0", "counts how long each function has been executed, these counts are displayed in prvm_profile output (if enabled)"}; -cvar_t prvm_coverage = {CVAR_CLIENT | CVAR_SERVER, "prvm_coverage", "0", "report and count coverage events (1: per-function, 2: coverage() builtin, 4: per-statement)"}; -cvar_t prvm_backtraceforwarnings = {CVAR_CLIENT | CVAR_SERVER, "prvm_backtraceforwarnings", "0", "print a backtrace for warnings too"}; -cvar_t prvm_leaktest = {CVAR_CLIENT | CVAR_SERVER, "prvm_leaktest", "0", "try to detect memory leaks in strings or entities"}; -cvar_t prvm_leaktest_follow_targetname = {CVAR_CLIENT | CVAR_SERVER, "prvm_leaktest_follow_targetname", "0", "if set, target/targetname links are considered when leak testing; this should normally not be required, as entities created during startup - e.g. info_notnull - are never considered leaky"}; -cvar_t prvm_leaktest_ignore_classnames = {CVAR_CLIENT | CVAR_SERVER, "prvm_leaktest_ignore_classnames", "", "classnames of entities to NOT leak check because they are found by find(world, classname, ...) but are actually spawned by QC code (NOT map entities)"}; -cvar_t prvm_errordump = {CVAR_CLIENT | CVAR_SERVER, "prvm_errordump", "0", "write a savegame on crash to crash-server.dmp"}; -cvar_t prvm_breakpointdump = {CVAR_CLIENT | CVAR_SERVER, "prvm_breakpointdump", "0", "write a savegame on breakpoint to breakpoint-server.dmp"}; -cvar_t prvm_reuseedicts_startuptime = {CVAR_CLIENT | CVAR_SERVER, "prvm_reuseedicts_startuptime", "2", "allows immediate re-use of freed entity slots during start of new level (value in seconds)"}; -cvar_t prvm_reuseedicts_neverinsameframe = {CVAR_CLIENT | CVAR_SERVER, "prvm_reuseedicts_neverinsameframe", "1", "never allows re-use of freed entity slots during same frame"}; -cvar_t prvm_garbagecollection_enable = {CVAR_CLIENT | CVAR_SERVER, "prvm_garbagecollection_enable", "1", "automatically scan for and free resources that are not referenced by the code being executed in the VM"}; -cvar_t prvm_garbagecollection_notify = {CVAR_CLIENT | CVAR_SERVER, "prvm_garbagecollection_notify", "0", "print out a notification for each resource freed by garbage collection"}; -cvar_t prvm_garbagecollection_scan_limit = {CVAR_CLIENT | CVAR_SERVER, "prvm_garbagecollection_scan_limit", "10000", "scan this many fields or resources per frame to free up unreferenced resources"}; -cvar_t prvm_garbagecollection_strings = {CVAR_CLIENT | CVAR_SERVER, "prvm_garbagecollection_strings", "1", "automatically call strunzone() on strings that are not referenced"}; -cvar_t prvm_stringdebug = {CVAR_CLIENT | CVAR_SERVER, "prvm_stringdebug", "0", "Print debug and warning messages related to strings"}; +cvar_t prvm_statementprofiling = {CF_CLIENT | CF_SERVER, "prvm_statementprofiling", "0", "counts how many times each QuakeC statement has been executed, these counts are displayed in prvm_printfunction output (if enabled)"}; +cvar_t prvm_timeprofiling = {CF_CLIENT | CF_SERVER, "prvm_timeprofiling", "0", "counts how long each function has been executed, these counts are displayed in prvm_profile output (if enabled)"}; +cvar_t prvm_coverage = {CF_CLIENT | CF_SERVER, "prvm_coverage", "0", "report and count coverage events (1: per-function, 2: coverage() builtin, 4: per-statement)"}; +cvar_t prvm_backtraceforwarnings = {CF_CLIENT | CF_SERVER, "prvm_backtraceforwarnings", "0", "print a backtrace for warnings too"}; +cvar_t prvm_leaktest = {CF_CLIENT | CF_SERVER, "prvm_leaktest", "0", "try to detect memory leaks in strings or entities"}; +cvar_t prvm_leaktest_follow_targetname = {CF_CLIENT | CF_SERVER, "prvm_leaktest_follow_targetname", "0", "if set, target/targetname links are considered when leak testing; this should normally not be required, as entities created during startup - e.g. info_notnull - are never considered leaky"}; +cvar_t prvm_leaktest_ignore_classnames = {CF_CLIENT | CF_SERVER, "prvm_leaktest_ignore_classnames", "", "classnames of entities to NOT leak check because they are found by find(world, classname, ...) but are actually spawned by QC code (NOT map entities)"}; +cvar_t prvm_errordump = {CF_CLIENT | CF_SERVER, "prvm_errordump", "0", "write a savegame on crash to crash-server.dmp"}; +cvar_t prvm_breakpointdump = {CF_CLIENT | CF_SERVER, "prvm_breakpointdump", "0", "write a savegame on breakpoint to breakpoint-server.dmp"}; +cvar_t prvm_reuseedicts_startuptime = {CF_CLIENT | CF_SERVER, "prvm_reuseedicts_startuptime", "2", "allows immediate re-use of freed entity slots during start of new level (value in seconds)"}; +cvar_t prvm_reuseedicts_neverinsameframe = {CF_CLIENT | CF_SERVER, "prvm_reuseedicts_neverinsameframe", "1", "never allows re-use of freed entity slots during same frame"}; +cvar_t prvm_garbagecollection_enable = {CF_CLIENT | CF_SERVER, "prvm_garbagecollection_enable", "1", "automatically scan for and free resources that are not referenced by the code being executed in the VM"}; +cvar_t prvm_garbagecollection_notify = {CF_CLIENT | CF_SERVER, "prvm_garbagecollection_notify", "0", "print out a notification for each resource freed by garbage collection"}; +cvar_t prvm_garbagecollection_scan_limit = {CF_CLIENT | CF_SERVER, "prvm_garbagecollection_scan_limit", "10000", "scan this many fields or resources per frame to free up unreferenced resources"}; +cvar_t prvm_garbagecollection_strings = {CF_CLIENT | CF_SERVER, "prvm_garbagecollection_strings", "1", "automatically call strunzone() on strings that are not referenced"}; +cvar_t prvm_stringdebug = {CF_CLIENT | CF_SERVER, "prvm_stringdebug", "0", "Print debug and warning messages related to strings"}; static double prvm_reuseedicts_always_allow = 0; -qboolean prvm_runawaycheck = true; +qbool prvm_runawaycheck = true; //============================================================================ // mempool handling @@ -127,7 +127,7 @@ void PRVM_MEM_IncreaseEdicts(prvm_prog_t *prog) int PRVM_ED_FindFieldOffset(prvm_prog_t *prog, const char *field) { - ddef_t *d; + mdef_t *d; d = PRVM_ED_FindField(prog, field); if (!d) return -1; @@ -136,7 +136,7 @@ int PRVM_ED_FindFieldOffset(prvm_prog_t *prog, const char *field) int PRVM_ED_FindGlobalOffset(prvm_prog_t *prog, const char *global) { - ddef_t *d; + mdef_t *d; d = PRVM_ED_FindGlobal(prog, global); if (!d) return -1; @@ -233,7 +233,7 @@ PRVM_ED_CanAlloc Returns if this particular edict could get allocated by PRVM_ED_Alloc ================= */ -qboolean PRVM_ED_CanAlloc(prvm_prog_t *prog, prvm_edict_t *e) +qbool PRVM_ED_CanAlloc(prvm_prog_t *prog, prvm_edict_t *e) { if(!e->priv.required->free) return false; @@ -324,9 +324,9 @@ void PRVM_ED_Free(prvm_prog_t *prog, prvm_edict_t *ed) PRVM_ED_GlobalAtOfs ============ */ -static ddef_t *PRVM_ED_GlobalAtOfs (prvm_prog_t *prog, int ofs) +static mdef_t *PRVM_ED_GlobalAtOfs (prvm_prog_t *prog, unsigned int ofs) { - ddef_t *def; + mdef_t *def; int i; for (i = 0;i < prog->numglobaldefs;i++) @@ -343,9 +343,9 @@ static ddef_t *PRVM_ED_GlobalAtOfs (prvm_prog_t *prog, int ofs) PRVM_ED_FieldAtOfs ============ */ -ddef_t *PRVM_ED_FieldAtOfs (prvm_prog_t *prog, int ofs) +mdef_t *PRVM_ED_FieldAtOfs (prvm_prog_t *prog, unsigned int ofs) { - ddef_t *def; + mdef_t *def; int i; for (i = 0;i < prog->numfielddefs;i++) @@ -362,9 +362,9 @@ ddef_t *PRVM_ED_FieldAtOfs (prvm_prog_t *prog, int ofs) PRVM_ED_FindField ============ */ -ddef_t *PRVM_ED_FindField (prvm_prog_t *prog, const char *name) +mdef_t *PRVM_ED_FindField (prvm_prog_t *prog, const char *name) { - ddef_t *def; + mdef_t *def; int i; for (i = 0;i < prog->numfielddefs;i++) @@ -381,9 +381,9 @@ ddef_t *PRVM_ED_FindField (prvm_prog_t *prog, const char *name) PRVM_ED_FindGlobal ============ */ -ddef_t *PRVM_ED_FindGlobal (prvm_prog_t *prog, const char *name) +mdef_t *PRVM_ED_FindGlobal (prvm_prog_t *prog, const char *name) { - ddef_t *def; + mdef_t *def; int i; for (i = 0;i < prog->numglobaldefs;i++) @@ -402,7 +402,7 @@ PRVM_ED_FindGlobalEval */ prvm_eval_t *PRVM_ED_FindGlobalEval(prvm_prog_t *prog, const char *name) { - ddef_t *def = PRVM_ED_FindGlobal(prog, name); + mdef_t *def = PRVM_ED_FindGlobal(prog, name); return def ? (prvm_eval_t *) &prog->globals.fp[def->ofs] : NULL; } @@ -435,7 +435,7 @@ Returns a string describing *data in a type specific manner */ static char *PRVM_ValueString (prvm_prog_t *prog, etype_t type, prvm_eval_t *val, char *line, size_t linelength) { - ddef_t *def; + mdef_t *def; mfunction_t *f; int n; @@ -503,7 +503,7 @@ char *PRVM_UglyValueString (prvm_prog_t *prog, etype_t type, prvm_eval_t *val, c { int i; const char *s; - ddef_t *def; + mdef_t *def; mfunction_t *f; type = (etype_t)((int)type & ~DEF_SAVEGLOBAL); @@ -592,7 +592,7 @@ char *PRVM_GlobalString (prvm_prog_t *prog, int ofs, char *line, size_t lineleng { char *s; //size_t i; - ddef_t *def; + mdef_t *def; prvm_eval_t *val; char valuebuf[MAX_INPUTLINE]; @@ -617,7 +617,7 @@ char *PRVM_GlobalString (prvm_prog_t *prog, int ofs, char *line, size_t lineleng char *PRVM_GlobalStringNoContents (prvm_prog_t *prog, int ofs, char *line, size_t linelength) { //size_t i; - ddef_t *def; + mdef_t *def; def = PRVM_ED_GlobalAtOfs(prog, ofs); if (!def) @@ -646,7 +646,7 @@ For debugging void PRVM_ED_Print(prvm_prog_t *prog, prvm_edict_t *ed, const char *wildcard_fieldname) { size_t l; - ddef_t *d; + mdef_t *d; prvm_eval_t *val; int i, j; const char *name; @@ -727,7 +727,7 @@ For savegames */ void PRVM_ED_Write (prvm_prog_t *prog, qfile_t *f, prvm_edict_t *ed) { - ddef_t *d; + mdef_t *d; prvm_eval_t *val; int i, j; const char *name; @@ -889,7 +889,7 @@ PRVM_ED_WriteGlobals */ void PRVM_ED_WriteGlobals (prvm_prog_t *prog, qfile_t *f) { - ddef_t *def; + mdef_t *def; int i; const char *name; int type; @@ -929,7 +929,7 @@ PRVM_ED_ParseGlobals void PRVM_ED_ParseGlobals (prvm_prog_t *prog, const char *data) { char keyname[MAX_INPUTLINE]; - ddef_t *key; + mdef_t *key; while (1) { @@ -977,11 +977,11 @@ Can parse either fields or globals returns false if error ============= */ -qboolean PRVM_ED_ParseEpair(prvm_prog_t *prog, prvm_edict_t *ent, ddef_t *key, const char *s, qboolean parsebackslash) +qbool PRVM_ED_ParseEpair(prvm_prog_t *prog, prvm_edict_t *ent, mdef_t *key, const char *s, qbool parsebackslash) { int i, l; char *new_p; - ddef_t *def; + mdef_t *def; prvm_eval_t *val; mfunction_t *func; @@ -1147,7 +1147,7 @@ static void PRVM_ED_EdictGet_f(cmd_state_t *cmd) { prvm_prog_t *prog; prvm_edict_t *ed; - ddef_t *key; + mdef_t *key; const char *s; prvm_eval_t *v; char valuebuf[MAX_INPUTLINE]; @@ -1190,7 +1190,7 @@ fail: static void PRVM_ED_GlobalGet_f(cmd_state_t *cmd) { prvm_prog_t *prog; - ddef_t *key; + mdef_t *key; const char *s; prvm_eval_t *v; char valuebuf[MAX_INPUTLINE]; @@ -1239,7 +1239,7 @@ static void PRVM_ED_EdictSet_f(cmd_state_t *cmd) { prvm_prog_t *prog; prvm_edict_t *ed; - ddef_t *key; + mdef_t *key; if(Cmd_Argc(cmd) != 5) { @@ -1253,7 +1253,7 @@ static void PRVM_ED_EdictSet_f(cmd_state_t *cmd) ed = PRVM_EDICT_NUM(atoi(Cmd_Argv(cmd, 2))); if((key = PRVM_ED_FindField(prog, Cmd_Argv(cmd, 3))) == 0) - Con_Printf("Key %s not found !\n", Cmd_Argv(cmd, 3)); + Con_Printf("Key %s not found!\n", Cmd_Argv(cmd, 3)); else PRVM_ED_ParseEpair(prog, ed, key, Cmd_Argv(cmd, 4), true); } @@ -1269,9 +1269,9 @@ Used for initial level load and for savegames. */ const char *PRVM_ED_ParseEdict (prvm_prog_t *prog, const char *data, prvm_edict_t *ent) { - ddef_t *key; - qboolean anglehack; - qboolean init; + mdef_t *key; + qbool anglehack; + qbool init; char keyname[256]; size_t n; @@ -1358,6 +1358,112 @@ const char *PRVM_ED_ParseEdict (prvm_prog_t *prog, const char *data, prvm_edict_ return data; } +void PRVM_ED_CallPrespawnFunction(prvm_prog_t *prog, prvm_edict_t *ent) +{ + if (PRVM_serverfunction(SV_OnEntityPreSpawnFunction)) + { + // self = ent + PRVM_serverglobalfloat(time) = sv.time; + PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent); + prog->ExecuteProgram(prog, PRVM_serverfunction(SV_OnEntityPreSpawnFunction), "QC function SV_OnEntityPreSpawnFunction is missing"); + } +} + +qbool PRVM_ED_CallSpawnFunction(prvm_prog_t *prog, prvm_edict_t *ent, const char *data, const char *start) +{ + const char *funcname; + mfunction_t *func; + prvm_eval_t *fulldata = NULL; + char vabuf[1024]; + +// +// immediately call spawn function, but only if there is a self global and a classname +// + if (!ent->priv.required->free) + { + if (!PRVM_alledictstring(ent, classname)) + { + Con_Print("No classname for:\n"); + PRVM_ED_Print(prog, ent, NULL); + PRVM_ED_Free (prog, ent); + return false; + } + /* + * This is required for FTE compatibility (FreeCS). + * It copies the key/value pairs themselves into a + * global for QC to parse on its own. + */ + else if (data && start) + { + if((fulldata = PRVM_ED_FindGlobalEval(prog, "__fullspawndata"))) + { + const char *in; + char *spawndata; + fulldata->string = PRVM_AllocString(prog, data - start + 1, &spawndata); + for(in = start; in < data; ) + { + char c = *in++; + if(c == '\n') + *spawndata++ = '\t'; + else + *spawndata++ = c; + } + *spawndata = 0; + } + } + + // look for the spawn function + funcname = PRVM_GetString(prog, PRVM_alledictstring(ent, classname)); + func = PRVM_ED_FindFunction (prog, va(vabuf, sizeof(vabuf), "spawnfunc_%s", funcname)); + if(!func) + if(!PRVM_allglobalfloat(require_spawnfunc_prefix)) + func = PRVM_ED_FindFunction (prog, funcname); + + if (!func) + { + // check for OnEntityNoSpawnFunction + if (PRVM_serverfunction(SV_OnEntityNoSpawnFunction)) + { + // self = ent + PRVM_serverglobalfloat(time) = sv.time; + PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent); + prog->ExecuteProgram(prog, PRVM_serverfunction(SV_OnEntityNoSpawnFunction), "QC function SV_OnEntityNoSpawnFunction is missing"); + } + else + { + + Con_DPrint("No spawn function for:\n"); + if (developer.integer > 0) // don't confuse non-developers with errors + PRVM_ED_Print(prog, ent, NULL); + + PRVM_ED_Free (prog, ent); + return false; // not included in "inhibited" count + } + } + else + { + // self = ent + PRVM_serverglobalfloat(time) = sv.time; + PRVM_allglobaledict(self) = PRVM_EDICT_TO_PROG(ent); + prog->ExecuteProgram(prog, func - prog->functions, ""); + } + return true; + } + PRVM_ED_Free(prog, ent); + return false; +} + +void PRVM_ED_CallPostspawnFunction (prvm_prog_t *prog, prvm_edict_t *ent) +{ + if(!ent->priv.required->free) + if (PRVM_serverfunction(SV_OnEntityPostSpawnFunction)) + { + // self = ent + PRVM_serverglobalfloat(time) = sv.time; + PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent); + prog->ExecuteProgram(prog, PRVM_serverfunction(SV_OnEntityPostSpawnFunction), "QC function SV_OnEntityPostSpawnFunction is missing"); + } +} /* ================ @@ -1379,11 +1485,6 @@ void PRVM_ED_LoadFromFile (prvm_prog_t *prog, const char *data) prvm_edict_t *ent; const char *start; int parsed, inhibited, spawned, died; - ddef_t *fulldata_ddef = NULL; - prvm_eval_t *fulldata = NULL; - const char *funcname; - mfunction_t *func; - char vabuf[1024]; parsed = 0; inhibited = 0; @@ -1427,13 +1528,7 @@ void PRVM_ED_LoadFromFile (prvm_prog_t *prog, const char *data) continue; } - if (PRVM_serverfunction(SV_OnEntityPreSpawnFunction)) - { - // self = ent - PRVM_serverglobalfloat(time) = sv.time; - PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent); - prog->ExecuteProgram(prog, PRVM_serverfunction(SV_OnEntityPreSpawnFunction), "QC function SV_OnEntityPreSpawnFunction is missing"); - } + PRVM_ED_CallPrespawnFunction(prog, ent); if(ent->priv.required->free) { @@ -1441,90 +1536,12 @@ void PRVM_ED_LoadFromFile (prvm_prog_t *prog, const char *data) continue; } -// -// immediately call spawn function, but only if there is a self global and a classname -// - if(!ent->priv.required->free) - { - if (!PRVM_alledictstring(ent, classname)) - { - Con_Print("No classname for:\n"); - PRVM_ED_Print(prog, ent, NULL); - PRVM_ED_Free (prog, ent); - continue; - } - /* - * This is required for FTE compatibility (FreeCS). - * It copies the key/value pairs themselves into a - * global for QC to parse on its own. - */ - else - { - fulldata_ddef = PRVM_ED_FindGlobal(prog, "__fullspawndata"); - if(fulldata_ddef) - fulldata = (prvm_eval_t *) &prog->globals.fp[fulldata_ddef->ofs]; - if(fulldata) - { - const char *in; - char *spawndata; - fulldata->string = PRVM_AllocString(prog, data - start + 1, &spawndata); - for(in = start; in < data; ) - { - char c = *in++; - if(c == '\n') - *spawndata++ = '\t'; - else - *spawndata++ = c; - } - *spawndata = 0; - } - } - - // look for the spawn function - funcname = PRVM_GetString(prog, PRVM_alledictstring(ent, classname)); - func = PRVM_ED_FindFunction (prog, va(vabuf, sizeof(vabuf), "spawnfunc_%s", funcname)); - if(!func) - if(!PRVM_allglobalfloat(require_spawnfunc_prefix)) - func = PRVM_ED_FindFunction (prog, funcname); - - if (!func) - { - // check for OnEntityNoSpawnFunction - if (PRVM_serverfunction(SV_OnEntityNoSpawnFunction)) - { - // self = ent - PRVM_serverglobalfloat(time) = sv.time; - PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent); - prog->ExecuteProgram(prog, PRVM_serverfunction(SV_OnEntityNoSpawnFunction), "QC function SV_OnEntityNoSpawnFunction is missing"); - } - else - { - if (developer.integer > 0) // don't confuse non-developers with errors - { - Con_Print("No spawn function for:\n"); - PRVM_ED_Print(prog, ent, NULL); - } - PRVM_ED_Free (prog, ent); - continue; // not included in "inhibited" count - } - } - else - { - // self = ent - PRVM_serverglobalfloat(time) = sv.time; - PRVM_allglobaledict(self) = PRVM_EDICT_TO_PROG(ent); - prog->ExecuteProgram(prog, func - prog->functions, ""); - } - } + SV_LinkEdict(ent); - if(!ent->priv.required->free) - if (PRVM_serverfunction(SV_OnEntityPostSpawnFunction)) - { - // self = ent - PRVM_serverglobalfloat(time) = sv.time; - PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent); - prog->ExecuteProgram(prog, PRVM_serverfunction(SV_OnEntityPostSpawnFunction), "QC function SV_OnEntityPostSpawnFunction is missing"); - } + if(!PRVM_ED_CallSpawnFunction(prog, ent, data, start)) + continue; + + PRVM_ED_CallPostspawnFunction(prog, ent); spawned++; if (ent->priv.required->free) @@ -1714,7 +1731,7 @@ static void PRVM_PO_ParseString(char *out, const char *in, size_t outsize) case '\\': if(outsize > 0) { *out++ = '\\'; --outsize; } break; case '"': if(outsize > 0) { *out++ = '"'; --outsize; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - if(outsize > 0) + if(outsize > 0) *out = *in - '0'; ++in; if(*in >= '0' && *in <= '7') @@ -1858,7 +1875,7 @@ static po_t *PRVM_PO_Load(const char *filename, const char *filename2, mempool_t memset(&thisstr, 0, sizeof(thisstr)); } } - + Mem_Free((char *) buf); } @@ -1979,9 +1996,14 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da { int i; dprograms_t *dprograms; - dstatement_t *instatements; - ddef_t *infielddefs; - ddef_t *inglobaldefs; + + dstatement16_t *instatements16; + dstatement32_t *instatements32; + ddef16_t *infielddefs16; + ddef32_t *infielddefs32; + ddef16_t *inglobaldefs16; + ddef32_t *inglobaldefs32; + int *inglobals; dfunction_t *infunctions; char *instrings; @@ -2001,6 +2023,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da char vabuf[1024]; char vabuf2[1024]; cvar_t *cvar; + int structtype = 0; if (prog->loaded) prog->error_cmd("PRVM_LoadProgs: there is already a %s program loaded!", prog->name ); @@ -2031,13 +2054,29 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da // byte swap the header prog->progs_version = LittleLong(dprograms->version); prog->progs_crc = LittleLong(dprograms->crc); - if (prog->progs_version != PROG_VERSION) + if (prog->progs_version == 7) + { + dprograms_v7_t *v7 = (dprograms_v7_t*)dprograms; + structtype = LittleLong(v7->secondaryversion); + if (structtype == PROG_SECONDARYVERSION16 || + structtype == PROG_SECONDARYVERSION32) // barely supported + Con_Printf(CON_WARN "WARNING: %s: %s targets FTEQW, for which support is incomplete. Proceed at your own risk.\n", prog->name, filename); + else + prog->error_cmd("%s: %s targets unknown engine", prog->name, filename); + + if (v7->numbodylessfuncs != 0 || v7->numtypes != 0 || v7->blockscompressed != 0) + prog->error_cmd("%s: %s uses unsupported features.", prog->name, filename); + } + else if (prog->progs_version != PROG_VERSION) prog->error_cmd("%s: %s has wrong version number (%i should be %i)", prog->name, filename, prog->progs_version, PROG_VERSION); - instatements = (dstatement_t *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_statements)); + instatements16 = (dstatement16_t *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_statements)); + instatements32 = (dstatement32_t *)instatements16; prog->progs_numstatements = LittleLong(dprograms->numstatements); - inglobaldefs = (ddef_t *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_globaldefs)); + inglobaldefs16 = (ddef16_t *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_globaldefs)); + inglobaldefs32 = (ddef32_t *)inglobaldefs16; prog->progs_numglobaldefs = LittleLong(dprograms->numglobaldefs); - infielddefs = (ddef_t *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_fielddefs)); + infielddefs16 = (ddef16_t *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_fielddefs)); + infielddefs32 = (ddef32_t *)infielddefs16; prog->progs_numfielddefs = LittleLong(dprograms->numfielddefs); infunctions = (dfunction_t *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_functions)); prog->progs_numfunctions = LittleLong(dprograms->numfunctions); @@ -2069,12 +2108,12 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da Mem_ExpandableArray_NewArray(&prog->stringbuffersarray, prog->progs_mempool, sizeof(prvm_stringbuffer_t), 64); // we need to expand the globaldefs and fielddefs to include engine defs - prog->globaldefs = (ddef_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numglobaldefs + numrequiredglobals) * sizeof(ddef_t)); + prog->globaldefs = (mdef_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numglobaldefs + numrequiredglobals) * sizeof(mdef_t)); prog->globals.fp = (prvm_vec_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numglobals + requiredglobalspace + 2) * sizeof(prvm_vec_t)); // + 2 is because of an otherwise occurring overrun in RETURN instruction // when trying to return the last or second-last global // (RETURN always returns a vector, there is no RETURN_F instruction) - prog->fielddefs = (ddef_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numfielddefs + numrequiredfields) * sizeof(ddef_t)); + prog->fielddefs = (mdef_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numfielddefs + numrequiredfields) * sizeof(mdef_t)); // we need to convert the statements to our memory format prog->statements = (mstatement_t *)Mem_Alloc(prog->progs_mempool, prog->progs_numstatements * sizeof(mstatement_t)); // allocate space for profiling statement usage @@ -2098,12 +2137,26 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da } // copy the globaldefs to the new globaldefs list - for (i=0 ; inumglobaldefs ; i++) + switch(structtype) { - prog->globaldefs[i].type = LittleShort(inglobaldefs[i].type); - prog->globaldefs[i].ofs = LittleShort(inglobaldefs[i].ofs); - prog->globaldefs[i].s_name = LittleLong(inglobaldefs[i].s_name); - // TODO bounds check ofs, s_name + case PROG_SECONDARYVERSION32: + for (i=0 ; inumglobaldefs ; i++) + { + prog->globaldefs[i].type = LittleLong(inglobaldefs32[i].type); + prog->globaldefs[i].ofs = LittleLong(inglobaldefs32[i].ofs); + prog->globaldefs[i].s_name = LittleLong(inglobaldefs32[i].s_name); + // TODO bounds check ofs, s_name + } + break; + default: + for (i=0 ; inumglobaldefs ; i++) + { + prog->globaldefs[i].type = (unsigned short)LittleShort(inglobaldefs16[i].type); + prog->globaldefs[i].ofs = (unsigned short)LittleShort(inglobaldefs16[i].ofs); + prog->globaldefs[i].s_name = LittleLong(inglobaldefs16[i].s_name); + // TODO bounds check ofs, s_name + } + break; } // append the required globals @@ -2120,14 +2173,30 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da } // copy the progs fields to the new fields list - for (i = 0;i < prog->numfielddefs;i++) + switch(structtype) { - prog->fielddefs[i].type = LittleShort(infielddefs[i].type); - if (prog->fielddefs[i].type & DEF_SAVEGLOBAL) - prog->error_cmd("PRVM_LoadProgs: prog->fielddefs[i].type & DEF_SAVEGLOBAL in %s", prog->name); - prog->fielddefs[i].ofs = LittleShort(infielddefs[i].ofs); - prog->fielddefs[i].s_name = LittleLong(infielddefs[i].s_name); - // TODO bounds check ofs, s_name + case PROG_SECONDARYVERSION32: + for (i = 0;i < prog->numfielddefs;i++) + { + prog->fielddefs[i].type = LittleLong(infielddefs32[i].type); + if (prog->fielddefs[i].type & DEF_SAVEGLOBAL) + prog->error_cmd("PRVM_LoadProgs: prog->fielddefs[i].type & DEF_SAVEGLOBAL in %s", prog->name); + prog->fielddefs[i].ofs = LittleLong(infielddefs32[i].ofs); + prog->fielddefs[i].s_name = LittleLong(infielddefs32[i].s_name); + // TODO bounds check ofs, s_name + } + break; + default: + for (i = 0;i < prog->numfielddefs;i++) + { + prog->fielddefs[i].type = (unsigned short)LittleShort(infielddefs16[i].type); + if (prog->fielddefs[i].type & DEF_SAVEGLOBAL) + prog->error_cmd("PRVM_LoadProgs: prog->fielddefs[i].type & DEF_SAVEGLOBAL in %s", prog->name); + prog->fielddefs[i].ofs = (unsigned short)LittleShort(infielddefs16[i].ofs); + prog->fielddefs[i].s_name = LittleLong(infielddefs16[i].s_name); + // TODO bounds check ofs, s_name + } + break; } // append the required fields @@ -2170,14 +2239,24 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da } } - // LadyHavoc: TODO: support 32bit progs statement formats // copy, remap globals in statements, bounds check for (i = 0;i < prog->progs_numstatements;i++) { - op = (opcode_t)LittleShort(instatements[i].op); - a = (unsigned short)LittleShort(instatements[i].a); - b = (unsigned short)LittleShort(instatements[i].b); - c = (unsigned short)LittleShort(instatements[i].c); + switch(structtype) + { + case PROG_SECONDARYVERSION32: + op = (opcode_t)LittleLong(instatements32[i].op); + a = (unsigned int)LittleLong(instatements32[i].a); + b = (unsigned int)LittleLong(instatements32[i].b); + c = (unsigned int)LittleLong(instatements32[i].c); + break; + default: + op = (opcode_t)LittleShort(instatements16[i].op); + a = (unsigned short)LittleShort(instatements16[i].a); + b = (unsigned short)LittleShort(instatements16[i].b); + c = (unsigned short)LittleShort(instatements16[i].c); + break; + } switch (op) { case OP_IF: @@ -2203,7 +2282,82 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da break; default: Con_DPrintf("PRVM_LoadProgs: unknown opcode %d at statement %d in %s\n", (int)op, i, prog->name); + + //make sure its something well defined. + prog->statements[i].op = OP_BOUNDCHECK; + prog->statements[i].operand[0] = 0; + prog->statements[i].operand[1] = + prog->statements[i].operand[2] = op; + prog->statements[i].jumpabsolute = -1; break; + case OP_STORE_I: + case OP_ADD_I: + case OP_ADD_FI: + case OP_ADD_IF: + case OP_SUB_I: + case OP_SUB_FI: + case OP_SUB_IF: + case OP_CONV_IF: + case OP_CONV_FI: + case OP_LOAD_I: + case OP_STOREP_I: + case OP_BITAND_I: + case OP_BITOR_I: + case OP_MUL_I: + case OP_DIV_I: + case OP_EQ_I: + case OP_NE_I: + case OP_NOT_I: + case OP_DIV_VF: + case OP_STORE_P: + case OP_LE_I: + case OP_GE_I: + case OP_LT_I: + case OP_GT_I: + case OP_LE_IF: + case OP_GE_IF: + case OP_LT_IF: + case OP_GT_IF: + case OP_LE_FI: + case OP_GE_FI: + case OP_LT_FI: + case OP_GT_FI: + case OP_EQ_IF: + case OP_EQ_FI: + case OP_MUL_IF: + case OP_MUL_FI: + case OP_MUL_VI: + case OP_DIV_IF: + case OP_DIV_FI: + case OP_BITAND_IF: + case OP_BITOR_IF: + case OP_BITAND_FI: + case OP_BITOR_FI: + case OP_AND_I: + case OP_OR_I: + case OP_AND_IF: + case OP_OR_IF: + case OP_AND_FI: + case OP_OR_FI: + case OP_NE_IF: + case OP_NE_FI: + case OP_GSTOREP_I: + case OP_GSTOREP_F: + case OP_GSTOREP_ENT: + case OP_GSTOREP_FLD: + case OP_GSTOREP_S: + case OP_GSTOREP_FNC: + case OP_GSTOREP_V: +// case OP_GADDRESS: + case OP_GLOAD_I: + case OP_GLOAD_F: + case OP_GLOAD_FLD: + case OP_GLOAD_ENT: + case OP_GLOAD_S: + case OP_GLOAD_FNC: + case OP_BOUNDCHECK: + case OP_GLOAD_V: + // global global global case OP_ADD_F: case OP_ADD_V: @@ -2267,6 +2421,9 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da case OP_STOREP_FLD: case OP_STOREP_S: case OP_STOREP_FNC: + if (c) //Spike -- DP is alergic to pointers in QC. Try to avoid too many nasty surprises. + Con_DPrintf("PRVM_LoadProgs: storep-with-offset is not permitted in %s\n", prog->name); + //fallthrough case OP_STORE_F: case OP_STORE_ENT: case OP_STORE_FLD: @@ -2302,6 +2459,8 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da case OP_RETURN: if ( a >= prog->progs_numglobals) prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d) in %s", i, prog->name); + if (b || c) //Spike -- added this check just as a diagnostic... + Con_DPrintf("PRVM_LoadProgs: unexpected offset on call opcode in %s. Hexen2 format is not supported\n", prog->name); prog->statements[i].op = op; prog->statements[i].operand[0] = remapglobal(a); prog->statements[i].operand[1] = -1; @@ -2343,7 +2502,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da // in CSQC we really shouldn't be able to change how stuff works... sorry for now // later idea: include a list of authorized .po file checksums with the csprogs { - qboolean deftrans = prog == CLVM_prog; + qbool deftrans = prog == CLVM_prog; const char *realfilename = (prog != CLVM_prog ? filename : csqc_progname.string); if(deftrans) // once we have dotranslate_ strings, ALWAYS use the opt-in method! { @@ -2488,7 +2647,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da prog->error_cmd("PRVM_LoadProgs: could not create cvar for autocvar global %s in %s", name, prog->name); cvar->globaldefindex[prog - prvm_prog_list] = i; } - else if((cvar->flags & CVAR_PRIVATE) == 0) + else if((cvar->flags & CF_PRIVATE) == 0) { // MUST BE SYNCED WITH cvar.c Cvar_Set int j; @@ -2535,7 +2694,7 @@ fail: PRVM_UpdateBreakpoints(prog); - // set flags & ddef_ts in prog + // set flags & mdef_ts in prog prog->flag = 0; @@ -2562,7 +2721,7 @@ static void PRVM_Fields_f(cmd_state_t *cmd) char tempstring[MAX_INPUTLINE], tempstring2[260]; const char *name; prvm_edict_t *ed; - ddef_t *d; + mdef_t *d; prvm_eval_t *val; // TODO @@ -2725,7 +2884,7 @@ PRVM_Global static void PRVM_Global_f(cmd_state_t *cmd) { prvm_prog_t *prog; - ddef_t *global; + mdef_t *global; char valuebuf[MAX_INPUTLINE]; if( Cmd_Argc(cmd) != 3 ) { Con_Printf( "prvm_global \n" ); @@ -2750,7 +2909,7 @@ PRVM_GlobalSet static void PRVM_GlobalSet_f(cmd_state_t *cmd) { prvm_prog_t *prog; - ddef_t *global; + mdef_t *global; if( Cmd_Argc(cmd) != 4 ) { Con_Printf( "prvm_globalset \n" ); return; @@ -2841,7 +3000,7 @@ static void PRVM_UpdateBreakpoints(prvm_prog_t *prog) if (debug->watch_global[0]) { - ddef_t *global = PRVM_ED_FindGlobal( prog, debug->watch_global ); + mdef_t *global = PRVM_ED_FindGlobal( prog, debug->watch_global ); if( !global ) { Con_Printf( "%s progs: no global named '%s' to watch!\n", prog->name, debug->watch_global ); @@ -2862,7 +3021,7 @@ static void PRVM_UpdateBreakpoints(prvm_prog_t *prog) if (debug->watch_field[0]) { - ddef_t *field = PRVM_ED_FindField( prog, debug->watch_field ); + mdef_t *field = PRVM_ED_FindField( prog, debug->watch_field ); if( !field ) { Con_Printf( "%s progs: no field named '%s' to watch!\n", prog->name, debug->watch_field ); @@ -2981,26 +3140,26 @@ PRVM_Init */ void PRVM_Init (void) { - Cmd_AddCommand(CMD_SHARED, "prvm_edict", PRVM_ED_PrintEdict_f, "print all data about an entity number in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_edicts", PRVM_ED_PrintEdicts_f, "prints all data about all entities in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_edictcount", PRVM_ED_Count_f, "prints number of active entities in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_profile", PRVM_Profile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_childprofile", PRVM_ChildProfile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu), sorted by time taken in function with child calls"); - Cmd_AddCommand(CMD_SHARED, "prvm_callprofile", PRVM_CallProfile_f, "prints execution statistics about the most time consuming QuakeC calls from the engine in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_fields", PRVM_Fields_f, "prints usage statistics on properties (how many entities have non-zero values) in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_globals", PRVM_Globals_f, "prints all global variables in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_global", PRVM_Global_f, "prints value of a specified global variable in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_globalset", PRVM_GlobalSet_f, "sets value of a specified global variable in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_edictset", PRVM_ED_EdictSet_f, "changes value of a specified property of a specified entity in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "prvm_edictget", PRVM_ED_EdictGet_f, "retrieves the value of a specified property of a specified entity in the selected VM (server, client menu) into a cvar or to the console"); - Cmd_AddCommand(CMD_SHARED, "prvm_globalget", PRVM_ED_GlobalGet_f, "retrieves the value of a specified global variable in the selected VM (server, client menu) into a cvar or to the console"); - Cmd_AddCommand(CMD_SHARED, "prvm_printfunction", PRVM_PrintFunction_f, "prints a disassembly (QuakeC instructions) of the specified function in the selected VM (server, client, menu)"); - Cmd_AddCommand(CMD_SHARED, "cl_cmd", PRVM_GameCommand_Client_f, "calls the client QC function GameCommand with the supplied string as argument"); - Cmd_AddCommand(CMD_SHARED, "menu_cmd", PRVM_GameCommand_Menu_f, "calls the menu QC function GameCommand with the supplied string as argument"); - Cmd_AddCommand(CMD_SHARED, "sv_cmd", PRVM_GameCommand_Server_f, "calls the server QC function GameCommand with the supplied string as argument"); - Cmd_AddCommand(CMD_SHARED, "prvm_breakpoint", PRVM_Breakpoint_f, "marks a statement or function as breakpoint (when this is executed, a stack trace is printed); to actually halt and investigate state, combine this with a gdb breakpoint on PRVM_Breakpoint, or with prvm_breakpointdump; run with just progs name to clear breakpoint"); - Cmd_AddCommand(CMD_SHARED, "prvm_globalwatchpoint", PRVM_GlobalWatchpoint_f, "marks a global as watchpoint (when this is executed, a stack trace is printed); to actually halt and investigate state, combine this with a gdb breakpoint on PRVM_Breakpoint, or with prvm_breakpointdump; run with just progs name to clear watchpoint"); - Cmd_AddCommand(CMD_SHARED, "prvm_edictwatchpoint", PRVM_EdictWatchpoint_f, "marks an entity field as watchpoint (when this is executed, a stack trace is printed); to actually halt and investigate state, combine this with a gdb breakpoint on PRVM_Breakpoint, or with prvm_breakpointdump; run with just progs name to clear watchpoint"); + Cmd_AddCommand(CF_SHARED, "prvm_edict", PRVM_ED_PrintEdict_f, "print all data about an entity number in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_edicts", PRVM_ED_PrintEdicts_f, "prints all data about all entities in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_edictcount", PRVM_ED_Count_f, "prints number of active entities in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_profile", PRVM_Profile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_childprofile", PRVM_ChildProfile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu), sorted by time taken in function with child calls"); + Cmd_AddCommand(CF_SHARED, "prvm_callprofile", PRVM_CallProfile_f, "prints execution statistics about the most time consuming QuakeC calls from the engine in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_fields", PRVM_Fields_f, "prints usage statistics on properties (how many entities have non-zero values) in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_globals", PRVM_Globals_f, "prints all global variables in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_global", PRVM_Global_f, "prints value of a specified global variable in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_globalset", PRVM_GlobalSet_f, "sets value of a specified global variable in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_edictset", PRVM_ED_EdictSet_f, "changes value of a specified property of a specified entity in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "prvm_edictget", PRVM_ED_EdictGet_f, "retrieves the value of a specified property of a specified entity in the selected VM (server, client menu) into a cvar or to the console"); + Cmd_AddCommand(CF_SHARED, "prvm_globalget", PRVM_ED_GlobalGet_f, "retrieves the value of a specified global variable in the selected VM (server, client menu) into a cvar or to the console"); + Cmd_AddCommand(CF_SHARED, "prvm_printfunction", PRVM_PrintFunction_f, "prints a disassembly (QuakeC instructions) of the specified function in the selected VM (server, client, menu)"); + Cmd_AddCommand(CF_SHARED, "cl_cmd", PRVM_GameCommand_Client_f, "calls the client QC function GameCommand with the supplied string as argument"); + Cmd_AddCommand(CF_SHARED, "menu_cmd", PRVM_GameCommand_Menu_f, "calls the menu QC function GameCommand with the supplied string as argument"); + Cmd_AddCommand(CF_SHARED, "sv_cmd", PRVM_GameCommand_Server_f, "calls the server QC function GameCommand with the supplied string as argument"); + Cmd_AddCommand(CF_SHARED, "prvm_breakpoint", PRVM_Breakpoint_f, "marks a statement or function as breakpoint (when this is executed, a stack trace is printed); to actually halt and investigate state, combine this with a gdb breakpoint on PRVM_Breakpoint, or with prvm_breakpointdump; run with just progs name to clear breakpoint"); + Cmd_AddCommand(CF_SHARED, "prvm_globalwatchpoint", PRVM_GlobalWatchpoint_f, "marks a global as watchpoint (when this is executed, a stack trace is printed); to actually halt and investigate state, combine this with a gdb breakpoint on PRVM_Breakpoint, or with prvm_breakpointdump; run with just progs name to clear watchpoint"); + Cmd_AddCommand(CF_SHARED, "prvm_edictwatchpoint", PRVM_EdictWatchpoint_f, "marks an entity field as watchpoint (when this is executed, a stack trace is printed); to actually halt and investigate state, combine this with a gdb breakpoint on PRVM_Breakpoint, or with prvm_breakpointdump; run with just progs name to clear watchpoint"); Cvar_RegisterVariable (&prvm_language); Cvar_RegisterVariable (&prvm_traceqc); @@ -3022,7 +3181,7 @@ void PRVM_Init (void) Cvar_RegisterVariable (&prvm_stringdebug); // COMMANDLINEOPTION: PRVM: -norunaway disables the runaway loop check (it might be impossible to exit DarkPlaces if used!) - prvm_runawaycheck = !COM_CheckParm("-norunaway"); + prvm_runawaycheck = !Sys_CheckParm("-norunaway"); //VM_Cmd_Init(); } @@ -3271,13 +3430,13 @@ void PRVM_FreeString(prvm_prog_t *prog, int num) prog->error_cmd("PRVM_FreeString: invalid string offset %i", num); } -static qboolean PRVM_IsStringReferenced(prvm_prog_t *prog, string_t string) +static qbool PRVM_IsStringReferenced(prvm_prog_t *prog, string_t string) { int i, j; for (i = 0;i < prog->numglobaldefs;i++) { - ddef_t *d = &prog->globaldefs[i]; + mdef_t *d = &prog->globaldefs[i]; if((etype_t)((int) d->type & ~DEF_SAVEGLOBAL) != ev_string) continue; if(string == PRVM_GLOBALFIELDSTRING(d->ofs)) @@ -3291,7 +3450,7 @@ static qboolean PRVM_IsStringReferenced(prvm_prog_t *prog, string_t string) continue; for (i=0; inumfielddefs; ++i) { - ddef_t *d = &prog->fielddefs[i]; + mdef_t *d = &prog->fielddefs[i]; if((etype_t)((int) d->type & ~DEF_SAVEGLOBAL) != ev_string) continue; if(string == PRVM_EDICTFIELDSTRING(ed, d->ofs)) @@ -3302,7 +3461,7 @@ static qboolean PRVM_IsStringReferenced(prvm_prog_t *prog, string_t string) return false; } -static qboolean PRVM_IsEdictRelevant(prvm_prog_t *prog, prvm_edict_t *edict) +static qbool PRVM_IsEdictRelevant(prvm_prog_t *prog, prvm_edict_t *edict) { char vabuf[1024]; char vabuf2[1024]; @@ -3354,7 +3513,7 @@ static qboolean PRVM_IsEdictRelevant(prvm_prog_t *prog, prvm_edict_t *edict) return false; } -static qboolean PRVM_IsEdictReferenced(prvm_prog_t *prog, prvm_edict_t *edict, int mark) +static qbool PRVM_IsEdictReferenced(prvm_prog_t *prog, prvm_edict_t *edict, int mark) { int i, j; int edictnum = PRVM_NUM_FOR_EDICT(edict); @@ -3383,7 +3542,7 @@ static qboolean PRVM_IsEdictReferenced(prvm_prog_t *prog, prvm_edict_t *edict, i } for (i=0; inumfielddefs; ++i) { - ddef_t *d = &prog->fielddefs[i]; + mdef_t *d = &prog->fielddefs[i]; if((etype_t)((int) d->type & ~DEF_SAVEGLOBAL) != ev_entity) continue; if(edictnum == PRVM_EDICTFIELDEDICT(ed, d->ofs)) @@ -3397,7 +3556,7 @@ static qboolean PRVM_IsEdictReferenced(prvm_prog_t *prog, prvm_edict_t *edict, i static void PRVM_MarkReferencedEdicts(prvm_prog_t *prog) { int i, j; - qboolean found_new; + qbool found_new; int stage; // Stage 1: world, all entities that are relevant, and all entities that are referenced by globals. @@ -3411,7 +3570,7 @@ static void PRVM_MarkReferencedEdicts(prvm_prog_t *prog) } for (i = 0;i < prog->numglobaldefs;i++) { - ddef_t *d = &prog->globaldefs[i]; + mdef_t *d = &prog->globaldefs[i]; prvm_edict_t *ed; if((etype_t)((int) d->type & ~DEF_SAVEGLOBAL) != ev_entity) continue; @@ -3450,7 +3609,7 @@ static void PRVM_MarkReferencedEdicts(prvm_prog_t *prog) void PRVM_LeakTest(prvm_prog_t *prog) { int i, j; - qboolean leaked = false; + qbool leaked = false; if(!prog->leaktest_active) return; @@ -3541,7 +3700,7 @@ void PRVM_GarbageCollection(prvm_prog_t *prog) case PRVM_GC_GLOBALS_MARK: for (; gc->globals_mark_progress < prog->numglobaldefs && (limit--) > 0; gc->globals_mark_progress++) { - ddef_t *d = &prog->globaldefs[gc->globals_mark_progress]; + mdef_t *d = &prog->globaldefs[gc->globals_mark_progress]; switch (d->type) { case ev_string: @@ -3571,7 +3730,7 @@ void PRVM_GarbageCollection(prvm_prog_t *prog) case PRVM_GC_FIELDS_MARK: for (; gc->fields_mark_progress < prog->numfielddefs && limit > 0;) { - ddef_t *d = &prog->fielddefs[gc->fields_mark_progress]; + mdef_t *d = &prog->fielddefs[gc->fields_mark_progress]; switch (d->type) { case ev_string: