Hey forum : )
I wanted to know what I could do to provide a fluid and automated saving.
First, I do not want to frustrate my users by having the app crash. One reasoning could be Android's nature of closing/killing application that seem to idle. The easy solution would be, once my game loses focus, initiate a last save and then idle.
But what is when a random bug occurs and all progress is lost during gameplay? Additionally, I do not want to bother my player to think about saving.
So, this is how I structure my level-files at the moment: One Lua-table entry represents on entity/object and its attributes/components are further tables within the object. Every object is changing its state quite often. E.g. There are certain types of entities, so entity a and entity b share the same object-type x. Does not mean, that there is no object-type y.
I deserialise my entities and their components to C++-objects. In order to save, I would have to serialise them and write the entire file again. As I want to save frequently (about after every move/change the player commits), I thought about ways to make serialise small changes faster.
One idea was, to make the actual level-file contain only references to current entities. E.g.
local objects
{
reference[1] = "object_a_1.lua",
reference[2] = "object_a_2.lua",
reference[3] = "object_a_3.lua",
reference[4] = "object_b_1.lua",
reference[5] = "object_b_2.lua"
}
Could also drop the .lua-suffix, of course. Then, I could move the current instance/state of each object into their own file. Each C++-object would just have a reference to that object-instance-file and write changes to their equivalent.
What would your take-on be if you want to save frequently without any interrupt? We are talking about small changes and few changes per user-interaction. Is there any common practice?
I mean, I do not have to save every single action, but would like to do so in reasonable portions. This game is working on Android, Windows and Linux.
Thanks for your time, have a great day : )