Prefs. How do they work?
by Alex Green · in iTorque 2D · 10/06/2011 (2:25 pm) · 5 replies
Hey,
So I'm trying to get a handle on how prefs should be saved and restored (in v1.5). I had something working in v1.4.1 (thanks to what someone posted in these newsgroups in another thread), but after upgrading to 1.5 I wanted to see what the recommended approach was as I'd rather use any built in iTorque native functionality where possible rather than depending on custom code.
As it stands, I now see a defaultPrefs.cs in the scripts/system directory. When I launch my game from TGB it immediately generates a prefs.cs in the same directory (scripts/system/prefs.cs) - which leads to my first question, why does it do this? One side effect of this, is that it destroys any custom data that I may have saved during the running of the game, as it's not calling the same function to save the prefs - so on subsequent runs, anything that doesn't fall in to the default set of prefs gets lost. Also, if a defaultPrefs.cs is already present, should TGB be responsible for creating a file that immediately supersedes it's settings?
If I run my game (on the Mac) outside of the TGB, by launching iTorque2dGame directly it doesn't automatically generate the prefs.cs, but it does compile any existing one. Should the prefs.cs get compiled? If the prefs.cs.dso is copied to the actual device, will that be read ahead of the prefs.cs?
In the automatically generated script in main.cs, on exit of the game there's a call to _saveGameConfigurationData which is only called if running on Windows or Mac OS (i.e. not the iOS devices). Is there are reason why we shouldn't use _saveGameConfigurationData on the iOS devices? I've noticed that it doesn't actually work on the devices ("Unable to open file for writing"), so obviously that's a contributing factor! But that leads me to my main question - it seems like there's built in functionality to save the prefs, but how is it done on the actual devices?
Cheers,
Alex.
So I'm trying to get a handle on how prefs should be saved and restored (in v1.5). I had something working in v1.4.1 (thanks to what someone posted in these newsgroups in another thread), but after upgrading to 1.5 I wanted to see what the recommended approach was as I'd rather use any built in iTorque native functionality where possible rather than depending on custom code.
As it stands, I now see a defaultPrefs.cs in the scripts/system directory. When I launch my game from TGB it immediately generates a prefs.cs in the same directory (scripts/system/prefs.cs) - which leads to my first question, why does it do this? One side effect of this, is that it destroys any custom data that I may have saved during the running of the game, as it's not calling the same function to save the prefs - so on subsequent runs, anything that doesn't fall in to the default set of prefs gets lost. Also, if a defaultPrefs.cs is already present, should TGB be responsible for creating a file that immediately supersedes it's settings?
If I run my game (on the Mac) outside of the TGB, by launching iTorque2dGame directly it doesn't automatically generate the prefs.cs, but it does compile any existing one. Should the prefs.cs get compiled? If the prefs.cs.dso is copied to the actual device, will that be read ahead of the prefs.cs?
In the automatically generated script in main.cs, on exit of the game there's a call to _saveGameConfigurationData which is only called if running on Windows or Mac OS (i.e. not the iOS devices). Is there are reason why we shouldn't use _saveGameConfigurationData on the iOS devices? I've noticed that it doesn't actually work on the devices ("Unable to open file for writing"), so obviously that's a contributing factor! But that leads me to my main question - it seems like there's built in functionality to save the prefs, but how is it done on the actual devices?
Cheers,
Alex.
#2
10/06/2011 (7:16 pm)
@Alex - Marc is correct. That prefs file is completely geared toward what the engine requires. The only thing that should be modifying that file is the editor. That is also why the game configuration save function is disabled on an iOS device.
#3
Is the recommended function iPhoneSaveStringToDevice to save user preferences then? Also, for actual save game data, what functions are preferable for that, or is that all going to have to be custom code to serialize the data?
@Marc - I realize the version that's launched from the TGB isn't the final version, but it definitely improves iteration times, rather than having to launch on the simulator or the actual device. Obviously the final testing would need to happen on the device, but if the bulk of the work can be done on the Mac I'm going to gravitate to getting that working as much as possible (or at least keeping it working as long as possible).
Cheers,
Alex.
10/06/2011 (8:14 pm)
Thanks for the responses, guys! I'm still not quite sure why there's a need for defaultPrefs and a prefs though - the only reason that occurs to me is that prefs.cs is a superset of defaultPrefs.cs.Is the recommended function iPhoneSaveStringToDevice to save user preferences then? Also, for actual save game data, what functions are preferable for that, or is that all going to have to be custom code to serialize the data?
@Marc - I realize the version that's launched from the TGB isn't the final version, but it definitely improves iteration times, rather than having to launch on the simulator or the actual device. Obviously the final testing would need to happen on the device, but if the bulk of the work can be done on the Mac I'm going to gravitate to getting that working as much as possible (or at least keeping it working as long as possible).
Cheers,
Alex.
#4
DefaultPrefs is what the engine uses on first startup or when prefs is missing, prefs itself is on the desktop what you configure in the options screen and its executed after defaultprefs and overwrites it where set.
Its a dead body that I would agree should be cleaned too. There were different things updated and removed in 1.5 already in the sense of getting rid of unused / meaningless stuff rooting back to TGE (cause thats where most that comes from, TGB just carried it on) and its getting better and better :)
As for the version built: I wasn't refering to T2D/TGB actually but iT2D cause you mentioned windows and osx, so I thought it would make sense to point out that you can't use it to create desktop games. To create desktop games you would use T2D which is targeted at the desktop and port your game :)
That was just to prevent frustration cause iT2D definitely (and luckily - initially it tried to do) support desktop targeting anymore in favor of a better iOS support so if you tried it it would bite ya.
10/07/2011 (8:14 am)
Actually that default prefs - prefs stuff is a thing rooting to the desktop.DefaultPrefs is what the engine uses on first startup or when prefs is missing, prefs itself is on the desktop what you configure in the options screen and its executed after defaultprefs and overwrites it where set.
Its a dead body that I would agree should be cleaned too. There were different things updated and removed in 1.5 already in the sense of getting rid of unused / meaningless stuff rooting back to TGE (cause thats where most that comes from, TGB just carried it on) and its getting better and better :)
As for the version built: I wasn't refering to T2D/TGB actually but iT2D cause you mentioned windows and osx, so I thought it would make sense to point out that you can't use it to create desktop games. To create desktop games you would use T2D which is targeted at the desktop and port your game :)
That was just to prevent frustration cause iT2D definitely (and luckily - initially it tried to do) support desktop targeting anymore in favor of a better iOS support so if you tried it it would bite ya.
#5
To clarify what I meant re: running on the desktop/Mac - I meant building the Xcode project that resides under MyGame/buildFiles/XCode (as opposed to MyGame/buildFiles/XCode_iPhone) that generates the iTorque2dGame application that resides in MyGame/projectFiles. This is also the one that TGB launches when the game is launched from within TGB (at least that's my understanding). I run this version to verify my script changes (and also to compile them) without having to open TGB. In this case, the platform is set to "macos" in the scripts - which is what I was alluding to previously when I was saying the prefs are saved out on application exit.
Cheers,
Alex.
10/07/2011 (10:26 am)
Thanks for the info, Marc. Being new to iTorque I definitely appreciate the background on this stuff.To clarify what I meant re: running on the desktop/Mac - I meant building the Xcode project that resides under MyGame/buildFiles/XCode (as opposed to MyGame/buildFiles/XCode_iPhone) that generates the iTorque2dGame application that resides in MyGame/projectFiles. This is also the one that TGB launches when the game is launched from within TGB (at least that's my understanding). I run this version to verify my script changes (and also to compile them) without having to open TGB. In this case, the platform is set to "macos" in the scripts - which is what I was alluding to previously when I was saying the prefs are saved out on application exit.
Cheers,
Alex.
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft
The reason why you don't want the save to be called is that it would require script code ompilation on the device which you don't want to happen for various reasons.
If I recall right iT2D got a true iOS focused save game capability that builds upon the standard NSUserDefaults
PS: do yourself the favor and don't test nor look at the desktop. iT2D does not support them for deployment, they are only there for testing and there are quite some deltas due to platform dependent aspects