Quote:Original post by mikemanIt can be done, you have to associate the entity and the actor before you lose the type information; the consequence of that is you must have something that knows about both types. Unfortunately I'm far too busy to provide a good example of how to do this but I have knocked up some rather rubbishy pseudo code to demonstrate the concept:
This exactly is the problem. *How* to be enforced at compile-time, since the class of the entity and controller created is decided at run-time by the level designer himself? Is it possible?
struct actor{ entity_ptr e; controller_ptr c;};struct actor_assembler{ virtual actor create() = 0;};struct player_assembler : actor_assembler{ actor create() { actor a; a.c = new player_controller(new player); a.e = a.c->the_entity(); return a; }};std::map<actor_desc, actor_assembler_ptr> actor_factory;// ...actor avatar = actor_factory[entity_desc("avatar", "fast_sharp_shooter")]->create();
In practice you might want a single assembler to be able to create different types of actors (in the traditional Factory Method way) which, of course, is doable too.