fixed nolok test level -nolok is throwing snails, moved around my castle testing...
[supertux.git] / src / main.cpp
index 84b0e96..f89805d 100644 (file)
 #include "gettext.hpp"
 #include "audio/sound_manager.hpp"
 #include "video/surface.hpp"
+#include "video/texture_manager.hpp"
 #include "control/joystickkeyboardcontroller.hpp"
 #include "misc.hpp"
 #include "title.hpp"
 #include "game_session.hpp"
 #include "file_system.hpp"
 #include "physfs/physfs_sdl.hpp"
+#include "exceptions.hpp"
 
 SDL_Surface* screen = 0;
 JoystickKeyboardController* main_controller = 0;
@@ -228,10 +230,10 @@ static void parse_commandline(int argc, char** argv)
       config->record_demo = argv[++i];
     } else if(arg == "--help") {
       print_usage(argv[0]);
-      throw std::runtime_error("");
+      throw graceful_shutdown();
     } else if(arg == "--version") {
       std::cerr << PACKAGE_NAME << " " << PACKAGE_VERSION << "\n";
-      throw std::runtime_error("");
+      throw graceful_shutdown();
     } else if(arg[0] != '-') {
       config->start_level = arg;
     } else {
@@ -301,6 +303,9 @@ static void check_gl_error()
 
 void init_video()
 {
+  if(texture_manager != NULL)
+    texture_manager->save_textures();
+  
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 
   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
@@ -339,6 +344,9 @@ void init_video()
   // setup opengl state and transform
   glDisable(GL_DEPTH_TEST);
   glDisable(GL_CULL_FACE);
+  glEnable(GL_TEXTURE_2D);
+  glEnable(GL_BLEND);
+  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
   glViewport(0, 0, screen->w, screen->h);
   glMatrixMode(GL_PROJECTION);
@@ -351,7 +359,10 @@ void init_video()
 
   check_gl_error();
 
-  Surface::reload_all();
+  if(texture_manager != NULL)
+    texture_manager->reload_textures();
+  else
+    texture_manager = new TextureManager();
 }
 
 static void init_audio()
@@ -395,7 +406,7 @@ void wait_for_event(float min_delay, float max_delay)
     while(SDL_PollEvent(&event)) {
       switch(event.type) {
         case SDL_QUIT:
-          throw std::runtime_error("received window close");
+          throw graceful_shutdown();
         case SDL_KEYDOWN:
         case SDL_JOYBUTTONDOWN:
         case SDL_MOUSEBUTTONDOWN:
@@ -439,7 +450,8 @@ int main(int argc, char** argv)
     } else {
       // normal game
       title();
-    }    
+    }
+  } catch(graceful_shutdown& e) {
   } catch(std::exception& e) {
     std::cerr << "Unexpected exception: " << e.what() << std::endl;
     return 1;
@@ -450,15 +462,13 @@ int main(int argc, char** argv)
 
   free_menu();
   unload_shared();
-#ifdef DEBUG
-  Surface::debug_check();
-#endif
   quit_audio();
 
   if(config)
     config->save();
   delete config;
   delete main_controller;
+  delete texture_manager;
   SDL_Quit();
   PHYSFS_deinit();