Page 1 of 1

Stuck implementing more commnad line arugments

PostPosted: 28 Apr 2012, 08:16
by Edward_Lii
Hello all,

I'm trying to extend the set of command line arguments to also support changing settings.
What seemed to be an easy task, turned out to be quite hard.

The problem
This is the current flow of the program.
    - Parse arguments (possibly setting data/user paths).
    - Configure paths, if some set in previous step it won't configure those.
    - Load settings
    - Init, gameloop, etc...

Now we can't add for example -w, --windowed since that needs to change the settings object which isn't created yet.
I thought of creating it first, but then the changed settings would be overridden by the load settings step.

A simple solution would be to move the Load settings step up, before the argument parsing.
But in order to find the settings file the paths need to be configured, thus:
    - Configure paths, none can be set (if the auto data path detection fails the game will exit).
    - Load settings
    - Parse arguments (setting data/user path doesn't do anything)
    - Init, gameloop, etc...


Possible solutions
A possible solution would be to create a Settings instance, change the configured values and upon loading from the config file only change the settings not set/not changed.
I don't think this is a good idea, just for the sake of the settings class. Parse file should parse the file and configure everything IMHO.

Another solution would be to move the path configuring and setting loading before argument parsing.
Don't let the configurePaths method quit the program but check the paths after argument parsing.
One problem left is that the configurePaths method creates directory which might not be desired in case of manually defining the data/user path.

What also could work is split the parsing in paths and other.
The paths parsing doesn't return the help/usage message or other output (except for errors).

Any suggestions?

Re: Stuck implementing more commnad line arugments

PostPosted: 28 Apr 2012, 09:42
by MCMic
My suggestion:
Parse all arguments, store the values that need to change settings.
Load the settings from the path (eventually comand line specified)
Change the settings by the stored values fi there are any.

You just need to store a few temp values waiting for the config file to be parsed.