--- /dev/null
+// $Id$
+//
+// SuperTux
+// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+#ifndef __EXCEPTIONS_H__
+#define __EXCEPTIONS_H__
+
+#include <exception>
+
+/** Throw this exception to gracefully shut SuperTux down.
+ */
+class graceful_shutdown : public std::exception
+{
+public:
+ explicit graceful_shutdown() {};
+};
+
+#endif
#include "file_system.hpp"
#include "gameconfig.hpp"
#include "gettext.hpp"
+#include "exceptions.hpp"
// the engine will be run with a logical framerate of 64fps.
// We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
Menu::current()->event(event);
main_controller->process_event(event);
if(event.type == SDL_QUIT)
- throw std::runtime_error("Received window close");
+ throw graceful_shutdown();
}
// playback a demo?
while (SDL_PollEvent(&event)) {
main_controller->process_event(event);
if(event.type == SDL_QUIT)
- throw std::runtime_error("Received window close event");
+ throw graceful_shutdown();
}
if(main_controller->pressed(Controller::JUMP)
#include "main.hpp"
#include "resources.hpp"
#include "control/joystickkeyboardcontroller.hpp"
+#include "exceptions.hpp"
static const int MENU_REPEAT_INITIAL = 400;
static const int MENU_REPEAT_RATE = 200;
SDL_Event event;
while (SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT)
- throw std::runtime_error("received window close event");
+ throw graceful_shutdown();
main_controller->process_event(event);
dialog->event(event);
}
#include "game_session.hpp"
#include "file_system.hpp"
#include "physfs/physfs_sdl.hpp"
+#include "exceptions.hpp"
SDL_Surface* screen = 0;
JoystickKeyboardController* main_controller = 0;
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 {
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:
} else {
// normal game
title();
- }
+ }
+ } catch(graceful_shutdown& e) {
} catch(std::exception& e) {
std::cerr << "Unexpected exception: " << e.what() << std::endl;
return 1;
#include "audio/sound_manager.hpp"
#include "main.hpp"
#include "control/joystickkeyboardcontroller.hpp"
+#include "exceptions.hpp"
static const float DEFAULT_SPEED = .02;
static const float SCROLL = 60;
while(SDL_PollEvent(&event)) {
main_controller->process_event(event);
if(event.type == SDL_QUIT)
- throw std::runtime_error("received window close");
+ throw graceful_shutdown();
}
if(main_controller->hold(Controller::UP)) {
#include "control/joystickkeyboardcontroller.hpp"
#include "control/codecontroller.hpp"
#include "main.hpp"
+#include "exceptions.hpp"
static Surface* bkg_title;
static Surface* logo;
}
main_controller->process_event(event);
if (event.type == SDL_QUIT)
- throw std::runtime_error("Received window close");
+ throw graceful_shutdown();
}
/* Draw the background: */
#include "object/background.hpp"
#include "object/tilemap.hpp"
#include "scripting/script_interpreter.hpp"
+#include "exceptions.hpp"
Menu* worldmap_menu = 0;
Menu::current()->event(event);
main_controller->process_event(event);
if(event.type == SDL_QUIT)
- throw std::runtime_error("Received window close");
+ throw graceful_shutdown();
}
}