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-10-18 14:44:13 +0000
committerStijn Buys <ingar@osirion.org>2008-10-18 14:44:13 +0000
commitdb287e4a5133125bb6f25ba21ea97c47b19ac67f (patch)
treec977e4da6203344362a186010d017463d88def6e /src/core
parentade4627e7fe0f89d9fdb2e27f01444ad0aa2d41d (diff)
minor module updates
Diffstat (limited to 'src/core')
-rw-r--r--src/core/application.cc6
-rw-r--r--src/core/commandbuffer.cc10
-rw-r--r--src/core/module.cc50
-rw-r--r--src/core/module.h22
4 files changed, 59 insertions, 29 deletions
diff --git a/src/core/application.cc b/src/core/application.cc
index 837f294..0d52b76 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -309,9 +309,9 @@ void Application::quit(int status)
}
-Module *Application::load(std::string const &module_name)
+Module *Application::load(std::string const &module_label)
{
- if (game()) {
+ if (game() && Module::current()->interactive()) {
con_warn << "Connected. Disconnect first.\n";
return 0;
}
@@ -319,7 +319,7 @@ Module *Application::load(std::string const &module_name)
if (Module::current() && Module::current()->interactive()) {
module_interactive = Module::current();
}
- return Module::load(module_name.c_str());
+ return Module::load(module_label.c_str());
}
void Application::connect(std::string const &host)
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 5ed3787..8c3c8a1 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -69,6 +69,12 @@ void func_list_model(std::string const &args)
model::Model::list();
}
+
+void func_list_module(std::string const &args)
+{
+ Module::list();
+}
+
void func_set(std::string const &args)
{
std::istringstream argstream(args);
@@ -168,6 +174,9 @@ void CommandBuffer::init()
Func::add("list_model", (FuncPtr) func_list_model);
func->set_info("list models");
+ Func::add("list_module", (FuncPtr) func_list_module);
+ func->set_info("list game modules");
+
func = Func::add("set", (FuncPtr)func_set);
func->set_info("[variable] [str] set variable value");
@@ -194,6 +203,7 @@ void CommandBuffer::shutdown()
Func::remove("list_func");
Func::remove("list_ent");
Func::remove("list_model");
+ Func::remove("list_module");
Func::remove("list_zone");
Func::remove("print");
Func::remove("print_file");
diff --git a/src/core/module.cc b/src/core/module.cc
index ae78260..319d651 100644
--- a/src/core/module.cc
+++ b/src/core/module.cc
@@ -4,6 +4,7 @@
the terms of the GNU General Public License version 2
*/
+#include "auxiliary/functions.h"
#include "core/module.h"
#include "sys/sys.h"
@@ -15,46 +16,51 @@ namespace core
Module *Module::module_preload = 0;
Module::Registry Module::module_registry;
-Module *Module::find(std::string const &name)
+Module *Module::find(const std::string &label)
{
- Registry::iterator it = module_registry.find(name);
+ Registry::iterator it = module_registry.find(label);
if (it == module_registry.end())
return 0;
else
return (*it).second;
}
-Module *Module::find(const char *name)
+Module *Module::find(const char *label)
{
- return(find(std::string(name)));
+ return(find(std::string(label)));
}
-Module *Module::add(const char *name, Module *module)
+Module *Module::add(Module *module)
{
- Module *m = find(name);
+ Module *m = find(module->label());
if (m) {
- con_warn << "module '" << name << "' already loaded!" << std::endl;
+ con_warn << "module '" << module->label() << "' already registered!" << std::endl;
delete module;
return 0;
}
- module_registry[std::string(name)] = module;
- module->module_label.assign(name);
+
+ module_registry[module->label()] = module;
+
if (!module_preload) {
module_preload = module;
- con_debug << " " << name << " " << module->name() << std::endl;
}
+ con_debug << " " << module->label() << " " << module->name() << std::endl;
+
return module;
}
-Module *Module::load(const char *name)
+Module *Module::load(const char *label)
{
- Module *module = find(name);
+ if (!label)
+ return 0;
+
+ Module *module = find(label);
if (!module) {
- con_warn << "could not find module '" << name << "'" << std::endl;
+ con_warn << "Could not find module '" << label << "'" << std::endl;
return 0;
}
- con_debug << " " << name << " " << module->name() << std::endl;
+ con_print << " module" << module->label() << " " << module->name() << std::endl;
module_preload = module;
return module;
}
@@ -63,17 +69,27 @@ void Module::clear()
{
for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
Module *module = (*it).second;
- delete module;
+ con_print << " " << module->label() << " " << module->name() << std::endl;
}
module_registry.clear();
module_preload = 0;
}
+void Module::list()
+{
+ for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
+ Module *module = (*it).second;
+ con_print << " " << module->label() << " " << module->name() << std::endl;
+
+ }
+ con_print << module_registry.size() << " registered game " << aux::plural("modules", module_registry.size()) << std::endl;
+}
+
/*-- instance functions --------------------------------------------*/
-Module::Module(const char *name) :
- module_name(name)
+Module::Module(const char *label, const char *name) :
+ module_label(label), module_name(name)
{
module_running = false;
module_interactive = true;
diff --git a/src/core/module.h b/src/core/module.h
index 20029cf..bc4f765 100644
--- a/src/core/module.h
+++ b/src/core/module.h
@@ -17,7 +17,7 @@ namespace core
class Module
{
public:
- Module(const char *name);
+ Module(const char *label, const char *name);
virtual ~Module();
/*----- inspectors ------------------------------------------------ */
@@ -27,12 +27,12 @@ public:
/// 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; }
+ /// return the name of the module
+ inline std::string const & name() const { return module_name; }
+
/// indicates if this is an interactive module or not
inline bool interactive() const { return module_interactive; }
@@ -58,16 +58,19 @@ public:
typedef std::map<std::string, Module *> Registry;
/// find a registered game module
- static Module *find(const char *name);
+ static Module *find(const char *label);
/// find a registered game module
- static Module *find(std::string const &name);
+ static Module *find(const std::string &label);
/// register a game module
- static Module *add(const char *name, Module *module);
+ static Module *add(Module *module);
/// load a registered game module
- static Module *load(const char *name);
+ static Module *load(const char *label);
+
+ /// list modules
+ static void list();
/// unload all modules
static void clear();
@@ -79,6 +82,7 @@ public:
static inline Registry & registry() { return module_registry; }
protected:
+
/// set the disconnected state
void abort();
@@ -86,8 +90,8 @@ protected:
bool module_interactive;
private:
- std::string module_name;
std::string module_label;
+ std::string module_name;
static Module *module_preload;