+3 votes

Hi,

I'm developing a game which should be saved automatically so that the player get's to the same point on restarting my app, no matter when he closes the app.
I have two basic ideas for this:

Approach 1: Save when user closes the app

The easiest would be to save when the user closes the app.
I know of two ways closing the app in android:
Back button: This is easy, as I can save when I get the MainLoop.NOTIFICATIONWMQUIT_REQUEST

The problem I have is when the user is minimizing the app and swiping it out of the recent apps. I get a notification MainLoop.NOTIFICATIONWMFOCUS_OUT but there seems to be only a short execution time, because my code after this isn't executed anymore. Is there a way to save my progress when the user closes the app like this?

Approach 2: Save everytime there is something to save
I implemented this approach until now, but it's not working that great.
When saving in my Main Thread that often during gameplay I am afraid that it wouldn't do the performance any good and doing file operations that are 99% of the time overwritten a few ms after that.
I also tried to save in a Thread, but its hard in my case to avoid that some part of my saved progresses is edited while saving, which leads to other problems. Using Mutexes in this case would be the same as doing the saving in the main thread, since it's not practical for me to split up my save data.

So what is the common approach for it? How would you do it?

in Engine by (181 points)

any idea you have to saving you need to acknowledge that saving to a ssd or flash storage(like on mobile phones) wears them out by a bit, so if you save a lot of times you are wearing the memory out(and it will require faster replacement), so unless it is needed for you to save at the exact moment for the next game session it is recommended to not save to the memory and keep working on the ram and not on the storage itself

Please let me know if you rectified this problem.
Thanks in advance.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.