2010-04-05 23:38:59 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "Engine.h"
|
|
|
|
|
|
|
|
#include "Controller.h"
|
|
|
|
#include "View.h"
|
|
|
|
#include "Model.h"
|
|
|
|
#include "Physics.h"
|
|
|
|
#include "EntityFactory.h"
|
2011-03-16 17:03:41 +01:00
|
|
|
#include "Game.h"
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2010-12-03 00:15:26 +01:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
2010-11-28 23:08:52 +01:00
|
|
|
#ifdef WIN32
|
2010-11-29 10:15:08 +01:00
|
|
|
#include <Windows.h>
|
2010-11-28 23:08:52 +01:00
|
|
|
#endif
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2010-12-03 00:15:26 +01:00
|
|
|
/* Returns a path where files such as logs and config files can be
|
|
|
|
* written to
|
|
|
|
*/
|
|
|
|
std::string create_user_path () {
|
|
|
|
std::string result_dir = ".";
|
|
|
|
std::string test_file_path = result_dir;
|
|
|
|
|
|
|
|
// first we check in $HOME/.fysxasteroids
|
|
|
|
char* env_home_dir = getenv("HOME");
|
|
|
|
result_dir = env_home_dir;
|
|
|
|
result_dir += "/.fysxasteroids";
|
|
|
|
|
|
|
|
boost::filesystem::path result_dir_path(result_dir);
|
|
|
|
if(!boost::filesystem::is_directory (result_dir_path)) {
|
|
|
|
if (!boost::filesystem::create_directory(result_dir_path)) {
|
|
|
|
cerr << "Warning: could not create user data directory " << result_dir<< endl;
|
|
|
|
result_dir = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test_file_path = result_dir;
|
|
|
|
test_file_path += "/game.log";
|
|
|
|
ofstream test_file (test_file_path.c_str(), ios_base::app);
|
|
|
|
if (!test_file) {
|
|
|
|
test_file.close();
|
|
|
|
cerr << "Warning: user data directory not writable! " << result_dir << endl;
|
|
|
|
result_dir = "";
|
|
|
|
} else {
|
|
|
|
test_file.close();
|
|
|
|
return result_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// then we check the local directory
|
|
|
|
result_dir = ".";
|
|
|
|
test_file_path = result_dir;
|
|
|
|
test_file_path += "/game.log";
|
|
|
|
test_file.open (test_file_path.c_str(), ios_base::out);
|
|
|
|
if (test_file) {
|
|
|
|
test_file.close();
|
|
|
|
return result_dir;
|
|
|
|
} else {
|
|
|
|
cerr << "Warning could not find suitable user data directory" << endl;
|
|
|
|
result_dir = "";
|
|
|
|
}
|
|
|
|
test_file.close();
|
|
|
|
|
|
|
|
return result_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string find_game_data_dir () {
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
std::vector<std::string> paths;
|
|
|
|
paths.push_back(".");
|
|
|
|
paths.push_back("/usr/local/share/fysxasteroids");
|
|
|
|
paths.push_back("/usr/share/fysxasteroids");
|
|
|
|
|
|
|
|
std::vector<std::string>::iterator iter = paths.begin();
|
|
|
|
for (iter; iter != paths.end(); iter++) {
|
|
|
|
std::string test_path = *iter;
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_directory(test_path + "/data/fonts"))
|
|
|
|
continue;
|
|
|
|
if (!boost::filesystem::is_directory(test_path + "/data/levels"))
|
|
|
|
continue;
|
|
|
|
if (!boost::filesystem::is_directory(test_path + "/data/sounds"))
|
|
|
|
continue;
|
|
|
|
if (!boost::filesystem::is_directory(test_path + "/data/textures"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iter != paths.end())
|
|
|
|
return *iter;
|
|
|
|
|
|
|
|
cerr << "Could not find game data" << endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
int main (int argc, char* argv[]) {
|
|
|
|
cout << "Game Start" << endl;
|
2010-11-28 23:08:52 +01:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2010-11-29 10:15:08 +01:00
|
|
|
HWND hWnd = GetConsoleWindow();
|
|
|
|
ShowWindow( hWnd, SW_HIDE );
|
2010-11-28 23:08:52 +01:00
|
|
|
#endif
|
2011-02-12 16:34:47 +01:00
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
Engine::Engine engine;
|
|
|
|
|
|
|
|
engine.SetEntityFactory (new asteroids::EntityFactory);
|
|
|
|
engine.SetController (new asteroids::Controller);
|
|
|
|
engine.SetModel (new asteroids::Model);
|
|
|
|
engine.SetPhysics (new asteroids::Physics);
|
|
|
|
engine.SetView (new asteroids::View);
|
|
|
|
|
2011-03-16 23:21:22 +01:00
|
|
|
SetLogPrintLevel (Engine::LogLevelWarning);
|
2010-12-03 00:15:26 +01:00
|
|
|
|
2011-02-13 15:31:42 +01:00
|
|
|
std::string user_path = ".";
|
|
|
|
std::string game_data_path = ".";
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
user_path = create_user_path();
|
|
|
|
game_data_path = find_game_data_dir();
|
|
|
|
#endif
|
|
|
|
|
2010-12-03 00:15:26 +01:00
|
|
|
// we assume the user path to be local folder
|
|
|
|
std::string log_file_path = user_path;
|
|
|
|
log_file_path += "/game.log";
|
|
|
|
|
|
|
|
cout << "User Data Dir = " << user_path << endl;
|
|
|
|
engine.SetUserDataPath (user_path);
|
2011-03-16 23:21:22 +01:00
|
|
|
|
2010-12-03 00:15:26 +01:00
|
|
|
Engine::SetLogFilename (log_file_path.c_str());
|
|
|
|
|
|
|
|
engine.SetGameDataPath (game_data_path);
|
|
|
|
cout << "Game Data Dir = " << game_data_path << endl;
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
if (engine.Init (argc, argv) != 0) {
|
|
|
|
cout << "Could not start engine!" << endl;
|
|
|
|
exit (-1);
|
|
|
|
}
|
2010-04-08 20:04:39 +02:00
|
|
|
|
|
|
|
// Load the icon
|
|
|
|
Uint32 colorkey;
|
|
|
|
SDL_Surface *image = NULL;
|
|
|
|
image = SDL_LoadBMP("./data/textures/icon.bmp");
|
|
|
|
if (!image)
|
|
|
|
Engine::LogWarning("Could not load icon: ./data/textures/icon.bmp");
|
|
|
|
else
|
|
|
|
SDL_WM_SetIcon(image,NULL);
|
|
|
|
|
2011-02-13 15:31:42 +01:00
|
|
|
SDL_WM_SetCaption("fysxasteroids -BETA 2-","fysxasteroids -BETA 2-");
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
engine.GetView()->SetGridSize (8,8);
|
2011-02-01 18:24:33 +01:00
|
|
|
|
|
|
|
/// \todo get rid of the world settings in asteroids
|
2010-12-01 10:48:10 +01:00
|
|
|
dynamic_cast<asteroids::Physics*>(engine.GetPhysics())->SetWorldSize (26, 20);
|
2011-02-01 18:24:33 +01:00
|
|
|
engine.GetPhysics()->SetWorldBounds (vector3d (-13, 0, -10), vector3d (13, 0, 10));
|
|
|
|
engine.GetPhysics()->EnableWorldWarp(Engine::PhysicsBase::WorldWarpModeX);
|
|
|
|
engine.GetPhysics()->EnableWorldWarp(Engine::PhysicsBase::WorldWarpModeZ);
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2010-11-28 01:13:45 +01:00
|
|
|
// run the default commands and load the configuration
|
2010-04-06 00:12:26 +02:00
|
|
|
Engine::RunCommand ("exec asteroids.rc");
|
2010-11-28 01:13:45 +01:00
|
|
|
Engine::RunCommand ("exec config.rc");
|
2010-11-28 00:20:58 +01:00
|
|
|
|
2011-02-13 15:31:42 +01:00
|
|
|
Engine::PlayMusic (Engine::GetResourceFullPath("/data/sounds/intro_music.ogg"));
|
|
|
|
|
2011-03-16 23:21:22 +01:00
|
|
|
// load highscore list (either remote or local, depending on settings)
|
2011-03-16 17:03:41 +01:00
|
|
|
asteroids::GetModel()->LoadHighscoreList();
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
engine.MainLoop ();
|
|
|
|
|
2010-11-28 01:13:45 +01:00
|
|
|
// save the configuration
|
2010-12-03 00:15:26 +01:00
|
|
|
std::ofstream config_file (engine.GetUserDirFullPath("/config.rc").c_str());
|
2010-11-28 01:13:45 +01:00
|
|
|
config_file << "set effects_volume " << Engine::GetEffectsVolume() << std::endl;
|
|
|
|
config_file << "set music_volume " << Engine::GetMusicVolume() << std::endl;
|
2011-03-16 17:03:41 +01:00
|
|
|
config_file << "set use_server_highscore " << Engine::GetVariableString("use_server_highscore") << std::endl;
|
2010-11-28 01:13:45 +01:00
|
|
|
config_file.close();
|
|
|
|
|
2010-04-08 20:04:39 +02:00
|
|
|
SDL_WM_SetIcon(NULL,NULL);
|
|
|
|
SDL_FreeSurface (image);
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
engine.Destroy ();
|
|
|
|
|
|
|
|
cout << "Game Quit" << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|