Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/file.cc61
-rw-r--r--src/game/file.h30
-rw-r--r--src/game/game.cc27
-rw-r--r--src/game/game.h9
-rw-r--r--src/game/player.h11
-rw-r--r--src/game/sector.h8
-rw-r--r--src/game/ship.cc9
7 files changed, 142 insertions, 13 deletions
diff --git a/src/game/file.cc b/src/game/file.cc
new file mode 100644
index 0000000..b819416
--- /dev/null
+++ b/src/game/file.cc
@@ -0,0 +1,61 @@
+/* file.cc
+ 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 "file.h"
+
+namespace game {
+
+void File::open(const char * filename, ios_base::openmode mode)
+{
+ std::string fn;
+
+ // if moddir is set, try the mods subdir first
+ if (game::moddir.size() > 0) {
+ // try game::homedir+game::moddir
+ fn = homedir;
+ fn.append(moddir);
+ fn.append(filename);
+ std::ifstream::open(fn.c_str(), mode);
+ if (this->is_open()) {
+ std::cerr << "game::File opened " << fn << std::endl;
+ return;
+ }
+
+ // try datadir + moddir
+ fn = game::datadir;
+ fn.append(game::moddir);
+ std::ifstream::open(fn.c_str(), mode);
+ if (this->is_open()) {
+ std::cerr << "game::File opened " << fn << std::endl;
+ return;
+ }
+ }
+
+ // try game::homedir+game::basedir
+ fn = homedir;
+ fn.append(basedir);
+ fn.append(filename);
+ std::ifstream::open(fn.c_str(), mode);
+ if (this->is_open()) {
+ std::cerr << "game::File opened " << fn << std::endl;
+ return;
+ }
+
+ // try game::datadir+game::basedir
+ fn = datadir;
+ fn.append(basedir);
+ fn.append(filename);
+ std::ifstream::open(fn.c_str(), mode);
+
+ // FIXME console
+ if (!this->is_open()) {
+ std::cerr << "game::File could not open " << filename << std::endl;
+ } else {
+ std::cerr << "game::File opened " << fn << std::endl;
+ }
+}
+
+}
diff --git a/src/game/file.h b/src/game/file.h
new file mode 100644
index 0000000..ebdff9e
--- /dev/null
+++ b/src/game/file.h
@@ -0,0 +1,30 @@
+/* file.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_FILE_H__
+#define __INCLUDED_FILE_H__
+
+// C++ headers
+#include <string>
+#include <fstream>
+
+// project headers
+#include "game.h"
+
+
+namespace game {
+
+/// a class to open data files
+class File : public std::ifstream
+{
+public:
+ /// open the file for reading
+ void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in );
+
+}; // class File
+
+} // namesoace game
+
+#endif // __INCLUDED_GAME_H__
diff --git a/src/game/game.cc b/src/game/game.cc
index dfa5fe5..e34a7b8 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -1,10 +1,13 @@
-/* game.cc
- This file is part of the Osirion project
+/* game.h
+ 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 "ship.h"
#include "star.h"
+#include "file.h"
namespace game {
@@ -12,10 +15,28 @@ Ship ship;
Star star;
bool initialized = false;
+// TODO datadir should by set by ./configure and read from config.h
+// FIXME win32
+std::string datadir("./data/");
+std::string homedir("~/.osirion/");
+std::string basedir("base/");
+std::string moddir;
+
void init()
{
+ // load the world
star.location = Vector3f(256.0f, 0.0f, 256.0f);
- initialized = true;
+ ship.location = Vector3f(0,0,0);
+
+ // TODO create game::homedir if it doesn't exist
+
+ // read game.ini
+ File f;
+ f.open("game.ini");
+ f.close();
+
+ // all done, ready to run
+ initialized = true;
}
void shutdown()
diff --git a/src/game/game.h b/src/game/game.h
index 7c1cc0c..9f3b19a 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -28,6 +28,15 @@ namespace game
/// true while the game is running
extern bool initialized;
+
+ /// location of the main data files, includes trailing /
+ extern std::string datadir;
+ /// location of the personal data files, includes trailing /
+ extern std::string homedir;
+ /// subdirectory with the base data files, includes trailing /
+ extern std::string basedir;
+ /// subdirectory for the current mod, includes trailing /
+ extern std::string moddir;
};
#endif // __INCLUDED_GAME_H__
diff --git a/src/game/player.h b/src/game/player.h
index 4c75206..a3850a5 100644
--- a/src/game/player.h
+++ b/src/game/player.h
@@ -3,18 +3,23 @@
the terms and conditions of the GNU General Public License version 2
*/
-#ifndef __INCLUDED_PLAyER_H__
-#define __INCLUDED_PLAyER_H__
+#ifndef __INCLUDED_PLAYER_H__
+#define __INCLUDED_PLAYER_H__
#include <string>
+namespace game {
+
/// A player in the game
class Player {
public:
Player();
~Player();
+ /// name of the player
std::string name;
};
-#endif // __INCLUDED_PLAyER_H__
+} // namespace game
+
+#endif // __INCLUDED_PLAYER_H__
diff --git a/src/game/sector.h b/src/game/sector.h
index 10f548c..3f6b3e4 100644
--- a/src/game/sector.h
+++ b/src/game/sector.h
@@ -10,13 +10,17 @@
namespace game
{
+
+/// a sector of space
class Sector {
public:
+ /// default constructor
Sector();
+ /// default destructor
~Sector();
- /// tag used in configuration files, e.g. "terran"
- std::string tag;
+ /// label used in configuration files, e.g. "terran"
+ std::string label;
/// name to display, e.g. "Terran System"
std::string name;
};
diff --git a/src/game/ship.cc b/src/game/ship.cc
index a24be0d..84e9f41 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -7,7 +7,6 @@
// project headers
#include "common/functions.h"
-#include "common/osirion.h"
#include "ship.h"
@@ -20,11 +19,11 @@ Ship::Ship()
thrust = 0;
// ship specs
- acceleration = 6 * GAMESCALE;
- max_speed = 16.0f * GAMESCALE;
+ acceleration = 1.5f;
+ max_speed = 4.0f;
- max_yaw_offset = 45;
- yaw_speed = 4;
+ max_yaw_offset = 45.0f;
+ yaw_speed = 4.0f;
}
Ship::~Ship()