Module Development for Game Design

By Jeff Verkoeyen

This article is going to cover the creation of a game system using what I call modules. The design of a module system is relatively simple and once you've put it together correctly, you'll be able to make different parts of your game very easily and basically plug them in wherever you want.

Each module will inherit from a module class and implement 3 virtual functions which will handle initialization, execution, and cleanup. We can add other functions, but these are the three basic functions.

The Module prototype looks like this:
class Module
        virtual void Initialize()=0;
        virtual Module* ExecuteModule()=0;
        virtual void Shutdown()=0;
We won't go through actually implementing a module, as that should be easy to do. We're going to concentrate more on the frame of the module program itself.

Next we need to make the game loop, which is also very simple:
Module* oldMod=gamemod;
This code grabs the current module (gamemod being a predeclare Module* that points to whichever module you are currently wanting to run), it then runs the module and the execute module function will return a Module*

If this returned Module* doesn't equal the old Module*, then that means we've changed modules, so we shut down the old module and initialize the new one, and then continue on in the game loop.

With those few lines of code, you can create whatever you want and expand however you want in any direction and have interlinked modules linking to each other very easily.

This is a great alternative to having a switch statement testing the current game state, and also works very nicely for developing games rather quickly (this is the method I use in developing games for the 72 hour game development competitions).

Hopefully that sheds some light on an easier method of game development!

Read the discussion!
Related articles

Classes in C++

Understanding inheritance