Preferences in INI-files

StandardGame expects GameSettings, and I was too lazy to make my own implementation, and so I used PreferencesGameSettings. However I didn't like the idea to store Preferences in the registry (under Windows) for various reasons, so I'd prefer to use a file instead. Recently I found a very easy solution: ini4j (http://sourceforge.net/projects/ini4j/) implements (with some limitations, e.g. only one level of childnodes below root) Preferences stored in INI files. This might sound a little bit unusual, but makes sense especially for games, as the user can edit these files very easyly. The structure looks like this (if you use just one node):



[mygame]



GameWidth = 1024

GameHeight = 768

GameFreq = 60



KeyW = forward

KeyS = backward

KeyA = left

KeyD = right

Interesting…so many questions. :o



First, why do you have a problem with preferences being stored in the registry?  It's completely transparent to you, so who cares?



Second, why use an INI file?  If you want to actually use a file, then why not use a Properties file?  That's the Java way. :o



Third, you realize you lose one of the major benefits of Preferences by using a file?  The file has to be stored someplace and unless you've determine a way to store it in a unique place you will lose your settings every time you load from a different place (ex. load it when you're developing it and then load it from a WebStart and it will have to re-create those settings again in another place).



Fourth, you lose the ability to store Java objects which is one of the really cool features of Preferences.

Well preferences has got my vote! It is nice to have key bindings stored in an INI file sometimes tho.

First, why do you have a problem with preferences being stored in the registry?


When you copy your game to another machine or another installation (eg another version of windows you have installed) you loose your settings. Copying between registries is a hassle. An INI file can be saved with the game or in your home directory. I agree though that a property file is fine as well.

Dear Rana Tenebrarum:

  • The only "clean" way to deal with registry entries is an installer, not only for providing defaults, but also for cleaning up after the game. Same for copying (as llama pointed out)
  • Property might be nice and the "java way", but if a user has to edit the preferences under some circumstances (hopefully not…), INI files are much easier
  • the solution should also work under non-Windows Systems



    Strange enough, I found no code which implements Preferences by storing property files…



    Following the interesting discussion, I see two potential jME improvements:
  • maybe there should be PropertyGameSettings as an alternative implementation (it could hide the "String-only"-weakness of Properties with conversions)
  • maybe the GameSetting interface should be extended to provide direct key binding support. It's easy to build an individual solution, but having the possibility to call simply something like super.initKeyBindings(properties) in your GameState would be quite elegant… (of course, you had to setup your GameControls first)

The way I handle key bindings in GB is to simply store the Java object for GameControlManager (that includes all of my keys) in the Preferences system. :slight_smile:



Feel free to write a INIGameSettings implementation. :wink:

darkfrog said:

The way I handle key bindings in GB is to simply store the Java object for GameControlManager (that includes all of my keys) in the Preferences system. :)

Call me parnoid, but I prefer to see my key settings (and to be able to edit them)


Feel free to write a INIGameSettings implementation. ;)

I like to abuse your PreferencesGameSettings for writing in INI-files, hehe...
But to be honest, PropertyGameSettings seem to make more sense

In GB I have an in-game control editor and settings editor (using the Swing widgets that are contributed to jME for the same), so no, you don't see them on your filesystem, but when was the last time you played a game that you ended up changing a preferences file on your drive rather than in-game?

OK, I see that this is a deep philosophical question.  8)



To answer your question: the last time I changed settings manually in a game was about 4-5 weeks ago, in AssaultCube. And I was happy that I could do it (strange that people talke about "inverted" mouse axis as a special feature - this is is the only way to play)



BTW, talking about GUI: Do you have any idea regarding http://www.jmonkeyengine.com/jmeforum/index.php?topic=5478.0 ? Probably really easy, but it drives me crazy  :expressionless:

darkfrog said:

In GB I have an in-game control editor and settings editor (using the Swing widgets that are contributed to jME for the same), so no, you don't see them on your filesystem, but when was the last time you played a game that you ended up changing a preferences file on your drive rather than in-game?


Many times. Usually by copying files from other people online that have made special keybinds, etc.

I'm sorry man, but the windows registry just sucks.

In general I would agree, but the fact that Preferences is kept "somewhere" and I don't have to care where makes it very nice.  I don't have to worry about having permissions to a file, I don't have to worry about remembering where that file is kept, etc.



I can understand wanting to copy your keybindings (I keep a backup of mine for BF2 so when I reinstall I don't have to re-set it all up), but what about the ability to export to a file and import rather than keeping everything file driven in the first place?



I guess it doesn't really matter, and I had intentions of creating a PropertyGameSettings object eventually anyway, so anyone interested in doing so would be appreciated. :slight_smile: