-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-#include <config.h>
-#include <assert.h>
-
-#include "main.h"
-
-#include <stdexcept>
-#include <iostream>
-#include <sstream>
-#include <time.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <assert.h>
-#ifndef WIN32
-#include <libgen.h>
-#endif
-#include <SDL.h>
-#include <SDL_mixer.h>
-#include <SDL_image.h>
-#include <SDL_opengl.h>
-
-#include "gameconfig.h"
-#include "resources.h"
-#include "gettext.h"
-#include "audio/sound_manager.h"
-#include "video/surface.h"
-#include "control/joystickkeyboardcontroller.h"
-#include "misc.h"
-#include "title.h"
-#include "game_session.h"
-#include "file_system.h"
-
-#ifdef WIN32
-#define mkdir(dir, mode) mkdir(dir)
-#endif
-
-SDL_Surface* screen = 0;
-JoystickKeyboardController* main_controller = 0;
-TinyGetText::DictionaryManager dictionary_manager;
-
-static void init_config()
-{
- config = new Config();
- try {
- config->load();
- } catch(std::exception& e) {
-#ifdef DEBUG
- std::cerr << "Couldn't load config file: " << e.what() << "\n";
-#endif
- }
-}
-
-static void find_directories()
-{
- const char* home = getenv("HOME");
- if(home == 0) {
-#ifdef DEBUG
- std::cerr << "Couldn't find home directory.\n";
-#endif
- home = ".";
- }
-
- user_dir = home;
- user_dir += "/.supertux";
-
- // create directories
- std::string savedir = user_dir + "/save";
- mkdir(user_dir.c_str(), 0755);
- mkdir(savedir.c_str(), 0755);
-
- // try current directory as datadir
- if(datadir.empty()) {
- if(FileSystem::faccessible("./data/credits.txt")) {
- datadir = "./data/";
- }
- }
-
- // Detect datadir with some linux magic
- if(datadir.empty()) {
- std::string exedir;
-#ifdef WIN32
- exedir = ".";
-#else
- char exe_file[PATH_MAX];
- if(readlink("/proc/self/exe", exe_file, PATH_MAX) >= 0) {
- exedir = std::string(dirname(exe_file));
- } else {
-#ifdef DEBUG
- std::cerr << "Couldn't read /proc/self/exe \n";
-#endif
- exedir = ".";
- }
-#endif
- std::string testdir = exedir + "/data/";
- if(access(testdir.c_str(), F_OK) == 0) {
- datadir = testdir;
- }
-
- testdir = exedir + "/../share/supertux/";
- if(datadir.empty() && access(testdir.c_str(), F_OK) == 0) {
- datadir = testdir;
- }
- }
-
-#ifdef DATA_PREFIX
- // use default location
- if(datadir.empty()) {
- datadir = DATA_PREFIX;
- }
-#endif
-
- if(datadir.empty())
- throw std::runtime_error("Couldn't find datadir");
-}
-
-static void init_tinygettext()
-{
- dictionary_manager.add_directory(datadir + "/locale");
- dictionary_manager.set_charset("UTF-8");
-}
-
-static void print_usage(const char* argv0)
-{
- fprintf(stderr, _("Usage: %s [OPTIONS] LEVELFILE\n\n"), argv0);
- fprintf(stderr,
- _("Options:\n"
- " -f, --fullscreen Run in fullscreen mode.\n"
- " -w, --window Run in window mode.\n"
- " -g, --geometry WIDTHxHEIGHT Run SuperTux in give resolution\n"
- " --help Show this help message\n"
- " --version Display SuperTux version and quit\n"
- "\n"));
-}
-
-static void parse_commandline(int argc, char** argv)
-{
- for(int i = 1; i < argc; ++i) {
- std::string arg = argv[i];
-
- if(arg == "--fullscreen" || arg == "-f") {
- config->use_fullscreen = true;
- } else if(arg == "--window" || arg == "-w") {
- config->use_fullscreen = false;
- } else if(arg == "--geometry" || arg == "-g") {
- if(i+1 >= argc) {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a parameter for geometry switch");
- }
- if(sscanf(argv[++i], "%dx%d", &config->screenwidth, &config->screenheight)
- != 2) {
- print_usage(argv[0]);
- throw std::runtime_error("Invalid geometry spec, should be WIDTHxHEIGHT");
- }
- } else if(arg == "--show-fps") {
- config->show_fps = true;
- } else if(arg == "--play-demo") {
- if(i+1 >= argc) {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a demo filename");
- }
- config->start_demo = argv[++i];
- } else if(arg == "--record-demo") {
- if(i+1 >= argc) {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a demo filename");
- }
- config->record_demo = argv[++i];
- } else if(arg == "--help") {
- print_usage(argv[0]);
- throw std::runtime_error("");
- } else if(arg == "--version") {
- std::cerr << PACKAGE_NAME << " " << PACKAGE_VERSION << "\n";
- throw std::runtime_error("");
- } else if(arg[0] != '-') {
- config->start_level = arg;
- } else {
- std::cerr << "Unknown option '" << arg << "'.\n";
- std::cerr << "Use --help to see a list of options.\n";
- }
- }
-
- // TODO joystick switchyes...
-}
-
-static void init_sdl()
-{
- if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
- std::stringstream msg;
- msg << "Couldn't initialize SDL: " << SDL_GetError();
- throw std::runtime_error(msg.str());
- }