-
-
Notifications
You must be signed in to change notification settings - Fork 418
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/Deserialization of a world #114
Comments
@redstonedash nice timing- I just implemented a snapshot feature (#113) which takes a snapshot of the world which can be restored at a later point in time. The snapshot feature accepts a filter argument, which both lets you include and exclude components from the snapshot. Being able to store such a snapshot in a file would be useful. It would probably not be as a char array (flecs does not know the contents of a component, so it can't intelligently turn it into a string, unless you want to base64 everything), but I could do something like a ecs_world_t *world = ecs_init();
// do stuff ...
ecs_snapshot_t *s = ecs_snapshot_take(world);
size_t size;
void *blob = ecs_snapshot_to_blob(world, s, &size);
FILE *f = fopen("savefile", "w");
fwrite(blob, size, 1, f);
fclose(f);
ecs_snapshot_free(world, s);
ecs_fini(world); And to restore: ecs_world_t *world = ecs_init();
size_t size;
void *blob;
// boiler plate to load file into blob & size
ecs_snapshot_t *s = ecs_snapshot_from_blob(world, blob, size);
ecs_snapshot_restore(world, s);
ecs_fini(world); |
yeah that would be great! would be incredibly useful |
just curious, what would happen if this blob was loaded into another program that didn't have the same functions? that would be undefined behavior correct? |
I see that the snapshot feature has been pushed. about how hard would implementing ecs_snapshot_to_blob() be? is it contiguous in memory and lack pointers or no? i was trying to read through it's implementation but couldn't get a handle on it |
@SanderMertens ping for visibility. |
@redstonedash You will be able to load a blob into a different world that has a different set of systems. Since data and logic are separated in ECS, there will be no issues when you try to do this. I'm still fleshing out the API, as ideally I would like it to be possible to "stream" a blob in chunks of a fixed size. This would let you save blobs to a file / send them over the network without having to allocate the entire blob in RAM (which could be quite large). |
* #114 initial commit for blob API * implement table reader * #114 filter out unnecessary data * Add support for storing EcsId columns * #114 implement component writer * #114 implement table writer * #114 cleanup API, fix remaining issues * #114 add save_to_file example * #114 fix alignment issues * #114 add test * #114 add test for id fragmentation / alignment * #114 fix issues with id-only tables * #114 add test for unaligned components * #114 add support for serializing tags * #114 fix issues with serializing type flags * #114 add tests for inheritance * #114 add documentation to header * #114 add reader/writer to C++ API, add example * #114 don't use variable size arrays in tests * #114 prevent duplicate entities when there are conflicts * #114 improve coverage
Describe the problem you are trying to solve.
It is difficult to serialize/deserialize simulation state.
Describe the solution you'd like
a function which outputs a char array that can be written to a file, and a function to read that char array to recreate the world, ideally also a way to exclude some components from serialization (for instance components with pointers)
The text was updated successfully, but these errors were encountered: