Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
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
parentade4627e7fe0f89d9fdb2e27f01444ad0aa2d41d (diff)
minor module updates
Diffstat (limited to 'src')
-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
-rw-r--r--src/filesystem/filesystem.cc4
-rw-r--r--src/game/base/base.cc5
-rw-r--r--src/game/game.cc4
-rw-r--r--src/game/intro/intro.cc2
8 files changed, 67 insertions, 36 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;
diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc
index a8fca1d..19869a9 100644
--- a/src/filesystem/filesystem.cc
+++ b/src/filesystem/filesystem.cc
@@ -157,11 +157,11 @@ void init(std::string const & basename, std::string const & modname)
for (size_t i = 0; i < (*path).size(); i++)
if ((*path)[i] == '/') (*path)[i] = '\\';
#endif
- con_print << " directory: " << (*path) << std::endl;
+ con_print << " directory " << (*path) << std::endl;
}
// create writedir
- con_print << " home directory: " << filesystem_writedir << std::endl;
+ con_print << " home " << filesystem_writedir << std::endl;
}
void shutdown()
diff --git a/src/game/base/base.cc b/src/game/base/base.cc
index dee303b..f27d013 100644
--- a/src/game/base/base.cc
+++ b/src/game/base/base.cc
@@ -162,11 +162,11 @@ void func_impulse(core::Player *player, std::string const &args)
ship->impulse();
}
-/* ---- The Game class --------------------------------------------- */
+/* ---- class Base ------------------------------------------------ */
Base *Base::game_instance = 0;
-Base::Base() : core::Module("Project::OSiRiON")
+Base::Base() : core::Module("base", "Project::OSiRiON")
{
game_instance = this;
g_impulsespeed = 0;
@@ -216,6 +216,7 @@ void Base::init()
func = core::Func::add("list_ship", (core::FuncPtr) func_list_ship);
func->set_info("list ship statistics");
+ // add engine variables
g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive);
g_impulsespeed->set_info("[float] speed of the impulse drive");
diff --git a/src/game/game.cc b/src/game/game.cc
index 7e89a0d..9f5b395 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -19,11 +19,11 @@ void register_modules(bool register_noninteractive_modules)
con_print << "^BRegistering game modules..." << std::endl;
// non-interactive modules
- core::Module::add("base", new base::Base());
+ core::Module::add(new base::Base());
// interactive modules
if (register_noninteractive_modules) {
- core::Module::add("intro", new intro::Intro());
+ core::Module::add(new intro::Intro());
}
}
diff --git a/src/game/intro/intro.cc b/src/game/intro/intro.cc
index 4eb9a10..abb3ba8 100644
--- a/src/game/intro/intro.cc
+++ b/src/game/intro/intro.cc
@@ -14,7 +14,7 @@
namespace intro {
-Intro::Intro() : core::Module("Introduction")
+Intro::Intro() : core::Module("intro", "Introduction")
{
module_interactive = false;
intro_zone = 0;