Adam's Lair Forum

game development and casual madness
It is currently 2017/04/25, 12:34

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Saving and Loading Games
PostPosted: 2017/03/31, 13:17 
Junior Member
Junior Member

Joined: 2017/02/05, 13:06
Posts: 27
Role: Hobbyist
I've been doing some searching through the forum for any talk on this topic or examples and haven't found anything.

I think what I have to do is change the CorePlugin project into a standard class library rather than portable which would allow me to bring in System.Io and start working with FileStreams but before I do that I thought I'd check to see if there is anything that can be done to implement game state saving and loading using the Portable Class Library.

I noticed DualityApp has methods called SaveAppData, LoadAppData, SaveUserData, and LoadUserData but these return void and take nothing so I'm assuming I couldn't use these for loading and saving progress in a game, especially if I wanted multiple save points. I think these are probably just for settings such as screen resolution, fullscreen or window, etc...

So is my first instinct correct? Am I going to have to go with changing the project to a standard class library?


Top
 Profile  
 
PostPosted: 2017/03/31, 17:17 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1948
Location: Germany
Role: Professional
Hey there,

you do not have to change project types to get access to file streams. It is true that there is no file system access in Portable Class Libraries of the profile that Duality uses; but that is simply because direct file system access simply might not be available on all systems where Duality may one day deploy to, or it might behave differently on some systems than others - path separator chars being one example. You can go back to regular class libraries if you wish to (totally supported), but the "proper" / Duality way of solving this is to use its platform abstraction layer.

Long story short: Use Duality.IO and check out the static PathOp, DirectoryOp and FileOp classes, the last two being convenience wrappers around DualityApp.SystemBackend.FileSystem. In most cases, the static classes are all you need.

So now you're able to get a file stream to somewhere and if you want to code your savegames from scratch, then that is all you need. However, you can also use Duality serialization if that helps you along your path - it's how resources are serialized, but it can be used for any kind of object and data, not just resources.

The Duality.Serialization namespace has a Serializer class that provides some static methods to create a serializer for an existing stream, which you can then use to read and write objects manually. Alternatively, it provides some shortcut methods to quickly read or write an object without the manual serializer creation. For savegames that are not meant to be version-controlled or inspected by humans I would suggest to use binary serialization, which is an optional parameter for the methods you will find (typeof(BinarySerializer)).

Divarin wrote:
I noticed DualityApp has methods called SaveAppData, LoadAppData, SaveUserData, and LoadUserData [...] I think these are probably just for settings such as screen resolution, fullscreen or window, etc...


Yep, that is correct. AppData is for settings you set as a developer and UserData is for settings that users specify to match their system, like display resolution etc.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2017/04/01, 11:30 
Junior Member
Junior Member

Joined: 2017/02/05, 13:06
Posts: 27
Role: Hobbyist
Great, that's exactly what I'm looking for, thanks :)


Top
 Profile  
 
PostPosted: 2017/04/05, 22:40 
Junior Member
Junior Member

Joined: 2017/02/05, 13:06
Posts: 27
Role: Hobbyist
So, another question on this topic. How do I make use of the Duality.IO.NamedDirectory enum? I don't see any methods that take this enum as an argument. I'm trying to do saved games in a subdirectory under %AppData%


Top
 Profile  
 
PostPosted: 2017/04/06, 18:31 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1948
Location: Germany
Role: Professional
I think you're looking for DualityApp.SystemBackend.GetNamedPath ^^

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2017/04/07, 11:39 
Junior Member
Junior Member

Joined: 2017/02/05, 13:06
Posts: 27
Role: Hobbyist
Yup, that's it! Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group