The State pattern in action - the M5StateMachine class

The Mach5 Engine itself also has its own implementation of a State Machine, using inheritance to allow users to not have to rewrite the base functionality over and over again and using function pointers instead of having one function for each state. A function pointer is what it sounds like--a pointer to the address in memory where the function is--and we can call it from that information.

To learn more about function pointers and how they are used, check out http://www.cprogramming.com/tutorial/function-pointers.html.

You can take a look at the base version of one here, starting with the Header file:

#ifndef M5STATEMACNINE_H #define M5STATEMACNINE_H  #include "M5Component.h" #include ...

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.