Ok it goes like this, the Module class is basically a place for a 'chunk' of code to go. This could be any thing from a rendering process or intilizations or some thing or any thing, and returns the pointer to the next one.
Code:
class Module
{
protected:
bool Registered;
friend class ModuleHandler; //the Module and ModuleHandler classes are now friends, yay!!!
protected:
virtual void Initialize()=0;
virtual Module* Execute()=0;
virtual void Shutdown()=0;
};
The ModuleHandler is the class that manages all Modules, it loops through them, makes sure they are registered, delets them at the program end, ect. Module Handler is also the only way to acess a derived Module. NOTE: the shut down part is not in there yet.
Code:
class ModuleHandler
{
protected:
vector<Module*> ModuleList;
vector<Module*>::iterator ModuleListIterator;
Module* CurrentModule; //holds the current module of use
Module* LastModule; //holds the last module of use
public:
ModuleHandler(Module* FirstModule)
{
CurrentModule = FirstModule;
LastModule = CurrentModule;
}
void RegisterModule(Module* module)
{
if(module->Registered != true) //if this is false, the module is already registered
{
ModuleList.push_back(module);
module->Registered = true
}
}
void ModuleLoop()
{
if(CurrentModule != NULL && CurrentModule->Registered == true)
{
CurrentModule->Initialize(); //initialize module
CurrentModule = CurrentModule->Execute(); //execute module
if(CurrentModule != LastModule) //true, we have switched modules
{
LastModule->Shutdown();
LastModule = CurrentModule;
}
}
else
MessageBox(0, "Module Not Registered", 0, 0);
}
};