(svn r7231) -Codechange: rename ini_get_variable to GetVariableAddress for use both in settings.c
and saveload.c
--- a/saveload.c Tue Nov 21 16:54:16 2006 +0000
+++ b/saveload.c Tue Nov 21 20:20:30 2006 +0000
@@ -751,7 +751,7 @@
}
for (; sld->cmd != SL_END; sld++) {
- void *ptr = (byte*)object + (ptrdiff_t)sld->address;
+ void *ptr = GetVariableAddress(object, sld);
SlObjectMember(ptr, sld);
}
}
--- a/saveload.h Tue Nov 21 16:54:16 2006 +0000
+++ b/saveload.h Tue Nov 21 20:20:30 2006 +0000
@@ -271,6 +271,15 @@
return type & 0xF; // GB(type, 0, 4);
}
+/** Get the address of the variable. Which one to pick depends on the object
+ * pointer. If it is NULL we are dealing with global variables so the address
+ * is taken. If non-null only the offset is stored in the union and we need
+ * to add this to the address of the object */
+static inline void *GetVariableAddress(const void *object, const SaveLoad *sld)
+{
+ return (byte*)object + (ptrdiff_t)sld->address;
+}
+
int64 ReadValue(const void *ptr, VarType conv);
void WriteValue(void *ptr, VarType conv, int64 val);
--- a/settings.c Tue Nov 21 16:54:16 2006 +0000
+++ b/settings.c Tue Nov 21 20:20:30 2006 +0000
@@ -690,7 +690,7 @@
item = ini_getitem(group, s, false);
p = (item == NULL) ? sdb->def : string_to_val(sdb, item->value);
- ptr = ini_get_variable(sld, object);
+ ptr = GetVariableAddress(object, sld);
switch (sdb->cmd) {
case SDT_BOOLX: /* All four are various types of (integer) numbers */
@@ -766,7 +766,7 @@
}
item = ini_getitem(group, s, true);
- ptr = ini_get_variable(sld, object);
+ ptr = GetVariableAddress(object, sld);
if (item->value != NULL) {
// check if the value is the same as the old value
@@ -1582,7 +1582,7 @@
if (flags & DC_EXEC) {
Patches *patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
- void *var = ini_get_variable(&sd->save, patches_ptr);
+ void *var = GetVariableAddress(patches_ptr, &sd->save);
Write_ValidateSetting(var, sd, (int32)p2);
if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
@@ -1607,11 +1607,11 @@
* of patches because changing a player-based setting in a game also
* changes its defaults. At least that is the convention we have chosen */
if (sd->save.conv & SLF_NETWORK_NO) {
- void *var = ini_get_variable(&sd->save, object);
+ void *var = GetVariableAddress(object, &sd->save);
Write_ValidateSetting(var, sd, value);
if (_game_mode != GM_MENU) {
- void *var2 = ini_get_variable(&sd->save, &_patches_newgame);
+ void *var2 = GetVariableAddress(&_patches_newgame, &sd->save);
Write_ValidateSetting(var2, sd, value);
}
if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
@@ -1654,7 +1654,7 @@
}
patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
- ptr = ini_get_variable(&sd->save, patches_ptr);
+ ptr = GetVariableAddress(patches_ptr, &sd->save);
success = SetPatchValue(index, patches_ptr, value);
return success;
@@ -1672,7 +1672,7 @@
return;
}
- ptr = ini_get_variable(&sd->save, (_game_mode == GM_MENU) ? &_patches_newgame : &_patches);
+ ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_patches_newgame : &_patches, &sd->save);
if (sd->desc.cmd == SDT_BOOLX) {
snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off");
@@ -1692,7 +1692,7 @@
{
for (; osd->save.cmd != SL_END; osd++) {
const SaveLoad *sld = &osd->save;
- void *ptr = ini_get_variable(sld, object);
+ void *ptr = GetVariableAddress(object, sld);
if (!SlObjectMember(ptr, sld)) continue;
}
@@ -1722,7 +1722,7 @@
SlSetLength(length);
for (i = sd; i->save.cmd != SL_END; i++) {
- void *ptr = ini_get_variable(&i->save, object);
+ void *ptr = GetVariableAddress(object, &i->save);
SlObjectMember(ptr, &i->save);
}
}
--- a/settings.h Tue Nov 21 16:54:16 2006 +0000
+++ b/settings.h Tue Nov 21 20:20:30 2006 +0000
@@ -66,15 +66,6 @@
IGT_LIST = 1, ///< a list of values, seperated by \n and terminated by the next group block
} IniGroupType;
-/** Get the address of the variable. Which one to pick depends on the object
- * pointer. If it is NULL we are dealing with global variables so the address
- * is taken. If non-null only the offset is stored in the union and we need
- * to add this to the address of the object */
-static inline void *ini_get_variable(const SaveLoad *sld, const void *object)
-{
- return (object == NULL) ? sld->address : (byte*)object + (ptrdiff_t)sld->address;
-}
-
/** The patch values that are used for new games and/or modified in config file */
extern Patches _patches_newgame;
--- a/settings_gui.c Tue Nov 21 16:54:16 2006 +0000
+++ b/settings_gui.c Tue Nov 21 20:20:30 2006 +0000
@@ -719,7 +719,7 @@
for (i = 0; i != page->num; i++) {
const SettingDesc *sd = page->entries[i].setting;
const SettingDescBase *sdb = &sd->desc;
- const void *var = ini_get_variable(&sd->save, patches_ptr);
+ const void *var = GetVariableAddress(patches_ptr, &sd->save);
bool editable = true;
bool disabled = false;
@@ -788,7 +788,7 @@
if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return;
if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) return;
- var = ini_get_variable(&sd->save, patches_ptr);
+ var = GetVariableAddress(patches_ptr, &sd->save);
value = (int32)ReadValue(var, sd->save.conv);
/* clicked on the icon on the left side. Either scroller or bool on/off */