Sign in to follow this  

Component Based Game Engines

Recommended Posts

Marsol0x    122
I'm having trouble wrapping my head around the idea of a component based game engine. I know that instead of a deep hierarchy of classes to represent game objects, you would use components to give game objects broad abilities. For instance, a player's game object would not have a method that holds the data for how much HP that player has, but rather it would contain a component object that holds the data and has methods to operate on that data. That might even be wrong, I'm not sure. The problem is that there is plenty of information that discusses the theory but not enough that shows examples of how such a thing is done. What would help, I think, is an example of a component class, because I haven't seen those. Also, is there any open source games that use a component based engine?

Share this post

Link to post
Share on other sites
Antheus    2409
class Container
std::map< std::string, Component * > components;

That's about it.

The rest merely deals with typing the contents (which types of components do we have?) and similar.

All Containers are of exactly the same type and can be used indiscriminately. The basic idea is simply to apply functionality to everything.

for (Container c in monsters) {  // pseudo code
AIComponent aic = (AIComponent)c.components.get("AI");
if (c != NULL) c->doTheFoo(); // this monster implements AI

"Unfortunately", GPG6 does provide a good overview of the topic, but may require you to obtain the book, as it's not free.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this