Skip to content

Commit

Permalink
tloadscreen: Stub for progress/stage indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 29, 2016
1 parent 41095c1 commit d535ec4
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/game_config_manager.cpp
Expand Up @@ -150,7 +150,9 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
// Load the selected core.
// Handle terrains so that they are last loaded from the core.
// Load every compatible addon.
gui2::tloadscreen::progress("verify cache");
filesystem::data_tree_checksum();
gui2::tloadscreen::progress("create cache");

// Start transaction so macros are shared.
game_config::config_cache_transaction main_transaction;
Expand Down Expand Up @@ -470,6 +472,7 @@ void game_config_manager::set_color_info()
void game_config_manager::set_unit_data()
{
game_config_.merge_children("units");
gui2::tloadscreen::progress("load unit types");
if(config &units = game_config_.child("units")) {
unit_types.set_config(units);
}
Expand Down
1 change: 1 addition & 0 deletions src/game_launcher.cpp
Expand Up @@ -1012,6 +1012,7 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload)
}

gui2::tloadscreen::display(video());
gui2::tloadscreen::progress("load data");

if(reload == RELOAD_DATA) {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/game_state.cpp
Expand Up @@ -30,6 +30,7 @@
#include "teambuilder.hpp"
#include "units/unit.hpp"
#include "whiteboard/manager.hpp"
#include "gui/dialogs/loadscreen.hpp"

#include <boost/bind.hpp>
#include <boost/foreach.hpp>
Expand Down Expand Up @@ -165,6 +166,7 @@ void game_state::place_sides_in_preferred_locations(const config& level)
void game_state::init(const config& level, play_controller & pc)
{
events_manager_->read_scenario(level);
gui2::tloadscreen::progress("init teams");
if (level["modify_placing"].to_bool()) {
LOG_NG << "modifying placing..." << std::endl;
place_sides_in_preferred_locations(level);
Expand Down
15 changes: 15 additions & 0 deletions src/gui/dialogs/loadscreen.cpp
Expand Up @@ -64,4 +64,19 @@ void tloadscreen::post_show(twindow& /*window*/)
cursor::setter cur(cursor::NORMAL);
}

void tloadscreen::progress(const char* stage)
{
if(!current_load) {
return;
}
// Currently this is a no-op stub
if(stage) {
// TODO: Update displayed stage
current_load->current_stage = stage;
}
// TODO: Indicate progress somehow
}

tloadscreen* tloadscreen::current_load = NULL;

} // namespace gui2
10 changes: 10 additions & 0 deletions src/gui/dialogs/loadscreen.hpp
Expand Up @@ -27,19 +27,25 @@ class tloadscreen : public tdialog
public:
tloadscreen()
: window_(NULL)
, previous_load(current_load)
, current_stage(NULL)
{
current_load = this;
}

~tloadscreen()
{
close();
current_load = previous_load;
}

static void display(CVideo& video) {
tloadscreen().show(video);
}

void show(CVideo& video);

static void progress(const char* stage_name = NULL);

/**
* Hides the window.
Expand All @@ -61,6 +67,10 @@ class tloadscreen : public tdialog

/** Inherited from tdialog. */
void post_show(twindow& window);

static tloadscreen* current_load;
tloadscreen*const previous_load;
const char* current_stage;
};

} // namespace gui2
8 changes: 8 additions & 0 deletions src/play_controller.cpp
Expand Up @@ -225,6 +225,7 @@ struct throw_end_level
void play_controller::init(CVideo& video, const config& level)
{
gui2::tloadscreen::display(video);
gui2::tloadscreen::progress("load level");

LOG_NG << "initializing game_state..." << (SDL_GetTicks() - ticks()) << std::endl;
gamestate_.reset(new game_state(level, *this, tdata_));
Expand All @@ -246,12 +247,15 @@ void play_controller::init(CVideo& video, const config& level)
resources::whiteboard = whiteboard_manager_;

LOG_NG << "loading units..." << (SDL_GetTicks() - ticks()) << std::endl;
gui2::tloadscreen::progress("load units");
preferences::encounter_all_content(gamestate().board_);

LOG_NG << "initializing theme... " << (SDL_GetTicks() - ticks()) << std::endl;
gui2::tloadscreen::progress("init theme");
const config& theme_cfg = controller_base::get_theme(game_config_, level["theme"]);

LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks()) << std::endl;
gui2::tloadscreen::progress("build terrain");
gui_.reset(new game_display(gamestate().board_, video, whiteboard_manager_, *gamestate().reports_, gamestate().tod_manager_, theme_cfg, level));
if (!gui_->video().faked()) {
if (saved_game_.mp_settings().mp_countdown)
Expand All @@ -260,17 +264,20 @@ void play_controller::init(CVideo& video, const config& level)
gui_->get_theme().modify_label("time-icon", _ ("current local time"));
}

gui2::tloadscreen::progress("init display");
mouse_handler_.set_gui(gui_.get());
menu_handler_.set_gui(gui_.get());
resources::screen = gui_.get();

LOG_NG << "done initializing display... " << (SDL_GetTicks() - ticks()) << std::endl;

