This is a lot of text, jump straight to QUESTION.
CONTEXT:
Well I've been struggling with the serializing architecture of my project. I am making a game engine and the custom content is very important so i have to template most of the things to support easy extension.
I've tried a lot of different approaches, but with the little experience i have with templates and metaprogramming they turned into dead ends. Now i finally think i have something.
So there is this class called SceneSerializer.
template<typename ...Components>
class SceneSerializer {
(...)
}
it must create a list of Actors that can then be serialized with a library.
An actor is just std::vector<std::variant<Components...>> a list of components
I use EnTT for the managing the scene. This library offers some support for serializing. I can give this library a Archive and it will call some operators for me that i can use to get the value of the components for all actors.
template<typename Component>
class SceneArchive : ArchiveBase {
public:
void operator()(Actor actor0, Component component0) {
// Here I have to notify Scene Serializer that a actor0 has component0
// But SceneSerializer does not have any means of receiving it
}
Note that SceneSerializer only uses the base class ArchiveBase. The problem is that SceneArchive is Components Specific and does not know the type of the variant that SceneSerializer needs. So SceneSerializer works with std::variant<A,B,C>. SceneArchive<A> has no means of knowing that it must provide a variant of <A,B,C>.
QUESTION:
Can templates be used so that a class like:
class SceneSerializer {
(...)
}```
can have a method set(Component component) for each type in the packed parameter list 'Components' ?
so SceneSerializer<A,B,C> must have 3 methods set(A a), set(B b), set(C c).
I think some metaprogramming and multiple inheritance could make it possible, but it way over my head.