-
-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serialization #117
Comments
This has been discussed before. Have a read of that for a fairly complete solution. To summarise: internally, EntityX has no concept of the types of its components, so you'll have to use one As an aside, this is "solved" in the experimental/compile_time branch. The EntityManager in that branch is aware of all of its contained component types at compile time, so it could be made to serialize fairly easily. |
I did manage to get the experimental compile-time branch working, kind of. I used boost.serialization to copy the raw memory inside storage as a binary object. Problem is that it isn't actually aware of the type of the object, so it works with things like integers but fails to work with complex types. So the only way to do it is to use the public APIs to add components. Can you provide an overview of what I'd need to do to implement proper serialization for the experimental/compile-time branch, and what sort of template programming features I'd need to learn to do so? What would be the best way to store the "types" of components an entity has, so that you can add new component types without breaking compatibility? |
Sure. You need to look at variadic templates, in particular recursive iteration over types. The Components<> template shows examples of this (eg. destroy). It should be possible to add an |
Thanks for the references; I'll check them out. Hmm, if I manage to figure that out, the last pieces of the puzzle are encoding the components an entities has, and when loading, to use that info to load just the components necessary. I can't think of any way of doing that though without going back to square 1; a long if statement. |
I think I've figured out a relatively painless way of doing serialization using variadic templates. The idea is this: Serialization:
Deserialization is the reverse Implementation:
When saving, run getComponentsForEntity to generate the list. The strings in the list are then indices to function pointers that can be used to invoke the appropriate save and load functions without manual if statements. Hope this helps anyone else who may be wanting to do serialization. |
How would I do serialization using entityx? I thought of 2 possible approaches:
Has anyone attempted the first approach?
The text was updated successfully, but these errors were encountered: