/* core/module.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_MODULE_H__ #define __INCLUDED_CORE_MODULE_H__ #include #include "core/player.h" namespace core { // a loadable game module class Module { public: Module(const char *name); virtual ~Module(); /*----- inspectors ------------------------------------------------ */ /// return true if the game module can run a timeframe inline bool running() const { return module_running; } /// return true if the game module can not run a timeframe inline bool error() const { return !module_running; } /// return the name of the module inline std::string const & name() const { return module_name; } /// label of the module inline std::string const & label() const { return module_label; } /// indicates if this is an interactive module or not inline bool interactive() const { return module_interactive; } /*----- mutators -------------------------------------------------- */ /// initialize the game module virtual void init() = 0; /// shutdown the game module virtual void shutdown() = 0; /// run one timeframe virtual void frame(float seconds) = 0; /// is called when a player connects virtual void player_connect(Player *player) = 0; /// is called when a player disconnects virtual void player_disconnect(Player *player) = 0; /*----- static ---------------------------------------------------- */ typedef std::map Registry; /// find a registered game module static Module *find(const char *name); /// find a registered game module static Module *find(std::string const &name); /// register a game module static Module *add(const char *name, Module *module); /// load a registered game module static Module *load(const char *name); /// unload all modules static void clear(); /// currently loaded module static inline Module *current() { return module_preload; } /// module registry static inline Registry & registry() { return module_registry; } protected: /// set the disconnected state void abort(); bool module_running; bool module_interactive; private: std::string module_name; std::string module_label; static Module *module_preload; static Registry module_registry; }; } #endif // __INCLUDED_CORE_MODULE_H__