Implementing components

Now that you have seen the M5object, let's take a look at how the Mach5 Engine creates and uses the component hierarchy. Since this is an abstract class, there is no way to create an instance of an M5Component. It is only an interface.

As you will see, the base component contains some of the same members as the M5object. Since we will have a lot of components, it is important to give each one a type, so they can be searchable. It is important to give each a unique ID. Since these components can be deleted at any time, it is important to save an ID instead of a pointer, which can become invalid:

class M5Component {   public:     M5Component(M5ComponentTypes type);     virtual ~M5Component(void);  virtual M5Component* Clone(void) ...

Get Game Development Patterns and Best Practices 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.