Quote:
Frog is green and has two legs.
Basketball is orange.
Sure, a ColorController can control those abstractions that have color. But a Movement controller can only control those abstractions that have legs.
I don't think I'm understood correctly, it might be my fault. Entities are objects that just keep some state, or execute certain operations. It can be anything, an item, a weapon, an npc, a player. Now, a Controller is the "brain" of the entity. It translates input from the user or AI and instructs the entity it controls to perform some operations. For example, the entity could be an item like a switch that the user can operate on. Or an NPC that can "think" and do some things. Or a player avatar that takes input from the user. I'll give some examples:
class Switch:public Entity{ bool switched; public: Switch():switched(false); void SwithOn() { switched=true; }}class SwitchController:public Controller,IKeyboardListener{ void Think{...}; void OnKeyDown(key) { if (key==SPACE) switch->SwitchOn(); }};
class NPC:public Entity{ public: void TalkTo(NPC* other) { ... }}class NPCController:public Controller{ void Think { NPC* neighbour=npc->GetNeighbour(); if (neightbour->IsFriendly()) npc->TalkTo(neighbour); }; };
class Player:public Entity{ public: void Walk() { .... } void Shoot() { }}class PlayerController:public Controller,IKeyboardListener{ void Think{...}; void OnKeyDown(key) { if (key==SPACE) player->Fire(); if (key=='W') player->Walk(); }};
As you can see, there are various entity classes that can do various operations, and the "obey" to an attached controller. That doesn't mean that each entity class can work only with one controller. For example, I could create another variant of NPCController that "thinks" differently, and attach that to an NPC.
Now, the editor will work like this. In the left, there would be a combobox with all the entity classes, both built-ins and other that modders have created. In the right, there would be a combobox with all the controller classes. The designer will choose which entity and appropriate controller he wishes to attach, and that's it. For example, he could choose to create entity "NPC" and controller "EnemyNPC".Or "FriendlyNPC", or generally whatever the programmer/modder can think of. For example, a Switch that is controlled not by the KeyboardListener kind controller above, but a TimedSwitchController controller that automatically switches it on/off in intervals. I think it is understood that all entities can have a controller, but there are pairs that do not match. For example, an NPCController can't control a Switch. That's what the error("bad type") was in my first post, I'm just wondering if there's another way of doing this without casts.
Antheus also, your example didn't make sense to me, based on your code the Controller has access to Controllable interface so all it can do is call controllable->Think()? I don't understand what benefit this has. As I said, the controller just do what the name says: It makes the decisions and instructs the entity to perform certain operations.