From: black Date: Sun, 3 Jul 2005 11:23:47 +0000 (+0000) Subject: -Moved findflags and findchainflags to the prvm_cmds.c. X-Git-Tag: xonotic-v0.1.0preview~4702 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=73b087899f1ad0101e7250ed7722cf7d001d7c5d;p=xonotic%2Fdarkplaces.git -Moved findflags and findchainflags to the prvm_cmds.c. -Added support for default values to the cvar system. -Added a cvar_defstring builtin to the vm. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5484 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cvar.c b/cvar.c index 2337ae87..8236ae84 100644 --- a/cvar.c +++ b/cvar.c @@ -95,6 +95,21 @@ const char *Cvar_VariableString (const char *var_name) return var->string; } +/* +============ +Cvar_VariableDefString +============ +*/ +const char *Cvar_VariableDefString (const char *var_name) +{ + cvar_t *var; + + var = Cvar_FindVar (var_name); + if (!var) + return cvar_null_string; + return var->defstring; +} + /* ============ @@ -213,7 +228,7 @@ void Cvar_SetQuick (cvar_t *var, const char *value) } if (developer.integer) - Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i}, \"%s\");\n", var->name, var->string, var->flags, value); + Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i, \"%s\"}, \"%s\");\n", var->name, var->string, var->flags, var->defstring, value); Cvar_SetQuick_Internal(var, value); } @@ -266,7 +281,7 @@ Adds a freestanding variable to the variable list. */ void Cvar_RegisterVariable (cvar_t *variable) { - cvar_t *cvar, *cvar2; + cvar_t *current, *next, *cvar; char *oldstr; if (developer.integer) @@ -287,6 +302,7 @@ void Cvar_RegisterVariable (cvar_t *variable) variable->flags |= (cvar->flags & ~CVAR_ALLOCATED); // cvar->string is now owned by variable instead variable->string = cvar->string; + variable->defstring = cvar->defstring; variable->value = atof (variable->string); variable->integer = (int) variable->value; // replace cvar with this one... @@ -299,13 +315,13 @@ void Cvar_RegisterVariable (cvar_t *variable) else { // otherwise find it somewhere in the list - for (cvar2 = cvar_vars;cvar2->next != cvar;cvar2 = cvar2->next); - if (cvar2->next == cvar) - cvar2->next = variable; + for (current = cvar_vars;current->next != cvar;current = current->next) + ; + current->next = variable; } // get rid of old allocated cvar - // (but not the cvar->string, because we kept that) + // (but not cvar->string and cvar->defstring, because we kept those) Z_Free(cvar->name); Z_Free(cvar); } @@ -325,19 +341,21 @@ void Cvar_RegisterVariable (cvar_t *variable) oldstr = variable->string; variable->string = Z_Malloc (strlen(variable->string)+1); strcpy (variable->string, oldstr); + variable->defstring = Z_Malloc (strlen(variable->string)+1); + strcpy (variable->defstring, oldstr); variable->value = atof (variable->string); variable->integer = (int) variable->value; // link the variable in // alphanumerical order - for( cvar = NULL, cvar2 = cvar_vars ; cvar2 && strcmp( cvar2->name, variable->name ) < 0 ; cvar = cvar2, cvar2 = cvar->next ) + for( current = NULL, next = cvar_vars ; next && strcmp( next->name, variable->name ) < 0 ; current = next, next = next->next ) ; - if( cvar ) { - cvar->next = variable; + if( current ) { + current->next = variable; } else { cvar_vars = variable; } - variable->next = cvar2; + variable->next = next; } /* @@ -360,6 +378,15 @@ cvar_t *Cvar_Get (const char *name, const char *value, int flags) { cvar->flags |= flags; Cvar_SetQuick_Internal (cvar, value); + // also set the default value (but only once) + if (~cvar->flags & CVAR_DEFAULTSET) + { + cvar->flags |= CVAR_DEFAULTSET; + + Z_Free(cvar->defstring); + cvar->defstring = Z_Malloc(strlen(value) + 1); + strcpy(cvar->defstring, value); + } return cvar; } @@ -373,11 +400,13 @@ cvar_t *Cvar_Get (const char *name, const char *value, int flags) // allocate a new cvar, cvar name, and cvar string // FIXME: these never get Z_Free'd cvar = Z_Malloc(sizeof(cvar_t)); - cvar->flags = flags | CVAR_ALLOCATED; + cvar->flags = flags | CVAR_ALLOCATED | CVAR_DEFAULTSET; cvar->name = Z_Malloc(strlen(name)+1); strcpy(cvar->name, name); cvar->string = Z_Malloc(strlen(value)+1); strcpy(cvar->string, value); + cvar->defstring = Z_Malloc(strlen(value)+1); + strcpy(cvar->defstring, value); cvar->value = atof (cvar->string); cvar->integer = (int) cvar->value; @@ -407,7 +436,7 @@ qboolean Cvar_Command (void) // perform a variable print or set if (Cmd_Argc() == 1) { - Con_Printf("\"%s\" is \"%s\"\n", v->name, v->string); + Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, v->string, v->defstring); return true; } @@ -471,7 +500,7 @@ void Cvar_List_f (void) if (partial && strncasecmp (partial,cvar->name,len)) continue; - Con_Printf("%s is \"%s\"\n", cvar->name, cvar->string); + Con_Printf("%s is \"%s\" [\"%s\"]\n", cvar->name, cvar->string, cvar->defstring); count++; } diff --git a/cvar.h b/cvar.h index 9523404e..b587e6b1 100644 --- a/cvar.h +++ b/cvar.h @@ -64,6 +64,7 @@ interface from being ambiguous. // used to determine if flags is valid #define CVAR_MAXFLAGSVAL 7 // for internal use only! +#define CVAR_DEFAULTSET (1<<30) #define CVAR_ALLOCATED (1<<31) /* @@ -104,11 +105,16 @@ menucvar_t; typedef struct cvar_s { int flags; + char *name; + char *string; int integer; float value; float vector[3]; + + char *defstring; + //menucvar_t menuinfo; struct cvar_s *next; } cvar_t; @@ -141,6 +147,9 @@ float Cvar_VariableValue (const char *var_name); const char *Cvar_VariableString (const char *var_name); // returns an empty string if not defined +const char *Cvar_VariableDefString (const char *var_name); +// returns an empty string if not defined + const char *Cvar_CompleteVariable (const char *partial); // attempts to match a partial variable name for command line completion // returns NULL if nothing fits diff --git a/mvm_cmds.c b/mvm_cmds.c index 55f1340c..5e1e65a1 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -900,8 +900,11 @@ prvm_builtin_t vm_m_builtins[] = { VM_altstr_prepare, VM_altstr_get, VM_altstr_set, - VM_altstr_ins, // 86 - 0,0,0,0, // 90 + VM_altstr_ins, + VM_findflags, + VM_findchainflags, + VM_cvar_defstring, // 89 + 0, // 90 e10, // 100 e100, // 200 e100, // 300 diff --git a/prvm_cmds.c b/prvm_cmds.c index 388ea5b2..8e07db72 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -524,7 +524,7 @@ void VM_cvar_string(void) name = PRVM_G_STRING(OFS_PARM0); if(!name) - PRVM_ERROR("VM_str_cvar: %s: null string\n", PRVM_NAME); + PRVM_ERROR("VM_cvar_string: %s: null string\n", PRVM_NAME); VM_CheckEmptyString(name); @@ -537,6 +537,36 @@ void VM_cvar_string(void) PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out); } + +/* +======================== +VM_cvar_defstring + +const string VM_cvar_defstring (string) +======================== +*/ +void VM_cvar_defstring (void) +{ + char *out; + const char *name; + const char *cvar_string; + VM_SAFEPARMCOUNT(1,VM_cvar_string); + + name = PRVM_G_STRING(OFS_PARM0); + + if(!name) + PRVM_ERROR("VM_cvar_defstring: %s: null string\n", PRVM_NAME); + + VM_CheckEmptyString(name); + + out = VM_GetTempString(); + + cvar_string = Cvar_VariableDefString(name); + + strcpy(out, cvar_string); + + PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out); +} /* ================= VM_cvar_set @@ -836,7 +866,6 @@ VM_findchain entity findchain(.string field, string match) ========= */ -int PRVM_ED_FindFieldOffset(const char *field); // chained search for strings in entity fields // entity(.string field, string match) findchain = #402; void VM_findchain (void) @@ -930,6 +959,88 @@ void VM_findchainfloat (void) VM_RETURN_EDICT(chain); } +/* +======================== +VM_findflags + +entity findflags(entity start, .float field, float match) +======================== +*/ +// LordHavoc: search for flags in float fields +void VM_findflags (void) +{ + int e; + int f; + int s; + prvm_edict_t *ed; + + VM_SAFEPARMCOUNT(3, VM_findflags); + + + e = PRVM_G_EDICTNUM(OFS_PARM0); + f = PRVM_G_INT(OFS_PARM1); + s = (int)PRVM_G_FLOAT(OFS_PARM2); + + for (e++ ; e < prog->num_edicts ; e++) + { + prog->xfunction->builtinsprofile++; + ed = PRVM_EDICT_NUM(e); + if (ed->priv.required->free) + continue; + if ((int)PRVM_E_FLOAT(ed,f) & s) + { + VM_RETURN_EDICT(ed); + return; + } + } + + VM_RETURN_EDICT(prog->edicts); +} + +/* +======================== +VM_findchainflags + +entity findchainflags(.float field, float match) +======================== +*/ +// LordHavoc: chained search for flags in float fields +void VM_findchainflags (void) +{ + int i; + int f; + int s; + int chain_of; + prvm_edict_t *ent, *chain; + + VM_SAFEPARMCOUNT(2, VM_findchainflags); + + if(!prog->flag & PRVM_FE_CHAIN) + PRVM_ERROR("VM_findchainflags: %s doesnt have a chain field !\n", PRVM_NAME); + + chain_of = PRVM_ED_FindField("chain")->ofs; + + chain = (prvm_edict_t *)prog->edicts; + + f = PRVM_G_INT(OFS_PARM0); + s = (int)PRVM_G_FLOAT(OFS_PARM1); + + ent = PRVM_NEXT_EDICT(prog->edicts); + for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent)) + { + prog->xfunction->builtinsprofile++; + if (ent->priv.required->free) + continue; + if (!((int)PRVM_E_FLOAT(ent,f) & s)) + continue; + + PRVM_E_INT(ent,chain_of) = PRVM_EDICT_TO_PROG(chain); + chain = ent; + } + + VM_RETURN_EDICT(chain); +} + /* ========= VM_coredump diff --git a/prvm_cmds.h b/prvm_cmds.h index ef95c4f2..c7832647 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -101,11 +101,18 @@ string chr(float ascii) float itof(intt ent) intt ftoi(float num) +-------will be removed soon---------- float altstr_count(string) string altstr_prepare(string) string altstr_get(string,float) string altstr_set(string altstr, float num, string set) string altstr_ins(string altstr, float num, string set) +-------------------------------------- + +entity findflags(entity start, .float field, float match) +entity findchainflags(.float field, float match) + +const string VM_cvar_defstring (string) perhaps only : Menu : WriteMsg =============================== @@ -219,6 +226,7 @@ void VM_break (void); void VM_localcmd (void); void VM_cvar (void); void VM_cvar_string(void); +void VM_cvar_defstring (void); void VM_cvar_set (void); void VM_dprint (void); void VM_ftos (void); @@ -234,6 +242,8 @@ void VM_find (void); void VM_findfloat (void); void VM_findchain (void); void VM_findchainfloat (void); +void VM_findflags (void); +void VM_findchainflags (void); void VM_precache_file (void); void VM_precache_error (void); void VM_precache_sound (void); @@ -249,17 +259,6 @@ void VM_floor (void); void VM_ceil (void); void VM_nextent (void); -// REMOVE THESE -sizebuf_t *VM_WriteDest (void); -void VM_WriteByte (void); -void VM_WriteChar (void); -void VM_WriteShort (void); -void VM_WriteLong (void); -void VM_WriteAngle (void); -void VM_WriteCoord (void); -void VM_WriteString (void); -void VM_WriteEntity (void); - void VM_changelevel (void); void VM_sin (void); void VM_cos (void); diff --git a/prvm_edict.c b/prvm_edict.c index fd4440b8..c5b6f5ed 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1283,7 +1283,7 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required } prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false); - if (prog->progs == NULL) + if (prog->progs == NULL || fs_filesize < sizeof(dprograms_t)) PRVM_ERROR ("PRVM_LoadProgs: couldn't load %s for %s", filename, PRVM_NAME); Con_DPrintf("%s programs occupy %iK.\n", PRVM_NAME, fs_filesize/1024); @@ -1493,7 +1493,7 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required } } - PRVM_LoadLNO( filename ); + PRVM_LoadLNO(filename); PRVM_Init_Exec(); diff --git a/prvm_exec.c b/prvm_exec.c index 4c6ae452..7b0c0a5e 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -124,6 +124,13 @@ PRVM_PrintStatement void PRVM_PrintStatement (dstatement_t *s) { int i; + + if( prog->statement_linenums ) { + int opnum; + + opnum = s - prog->statements; + Con_Printf( "%s:%i: ", PRVM_GetString( prog->xfunction->s_file ), prog->statement_linenums[ opnum ] ); + } if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0])) { diff --git a/prvm_execprogram.h b/prvm_execprogram.h index fd50149a..d125cd7e 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -194,7 +194,7 @@ prog->xfunction->profile += profile - startprofile; startprofile = profile; prog->xstatement = st - prog->statements; - Host_Error("assignment to world entity in %s", PRVM_NAME); + PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME); return; } ed = PRVM_PROG_TO_EDICT(OPA->edict); diff --git a/svvm_cmds.c b/svvm_cmds.c index 5dae1f94..5eed529d 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -739,63 +739,6 @@ void PF_findradius (void) VM_RETURN_EDICT(chain); } -// LordHavoc: search for flags in float fields -void PF_findflags (void) -{ - int e; - int f; - int s; - prvm_edict_t *ed; - - e = PRVM_G_EDICTNUM(OFS_PARM0); - f = PRVM_G_INT(OFS_PARM1); - s = (int)PRVM_G_FLOAT(OFS_PARM2); - - for (e++ ; e < prog->num_edicts ; e++) - { - prog->xfunction->builtinsprofile++; - ed = PRVM_EDICT_NUM(e); - if (ed->priv.server->free) - continue; - if ((int)PRVM_E_FLOAT(ed,f) & s) - { - VM_RETURN_EDICT(ed); - return; - } - } - - VM_RETURN_EDICT(prog->edicts); -} - -// LordHavoc: chained search for flags in float fields -void PF_findchainflags (void) -{ - int i; - int f; - int s; - prvm_edict_t *ent, *chain; - - chain = (prvm_edict_t *)prog->edicts; - - f = PRVM_G_INT(OFS_PARM0); - s = (int)PRVM_G_FLOAT(OFS_PARM1); - - ent = PRVM_NEXT_EDICT(prog->edicts); - for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent)) - { - prog->xfunction->builtinsprofile++; - if (ent->priv.server->free) - continue; - if (!((int)PRVM_E_FLOAT(ent,f) & s)) - continue; - - ent->fields.server->chain = PRVM_EDICT_TO_PROG(chain); - chain = ent; - } - - VM_RETURN_EDICT(chain); -} - void PF_precache_file (void) { // precache_file is only used to copy files with qcc, it does nothing PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0); @@ -2513,8 +2456,8 @@ VM_search_end, // #445 void(float handle) search_end (DP_FS_SEARCH) VM_search_getsize, // #446 float(float handle) search_getsize (DP_FS_SEARCH) VM_search_getfilename, // #447 string(float handle, float num) search_getfilename (DP_FS_SEARCH) VM_cvar_string, // #448 string(string s) cvar_string (DP_QC_CVAR_STRING) -PF_findflags, // #449 entity(entity start, .float fld, float match) findflags (DP_QC_FINDFLAGS) -PF_findchainflags, // #450 entity(.float fld, float match) findchainflags (DP_QC_FINDCHAINFLAGS) +VM_findflags, // #449 entity(entity start, .float fld, float match) findflags (DP_QC_FINDFLAGS) +VM_findchainflags, // #450 entity(.float fld, float match) findchainflags (DP_QC_FINDCHAINFLAGS) PF_gettagindex, // #451 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO) PF_gettaginfo, // #452 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO) PF_dropclient, // #453 void(entity clent) dropclient (DP_SV_DROPCLIENT)