|
From: Tapio V. <aa...@us...> - 2009-10-29 22:43:56
|
Module: performous
Branch: master
Commit: 25703d0bb7eb185dc9f66c3226f45b54f9d45adc
Author: Tapio Vierros <tap...@gm...>
Date: Fri Oct 30 00:42:51 2009 +0200
Added fancy exception to Backgrounds' getRandom.
---
game/backgrounds.cc | 4 ++++
game/backgrounds.hh | 5 +----
game/screen_sing.cc | 3 ++-
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/game/backgrounds.cc b/game/backgrounds.cc
index 365d741..14b4090 100644
--- a/game/backgrounds.cc
+++ b/game/backgrounds.cc
@@ -71,4 +71,8 @@ void Backgrounds::reload_internal(fs::path const& parent) {
}
}
+std::string Backgrounds::getRandom() {
+ if (m_bgs.empty()) throw std::runtime_error("No random backgrounds available");
+ return m_bgs.at((++m_bgiter) % m_bgs.size());
+}
diff --git a/game/backgrounds.hh b/game/backgrounds.hh
index a193c6d..f25e2aa 100644
--- a/game/backgrounds.hh
+++ b/game/backgrounds.hh
@@ -31,10 +31,7 @@ class Backgrounds: boost::noncopyable {
/// true if empty
int empty() const { return m_bgs.empty(); };
/// returns random background
- std::string getRandom() {
- if (!m_bgs.empty()) return m_bgs.at((++m_bgiter) % m_bgs.size());
- else return "";
- }
+ std::string getRandom();
private:
typedef std::set<fs::path> BGDirs;
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 94061c5..b1bc46f 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -34,7 +34,8 @@ void ScreenSing::enter() {
}
if (foundbg == false) {
try {
- m_background.reset(new Surface(m_backgrounds.getRandom(), true));
+ std::string bgpath = m_backgrounds.getRandom();
+ m_background.reset(new Surface(bgpath, true));
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
|