I have recently read the Entity-Component article on here and I got really interested in the design. It sounds great. Functionality through property definitions. I have been waiting for the followup article about implementation, but it has not come yet. I have been reading and thinking about my own implementation and have a few questions. First, I want to start off with my assumptions/design.
1. All components inherit from a base component class that contains some pure virtual functions to be overwritten.
2. Components contain only data and do not directly have functionality.
3. All entities will be kept in a single container as the master list of entities.
4. Entities are a class that can contain one or more components.
5. A system can query the master list looking for entities that contain all required components. Once it finds one, it will then typically reference that entity by an ID number, not a pointer
Some of my design/assumptions may already be drifting away from the concept. I am trying to stay close to the concept because I feel that if I drift away from the component, then I may end up running into the snags the design was supposed to prevent. So without further ado, here are my questions:
1. How to provide custom functionality for entities that contain the exact same components. For instance, I may want to have different AI routines for different entities. My thought was to have a component that is a functor to the particular AI routine I would want to run. That would be a required component in order for the AI system to find that entity
2. How do most people deal with changes to the component list? Do they use the observer pattern to inform systems when an entity changes or does the system query the master list every time to find the entities that match its criteria. The observer pattern is the way I was thinking.
3. How do you handle shared components. An example would be several entities using the same material. My thought was to just have a component that contains a shared_ptr to the material.
4. Is it okay to have some inheritance at the component level or would this break the design? Based on what I know, I can't imagine it would break the design. I wanted for instance my graphics system to be able to find all entities that contain a VertexBuffer component, but I also want my material system to be looking for a particular type of VertexBuffer component (say one that provides texels).
5. My understanding is that most systems contain a reference to an entity by entity ID and not by pointer. Why is that? Is it common for the pointer to change, but the ID to remain the same? If so, what scenarios would that occur in? Does constant lookup not cause performance issues?
Also, any articles that go into some specifics about an Entity-Component system would be very helpful. Thanks.