Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
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 /src/game
parent44158ccfbe943b832c0e0bf9ce547212aa6c2b8b (diff)
clean module consturction/destruction
Diffstat (limited to 'src/game')
-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
7 files changed, 45 insertions, 65 deletions
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__