settings.c
changeset 3117 8066b8d0802b
parent 3116 031230112b25
child 3118 99926945ccb1
equal deleted inserted replaced
3116:031230112b25 3117:8066b8d0802b
   607 
   607 
   608 	for (; sd->save.cmd != SL_END; sd++) {
   608 	for (; sd->save.cmd != SL_END; sd++) {
   609 		const SettingDescBase *sdb = &sd->desc;
   609 		const SettingDescBase *sdb = &sd->desc;
   610 		const SaveLoad        *sld = &sd->save;
   610 		const SaveLoad        *sld = &sd->save;
   611 
   611 
       
   612 		if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
       
   613 
   612 		// XXX - wtf is this?? (group override?)
   614 		// XXX - wtf is this?? (group override?)
   613 		s = strchr(sdb->name, '.');
   615 		s = strchr(sdb->name, '.');
   614 		if (s != NULL) {
   616 		if (s != NULL) {
   615 			group = ini_getgroup(ini, sdb->name, s - sdb->name);
   617 			group = ini_getgroup(ini, sdb->name, s - sdb->name);
   616 			s++;
   618 			s++;
   671 		const SettingDescBase *sdb = &sd->desc;
   673 		const SettingDescBase *sdb = &sd->desc;
   672 		const SaveLoad        *sld = &sd->save;
   674 		const SaveLoad        *sld = &sd->save;
   673 
   675 
   674 		/* If the setting is not saved to the configuration
   676 		/* If the setting is not saved to the configuration
   675 		 * file, just continue with the next setting */
   677 		 * file, just continue with the next setting */
       
   678 		if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
   676 		if (sld->conv & SLF_CONFIG_NO) continue;
   679 		if (sld->conv & SLF_CONFIG_NO) continue;
   677 
   680 
   678 		// XXX - wtf is this?? (group override?)
   681 		// XXX - wtf is this?? (group override?)
   679 		s = strchr(sdb->name, '.');
   682 		s = strchr(sdb->name, '.');
   680 		if (s != NULL) {
   683 		if (s != NULL) {
  1250 	HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
  1253 	HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
  1251 	ini_save(_config_file, ini);
  1254 	ini_save(_config_file, ini);
  1252 	ini_free(ini);
  1255 	ini_free(ini);
  1253 }
  1256 }
  1254 
  1257 
       
  1258 /** Save and load handler for patches/settings
       
  1259  * @param osd SettingDesc struct containing all information
       
  1260  * @param object can be either NULL in which case we load global variables or
       
  1261  * a pointer to a struct which is getting saved */
       
  1262 static void LoadSettings(const SettingDesc *osd, void *object)
       
  1263 {
       
  1264 	for (; osd->save.cmd != SL_END; osd++) {
       
  1265 		const SaveLoad *sld = &osd->save;
       
  1266 		void *ptr = ini_get_variable(sld, object);
       
  1267 
       
  1268 		if (!SlObjectMember(ptr, sld)) continue;
       
  1269 	}
       
  1270 }
       
  1271 
       
  1272 /** Loadhandler for a list of global variables
       
  1273  * @note this is actually a stub for LoadSettings with the
       
  1274  * object pointer set to NULL */
       
  1275 static inline void LoadSettingsGlobList(const SettingDescGlobVarList *sdg)
       
  1276 {
       
  1277 	LoadSettings((const SettingDesc*)sdg, NULL);
       
  1278 }
       
  1279 
       
  1280 /** Save and load handler for patches/settings
       
  1281  * @param osd SettingDesc struct containing all information
       
  1282  * @param object can be either NULL in which case we load global variables or
       
  1283  * a pointer to a struct which is getting saved */
       
  1284 static void SaveSettings(const SettingDesc *sd, void *object)
       
  1285 {
       
  1286 	/* We need to write the CH_RIFF header, but unfortunately can't call
       
  1287 	 * SlCalcLength() because we have a different format. So do this manually */
       
  1288 	const SettingDesc *i;
       
  1289 	size_t length = 0;
       
  1290 	for (i = sd; i->save.cmd != SL_END; i++) {
       
  1291 		length += SlCalcObjMemberLength(&i->save);
       
  1292 	}
       
  1293 	SlSetLength(length);
       
  1294 
       
  1295 	for (i = sd; i->save.cmd != SL_END; i++) {
       
  1296 		void *ptr = ini_get_variable(&i->save, object);
       
  1297 		SlObjectMember(ptr, &i->save);
       
  1298 	}
       
  1299 }
       
  1300 
       
  1301 /** Savehandler for a list of global variables
       
  1302  * @note this is actually a stub for SaveSettings with the
       
  1303  * object pointer set to NULL */
       
  1304 static inline void SaveSettingsGlobList(const SettingDescGlobVarList *sdg)
       
  1305 {
       
  1306 	SaveSettings((const SettingDesc*)sdg, NULL);
       
  1307 }
       
  1308 
       
  1309 static void Load_OPTS(void)
       
  1310 {
       
  1311 	/* Copy over default setting since some might not get loaded in
       
  1312 	 * a networking environment. This ensures for example that the local
       
  1313 	 * autosave-frequency stays when joining a network-server */
       
  1314 	_opt = _opt_newgame;
       
  1315 	LoadSettings(_gameopt_settings, &_opt);
       
  1316 }
       
  1317 
       
  1318 static void Save_OPTS(void)
       
  1319 {
       
  1320 	SaveSettings(_gameopt_settings, &_opt);
       
  1321 }
       
  1322 
  1255 void CheckConfig(void)
  1323 void CheckConfig(void)
  1256 {
  1324 {
  1257 	// fix up news_display_opt from old to new
  1325 	// fix up news_display_opt from old to new
  1258 	int i;
  1326 	int i;
  1259 	uint32 tmp;
  1327 	uint32 tmp;
  1271 		_patches.pf_maxlength = 4096;
  1339 		_patches.pf_maxlength = 4096;
  1272 	}
  1340 	}
  1273 }
  1341 }
  1274 
  1342 
  1275 const ChunkHandler _setting_chunk_handlers[] = {
  1343 const ChunkHandler _setting_chunk_handlers[] = {
  1276 	{ 'OPTS', SaveLoad_OPTS, SaveLoad_OPTS, CH_RIFF | CH_LAST}
  1344 	{ 'OPTS', Save_OPTS, Load_OPTS, CH_RIFF | CH_LAST}
  1277 };
  1345 };