|
From: Lasse Kärkkäi. <tr...@us...> - 2010-01-17 22:16:51
|
Module: performous
Branch: master
Commit: 95d0a40cbb7df892f2f2a786d5da9794475e6f57
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Jan 17 08:19:48 2010 +0200
Handle running out of instruments properly so that other errors are not ignored by mistake.
---
game/joystick.hh | 6 +++++-
game/screen_sing.cc | 6 +++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/game/joystick.hh b/game/joystick.hh
index e55a9d5..356c025 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -111,6 +111,10 @@ namespace input {
int buttonFromSDL(input::Private::Type _type, unsigned int _sdl_button);
NavButton getNav(SDL_Event const &e);
+ struct NoDevError: std::runtime_error {
+ NoDevError(): runtime_error("No instrument of the requested type was available") {}
+ };
+
class InputDev {
public:
// First gives a correct instrument type
@@ -140,7 +144,7 @@ namespace input {
}
}
std::cout << "No InputDev was found!" << std::endl;
- throw std::runtime_error("No matching instrument available");
+ throw NoDevError();
};
~InputDev() {
using namespace input::Private;
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index b8316cb..7412e6b 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -69,7 +69,7 @@ void ScreenSing::enter() {
Instruments::iterator ite = m_instruments.end();
m_instruments.insert(ite, new GuitarGraph(m_audio, *m_song, *it));
assigned = true;
- } catch (std::runtime_error&) {}
+ } catch (input::NoDevError&) {}
}
if( !assigned ) break;
}
@@ -78,7 +78,7 @@ void ScreenSing::enter() {
Instruments::iterator it = m_instruments.end();
if (m_instruments.size() > 1) it = m_instruments.begin() + 1; // Drums go after the first guitar
m_instruments.insert(it, new GuitarGraph(m_audio, *m_song, "drums"));
- } catch (std::runtime_error&) { break; }
+ } catch (input::NoDevError&) { break; }
}
}
// Load dance tracks
@@ -86,7 +86,7 @@ void ScreenSing::enter() {
while(1) {
try {
m_dancers.push_back(new DanceGraph(m_audio, *m_song));
- } catch (std::runtime_error&) { break; }
+ } catch (input::NoDevError&) { break; }
}
}
// Startup delay for instruments is longer than for singing only
|