Storing the whole state of the Entity Data in memory (e.g. snapshots)?

Hi,

using Zay-ES what would be the prefered approach to store a snapshot of the whole Entity Data in memory for any given frame?

Use cases would be debugging (restore any given entity world state), replay functionality, undo, etc…

I know there is SqlEntityData to store everything to a file on disk, which is also useful but I want to store multiple state snapshots directly in memory (faster restore).

Also found this thread: EntityData memento
Which is about something similar, but it is 2+ years old and I wonder if there is a better more “official” approach available now.
And I don’t think I need to store entity IDs, those could be re-generated on each restore, because nothing really relies on them to be persistent.

Hi,

I haven’t worked with Zay-ES for a long time now, but my Entity Data Memento pattern should still be a good option for what you want to do.

You should ask to @pspeed if there is something in the framework for that now, as he was pretty interested by the memento approach.

About entity ID, you may be right. the ID is only used to connect components to each others. It would be sufficient to have a different data structure to keep these links.

Whether you can get away with all new entity IDs depends on your application and what it’s doing. For example, a lot of times a client will grab the player entity ID, etc. and then hold onto them. So as long as resetting the whole entity data means also resetting the client then you’ll be fine. It will have to ask for all of that stuff again.

Thanks guys!

So I will try extending EntityData and listen to entityChange events and store every component of each entity in a custom data structure.

In my case entity IDs could really be re-generated, because they only exist to hold components together in the current state snapshot. Across different states entities would be identifiable via name components containing unique strings.

Isn’t this what PersistentComponent is for (as opposed to EntityComponent) ?

I haven’t been working with Zay-ES for too long, but as far as I know PersistentComponent on its own is just a marker for the EntityData so it can save it to disk if supported (like SqlEntityData).

If I want to store snapshots of the whole entity system state in memory I still need to implement that myself in a custom EntityData class I guess.

But it writes to disk every x seconds right?.. so just hook into that and store whatever is written ? Anyway, it was just a thought.

He wants a snapshot of everything… not just what is marked as persistent.

I think I did something similar and ended up writting a wrapper for EntityData and kept the data in own hash maps. It was not beautiful but together with jackson I had an easy way to store and load the game any time. I can’t remember how I did the ids, but I kept them to be the same on load because of my Link entities…

Yes, and I basically want to be able to revert to an arbitrary state snapshot rather quickly, so it’s not enough to just store the latest state to a file.

That’s basically what I plan to do.

In my game if entities need to refer to other entities, they do this using unique persistent name string components.

Ah right I did the same :smile: I had a system to link the stuff by name. It was also nice to build up the levels that way as I had names instead of numbers…

Yeah definitly helps to have “HouseWestDoorFront” instead of “14223” as identifier :smiley:

1 Like