Runtime types - ability to define components in runtime (useful mostly for scripting)
richardbiely opened this issue · 1 comments
richardbiely commented
Runtime types - ability to define components in runtime (useful mostly for scripting)
richardbiely commented
Technically exists already. We can now define run-time tags because components are defined as entities now.
ecs::World w;
ecs::Entity teamA = w.add(); // entity representing some teamA we made up at run-time
ecs::Entity teamB = w.add(); // entity representing some teamB we made up at run-time
ecs::Entity player1 = w.add();
ecs::Entity player2 = w.add();
ecs::Entity player3 = w.add();
w.add(player1, teamA); // player1 now belongs to teamA
w.add(player2, teamA); // player2 now belongs to teamA
w.add(player3, teamB); // player3 now belongs to teamB
For values, we'd have something like this:
struct IntVal { int value; };
struct FltVal { float value; };
GAIA_ID(IntVal) = w.add<IntVal>();
...
ecs::Entity health = w.add();
ecs::Entity currVal = w.add();
ecs::Entity maxVal = w.add();
w.add(currVal, GAIA_ID(IntVal));
w.add(maxVal, GAIA_ID(IntVal));
w.add(health, currVal, IntVal{ 10 });
w.add(health, maxVal, IntVal{ 100});
w.add(player, health);