more hard-coded paths
[supertux.git] / src / main.cpp
index bf94f28..9157784 100644 (file)
@@ -18,6 +18,7 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //  02111-1307, USA.
 #include <config.h>
+#include <assert.h>
 
 #include "main.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 "app/globals.h"
-#include "app/setup.h"
-#include "app/gettext.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()
 {
@@ -75,12 +84,6 @@ static void find_directories()
   user_dir = home;
   user_dir += "/.supertux";
 
-  // Remove .supertux config file from old versions
-  if(FileSystem::faccessible(user_dir)) {
-    std::cerr << "Removing old config file " << user_dir << "\n";
-    remove(user_dir.c_str());
-  }
-
   // create directories
   std::string savedir = user_dir + "/save";
   mkdir(user_dir.c_str(), 0755);
@@ -88,8 +91,8 @@ static void find_directories()
 
   // try current directory as datadir
   if(datadir.empty()) {
-    if(FileSystem::faccessible("./data/credits.txt")) {
-      datadir = "./data/";
+    if(FileSystem::faccessible("./basest/credits.txt")) {
+      datadir = "./basest/";
     }
   }
 
@@ -103,7 +106,7 @@ static void find_directories()
 #endif
     } else {
       std::string exedir = std::string(dirname(exe_file)) + "/";
-      std::string testdir = exedir + "./data/";
+      std::string testdir = exedir + "./basest/";
       if(access(testdir.c_str(), F_OK) == 0) {
         datadir = testdir;
       }
@@ -205,6 +208,13 @@ static void init_sdl()
   }
 
   SDL_EnableUNICODE(1);
+
+  // wait 100ms and clear SDL event queue because sometimes we have random
+  // joystick events in the queue on startup...
+  SDL_Delay(100);
+  SDL_Event dummy;
+  while(SDL_PollEvent(&dummy))
+      ;
 }
 
 static void check_gl_error()
@@ -271,14 +281,14 @@ void init_video()
 
   // set icon
   SDL_Surface* icon = IMG_Load(
-    get_resource_filename("images/supertux.xpm").c_str());
+    get_resource_filename("images/engine/icons/supertux.xpm").c_str());
   if(icon != 0) {
     SDL_WM_SetIcon(icon, 0);
     SDL_FreeSurface(icon);
   }
 #ifdef DEBUG
   else {
-    std::cerr << "Warning: Couldn't find icon 'images/supertux.xpm'.\n";
+    std::cerr << "Warning: Couldn't find icon 'images/engine/icons/supertux.xpm'.\n";
   }
 #endif
 
@@ -335,6 +345,40 @@ static void quit_audio()
   }
 }
 
+void wait_for_event(float min_delay, float max_delay)
+{
+  assert(min_delay <= max_delay);
+  
+  Uint32 min = (Uint32) (min_delay * 1000);
+  Uint32 max = (Uint32) (max_delay * 1000);
+
+  SDL_Delay(min);
+
+  // clear even queue
+  SDL_Event event;
+  while (SDL_PollEvent(&event))
+  {}
+
+  /* Handle events: */
+  bool running = false;
+  Uint32 ticks = SDL_GetTicks();
+  while(running) {
+    while(SDL_PollEvent(&event)) {
+      switch(event.type) {
+        case SDL_QUIT:
+          throw std::runtime_error("received window close");
+        case SDL_KEYDOWN:
+        case SDL_JOYBUTTONDOWN:
+        case SDL_MOUSEBUTTONDOWN:
+          running = false;
+      }
+    }
+    if(SDL_GetTicks() - ticks >= (max - min))
+      running = false;
+    SDL_Delay(10);
+  }
+}
+
 int main(int argc, char** argv) 
 {
 #ifndef DEBUG // we want backtraces in debug mode so don't catch exceptions