LOG_NG << "building gamestate to gui and whiteboard... " << (SDL_GetTicks() - ticks()) << std::endl;
gui2::tloadscreen::progress("init whiteboard");
// This *needs* to be created before the show_intro and show_map_scene
// as that functions use the manager state_of_game
// Has to be done before registering any events!
gamestate().bind(whiteboard_manager_.get(), gui_.get());
gui2::tloadscreen::progress("init lua");
resources::lua_kernel = gamestate().lua_kernel_.get();

if(gamestate().first_human_team_ != -1) {
Expand All @@ -291,6 +298,7 @@ void play_controller::init(CVideo& video, const config& level)
}

init_managers();
gui2::tloadscreen::progress("start game");
//loadscreen_manager->reset();
gamestate().gamedata_.set_phase(game_data::PRELOAD);
gamestate().lua_kernel_->initialize(level);
Expand Down
7 changes: 7 additions & 0 deletions src/terrain/builder.cpp
Expand Up @@ -24,6 +24,7 @@
#include "log.hpp"
#include "map/map.hpp"
#include "serialization/string_utils.hpp"
#include "gui/dialogs/loadscreen.hpp"

#include <boost/foreach.hpp>

Expand Down Expand Up @@ -866,6 +867,7 @@ void terrain_builder::add_rotated_rules(building_ruleset &rules, building_rule &
void terrain_builder::parse_config(const config &cfg, bool local)
{
log_scope("terrain_builder::parse_config");
int n = 0;

// Parses the list of building rules (BRs)
BOOST_FOREACH(const config &br, cfg.child_range("terrain_graphics"))
Expand Down Expand Up @@ -946,6 +948,11 @@ void terrain_builder::parse_config(const config &cfg, bool local)
pbr.precedence = br["precedence"];

add_rotated_rules(building_rules_, pbr, rotations);

n++;
if(n % 10 == 0) {
gui2::tloadscreen::progress();
}
}

// Debug output for the terrain rules
Expand Down
7 changes: 7 additions & 0 deletions src/units/types.cpp
Expand Up @@ -32,6 +32,7 @@
#include "util.hpp"

#include "gui/auxiliary/formula.hpp"
#include "gui/dialogs/loadscreen.hpp"

#include <boost/foreach.hpp>
#include <boost/static_assert.hpp>
Expand Down Expand Up @@ -1011,12 +1012,14 @@ void unit_type_data::set_config(config &cfg)
BOOST_FOREACH(const config &mt, cfg.child_range("movetype"))
{
movement_types_.insert(std::make_pair(mt["name"].str(), movetype(mt)));
gui2::tloadscreen::progress();
}

BOOST_FOREACH(const config &r, cfg.child_range("race"))
{
const unit_race race(r);
races_.insert(std::pair<std::string,unit_race>(race.id(),race));
gui2::tloadscreen::progress();
}

// Movetype resistance patching
Expand Down Expand Up @@ -1098,6 +1101,7 @@ void unit_type_data::set_config(config &cfg)
if ( !id.empty() ) {
std::vector<std::string> base_tree(1, id);
apply_base_unit(ut, cfg, base_tree);
gui2::tloadscreen::progress();
}
}
}
Expand Down Expand Up @@ -1131,6 +1135,8 @@ void unit_type_data::set_config(config &cfg)
} else {
ERR_CF << "Multiple [unit_type]s with id=" << id << " encountered." << std::endl;
}

gui2::tloadscreen::progress();
}

// Build all unit types. (This was not done within the loop for performance.)
Expand Down Expand Up @@ -1196,6 +1202,7 @@ void unit_type_data::build_all(unit_type::BUILD_STATUS status)

for (unit_type_map::iterator u = types_.begin(), u_end = types_.end(); u != u_end; ++u) {
build_unit_type(u->second, status);
gui2::tloadscreen::progress();
}
// Handle [advancefrom] (once) after building to (at least) the CREATED level.
// (Currently, this could be simply a test for build_status_ == NOT_BUILT,
Expand Down
8 changes: 7 additions & 1 deletion src/wesnoth.cpp
Expand Up @@ -630,12 +630,13 @@ static int do_gameloop(const std::vector<std::string>& args)

check_fpu();
const cursor::manager cursor_manager;
//cursor::set(cursor::WAIT);
cursor::set(cursor::WAIT);

#if (defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
#endif

gui2::tloadscreen::progress("init gui"); // Does nothing since there's no loadscreen yet
gui2::init();
const gui2::event::tmanager gui_event_manager;

Expand All @@ -644,22 +645,27 @@ static int do_gameloop(const std::vector<std::string>& args)
game_config_manager config_manager(cmdline_opts, game->video(),
game->jump_to_editor());

gui2::tloadscreen::progress("load config");
res = config_manager.init_game_config(game_config_manager::NO_FORCE_RELOAD);
if(res == false) {
std::cerr << "could not initialize game config\n";
return 1;
}
gui2::tloadscreen::progress("init fonts");

res = font::load_font_config();
if(res == false) {
std::cerr << "could not re-initialize fonts for the current language\n";
return 1;
}

gui2::tloadscreen::progress("refresh addons");
refresh_addon_version_info_cache();

config tips_of_day;

gui2::tloadscreen::progress("titlescreen");

LOG_CONFIG << "time elapsed: "<< (SDL_GetTicks() - start_ticks) << " ms\n";

plugins_manager plugins_man(new application_lua_kernel(&game->video()));
Expand Down

0 comments on commit d535ec4

Please sign in to comment.