|
From: Tapio V. <aa...@us...> - 2010-09-14 17:06:29
|
Module: performous
Branch: master
Commit: 95d1976b857f62ff4c56b2509be50777d6138b78
Author: Tapio Vierros <tap...@gm...>
Date: Tue Sep 14 20:03:11 2010 +0300
Simple framework for indicating loading progress to user.
* Main loop loading and screen_sing loading converted.
* Give more info than before.
* Currently output looks as lame as before.
---
game/main.cc | 11 +++++++----
game/screen.hh | 4 +++-
game/screen_sing.cc | 17 +++++++++++++----
game/screenmanager.cc | 9 +++++++++
4 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/game/main.cc b/game/main.cc
index b91b40b..3c883ba 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -111,10 +111,11 @@ static void checkEvents_SDL(ScreenManager& sm) {
void mainLoop(std::string const& songlist) {
Window window(config["graphic/window_width"].i(), config["graphic/window_height"].i(), config["graphic/fullscreen"].b());
- Audio audio;
ScreenManager sm(window);
+ sm.loading(_("Audio..."), 0.1);
+ Audio audio;
try {
- sm.flashMessage(_("Miscellaneous..."), 0.0f, 1.0f, 1.0f); window.blank(); sm.drawNotifications(); window.swap();
+ sm.loading(_("Launching background loaders..."), 0.4);
Backgrounds backgrounds;
Database database(getConfigDir() / "database.xml");
Songs songs(database, songlist);
@@ -122,6 +123,7 @@ void mainLoop(std::string const& songlist) {
// TODO: Proper error handling...
try { midiDrums.reset(new input::MidiDrums); } catch (std::runtime_error&) {}
// Load audio samples
+ sm.loading(_("Loading audio samples..."), 0.5);
audio.loadSample("drum bass", getPath("sounds/drum_bass.ogg"));
audio.loadSample("drum snare", getPath("sounds/drum_snare.ogg"));
audio.loadSample("drum hi-hat", getPath("sounds/drum_hi-hat.ogg"));
@@ -135,6 +137,7 @@ void mainLoop(std::string const& songlist) {
audio.loadSample("guitar fail5", getPath("sounds/guitar_fail5.ogg"));
audio.loadSample("guitar fail6", getPath("sounds/guitar_fail6.ogg"));
// Load screens
+ sm.loading(_("Creating screens..."), 0.7);
sm.addScreen(new ScreenIntro("Intro", audio));
sm.addScreen(new ScreenSongs("Songs", audio, songs, database));
sm.addScreen(new ScreenSing("Sing", audio, database, backgrounds));
@@ -143,9 +146,9 @@ void mainLoop(std::string const& songlist) {
sm.addScreen(new ScreenAudioDevices("AudioDevices", audio));
sm.addScreen(new ScreenPlayers("Players", audio, database));
sm.activateScreen("Intro");
- sm.flashMessage(_("Main menu..."), 0.0f, 1.0f, 1.0f); window.blank(); sm.drawNotifications(); window.swap();
+ sm.loading(_("Entering main menu"), 0.8);
sm.updateScreen(); // exit/enter, any exception is fatal error
- sm.flashMessage("");
+ sm.loading(_("Loading complete"), 1.0);
// Main loop
boost::xtime time = now();
unsigned frames = 0;
diff --git a/game/screen.hh b/game/screen.hh
index 2ee93d3..b692ccb 100644
--- a/game/screen.hh
+++ b/game/screen.hh
@@ -53,8 +53,10 @@ class ScreenManager: public Singleton <ScreenManager> {
/// Returns a reference to the window
Window& window() { return m_window; };
+ /// Draw a loading progress indication
+ void loading(std::string const& message, float progress);
/// Set a message to flash in current screen
- void flashMessage(std::string const& name, float fadeIn=0.5f, float hold=1.5f, float fadeOut=1.0f);
+ void flashMessage(std::string const& message, float fadeIn=0.5f, float hold=1.5f, float fadeOut=1.0f);
/// Create a new dialog message
void dialog(std::string const& text);
/// Close dialog and return true if it was opened in the first place
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 486f8ad..daf4439 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -33,10 +33,10 @@ namespace {
void ScreenSing::enter() {
//m_practmode = true; // un-comment this line to play with practice mode. temporary, of course!
ScreenManager* sm = ScreenManager::getSingletonPtr();
- sm->flashMessage(_("Loading song..."), 0.0, 1.0, 0.5);
- sm->drawNotifications(); sm->window().swap(); // Make loading message show
+ sm->loading(_("Loading theme..."), 0.0);
theme.reset(new ThemeSing());
m_menuTheme.reset(new ThemeInstrumentMenu());
+ sm->loading(_("Loading song..."), 0.3);
// Load the rest of the song
if (m_song->loadStatus != Song::FULL) {
try { SongParser sp(*m_song); }
@@ -46,9 +46,8 @@ void ScreenSing::enter() {
sm->activateScreen("Songs");
}
}
- // Notify about broken tracks
- if (m_song->b0rkedTracks) ScreenManager::getSingletonPtr()->flashMessage(_("Song contains broken tracks!"));
// Load background
+ sm->loading(_("Loading background..."), 0.4);
bool foundbg = false;
if (!m_song->background.empty()) { // Load bg image
try {
@@ -60,17 +59,20 @@ void ScreenSing::enter() {
}
}
// Initialize webcam
+ sm->loading(_("Initializing webcam..."), 0.5);
if (config["graphic/webcam"].b() && Webcam::enabled()) {
try {
m_cam.reset(new Webcam(config["graphic/webcamid"].i()));
} catch (std::exception& e) { std::cout << e.what() << std::endl; };
}
// Load video
+ sm->loading(_("Loading video..."), 0.6);
if (!m_song->video.empty() && config["graphic/video"].b()) {
m_video.reset(new Video(m_song->path + m_song->video, m_song->videoGap));
}
// Use random bg if specified fails (also for tracks with video)
if (!foundbg) {
+ sm->loading(_("Random background..."), 0.65);
for (int i = 1; i <= 2; ++i) { // Try two times in case first is b0rked
try {
std::string bgpath = m_backgrounds.getRandom();
@@ -81,6 +83,7 @@ void ScreenSing::enter() {
}
}
}
+ sm->loading(_("Loading user interface..."), 0.7);
m_pause_icon.reset(new Surface(getThemePath("sing_pause.svg")));
m_help.reset(new Surface(getThemePath("instrumenthelp.svg")));
m_progress.reset(new ProgressBar(getThemePath("sing_progressbg.svg"), getThemePath("sing_progressfg.svg"), ProgressBar::HORIZONTAL, 0.01f, 0.01f, true));
@@ -89,6 +92,7 @@ void ScreenSing::enter() {
boost::ptr_vector<Analyzer>& analyzers = m_audio.analyzers();
m_layout_singer.reset(new LayoutSinger(m_song->vocals, m_database, theme));
// Load instrument and dance tracks
+ sm->loading(_("Loading instruments..."), 0.8);
{
int type = 0; // 0 for dance, 1 for guitars, 2 for drums
int idx = 0;
@@ -110,6 +114,7 @@ void ScreenSing::enter() {
}
}
// Populate the pause menu
+ sm->loading(_("Loading menu..."), 0.9);
m_menu.clear();
m_menu.add(MenuOption(_("Resume"), _("Back to performing!")));
m_menu.add(MenuOption(_("Restart"), _("Start the song\nfrom the beginning"), "Sing"));
@@ -117,8 +122,12 @@ void ScreenSing::enter() {
m_menu.close();
// Startup delay for instruments is longer than for singing only
double setup_delay = (m_instruments.empty() && m_dancers.empty() ? -1.0 : -3.0);
+ sm->loading(_("Finalizing..."), 0.95);
m_audio.playMusic(m_song->music, false, 0.0, setup_delay);
m_engine.reset(new Engine(m_audio, m_song->vocals, analyzers.begin(), analyzers.end(), m_database));
+ sm->loading(_("Loading complete"), 1.0);
+ // Notify about broken tracks
+ if (m_song->b0rkedTracks) ScreenManager::getSingletonPtr()->dialog(_("Song contains broken tracks!"));
}
diff --git a/game/screenmanager.cc b/game/screenmanager.cc
index ccbc7b7..82b7c4d 100644
--- a/game/screenmanager.cc
+++ b/game/screenmanager.cc
@@ -2,6 +2,7 @@
#include "fs.hh"
#include "configuration.hh"
+#include <boost/lexical_cast.hpp>
#include <stdexcept>
template<> ScreenManager* Singleton<ScreenManager>::ms_Singleton = NULL;
@@ -36,6 +37,14 @@ Screen* ScreenManager::getScreen(std::string const& name) {
}
}
+void ScreenManager::loading(std::string const& message, float progress) {
+ // TODO: Create a better one, this is quite ugly
+ flashMessage(message + " " + boost::lexical_cast<std::string>(progress*100) + "%", 0.0f, 1.0f, 1.0f);
+ m_window.blank();
+ drawNotifications();
+ m_window.swap();
+}
+
void ScreenManager::flashMessage(std::string const& message, float fadeIn, float hold, float fadeOut) {
m_message = message;
m_timeToFadeIn = fadeIn;
|