Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-09-28 15:05:13 +0000
committerStijn Buys <ingar@osirion.org>2008-09-28 15:05:13 +0000
commitfd778219e40c5fbb4d0af1839cbc313caaf10d9d (patch)
treeb6e413f4c1a5ba4091503ba97c784278485d3933 /src/core
parentbedcff956d253621ec00aa7d2919c22a4c88b0b2 (diff)
move base game module to new subdirectory
Diffstat (limited to 'src/core')
-rw-r--r--src/core/application.cc2
-rw-r--r--src/core/gameserver.cc5
-rw-r--r--src/core/module.cc70
-rw-r--r--src/core/module.h29
4 files changed, 83 insertions, 23 deletions
diff --git a/src/core/application.cc b/src/core/application.cc
index 6207a0d..f8b9a73 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -251,6 +251,8 @@ void Application::shutdown()
save_config();
+ Module::clear();
+
// remove our engine functions
Func::remove("say");
Func::remove("help");
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index f251b75..e086096 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -114,7 +114,7 @@ GameServer::GameServer() : GameInterface()
server_frametime = 0.0f;
server_maxplayerid = 1;
- server_module = Module::preload();
+ server_module = Module::current();
if (!server_module) {
con_error << "No module loaded.\n";
abort();
@@ -199,9 +199,6 @@ GameServer::~GameServer()
player_disconnect(localplayer());
server_module->shutdown();
-
- if (server_module != Module::preload())
- delete server_module;
}
Func::remove("kick");
diff --git a/src/core/module.cc b/src/core/module.cc
index 447e2b3..89bc2fe 100644
--- a/src/core/module.cc
+++ b/src/core/module.cc
@@ -5,36 +5,82 @@
*/
#include "core/module.h"
+#include "sys/sys.h"
namespace core
{
+/*-- static functions ----------------------------------------------*/
+
Module *Module::module_preload = 0;
+Module::Registry Module::module_registry;
-Module::Module(const char *name) :
- module_name(name)
+Module *Module::find(std::string const &name)
{
- module_running = false;
+ Registry::iterator it = module_registry.find(name);
+ if (it == module_registry.end())
+ return 0;
+ else
+ return (*it).second;
}
-Module::~Module()
+Module *Module::find(const char *name)
{
- module_running = false;
- module_name.clear();
+ return(find(std::string(name)));
}
-
-void Module::load(Module *module)
+Module *Module::add(const char *name, Module *module)
{
+ Module *m = find(name);
+ if (m) {
+ con_warn << "module '" << name << "' already loaded!" << std::endl;
+ delete module;
+ return 0;
+ }
+ module_registry[std::string(name)] = module;
+ if (!module_preload) {
+ module_preload = module;
+ con_debug << " " << name << " " << module->name() << std::endl;
+ }
+ return module;
+}
+
+Module *Module::load(const char *name)
+{
+ Module *module = find(name);
+ if (!module) {
+ con_warn << "could not find module '" << name << "'" << std::endl;
+ return 0;
+ }
+
+ con_debug << " " << name << " " << module->name() << std::endl;
module_preload = module;
+ return module;
}
-void Module::unload()
+void Module::clear()
{
- if (module_preload) {
- delete module_preload;
- module_preload = 0;
+ for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
+ Module *module = (*it).second;
+ delete module;
}
+
+ module_registry.clear();
+ module_preload = 0;
+}
+
+/*-- instance functions --------------------------------------------*/
+
+Module::Module(const char *name) :
+ module_name(name)
+{
+ module_running = false;
+}
+
+Module::~Module()
+{
+ module_running = false;
+ module_name.clear();
}
void Module::abort()
diff --git a/src/core/module.h b/src/core/module.h
index 61dc0dc..bd99034 100644
--- a/src/core/module.h
+++ b/src/core/module.h
@@ -49,23 +49,38 @@ public:
/*----- static ---------------------------------------------------- */
- /// load a game module
- static void load(Module *module);
+ typedef std::map<std::string, Module *> Registry;
- /// unload the preloaded module
- static void unload();
+ /// find a registered game module
+ static Module *find(const char *name);
+
+ /// find a registered game module
+ static Module *find(std::string const &name);
- /// the preloaded module
- inline static Module *preload() { return module_preload; };
+ /// 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; }
protected:
/// set the disconnected state
void abort();
+
bool module_running;
private:
- static Module *module_preload;
std::string module_name;
+
+ static Module *module_preload;
+
+ static Registry module_registry;
};
}