Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/module.h')
-rw-r--r--src/core/module.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/core/module.h b/src/core/module.h
new file mode 100644
index 0000000..053c9e5
--- /dev/null
+++ b/src/core/module.h
@@ -0,0 +1,74 @@
+/*
+ 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 <string>
+#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; }
+
+/*----- 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 ---------------------------------------------------- */
+
+ /// load a game module
+ static void load(Module *module);
+
+ /// unload the preloaded module
+ static void unload();
+
+ /// the preloaded module
+ inline static Module *preload() { return module_preload; };
+
+protected:
+ /// set the disconnected state
+ void abort();
+ bool module_running;
+
+private:
+ static Module *module_preload;
+ std::string module_name;
+
+};
+
+}
+
+#endif // __INCLUDED_CORE_MODULE_H__