dominion-dev/dominion-ecs-java

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

sz-po opened this issue · 4 comments

sz-po commented

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?

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

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?

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.

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