Designing the component system

A component-based system can be implemented in many ways. So, before we write any code, let's look at some possibilities. The goal is to break reusable behavior into succinct components and be able to add and remove them from the existing objects with ease. All objects share a common base class named object so we'll add the facility to add components to and remove them from this class. We can then ensure that it will be propagated to all the subsequent classes in the project.

There are a number of ways to implement a component-based approach, and there is no single right answer. For example, we could create a function to add or remove each component individually. Here's an example:

bool AttachSpriteComponent(SpriteComponent ...

Get Procedural Content Generation for C++ Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.