autocvars: update to current value after loading a savegame, to always fulfill the...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 18 May 2010 18:46:29 +0000 (18:46 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 18 May 2010 18:46:29 +0000 (18:46 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10200 d7cf8633-e32d-0410-b094-e92efae38249

cvar.c
cvar.h
host_cmd.c

diff --git a/cvar.c b/cvar.c
index bf6df5a..c6f6936 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -253,6 +253,55 @@ void Cvar_CompleteCvarPrint (const char *partial)
                        Con_Printf ("^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
 }
 
+// we assume that prog is already set to the target progs
+static void Cvar_UpdateAutoCvar(cvar_t *var)
+{
+       int i;
+       if(!prog)
+               Host_Error("Cvar_UpdateAutoCvar: no prog set");
+       i = PRVM_GetProgNr();
+       if(var->globaldefindex_progid[i] == prog->id)
+       {
+               // MUST BE SYNCED WITH prvm_edict.c PRVM_LoadProgs
+               int j;
+               const char *s;
+               prvm_eval_t *val = (prvm_eval_t *)(prog->globals.generic + prog->globaldefs[var->globaldefindex[i]].ofs);
+               switch(prog->globaldefs[var->globaldefindex[i]].type & ~DEF_SAVEGLOBAL)
+               {
+                       case ev_float:
+                               val->_float = var->value;
+                               break;
+                       case ev_vector:
+                               s = var->string;
+                               VectorClear(val->vector);
+                               for (j = 0;j < 3;j++)
+                               {
+                                       while (*s && ISWHITESPACE(*s))
+                                               s++;
+                                       if (!*s)
+                                               break;
+                                       val->vector[j] = atof(s);
+                                       while (!ISWHITESPACE(*s))
+                                               s++;
+                                       if (!*s)
+                                               break;
+                               }
+                               break;
+                       case ev_string:
+                               PRVM_ChangeEngineString(var->globaldefindex_stringno[i], var->string);
+                               val->string = var->globaldefindex_stringno[i];
+                               break;
+               }
+       }
+}
+
+// called after loading a savegame
+void Cvar_UpdateAllAutoCvars(void)
+{
+       cvar_t *var;
+       for (var = cvar_vars ; var ; var = var->next)
+               Cvar_UpdateAutoCvar(var);
+}
 
 /*
 ============
@@ -344,39 +393,7 @@ void Cvar_SetQuick_Internal (cvar_t *var, const char *value)
                if(PRVM_ProgLoaded(i))
                {
                        PRVM_SetProg(i);
-                       if(var->globaldefindex_progid[i] == prog->id)
-                       {
-                               // MUST BE SYNCED WITH prvm_edict.c PRVM_LoadProgs
-                               int j;
-                               const char *s;
-                               prvm_eval_t *val = (prvm_eval_t *)(prog->globals.generic + prog->globaldefs[var->globaldefindex[i]].ofs);
-                               switch(prog->globaldefs[var->globaldefindex[i]].type & ~DEF_SAVEGLOBAL)
-                               {
-                                       case ev_float:
-                                               val->_float = var->value;
-                                               break;
-                                       case ev_vector:
-                                               s = var->string;
-                                               VectorClear(val->vector);
-                                               for (j = 0;j < 3;j++)
-                                               {
-                                                       while (*s && ISWHITESPACE(*s))
-                                                               s++;
-                                                       if (!*s)
-                                                               break;
-                                                       val->vector[j] = atof(s);
-                                                       while (!ISWHITESPACE(*s))
-                                                               s++;
-                                                       if (!*s)
-                                                               break;
-                                               }
-                                               break;
-                                       case ev_string:
-                                               PRVM_ChangeEngineString(var->globaldefindex_stringno[i], var->string);
-                                               val->string = var->globaldefindex_stringno[i];
-                                               break;
-                               }
-                       }
+                       Cvar_UpdateAutoCvar(var);
                }
        }
        prog = tmpprog;
diff --git a/cvar.h b/cvar.h
index 1c04d86..3c94aae 100644 (file)
--- a/cvar.h
+++ b/cvar.h
@@ -216,6 +216,8 @@ cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *ne
 extern char *cvar_dummy_description; // ALWAYS the same pointer
 extern cvar_t *cvar_vars; // used to list all cvars
 
+void Cvar_UpdateAllAutoCvars(void); // updates ALL autocvars of the active prog to the cvar values (savegame loading)
+
 #ifdef FILLALLCVARSWITHRUBBISH
 void Cvar_FillAll_f();
 #endif /* FILLALLCVARSWITHRUBBISH */
index f341d7d..202e4d9 100644 (file)
@@ -924,6 +924,9 @@ void Host_Loadgame_f (void)
 
                        // parse the global vars
                        PRVM_ED_ParseGlobals (start);
+
+                       // restore the autocvar globals
+                       Cvar_UpdateAllAutoCvars();
                }
                else
                {