Any way to “save state” in a C # game?

This is normal if the answer to this is "this is not possible." I will not be upset. But I'm interested in creating a game using C #, if there is a way to simulate the functionality of the "save state" function of console emulators. From what I understand, emulators have a somewhat simple way, they just dump all the contents of virtualized memory, command pointers and all. Thus, they can resume in the same way, in the same place in the game code as before. I know that I can’t resume work from one line of code, but can I maintain the entire state of the game without manually saving each individual variable? I need a way that I don’t need to expand or change every time I add something to my game.

I guess if there is any possible way to do this, it will use p / invoke ...

+3
source share
3 answers

Well, in C # you can do the same thing basically. It is called serialization . I agree, this is not the same as a memory dump, but it comes close enough.

To mark a class as serializable, simply add an attribute to it Serializable:

[Serializable]
class GameState

Additional information on classes that may change:

, OptionalField, . , . NonSerialized, , . .

(, , NonSerialized), IDeserializationCallback IDeserializationCallback.OnDeserialization.

.NET. SoapFormatter XmlSerializer -, - XML.

- : ,.NET Framework

+12

"" Serializable, . , .

. ISerializable

+3

Source: https://habr.com/ru/post/1733181/


All Articles