diff --git a/src/gui/dialogs/loading_screen.cpp b/src/gui/dialogs/loading_screen.cpp index 47fa759e82fe..988094f1c0f7 100644 --- a/src/gui/dialogs/loading_screen.cpp +++ b/src/gui/dialogs/loading_screen.cpp @@ -18,24 +18,24 @@ #define GETTEXT_DOMAIN "wesnoth-lib" -#include "cursor.hpp" #include "gui/dialogs/loading_screen.hpp" -#include "gui/widgets/label.hpp" -#include "gui/widgets/window.hpp" -#include "gui/widgets/settings.hpp" -#include "gui/core/timer.hpp" -#include "gui/auxiliary/find_widget.hpp" -#include "video.hpp" #include "cursor.hpp" #include "gettext.hpp" +#include "gui/auxiliary/find_widget.hpp" +#include "gui/core/timer.hpp" +#include "gui/widgets/label.hpp" +#include "gui/widgets/settings.hpp" +#include "gui/widgets/window.hpp" #include "log.hpp" #include "preferences/general.hpp" #include "utils/functional.hpp" +#include "video.hpp" -#include #include +#include + #if defined(_MSC_VER) && _MSC_VER <= 1800 #include #endif @@ -76,7 +76,6 @@ namespace gui2 { namespace dialogs { - REGISTER_DIALOG(loading_screen) loading_screen::loading_screen(std::function f) @@ -93,32 +92,37 @@ loading_screen::loading_screen(std::function f) , current_visible_stage_() , is_worker_running_(false) { - for (const auto& pair : stages) { + for(const auto& pair : stages) { visible_stages_[pair.first] = t_string(pair.second, "wesnoth-lib") + "..."; } - for (int i = 0; i != 20; ++i) { + + for(int i = 0; i != 20; ++i) { std::string s(20, ' '); s[i] = '.'; animation_stages_.push_back(s); } + current_visible_stage_ = visible_stages_.end(); current_load = this; } void loading_screen::pre_show(window& window) { - if (work_) { + if(work_) { worker_.reset(new boost::thread([this]() { is_worker_running_ = true; + try { work_(); } catch(...) { - //TODO: guard this with a mutex. + // TODO: guard this with a mutex. exception_ = std::current_exception(); } + is_worker_running_ = false; })); } + timer_id_ = add_timer(100, std::bind(&loading_screen::timer_callback, this, std::ref(window)), true); cursor_setter_.reset(new cursor::setter(cursor::WAIT)); progress_stage_label_ = &find_widget