deathkiller / jazz2

🎮 · Jazz² Resurrection: Open-source reimplementation of Jazz Jackrabbit 2
https://deat.tk/jazz2/
GNU General Public License v3.0
492 stars 18 forks source link

Minimizing the application leads to loss of state #48

Closed MihaiChirculete closed 9 months ago

MihaiChirculete commented 3 years ago

Tested environment Android:

When you minimize the app and come back to it, the game restarts and progress is lost.

Expected: When app is minimized, onPause() should be called and state instance saved so that it gets resumed in onResume() Actual: No state seems to be saved when minimizing the application

deathkiller commented 3 years ago

That's right, but it's not so easy to implement, because the game cannot save its state at all. Desktop version does not need to save state anywhere. Progress is saved on the beginning of each level.

MihaiChirculete commented 3 years ago

Hmmm, I see. Well I'm still new to dot net and stuff but I have quiet some experience with Android. I could try find a solution for this and create a pull request when done.

deathkiller commented 3 years ago

That would be awesome, but I'm afraid that some state serialization for each object/actor has to be implemented to make this work.

MihaiChirculete commented 3 years ago

Yea most likely. I was thinking of maybe creating a special utility class to take care of that.

Maybe not everything should be serialized as enemies can respawn for example. I was thinking of serializing only essential data such as: player score, lives, current hp, pozition in level; level related stuff: blocks that were destroyed, blocks created etc.

Most of this stuff can be easily serialized I believe. At least the palyer related data should be pretty straight forward to serialize since most of this fields are just primitives such as ints, floats

deathkiller commented 9 months ago

Added automatic saving on each checkpoint and automatic restore if the game was minimized and then terminated by operating system - in commit https://github.com/deathkiller/jazz2-native/commit/a32159f69131d6f79e23c8cbb1e6ad3e5d60dc43. Saving current state (not the checkpoint one) is still not supported, but it should work better than before.