Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-11-23 12:34:07 +0000
committerStijn Buys <ingar@osirion.org>2008-11-23 12:34:07 +0000
commit583ec3285c41e9d253c4aaabd2af4dadac75f3a7 (patch)
tree5ec345e44af9d3699a95f493d8358ee766e23330
parent44158ccfbe943b832c0e0bf9ce547212aa6c2b8b (diff)
clean module consturction/destruction
-rw-r--r--src/client/client.cc17
-rw-r--r--src/client/soundext.cc8
-rw-r--r--src/client/targets.cc14
-rw-r--r--src/core/Makefile.am6
-rw-r--r--src/core/application.cc66
-rw-r--r--src/core/application.h3
-rw-r--r--src/core/commandbuffer.cc3
-rw-r--r--src/core/gameserver.cc22
-rw-r--r--src/core/loader.cc93
-rw-r--r--src/core/loader.h62
-rw-r--r--src/core/module.cc106
-rw-r--r--src/core/module.h58
-rw-r--r--src/game/base/game.cc16
-rw-r--r--src/game/base/game.h10
-rw-r--r--src/game/example/example.cc26
-rw-r--r--src/game/example/example.h19
-rw-r--r--src/game/game.cc8
-rw-r--r--src/game/intro/intro.cc14
-rw-r--r--src/game/intro/intro.h17
19 files changed, 287 insertions, 281 deletions
diff --git a/src/client/client.cc b/src/client/client.cc
index 061f29b..650813c 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -17,6 +17,7 @@
#include "client/input.h"
#include "client/view.h"
#include "core/core.h"
+#include "core/loader.h"
#include "core/zone.h"
#include "render/render.h"
#include "ui/ui.h"
@@ -167,15 +168,21 @@ void Client::run()
void Client::frame(unsigned long timestamp)
{
+ input::frame();
+
core::Application::frame(timestamp);
- if (!core::application()->connected()) {
+ if (!connected()) {
+ std::string module_label(core::Loader::label());
+
// load the intro if nothing is running
- if (core::application()->load("intro")) {
- core::application()->connect("");
+ if (load("intro")) {
+ connect("");
+ if (module_label.size())
+ load(module_label);
}
// show the console if everything fails
- if (!core::application()->connected() && !ui::console()->visible()) {
+ if (!connected() && !ui::console()->visible()) {
ui::console()->toggle();
}
} else if (!ui::root()->active()) {
@@ -207,7 +214,7 @@ void Client::frame(unsigned long timestamp)
}
video::frame((float)(timestamp - previous_timestamp) / 1000.0f);
- input::frame();
+
previous_timestamp = timestamp;
}
diff --git a/src/client/soundext.cc b/src/client/soundext.cc
index 421575d..9b15597 100644
--- a/src/client/soundext.cc
+++ b/src/client/soundext.cc
@@ -134,11 +134,15 @@ void SoundExt::frame(float elapsed)
}
+ float x = entity->radius();
+ if (entity->model())
+ x = entity->model()->maxbbox().x;
+
audio::update_source(state_engineloopsource,
- entity->location() - entity->axis().forward() * entity->model()->maxbbox().x , entity->axis().forward() * speed, pitch, gain);
+ entity->location() - entity->axis().forward() * x , entity->axis().forward() * speed, pitch, gain);
audio::update_source(state_engineeventsource,
- entity->location() - entity->axis().forward() * entity->model()->maxbbox().x , entity->axis().forward() * speed);
+ entity->location() - entity->axis().forward() * x , entity->axis().forward() * speed);
}
diff --git a/src/client/targets.cc b/src/client/targets.cc
index 3ccea8a..c544e73 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -45,6 +45,8 @@ bool is_legal_target(core::Entity *entity)
{
if (entity->serverside()) {
return false;
+ } else if (!ext_render(entity)) {
+ return false;
} else if (entity == core::localplayer()->mission_target()) {
return true;
} else if (entity == core::localcontrol()) {
@@ -307,17 +309,17 @@ void render_entity_sound(core::Entity *entity)
return;
}
- if (!ext_render(entity) || !ext_render(entity)->visible()) {
+ if (!ext_render(entity) || (ext_render(entity) && !ext_render(entity)->visible())) {
if (ext_sound(entity))
delete ext_sound(entity);
return;
- }
+ } else {
+ if (!ext_sound(entity)) {
+ new SoundExt(entity);
+ }
- if (!ext_sound(entity)) {
- new SoundExt(entity);
+ ext_sound(entity)->frame(0.0f);
}
-
- entity->extension((size_t) core::Extension::Sound)->frame(0.0f);
}
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index fbdf311..317a99e 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -3,8 +3,8 @@ INCLUDES = -I$(top_srcdir)/src
libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc \
descriptions.cc entity.cc extension.cc func.cc gameconnection.cc gameinterface.cc \
- gameserver.cc module.cc netclient.cc netconnection.cc netplayer.cc netserver.cc \
- parser.cc player.cc stats.cc timer.cc zone.cc
+ gameserver.cc loader.cc module.cc netclient.cc netconnection.cc netplayer.cc \
+ netserver.cc parser.cc player.cc stats.cc timer.cc zone.cc
libcore_la_LDFLAGS = -avoid-version -no-undefined
libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \
$(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la \
@@ -14,4 +14,4 @@ noinst_LTLIBRARIES = libcore.la
noinst_HEADERS = application.h commandbuffer.h core.h cvar.h entity.h func.h \
gameconnection.h gameinterface.h gameserver.h message.h module.h net.h netclient.h \
netconnection.h netserver.h player.h range.h stats.h timer.h parser.h descriptions.h \
- extension.h
+ extension.h loader.h
diff --git a/src/core/application.cc b/src/core/application.cc
index f24f0f7..1cba59a 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -23,6 +23,7 @@
#include "core/func.h"
#include "core/gameconnection.h"
#include "core/gameserver.h"
+#include "core/loader.h"
namespace core
{
@@ -66,7 +67,7 @@ Application *Application::application_instance = 0;
Application::Application()
{
if (application_instance) {
- std::cerr << "multiple core::Application instances!\n";
+ std::cerr << "multiple core::Application instances\n";
sys::quit(2);
}
@@ -74,8 +75,6 @@ Application::Application()
application_timestamp = 0;
application_game = 0;
- module_interactive = 0;
-
#ifndef _WIN32
sys::signal(SIGHUP, signal_handler);
sys::signal(SIGINT, signal_handler);
@@ -97,7 +96,9 @@ void Application::init(int count, char **arguments)
{
con_print << "^BInitializing core...\n";
con_debug << " debug messages enabled\n";
+
filesystem::init("base", "");
+ Loader::load("base");
CommandBuffer::init();
@@ -210,7 +211,7 @@ void Application::shutdown()
save_config();
- Module::clear();
+ Loader::clear();
// remove our engine functions
Func::remove("msg");
@@ -238,57 +239,34 @@ void Application::quit(int status)
}
-Module *Application::load(std::string const &module_label)
+bool Application::load(std::string const &label)
{
- if (!module_label.size()) {
- if (Module::active()) {
- con_print << " active module: " << Module::active()->label() << " " << Module::active()->name() << std::endl;
- }
- if (Module::loaded()) {
- con_print << " loaded module: " << Module::loaded()->label() << " " << Module::loaded()->name() << std::endl;
- }
- if (module_interactive) {
- con_print << " fallback module: " << module_interactive->label() << " " << module_interactive->name() << std::endl;
- }
- std::string helpstr(" available modules:");
- for(Module::Registry::iterator it = Module::registry().begin(); it != Module::registry().end(); it++) {
- helpstr += ' ';
- helpstr += (*it).first;
- }
- con_print << helpstr << std::endl;
- return 0;
+ if (!label.size()) {
+ Loader::list();
+ return false;
}
-/*
- if (Module::active() && Module::active()->interactive()) {
+
+ if (connected() && game()->interactive()) {
con_warn << "Connected. Disconnect first.\n";
- return 0;
+ return false;
}
-*/
- if (Module::loaded() && Module::loaded()->interactive()) {
- module_interactive = Module::loaded();
+
+ if (!Loader::load(label)) {
+ return false;
}
- return Module::load(module_label.c_str());
+
+ return true;
}
void Application::connect(std::string const &host)
{
- if (connected()) {
- if (!Module::active()->interactive()) {
- if ((Module::loaded() == Module::active()) && (module_interactive)) {
- disconnect();
- Module::load(module_interactive->label().c_str());
- } else {
- disconnect();
- }
- } else {
- con_warn << "Connected. Disconnect first.\n";
- return;
- }
+ if (connected() && game()->interactive()) {
+ con_warn << "Connected. Disconnect first.\n";
+ return;
}
if (application_game) {
- delete application_game;
- application_game = 0;
+ disconnect();
}
if (host.size()) {
@@ -317,9 +295,9 @@ void Application::connect(std::string const &host)
void Application::disconnect()
{
if(application_game) {
- notify_disconnect();
delete application_game;
application_game = 0;
+ notify_disconnect();
con_print << "^BDisconnected.\n";
}
}
diff --git a/src/core/application.h b/src/core/application.h
index e992131..45c316f 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -51,7 +51,7 @@ public:
void disconnect();
/// load a module
- Module *load(std::string const &module_name);
+ bool load(std::string const &module_name);
/*----- virtual mutators ------------------------------------------ */
@@ -105,7 +105,6 @@ private:
unsigned long application_timestamp;
GameInterface *application_game;
- Module *module_interactive;
static Application *application_instance;
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 4addd10..98cdc7a 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -17,6 +17,7 @@
#include "core/gameconnection.h"
#include "core/func.h"
#include "core/cvar.h"
+#include "core/loader.h"
#include "core/zone.h"
namespace core
@@ -72,7 +73,7 @@ void func_list_model(std::string const &args)
void func_list_module(std::string const &args)
{
- Module::list();
+ Loader::list();
}
void func_set(std::string const &args)
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index b8f8730..f614fa9 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -12,6 +12,7 @@
#include "core/cvar.h"
#include "core/func.h"
#include "core/gameserver.h"
+#include "core/loader.h"
#include "core/netserver.h"
#include "filesystem/filesystem.h"
#include "sys/sys.h"
@@ -125,26 +126,28 @@ GameServer::GameServer() : GameInterface()
server_maxplayerid = 1;
server_startup = application()->timestamp();
- server_module = Module::loaded();
+ server_module = Loader::init();
if (!server_module) {
con_error << "No module loaded.\n";
abort();
return;
}
- if (server_module->interactive())
- load_config(); //FIXME interferes with command line because of cmd.exec
-
- // set the name of the game
- core::Cvar::set("g_name", server_module->name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly);
-
- server_module->run();
if (!server_module->running()) {
con_error << "Could not initialize module '" << server_module->name() << "'\n";
abort();
return;
}
+ if (server_module->interactive()) {
+ //FIXME interferes with command line because of cmd.exec
+ load_config();
+ }
+
+ // set the name of the game
+ core::Cvar::set("g_name", server_module->name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly);
+
+
con_print << " module '^B" << server_module->name() << "^N'\n";
if (server_module->interactive() && (Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {
@@ -205,7 +208,8 @@ GameServer::~GameServer()
if (server_module->running() && !Cvar::sv_dedicated->value())
player_disconnect(localplayer());
- server_module->terminate();
+ delete server_module;
+ server_module = 0;
}
Func::remove("kick");
diff --git a/src/core/loader.cc b/src/core/loader.cc
new file mode 100644
index 0000000..46e0990
--- /dev/null
+++ b/src/core/loader.cc
@@ -0,0 +1,93 @@
+/*
+ core/loader.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "auxiliary/functions.h"
+#include "core/loader.h"
+#include "sys/sys.h"
+
+namespace core {
+
+Loader::Registry Loader::loader_registry;
+std::string Loader::loader_label;
+
+Loader::FactoryFuncPtr Loader::find(const char *label)
+{
+ Registry::iterator it = loader_registry.find(label);
+ if (it == loader_registry.end())
+ return 0;
+ else
+ return (*it).second;
+}
+
+Loader::FactoryFuncPtr Loader::find(const std::string &label)
+{
+ return (find(label.c_str()));
+}
+
+void Loader::add(const std::string &label, FactoryFuncPtr factory)
+{
+ if (find(label)) {
+ con_warn << "module '" << label << "' already registered" << std::endl;
+ return;
+ }
+
+ loader_registry[label] = factory;
+ con_debug << " registering module '" << label << "'" << std::endl;
+}
+
+bool Loader::load(const char *label)
+{
+ FactoryFuncPtr factory = find(label);
+ if (!factory) {
+ con_warn << "module '" << label << "' not found" << std::endl;
+ return false;
+ }
+
+ con_debug << " loading module '" << label << "'" << std::endl;
+ loader_label.assign(label);
+ return true;
+}
+
+bool Loader::load(const std::string &label)
+{
+ return load(label.c_str());
+}
+
+Module *Loader::init()
+{
+ FactoryFuncPtr factory = find(loader_label);
+ if (!factory) {
+ con_warn << "module '" << loader_label << "' not found" << std::endl;
+ }
+
+ Module *module = factory();
+ module->set_label(loader_label);
+ return module;
+}
+
+void Loader::clear()
+{
+ loader_registry.clear();
+ loader_label.clear();
+}
+
+void Loader::list()
+{
+ std::string loaderlist;
+ for (Registry::iterator it = loader_registry.begin(); it != loader_registry.end(); it++) {
+ if (loaderlist.size())
+ loaderlist += " ";
+ loaderlist += (*it).first;
+
+ }
+ con_print << loaderlist << std::endl;
+ con_print << loader_registry.size() << " registered " << aux::plural("modules", loader_registry.size()) << std::endl;
+}
+
+
+}
+
+
diff --git a/src/core/loader.h b/src/core/loader.h
new file mode 100644
index 0000000..1fde764
--- /dev/null
+++ b/src/core/loader.h
@@ -0,0 +1,62 @@
+/*
+ core/loader.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_LOADER_H__
+#define __INCLUDED_CORE_LOADER_H__
+
+#include <string>
+
+#include "core/module.h"
+
+namespace core {
+
+/// module factory registry
+/** The Loader contains a list of module factories and can load
+ * the desired module on request
+ */
+class Loader
+{
+public:
+ /// function pointer type for a module factory
+ typedef Module * (* FactoryFuncPtr)();
+
+ /// find a registered mmodule factory
+ static FactoryFuncPtr find(const char *label);
+
+ /// find a registered module factory
+ static FactoryFuncPtr find(const std::string &label);
+
+ /// add a factory to the loader registry
+ static void add(const std::string & label, FactoryFuncPtr factory);
+
+ /// assign the next module to init
+ static bool load(const char *label);
+
+ /// assign the next module to init
+ static bool load(const std::string &label);
+
+ static inline const std::string &label() { return loader_label; }
+
+ /// initialize a game module
+ static Module *init();
+
+ /// list registered modules
+ static void list();
+
+ /// clear the loader registry
+ static void clear();
+
+private:
+ typedef std::map<std::string, FactoryFuncPtr> Registry;
+
+ static Registry loader_registry;
+ static std::string loader_label;
+};
+
+}
+
+#endif // __INCLUDED_CORE_LOADER_H__
+
diff --git a/src/core/module.cc b/src/core/module.cc
index eec250e..5dd07b5 100644
--- a/src/core/module.cc
+++ b/src/core/module.cc
@@ -11,117 +11,37 @@
namespace core
{
-/*-- static functions ----------------------------------------------*/
+Module* Module::module_instance = 0;
-Module *Module::module_preload = 0;
-Module *Module::module_active = 0;
-
-Module::Registry Module::module_registry;
-
-Module *Module::find(const std::string &label)
-{
- Registry::iterator it = module_registry.find(label);
- if (it == module_registry.end())
- return 0;
- else
- return (*it).second;
-}
-
-Module *Module::find(const char *label)
-{
- return(find(std::string(label)));
-}
-
-Module *Module::add(Module *module)
-{
- Module *m = find(module->label());
- if (m) {
- con_warn << "module '" << module->label() << "' already registered!" << std::endl;
- delete module;
- return 0;
- }
-
- module_registry[module->label()] = module;
-
- if (!module_preload) {
- module_preload = module;
- }
- con_debug << " " << module->label() << " " << module->name() << std::endl;
-
- return module;
-}
-
-Module *Module::load(const char *label)
-{
- if (!label)
- return 0;
-
- Module *module = find(label);
- if (!module) {
- con_warn << "Could not find module '" << label << "'" << std::endl;
- return 0;
- }
-
- con_print << " module " << module->label() << " " << module->name() << std::endl;
- module_preload = module;
- return module;
-}
-
-void Module::clear()
-{
- for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
- Module *module = (*it).second;
- con_print << " " << module->label() << " " << module->name() << std::endl;
- }
-
- module_registry.clear();
- module_preload = 0;
-}
-
-void Module::list()
+Module::Module(const char *name, bool interactive) :
+ module_name(name)
{
- for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
- Module *module = (*it).second;
- con_print << " " << module->label() << " " << module->name() << std::endl;
+ module_running = true;
+ module_interactive = interactive;
+ if (module_instance) {
+ std::cerr << "multiple core::Module instances\n";
+ abort();
+ } else {
+ module_instance = this;
}
- con_print << module_registry.size() << " registered game " << aux::plural("modules", module_registry.size()) << std::endl;
-}
-
-/*-- instance functions --------------------------------------------*/
-
-Module::Module(const char *label, const char *name, bool interactive) :
- module_label(label), module_name(name)
-{
- module_running = false;
- module_interactive = interactive;
}
Module::~Module()
{
module_running = false;
module_name.clear();
+ module_instance = 0;
}
-void Module::run()
-{
- module_active = this;
- module_running = true;
-
- init();
-}
-
-void Module::terminate()
+void Module::set_label(const std::string &label)
{
- shutdown();
- module_running = false;
- module_active = 0;
+ module_label.assign(label);
}
void Module::abort()
{
module_running = false;
- module_active = 0;
}
}
diff --git a/src/core/module.h b/src/core/module.h
index 64b41bd..240488f 100644
--- a/src/core/module.h
+++ b/src/core/module.h
@@ -13,11 +13,11 @@
namespace core
{
-// a loadable game module
+/// abstract base class for a game module
class Module
{
public:
- Module(const char *label, const char *name, bool interactive=true);
+ Module(const char *name, bool interactive=true);
virtual ~Module();
/*----- inspectors ------------------------------------------------ */
@@ -38,12 +38,6 @@ public:
/*----- mutators -------------------------------------------------- */
- /// run the game module
- void run();
-
- /// terminate a running game module
- void terminate();
-
/// run one timeframe
virtual void frame(float seconds) = 0;
@@ -53,61 +47,23 @@ public:
/// is called when a player disconnects
virtual void player_disconnect(Player *player) = 0;
-/*----- static ---------------------------------------------------- */
-
- typedef std::map<std::string, Module *> Registry;
-
- /// find a registered game module
- static Module *find(const char *label);
-
- /// find a registered game module
- static Module *find(const std::string &label);
-
- /// register a game module
- static Module *add(Module *module);
-
- /// load a registered game module
- static Module *load(const char *label);
-
- /// list modules
- static void list();
-
- /// unload all modules
- static void clear();
+ /// set the module label
+ void set_label(const std::string &label);
- /// currently active module
- static inline Module *active() { return module_active; }
-
- /// currently loaded module
- static inline Module *loaded() { return module_preload; }
-
- /// module registry
- static inline Registry & registry() { return module_registry; }
+ static inline Module *instance() { return module_instance; }
protected:
-
- /// initialize the game module
- virtual void init() = 0;
-
- /// shutdown the game module
- virtual void shutdown() = 0;
-
/// abort a running module
void abort();
private:
-
bool module_interactive;
bool module_running;
std::string module_label;
- std::string module_name;
-
- static Registry module_registry;
+ std::string module_name;
- static Module *module_preload;
- static Module *module_active;
-
+ static Module* module_instance;
};
}
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 7dcf300..cb3bcf0 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -40,6 +40,11 @@ core::Cvar *Game::g_devel = 0;
core::Zone *Game::default_zone = 0;
ShipModel *Game::default_shipmodel = 0;
+core::Module *factory()
+{
+ return new Game();
+}
+
// list the ship model registry
void Game::func_list_ship(std::string const &args)
{
@@ -256,18 +261,11 @@ void Game::func_goto(core::Player *player, const std::string &args)
/* -- class Game -------------------------------------------------- */
-Game::Game() : core::Module("base", "Project::OSiRiON", true)
+Game::Game() : core::Module("Project::OSiRiON", true)
{
default_shipmodel = 0;
default_zone = 0;
-}
-
-Game::~Game()
-{
-}
-void Game::init()
-{
ShipModel::clear();
if (!load_ships()) {
@@ -330,7 +328,7 @@ void Game::init()
g_devel->set_info("[bool] enable or disable developer mode");
}
-void Game::shutdown()
+Game::~Game()
{
g_impulsespeed = 0;
// game functions are automaticly removed
diff --git a/src/game/base/game.h b/src/game/base/game.h
index d4f0743..6f4cffd 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -64,13 +64,6 @@ public:
/// game variable: enable or disable development mode
static core::Cvar *g_devel;
-protected:
- /// initialize the game
- virtual void init();
-
- /// shutdown the game
- virtual void shutdown();
-
private:
bool load_world();
@@ -99,6 +92,9 @@ private:
static void func_goto(core::Player *player, const std::string &args);
};
+/// factory function
+core::Module *factory();
+
}
#endif // __INCLUDED_BASE_H__
diff --git a/src/game/example/example.cc b/src/game/example/example.cc
index 9c3d55a..25daef7 100644
--- a/src/game/example/example.cc
+++ b/src/game/example/example.cc
@@ -10,15 +10,12 @@
namespace example {
-Example::Example() : core::Module("example", "The Osirion Project Example", true)
+core::Module *factory()
{
+ return new Example();
}
-Example::~Example()
-{
-}
-
-void Example::init()
+Example::Example() : core::Module("The Osirion Project Example", true)
{
/*
Initialize engine game variables
@@ -81,6 +78,14 @@ void Example::init()
}
+Example::~Example()
+{
+ /*
+ The world is automaticly deleted on shutdown,
+ but local variables have to be cleaned up
+ */
+ zone = 0;
+}
void Example::player_connect(core::Player *player)
{
@@ -113,13 +118,4 @@ void Example::frame(float elapsed)
}
-void Example::shutdown()
-{
- /*
- The world is automaticly deleted on shutdown,
- but local variables have to be cleaned up
- */
- zone = 0;
-}
-
}
diff --git a/src/game/example/example.h b/src/game/example/example.h
index ba8aa72..64e9e4d 100644
--- a/src/game/example/example.h
+++ b/src/game/example/example.h
@@ -34,31 +34,26 @@ public:
Example();
/// desctructor, called on module unload
- ~Example();
+ virtual ~Example();
/// called once every server frame
/** @param elapsed time elapsed since the precious server frame, in seconds
*/
- void frame(float elapsed);
+ virtual void frame(float elapsed);
/// called when a player connects
- void player_connect(core::Player *player);
+ virtual void player_connect(core::Player *player);
/// called when a player disconnects
- void player_disconnect(core::Player *player);
-
-protected:
- /// called when the game starts
- void init();
-
- /// called when the game is shut down
- void shutdown();
-
+ virtual void player_disconnect(core::Player *player);
private:
core::Zone *zone;
};
+/// factory function
+core::Module *factory();
+
}
#endif // __INCLUDED_EXAMPLE_H__
diff --git a/src/game/game.cc b/src/game/game.cc
index a125eb7..719611c 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -5,7 +5,7 @@
*/
-#include "core/core.h"
+#include "core/loader.h"
#include "game/game.h"
#include "game/base/game.h"
#include "game/example/example.h"
@@ -18,11 +18,11 @@ void register_modules(bool register_noninteractive_modules)
con_print << "^BRegistering game modules..." << std::endl;
// non-interactive modules
- core::Module::add(new game::Game());
- core::Module::add(new example::Example());
+ core::Loader::add("base", game::factory);
+ core::Loader::add("example", example::factory);
// interactive modules
if (register_noninteractive_modules) {
- core::Module::add(new intro::Intro());
+ core::Loader::add("intro", intro::factory);
}
}
diff --git a/src/game/intro/intro.cc b/src/game/intro/intro.cc
index efb3b40..ed512ca 100644
--- a/src/game/intro/intro.cc
+++ b/src/game/intro/intro.cc
@@ -14,18 +14,16 @@
namespace intro {
-Intro::Intro() : core::Module("intro", "Introduction", false)
+core::Module *factory()
{
- intro_zone = 0;
- intro_convoy = 0;
+ return new Intro();
}
-Intro::~Intro()
+Intro::Intro() : core::Module("Introduction", false)
{
-}
+ intro_zone = 0;
+ intro_convoy = 0;
-void Intro::init()
-{
/// intialize a single zone for the introduction
intro_zone = new core::Zone("intro");
intro_zone->set_name("Introduction");
@@ -144,7 +142,7 @@ void Intro::frame(float seconds)
}
}
-void Intro::shutdown()
+Intro::~Intro()
{
intro_zone = 0;
diff --git a/src/game/intro/intro.h b/src/game/intro/intro.h
index da6fb80..d94b1f5 100644
--- a/src/game/intro/intro.h
+++ b/src/game/intro/intro.h
@@ -21,23 +21,17 @@ public:
/// create an introduction game module
Intro();
/// delete an introduction game module
- ~Intro();
+ virtual ~Intro();
/// run one frame
- void frame(float seconds);
+ virtual void frame(float seconds);
/// is called when a player connects
- void player_connect(core::Player *player);
+ virtual void player_connect(core::Player *player);
/// is called when a player disconnects
- void player_disconnect(core::Player *player);
+ virtual void player_disconnect(core::Player *player);
-protected:
- /// run the introduction
- void init();
-
- /// shutdown the introduction
- void shutdown();
private:
core::Zone *intro_zone;
Convoy *intro_convoy;
@@ -45,6 +39,9 @@ private:
bool load_world();
};
+/// factory function
+core::Module *factory();
+
}
#endif // __INCLUDED_INTRO_H__