Skip to content

ECS state serialization #25

Answered by rlipsc
ul asked this question in Q&A
Jul 5, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hey @ul,
I use nim-serialization/nim-json-serialization to persist entities to streams or files.

To save/load entity state, you need to be able to load/save a ComponentList. This is like a blueprint that you can pass to construct to create live entities. You can use toTemplate() to create these blueprints from individual entities or sequences of entities.

You will need to typecast Component to its 'real' value based on its typeId field, as Component itself is just an inheritable root type. The convenience template caseComponent helps with this by creating a case statement that matches typeId to registered component types.

Here's a pared down example:

import polymorph, streams, json_serial…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ul
Comment options

Answer selected by rlipsc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants