Changeset - r5141:e61bae029532
[Not reviewed]
master
0 5 0
Darkvater - 18 years ago 2006-11-21 20:20:30
darkvater@openttd.org
(svn r7231) -Codechange: rename ini_get_variable to GetVariableAddress for use both in settings.c
and saveload.c
5 files changed with 21 insertions and 21 deletions:
0 comments (0 inline, 0 general)
saveload.c
Show inline comments
 
@@ -751,7 +751,7 @@ void SlObject(void *object, const SaveLo
 
	}
 

	
 
	for (; sld->cmd != SL_END; sld++) {
 
		void *ptr = (byte*)object + (ptrdiff_t)sld->address;
 
		void *ptr = GetVariableAddress(object, sld);
 
		SlObjectMember(ptr, sld);
 
	}
 
}
saveload.h
Show inline comments
 
@@ -271,6 +271,15 @@ static inline VarType GetVarFileType(Var
 
	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);
 

	
settings.c
Show inline comments
 
@@ -690,7 +690,7 @@ static void ini_load_settings(IniFile *i
 

	
 
		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 @@ static void ini_save_settings(IniFile *i
 
		}
 

	
 
		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 @@ int32 CmdChangePatchSetting(TileIndex ti
 

	
 
	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 @@ bool SetPatchValue(uint index, const Pat
 
	 * 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 @@ bool IConsoleSetPatchSetting(const char 
 
	}
 

	
 
	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 @@ void IConsoleGetPatchSetting(const char 
 
		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 @@ static void LoadSettings(const SettingDe
 
{
 
	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 @@ static void SaveSettings(const SettingDe
 
	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);
 
	}
 
}
settings.h
Show inline comments
 
@@ -66,15 +66,6 @@ typedef enum {
 
	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;
 

	
settings_gui.c
Show inline comments
 
@@ -719,7 +719,7 @@ static void PatchesSelectionWndProc(Wind
 
		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 @@ static void PatchesSelectionWndProc(Wind
 
			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 */
0 comments (0 inline, 0 general)