57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
#ifndef MODULE_H
|
|
#define MODULE_H
|
|
|
|
#include "EventBase.h"
|
|
|
|
namespace Engine {
|
|
|
|
/** \brief Base class for the separate modules
|
|
*
|
|
* All Modules that are managed by the Engine::Engine base Module. Everything
|
|
* else is a Submodule of that or a Submodule of a Submodule.
|
|
*/
|
|
class Module {
|
|
public:
|
|
/** \brief Initializes the Module
|
|
*
|
|
* \note This function must only return if it was able to initialize
|
|
* successfully, otherwise it should log an error with LogError and exit
|
|
* the program itself!
|
|
*
|
|
* In general at first the Submodules get initialized and then the Module
|
|
* that has pointers to the Submodules. Exception: The main Module
|
|
* Engine::Engine.
|
|
*
|
|
* \note
|
|
* The function Engine::OnInit () performs the allocation
|
|
* and Initialization of all its Submodules.
|
|
*/
|
|
virtual int Init (int argc, char* argv[]) { return OnInit (argc, argv); }
|
|
/** \brief Frees the used memory of the Module
|
|
*
|
|
* The Destroy function is always called at first for the Module itself
|
|
* and then for its submodules so that a Module is still completely
|
|
* working. Again for the main Module Engine::Engine the reverse is the
|
|
* case (such as in Module::Init).
|
|
*/
|
|
virtual void Destroy () { OnDestroy (); }
|
|
/** \brief Calls the function that registers its commands to the
|
|
* Commandsystem */
|
|
virtual void RegisterCommands () { OnRegisterCommands (); }
|
|
virtual bool SendEvent (const EventBasePtr &event) { return OnReceiveEvent (event); }
|
|
|
|
protected:
|
|
/** \brief The actual function being called when Init () is called */
|
|
virtual int OnInit (int argc, char* argv[]) = 0;
|
|
/** \brief Frees the memory */
|
|
virtual void OnDestroy () { };
|
|
/** \brief Registers the commands of the Module */
|
|
virtual void OnRegisterCommands () { };
|
|
/** \brief Reacts on a event that was sent to the module */
|
|
virtual bool OnReceiveEvent (const EventBasePtr &event) { return false; };
|
|
};
|
|
|
|
}
|
|
|
|
#endif /* MODULE_H */
|