Removed some old event eating code, as randomly discarding events is a bad idea with...
[supertux.git] / src / supertux / main.cpp
index 3cd0912..509c60f 100644 (file)
@@ -29,6 +29,7 @@ extern "C" {
 }
 
 #include "video/renderer.hpp"
+#include "video/lightmap.hpp"
 #include "supertux/main.hpp"
 
 #include "addon/addon_manager.hpp"
@@ -74,7 +75,7 @@ Main::init_tinygettext()
 {
   dictionary_manager = new tinygettext::DictionaryManager();
   tinygettext::Log::set_log_info_callback(0);
-  dictionary_manager->set_filesystem(std::auto_ptr<tinygettext::FileSystem>(new PhysFSFileSystem));
+  dictionary_manager->set_filesystem(std::unique_ptr<tinygettext::FileSystem>(new PhysFSFileSystem));
 
   dictionary_manager->add_directory("locale");
   dictionary_manager->set_charset("UTF-8");
@@ -390,24 +391,13 @@ Main::parse_commandline(int argc, char** argv)
 void
 Main::init_sdl()
 {
-  if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
+  if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) {
     std::stringstream msg;
     msg << "Couldn't initialize SDL: " << SDL_GetError();
     throw std::runtime_error(msg.str());
   }
   // just to be sure
   atexit(SDL_Quit);
-
- // SDL_EnableUNICODE(1); //old code, mofif by giby 
- //   SDL_JoystickID myID = SDL_JoystickInstanceID(myOpenedStick);
-  
-
-  // 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))
-    ;
 }
 
 void
@@ -463,47 +453,6 @@ Main::quit_audio()
   }
 }
 
-void
-Main::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);
-
-  Uint32 ticks = SDL_GetTicks();
-  while(SDL_GetTicks() - ticks < min) {
-    SDL_Delay(10);
-    sound_manager->update();
-  }
-
-  // clear event queue
-  SDL_Event event;
-  while (SDL_PollEvent(&event))
-  {}
-
-  /* Handle events: */
-  bool running = false;
-  ticks = SDL_GetTicks();
-  while(running) {
-    while(SDL_PollEvent(&event)) {
-      switch(event.type) {
-        case SDL_QUIT:
-          g_screen_manager->quit();
-          break;
-        case SDL_KEYDOWN:
-        case SDL_JOYBUTTONDOWN:
-        case SDL_MOUSEBUTTONDOWN:
-          running = false;
-      }
-    }
-    if(SDL_GetTicks() - ticks >= (max - min))
-      running = false;
-    sound_manager->update();
-    SDL_Delay(10);
-  }
-}
-
 static Uint32 last_timelog_ticks = 0;
 static const char* last_timelog_component = 0;
 
@@ -546,8 +495,8 @@ Main::run(int argc, char** argv)
       return 0;
 
     timelog("video");
-    std::auto_ptr<Renderer> renderer(VideoSystem::new_renderer());
-    std::auto_ptr<Lightmap> lightmap(VideoSystem::new_lightmap());
+    std::unique_ptr<Renderer> renderer(VideoSystem::new_renderer());
+    std::unique_ptr<Lightmap> lightmap(VideoSystem::new_lightmap());
     DrawingContext context(*renderer, *lightmap);
     context_pointer = &context;
     init_video();
@@ -571,7 +520,7 @@ Main::run(int argc, char** argv)
 
     timelog(0);
 
-    const std::auto_ptr<PlayerStatus> default_playerstatus(new PlayerStatus());
+    const std::unique_ptr<PlayerStatus> default_playerstatus(new PlayerStatus());
 
     g_screen_manager = new ScreenManager();
 
@@ -594,7 +543,7 @@ Main::run(int argc, char** argv)
         g_screen_manager->push_screen(new worldmap::WorldMap(
                                  FileSystem::basename(g_config->start_level), default_playerstatus.get()));
       } else {
-        std::auto_ptr<GameSession> session (
+        std::unique_ptr<GameSession> session (
           new GameSession(FileSystem::basename(g_config->start_level), default_playerstatus.get()));
 
         g_config->random_seed =session->get_demo_random_seed(g_config->start_demo);