Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 9fe1133c4963bef186a59aac7310f9f29c1bd34e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
   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 
*/

// project headers
#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 {

Ship ship;
Star star;
bool initialized = false;

std::string name; 	// name of the game
std::string label;	// label of the game
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() 
{
	using namespace filesystem;
	using math::Vector3f;

	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;
	f.open("ini/game.ini");
	while (f) {
		f.getline();
		if (f.got_key()) {
			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;	
			}
		} 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;
		}
	}
	f.close();

	con_print << "game.ini loaded " << name << " [" << label << "] by " << author << std::endl;

	// read world.ini
	std::string tmp;
	Sector *sector =0;

	f.open("ini/world.ini");
	while (f) {
		f.getline();
		if (f.got_key()) {
			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;
			} 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;
			}
		} else if (f.got_section("world")) {
			con_debug << "[world] section" << std::endl;
		} else if (f.got_section("sector")) {
			sector = new Sector();
			sectors.push_back(sector);
		} else if (f.got_section()) {
			con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl;
		}
	}
	f.close();

	con_print << "Load sectors" << std::endl;
	for (unsigned n =0; n < sectors.size(); n++)
		con_print << sectors[n]->label << " " << sectors[n]->name << std::endl;

	star.location = Vector3f(256.0f, 0.0f, 256.0f);
	ship.location = Vector3f(0,0,0);

	// all done, ready to run
	initialized = true;	
}

void shutdown()
{
	initialized = false;
	
	// delete every sector object in the sectors vector
	for (unsigned int n =0; n< sectors.size(); n++) {
		delete sectors[n];
		sectors[n] = 0;
	}
	// clear the sectors vector
	sectors.clear();
}

void update(float elapsed) 
{
	ship.update(elapsed);
}
	
}; // namespace game