diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/Makefile.am | 9 | ||||
-rw-r--r-- | src/game/game.cc | 74 | ||||
-rw-r--r-- | src/game/game.h | 30 |
3 files changed, 51 insertions, 62 deletions
diff --git a/src/game/Makefile.am b/src/game/Makefile.am index 4268c84..1ed5015 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -1,11 +1,12 @@ INCLUDES = -I$(top_srcdir)/src METASOURCES = AUTO -libgame_la_LDFLAGS = -avoid-version -no-undefined +libgame_la_LDFLAGS = -avoid-version --no-undefined +libgame_la_LIBADD = $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/common/libcommon.la \ + $(top_builddir)/src/filesystem/libfilesystem.la \ + $(top_builddir)/src/core/libcore.la libgame_la_SOURCES = game.cc sector.cc ship.cc shipspecs.cc star.cc -libgame_la_LIBADD = $(top_builddir)/src/common/libcommon.la \ - $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/filesystem/libfilesystem.la noinst_LTLIBRARIES = libgame.la noinst_HEADERS = game.h player.h sector.h ship.h shipspecs.h star.h world.h diff --git a/src/game/game.cc b/src/game/game.cc index 9fe1133..b2b0822 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -1,21 +1,22 @@ /* game/game.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ // project headers +#include "game/game.h" #include "game/sector.h" #include "game/ship.h" #include "game/star.h" #include "filesystem/filesystem.h" -#include "filesystem/inifile.h" #include "common/common.h" // C++ headers #include <vector> -namespace game { +namespace game +{ Ship ship; Star star; @@ -28,31 +29,16 @@ std::string author; // author of the game // sectors in space std::vector<Sector*> sectors; -// TODO datadir should by set by ./configure and read from config.h -// FIXME win32 directory names -void init() +void Game::init() { - using namespace filesystem; using math::Vector3f; + using filesystem::IniFile; con_print << "Project::OSiRiON " << VERSION << std::endl; con_debug << "Debug messages enabled" << std::endl; - // initialize game data locations - datadir = "./data/"; - basedir = "base/"; - moddir = ""; - - // FIXME win32 - homedir = getenv("HOME"); - homedir = homedir + "/.osirion/"; - Path::create(homedir); - Path::create(homedir+basedir); - if (moddir.size() && !Path::exists(homedir+moddir)) - Path::create(homedir+moddir); - // read game.ini - filesystem::IniFile f; + IniFile f; f.open("ini/game.ini"); while (f) { f.getline(); @@ -60,15 +46,15 @@ void init() if (f.section() == "game") { // game::name if (f.got_key_string("name", name)); else - // game::label - if (f.got_key_string("label", label)); else - // game::author - if (f.got_key_string("author", author)); else - // unknown value - con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl; + // game::label + if (f.got_key_string("label", label)); else + // game::author + if (f.got_key_string("author", author)); else + // unknown value + con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl; } } else if (f.got_section("game")) { - + } else if (f.got_section()) { con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl; } @@ -88,21 +74,21 @@ void init() if (f.section() == "world") { // world::name if (f.got_key_string("name", tmp)); else - // world:label - if (f.got_key_string("label", tmp)); else - // unknown value - con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl; + // world:label + if (f.got_key_string("label", tmp)); else + // unknown value + con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl; } else if (f.section() == "sector") { // sector::name if (f.got_key_string("name", tmp)) { sector->name = tmp; } else - // sector:label - if (f.got_key_string("label", tmp)) { - sector->label = tmp; - } else - // unknown value - con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl; + // sector:label + if (f.got_key_string("label", tmp)) { + sector->label = tmp; + } else + // unknown value + con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl; } } else if (f.got_section("world")) { con_debug << "[world] section" << std::endl; @@ -123,13 +109,13 @@ void init() ship.location = Vector3f(0,0,0); // all done, ready to run - initialized = true; + initialized = true; } -void shutdown() +void Game::shutdown() { initialized = false; - + // delete every sector object in the sectors vector for (unsigned int n =0; n< sectors.size(); n++) { delete sectors[n]; @@ -139,9 +125,9 @@ void shutdown() sectors.clear(); } -void update(float elapsed) +void Game::frame(float elapsed) { ship.update(elapsed); } - + }; // namespace game diff --git a/src/game/game.h b/src/game/game.h index f2a0eab..ee9e286 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -7,17 +7,26 @@ #ifndef __INCLUDED_GAME_H__ #define __INCLUDED_GAME_H__ +// project headers #include "game/ship.h" #include "game/star.h" - +#include "core/core.h" #include "common/common.h" -/// the game engine -/** - * The main game functions. The console should be initialized before calling these. +/// the game-specific engine +/** The main game functions. The console should be initialized before calling these. */ namespace game { + +/// the only ship in the game +extern Ship ship; + +/// the only star in the game +extern Star star; + +class Game : public core::Game { +public: /// initialize the game void init(); @@ -25,17 +34,10 @@ namespace game void shutdown(); /// update the game state - void update(float elapsed); - - /// the only ship in the game - extern Ship ship; - - /// the only star in the game - extern Star star; - - /// true while the game is running - extern bool initialized; + void frame(float sec); }; +} + #endif // __INCLUDED_GAME_H__ |