I'd like a convenient way to serialize an ECS.
99% of the time, entity serialization will be sufficient, but I want to keep it generic and support 2D/3D tiles.
As such, entities would have to be keyed with SavepointID, xy, or xyz.
Reads/Writes should have a key and an associated component. To load everything, all keys for a particular level will have to be requested, then all components supported by the application for each key (Reads == N components * N entities == a lot). I probably need to figure out a way to deserialize the stored components for an entity, rather then having to try everything.
I could probably allow the user to give a deserialization callback for each component type. It would use the existing type hash for the debugger and map it to a callback. Each component table in sqlite3 would have to store a single type hash in the header. Then we could query all the components with an FK to the entity's PK
// already exists: SavepointID
struct SavepointTile2D { int X; int Y; };
struct SavepointTile3D { int X; int Y; int Z; }
using SavepointComponentKey = std::variant<SavepointID, SavepointTile2D, SavepointTile3D>;
entt::registry registry;
// uses the Transform to build a map of type hash to callback. creates any missing tables
Savepoint savepoint;
savepoint.RegisterComponent<Transform /* could auto deduce here */>([®istry](SavepointComponentKey key, Transform transform)
{
registry.emplace(entt::entity{std::get<SavepointID>(key).GetValue(), transform);
});
// creates a SavepointComponentKey from an entt::entity/SavepointID. assert that the component's registered
savepoint.Write(entt::to_integral(entt::entity{1234}), Transform{});
// invokes all the callbacks registered in RegisterComponent
savepoint.Read(entt::to_integral(entt::entity{1234}));
The sqlite3 schema would probably be:
- 3 tables for the SavepointComponentKey (1 for SavepointID, 1 for SavepointTile2D, one for SavepointTile3D)
- 1 table containing the list of all tables that hold components
- Nx3 tables for all the components with an FK to the SavepointComponentKey (x3 because of the different key tables)
I'd like a convenient way to serialize an ECS.
99% of the time, entity serialization will be sufficient, but I want to keep it generic and support 2D/3D tiles.
As such, entities would have to be keyed with SavepointID, xy, or xyz.
Reads/Writes should have a key and an associated component. To load everything, all keys for a particular level will have to be requested, then all components supported by the application for each key (Reads == N components * N entities == a lot). I probably need to figure out a way to deserialize the stored components for an entity, rather then having to try everything.
I could probably allow the user to give a deserialization callback for each component type. It would use the existing type hash for the debugger and map it to a callback. Each component table in sqlite3 would have to store a single type hash in the header. Then we could query all the components with an FK to the entity's PK
The sqlite3 schema would probably be: