/* 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/game.h" #include "game/sector.h" #include "game/ship.h" #include "game/star.h" #include "filesystem/filesystem.h" #include "sys/sys.h" // C++ headers #include namespace game { bool Game::init() { using math::Vector3f; using filesystem::IniFile; con_print << "Initializing game..." << std::endl; // read game.ini 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 << name << std::endl; con_print << "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 << "Loading 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); return true; } void Game::shutdown() { con_print << "Shutting down game..." << std::endl; // 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 Game::frame(float seconds) { ship.update(seconds); } }; // namespace game