Turned functions in video_systems.?pp into class VideoSystem
[supertux.git] / src / supertux / main.cpp
index bef5b08..0d88d31 100644 (file)
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include "supertux/main.hpp"
-
 #include <config.h>
 #include <version.h>
 
 #include <SDL_image.h>
 #include <physfs.h>
 #include <iostream>
+#include <binreloc.h>
+#include <tinygettext/log.hpp>
+
+#include "supertux/main.hpp"
 
 #ifdef MACOSX
 namespace supertux_apple {
@@ -29,11 +31,8 @@ namespace supertux_apple {
 } // namespace supertux_apple
 #endif
 
-#include "tinygettext/log.hpp"
-
 #include "addon/addon_manager.hpp"
 #include "audio/sound_manager.hpp"
-#include "binreloc/binreloc.h"
 #include "control/joystickkeyboardcontroller.hpp"
 #include "math/random_generator.hpp"
 #include "physfs/ifile_stream.hpp"
@@ -80,7 +79,7 @@ Main::init_tinygettext()
   }
 }
 
- void
+void
 Main::init_physfs(const char* argv0)
 {
   if(!PHYSFS_init(argv0)) {
@@ -94,7 +93,7 @@ Main::init_physfs(const char* argv0)
 
   // Initialize physfs (this is a slightly modified version of
   // PHYSFS_setSaneConfig
-  const char* application = "supertux2"; //instead of PACKAGE_NAME so we can coexist with MS1
+  const char* application = PACKAGE_NAME;
   const char* userdir = PHYSFS_getUserDir();
   char* writedir = new char[strlen(userdir) + strlen(application) + 2];
 
@@ -177,23 +176,21 @@ Main::init_physfs(const char* argv0)
 #endif
 
   if(!sourcedir) {
-#if defined(APPDATADIR) || defined(ENABLE_BINRELOC)
-    std::string datadir;
+    std::string datadir = PHYSFS_getBaseDir();
+    datadir = datadir.substr(0, datadir.rfind(INSTALL_SUBDIR_BIN));
+    datadir += "/" INSTALL_SUBDIR_SHARE;
 #ifdef ENABLE_BINRELOC
 
     char* dir;
     br_init (NULL);
-    dir = br_find_data_dir(APPDATADIR);
+    dir = br_find_data_dir(datadir.c_str());
     datadir = dir;
     free(dir);
 
-#else
-    datadir = APPDATADIR;
 #endif
     if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) {
       log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
     }
-#endif
   }
 
   //show search Path
@@ -206,27 +203,27 @@ Main::init_physfs(const char* argv0)
 void
 Main::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 given resolution\n"
-            "  -a, --aspect WIDTH:HEIGHT    Run SuperTux with given aspect ratio\n"
-            "  -d, --default                Reset video settings to default values\n"
-            "  --renderer RENDERER          Use sdl, opengl, or auto to render\n"
-            "  --disable-sfx                Disable sound effects\n"
-            "  --disable-music              Disable music\n"
-            "  -h, --help                   Show this help message and quit\n"
-            "  -v, --version                Show SuperTux version and quit\n"
-            "  --console                    Enable ingame scripting console\n"
-            "  --noconsole                  Disable ingame scripting console\n"
-            "  --show-fps                   Display framerate in levels\n"
-            "  --no-show-fps                Do not display framerate in levels\n"
-            "  --record-demo FILE LEVEL     Record a demo to FILE\n"
-            "  --play-demo FILE LEVEL       Play a recorded demo\n"
-            "  -s, --debug-scripts          Enable script debugger.\n"
-            "%s\n"), "");
+  std::cerr << _("Usage: ") << argv0 << _(" [OPTIONS] [LEVELFILE]\n\n")
+            << _("Options:\n"
+                 "  -f, --fullscreen             Run in fullscreen mode\n"
+                 "  -w, --window                 Run in window mode\n"
+                 "  -g, --geometry WIDTHxHEIGHT  Run SuperTux in given resolution\n"
+                 "  -a, --aspect WIDTH:HEIGHT    Run SuperTux with given aspect ratio\n"
+                 "  -d, --default                Reset video settings to default values\n"
+                 "  --renderer RENDERER          Use sdl, opengl, or auto to render\n"
+                 "  --disable-sfx                Disable sound effects\n"
+                 "  --disable-music              Disable music\n"
+                 "  -h, --help                   Show this help message and quit\n"
+                 "  -v, --version                Show SuperTux version and quit\n"
+                 "  --console                    Enable ingame scripting console\n"
+                 "  --noconsole                  Disable ingame scripting console\n"
+                 "  --show-fps                   Display framerate in levels\n"
+                 "  --no-show-fps                Do not display framerate in levels\n"
+                 "  --record-demo FILE LEVEL     Record a demo to FILE\n"
+                 "  --play-demo FILE LEVEL       Play a recorded demo\n"
+                 "  -s, --debug-scripts          Enable script debugger.\n"
+                 "\n")
+            << std::flush;
 }
 
 /**
@@ -265,14 +262,9 @@ Main::parse_commandline(int argc, char** argv)
     } else if(arg == "--default" || arg == "-d") {
       g_config->use_fullscreen = false;
       
-      g_config->window_width  = 800;
-      g_config->window_height = 600;
-
-      g_config->fullscreen_width  = 800;
-      g_config->fullscreen_height = 600;
-
-      g_config->aspect_width  = 0;  // auto detect
-      g_config->aspect_height = 0;
+      g_config->window_size     = Size(800, 600);
+      g_config->fullscreen_size = Size(800, 600);
+      g_config->aspect_size     = Size(0, 0);  // auto detect
       
     } else if(arg == "--window" || arg == "-w") {
       g_config->use_fullscreen = false;
@@ -293,11 +285,8 @@ Main::parse_commandline(int argc, char** argv)
         }
         else
         {
-          g_config->window_width  = width;
-          g_config->window_height = height;
-
-          g_config->fullscreen_width  = width;
-          g_config->fullscreen_height = height;
+          g_config->window_size     = Size(width, height);
+          g_config->fullscreen_size = Size(width, height);
         }
       }
     } else if(arg == "--aspect" || arg == "-a") {
@@ -323,16 +312,15 @@ Main::parse_commandline(int argc, char** argv)
         }
         else 
         {
-          float aspect_ratio = static_cast<double>(g_config->aspect_width) /
-            static_cast<double>(g_config->aspect_height);
+          float aspect_ratio = static_cast<float>(aspect_width) / static_cast<float>(aspect_height);
 
           // use aspect ratio to calculate logical resolution
           if (aspect_ratio > 1) {
-            g_config->aspect_width  = static_cast<int> (600 * aspect_ratio + 0.5);
-            g_config->aspect_height = 600;
+            g_config->aspect_size = Size(static_cast<int>(600 * aspect_ratio + 0.5),
+                                         600);
           } else {
-            g_config->aspect_width  = 600;
-            g_config->aspect_height = static_cast<int> (600 * 1/aspect_ratio + 0.5);
+            g_config->aspect_size = Size(600, 
+                                         static_cast<int>(600 * 1/aspect_ratio + 0.5));
           }
         }
       }
@@ -345,7 +333,7 @@ Main::parse_commandline(int argc, char** argv)
       } 
       else 
       {
-        g_config->video = get_video_system(argv[i]);
+        g_config->video = VideoSystem::get_video_system(argv[i]);
       }
     } else if(arg == "--show-fps") {
       g_config->show_fps = true;
@@ -452,9 +440,9 @@ Main::init_video()
   SDL_ShowCursor(0);
 
   log_info << (g_config->use_fullscreen?"fullscreen ":"window ")
-           << " Window: "     << g_config->window_width     << "x" << g_config->window_height
-           << " Fullscreen: " << g_config->fullscreen_width << "x" << g_config->fullscreen_height
-           << " Area: "       << g_config->aspect_width     << "x" << g_config->aspect_height << std::endl;
+           << " Window: "     << g_config->window_size
+           << " Fullscreen: " << g_config->fullscreen_size
+           << " Area: "       << g_config->aspect_size << std::endl;
 }
 
 void
@@ -538,7 +526,7 @@ static inline void timelog(const char* )
 #endif
 
 int
-Main::main(int argc, char** argv)
+Main::run(int argc, char** argv)
 {
   int result = 0;
 
@@ -578,7 +566,7 @@ Main::main(int argc, char** argv)
     Console::instance->init_graphics();
 
     timelog("scripting");
-    Scripting::init_squirrel(g_config->enable_script_debugger);
+    scripting::init_squirrel(g_config->enable_script_debugger);
 
     timelog("resources");
     Resources::load_shared();
@@ -596,7 +584,7 @@ Main::main(int argc, char** argv)
       if(g_config->start_level.size() > 4 &&
          g_config->start_level.compare(g_config->start_level.size() - 5, 5, ".stwm") == 0) {
         init_rand();
-        g_screen_manager->push_screen(new WorldMapNS::WorldMap(
+        g_screen_manager->push_screen(new worldmap::WorldMap(
                                  FileSystem::basename(g_config->start_level)));
       } else {
         init_rand();//If level uses random eg. for
@@ -643,7 +631,7 @@ Main::main(int argc, char** argv)
   g_main_controller = NULL;
   delete Console::instance;
   Console::instance = NULL;
-  Scripting::exit_squirrel();
+  scripting::exit_squirrel();
   delete texture_manager;
   texture_manager = NULL;
   SDL_Quit();