dominion-dev / dominion-ecs-java

Insanely fast ECS (Entity Component System) for Java
https://dominion-dev.github.io
MIT License
288 stars 17 forks source link

Question: What's the best way to save the world state and restore it? #177

Closed sz-po closed 11 months ago

sz-po commented 1 year ago

What's the best way to save the state and restore it? I can iterate over all entities, but how to recreate the state so that the IDs of the new entities are the same as in the saved state?

enricostara commented 1 year ago

Hi @sz-po , sorry for the delay in replying.

There is no specific way directly supported by the library regarding save/restore of entities. At this moment, It's up to you how you serialize/deserialize the state of your entities and what framework/data-format you use to get the job done. Only one thing you can consider without any doubt: you don't need to restore entities keeping the same id! the id should always be considered private and you shouldn't care about its value.

sz-po commented 1 year ago

Only one thing you can consider without any doubt: you don't need to restore entities keeping the same id! the id should always be considered private and you shouldn't care about its value.

Thank You from quick reply!

So maybe I do some misunderstanding, but how I should store references between entities?

enricostara commented 1 year ago

Let's say you have a component that references another entity. When you serialize, consider the transformation of the entity reference as a reference to the array of its components, and when you deserialize, consider the transformation as a reference of a new entity that you need to create with the original deserialized array of components. This pattern can be replicated at any depth.

enricostara commented 11 months ago

I'm closing this issue, please open a new one if you need further clarification.