Monday, July 8, 2013

Engine Design: Components, Managers, and Entities

I have spent quite some time on my engine trying to figure out a name. But what I have spent more time on is the infrastructure of the engine.

The component based design I have been going for has been coming together very well.

The layout of the design follows this pattern: Base Component class with necessary virtual functions such as type identifiers and a default constructor that requires any new component derived from the base Component to identify itself. There is a list of Component Types contained within a namespace and globally accessible. This list contains identifier names associated to a bit within a 32-bit field - each one must be different. This allows for only 32 types of components.

In conjunction with the Components is a component manager that holds vectors of all the different types of components. Now, one thing to note that there are n vectors in the Component Manager, where n represents the number of components. This is preferred to avoid searching one giant vector of components in order to collect components of a certain type. The Component Manager is responsible for storing all components in the game and giving them out to processes that require the component data.

Containing components is the Entity class. It is small, containing merely a vector of dynamically allocated Components and a name. When it is created, the components that it has are defined in the constructor and allocated into the Component vector. Then they components are registered to the component manager.

So far that is all that I have accomplished so far but it was a lot of fun implementing such a system into my game engine architecture. Soon, I hope to have video to show the design and methods behind the engine.

No comments:

Post a Comment