Skip to content

Commit

Permalink
rewrite the loading screen to use ImGui (#75998)
Browse files Browse the repository at this point in the history
* rewrite the loading screen to use ImGui

and simplify the usage too.

* write a loading screen for when we’re not using ImGui too

Fixes #75678

* add a stupid comment to appease clang

plus some other small changes to appease a different version of clang

---------

Co-authored-by: Daniel Brooks <[email protected]>
  • Loading branch information
db48x and Daniel Brooks authored Sep 5, 2024
1 parent 09af300 commit 734ec4c
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 176 deletions.
Binary file added gfx/cdda.avif
Binary file not shown.
3 changes: 0 additions & 3 deletions object_creator/creator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "game.h"
#include "game_ui.h"
#include "input.h"
#include "loading_ui.h"
#include "mapsharing.h"
#include "options.h"
#include "output.h"
Expand Down Expand Up @@ -164,8 +163,6 @@ int main( int argc, char *argv[] )
exit_handler( -999 );
}

loading_ui ui( false );

get_options().init();
get_options().load();

Expand Down
59 changes: 24 additions & 35 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void game::load_static_data()
get_safemode().load_global();
}

bool game::check_mod_data( const std::vector<mod_id> &opts, loading_ui &ui )
bool game::check_mod_data( const std::vector<mod_id> &opts )
{
dependency_tree &tree = world_generator->get_mod_manager().get_tree();

Expand All @@ -526,8 +526,8 @@ bool game::check_mod_data( const std::vector<mod_id> &opts, loading_ui &ui )

// if no loadable mods then test core data only
try {
load_core_data( ui );
DynamicDataLoader::get_instance().finalize_loaded_data( ui );
load_core_data();
DynamicDataLoader::get_instance().finalize_loaded_data();
} catch( const std::exception &err ) {
std::cerr << "Error loading data from json: " << err.what() << std::endl;
}
Expand Down Expand Up @@ -562,18 +562,18 @@ bool game::check_mod_data( const std::vector<mod_id> &opts, loading_ui &ui )
std::cout << "Checking mod " << mod.name() << " [" << mod.ident.str() << "]" << std::endl;

try {
load_core_data( ui );
load_core_data();

// Load any dependencies and de-duplicate them
std::vector<mod_id> dep_vector = tree.get_dependencies_of_X_as_strings( mod.ident );
std::set<mod_id> dep_set( dep_vector.begin(), dep_vector.end() );
for( const auto &dep : dep_set ) {
load_data_from_dir( dep->path, dep->ident.str(), ui );
load_data_from_dir( dep->path, dep->ident.str() );
}

// Load mod itself
load_data_from_dir( mod.path, mod.ident.str(), ui );
DynamicDataLoader::get_instance().finalize_loaded_data( ui );
load_data_from_dir( mod.path, mod.ident.str() );
DynamicDataLoader::get_instance().finalize_loaded_data();
} catch( const std::exception &err ) {
std::cerr << "Error loading data: " << err.what() << std::endl;
}
Expand All @@ -592,18 +592,18 @@ bool game::is_core_data_loaded() const
return DynamicDataLoader::get_instance().is_data_finalized();
}

void game::load_core_data( loading_ui &ui )
void game::load_core_data()
{
// core data can be loaded only once and must be first
// anyway.
DynamicDataLoader::get_instance().unload_data();

load_data_from_dir( PATH_INFO::jsondir(), "core", ui );
load_data_from_dir( PATH_INFO::jsondir(), "core" );
}

void game::load_data_from_dir( const cata_path &path, const std::string &src, loading_ui &ui )
void game::load_data_from_dir( const cata_path &path, const std::string &src )
{
DynamicDataLoader::get_instance().load_data_from_path( path, src, ui );
DynamicDataLoader::get_instance().load_data_from_path( path, src );
}

#if defined(TUI)
Expand Down Expand Up @@ -778,18 +778,16 @@ void game::reenter_fullscreen()
*/
void game::setup()
{
loading_ui ui( true );
new_game = true;
{
background_pane background;
static_popup popup;
popup.message( "%s", _( "Please wait while the world data loads…\nLoading core data" ) );
ui_manager::redraw();
refresh_display();

load_core_data( ui );
load_core_data();
}
load_world_modfiles( ui );
load_world_modfiles();
// Panel manager needs JSON data to be loaded before init
panel_manager::get_manager().init();

Expand Down Expand Up @@ -3013,9 +3011,6 @@ bool game::load( const std::string &world )

bool game::load( const save_t &name )
{
loading_ui ui( true );
ui.new_context( _( "Loading the save…" ) );

const cata_path worldpath = PATH_INFO::world_base_save_path_path();
const cata_path save_file_path = PATH_INFO::world_base_save_path_path() /
( name.base_path() + SAVE_EXTENSION );
Expand Down Expand Up @@ -3162,22 +3157,19 @@ bool game::load( const save_t &name )
};

for( const named_entry &e : entries ) {
ui.add_entry( e.first );
}

ui.show();
for( const named_entry &e : entries ) {
loading_ui::show( _( "Loading the save…" ), e.first );
e.second();
if( abort ) {
loading_ui::done();
return false;
}
ui.proceed();
}

loading_ui::done();
return true;
}

void game::load_world_modfiles( loading_ui &ui )
void game::load_world_modfiles()
{
auto &mods = world_generator->active_world->active_mod_order;

Expand All @@ -3204,40 +3196,37 @@ void game::load_world_modfiles( loading_ui &ui )
// are resolved during the creation of the world.
// That means world->active_mod_order contains a list
// of mods in the correct order.
load_packs( _( "Loading files" ), mods, ui );
load_packs( _( "Loading files" ), mods );

// Load additional mods from that world-specific folder
load_data_from_dir( PATH_INFO::world_base_save_path_path() / "mods", "custom", ui );
load_data_from_dir( PATH_INFO::world_base_save_path_path() / "mods", "custom" );

DynamicDataLoader::get_instance().finalize_loaded_data( ui );
DynamicDataLoader::get_instance().finalize_loaded_data();
}

void game::load_packs( const std::string &msg, const std::vector<mod_id> &packs, loading_ui &ui )
void game::load_packs( const std::string &msg, const std::vector<mod_id> &packs )
{
ui.new_context( msg );
std::vector<mod_id> missing;
std::vector<mod_id> available;

for( const mod_id &e : packs ) {
if( e.is_valid() ) {
available.emplace_back( e );
ui.add_entry( e->name() );
} else {
missing.push_back( e );
}
}

ui.show();
for( const auto &e : available ) {
loading_ui::show( msg, e->name() );
const MOD_INFORMATION &mod = *e;
restore_on_out_of_scope<check_plural_t> restore_check_plural( check_plural );
if( mod.ident.str() == "test_data" ) {
check_plural = check_plural_t::none;
}
load_data_from_dir( mod.path, mod.ident.str(), ui );

ui.proceed();
load_data_from_dir( mod.path, mod.ident.str() );
}
loading_ui::done();

std::unordered_set<mod_id> removed_mods {
MOD_INFORMATION_Graphical_Overmap // Removed in 0.I
Expand Down
11 changes: 5 additions & 6 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class field_entry;
class item;
class kill_tracker;
class live_view;
class loading_ui;
class map;
class map_item_stack;
class memorial_logger;
Expand Down Expand Up @@ -170,7 +169,7 @@ class game
void load_static_data();

/** Loads core dynamic data. May throw. */
void load_core_data( loading_ui &ui );
void load_core_data();

/** Returns whether the core data is currently loaded. */
bool is_core_data_loaded() const;
Expand All @@ -180,17 +179,17 @@ class game
* @param opts check specific mods (or all if unspecified)
* @return whether all mods were successfully loaded
*/
bool check_mod_data( const std::vector<mod_id> &opts, loading_ui &ui );
bool check_mod_data( const std::vector<mod_id> &opts );

/** Loads core data and mods from the active world. May throw. */
void load_world_modfiles( loading_ui &ui );
void load_world_modfiles();
/**
* Load content packs
* @param msg string to display whilst loading prompt
* @param packs content packs to load in correct dependent order
* @param ui structure for load progress display
*/
void load_packs( const std::string &msg, const std::vector<mod_id> &packs, loading_ui &ui );
void load_packs( const std::string &msg, const std::vector<mod_id> &packs );

/**
* @brief Should be invoked whenever options change.
Expand All @@ -199,7 +198,7 @@ class game

protected:
/** Loads dynamic data from the given directory. May throw. */
void load_data_from_dir( const cata_path &path, const std::string &src, loading_ui &ui );
void load_data_from_dir( const cata_path &path, const std::string &src );
public:
void setup();
/** Saving and loading functions. */
Expand Down
46 changes: 16 additions & 30 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ void DynamicDataLoader::initialize()
#endif
}

void DynamicDataLoader::load_data_from_path( const cata_path &path, const std::string &src,
loading_ui &ui )
void DynamicDataLoader::load_data_from_path( const cata_path &path, const std::string &src )
{
cata_assert( !finalized &&
"Can't load additional data after finalization. Must be unloaded first." );
Expand All @@ -523,15 +522,14 @@ void DynamicDataLoader::load_data_from_path( const cata_path &path, const std::s
try {
// parse it
JsonValue jsin = json_loader::from_path( file );
load_all_from_json( jsin, src, ui, path, file );
load_all_from_json( jsin, src, path, file );
} catch( const JsonError &err ) {
throw std::runtime_error( err.what() );
}
}
}

void DynamicDataLoader::load_all_from_json( const JsonValue &jsin, const std::string &src,
loading_ui &,
const cata_path &base_path, const cata_path &full_path )
{
if( jsin.test_object() ) {
Expand Down Expand Up @@ -674,15 +672,15 @@ void DynamicDataLoader::unload_data()
zone_type::reset();
}

void DynamicDataLoader::finalize_loaded_data()
{
// Create a dummy that will not display anything
// TODO: Make it print to stdout?
loading_ui ui( false );
finalize_loaded_data( ui );
}
// void DynamicDataLoader::finalize_loaded_data()
// {
// // Create a dummy that will not display anything
// // TODO: Make it print to stdout?
// background_pane bg;
// finalize_loaded_data( );
// }

void DynamicDataLoader::finalize_loaded_data( loading_ui &ui )
void DynamicDataLoader::finalize_loaded_data()
{
cata_assert( !finalized && "Can't finalize the data twice." );
cata_assert( !stream_cache && "Expected stream cache to be null before finalization" );
Expand All @@ -692,8 +690,6 @@ void DynamicDataLoader::finalize_loaded_data( loading_ui &ui )
} );
stream_cache = std::make_unique<cached_streams>();

ui.new_context( _( "Finalizing" ) );

using named_entry = std::pair<std::string, std::function<void()>>;
const std::vector<named_entry> entries = {{
{ _( "Flags" ), &json_flag::finalize_all },
Expand Down Expand Up @@ -772,25 +768,19 @@ void DynamicDataLoader::finalize_loaded_data( loading_ui &ui )
};

for( const named_entry &e : entries ) {
ui.add_entry( e.first );
}

ui.show();
for( const named_entry &e : entries ) {
loading_ui::show( _( "Finalizing" ), e.first );
e.second();
ui.proceed();
}

if( !get_option<bool>( "SKIP_VERIFICATION" ) ) {
check_consistency( ui );
check_consistency();
}
finalized = true;
loading_ui::done();
}

void DynamicDataLoader::check_consistency( loading_ui &ui )
void DynamicDataLoader::check_consistency()
{
ui.new_context( _( "Verifying" ) );

using named_entry = std::pair<std::string, std::function<void()>>;
const std::vector<named_entry> entries = {{
{ _( "Flags" ), &json_flag::check_consistency },
Expand Down Expand Up @@ -883,12 +873,8 @@ void DynamicDataLoader::check_consistency( loading_ui &ui )
};

for( const named_entry &e : entries ) {
ui.add_entry( e.first );
}

ui.show();
for( const named_entry &e : entries ) {
loading_ui::show( _( "Verifying" ), e.first );
e.second();
ui.proceed();
}
loading_ui::done();
}
7 changes: 2 additions & 5 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

class JsonObject;
class JsonValue;
class loading_ui;
struct json_source_location;

/**
Expand Down Expand Up @@ -100,7 +99,6 @@ class DynamicDataLoader
* @throws std::exception on all kind of errors.
*/
void load_all_from_json( const JsonValue &jsin, const std::string &src,
loading_ui &,
const cata_path &base_path, const cata_path &full_path );
/**
* Load a single object from a json object.
Expand All @@ -123,7 +121,7 @@ class DynamicDataLoader
* May print a debugmsg if something seems wrong.
* @param ui Finalization status display.
*/
void check_consistency( loading_ui &ui );
void check_consistency();

public:
/**
Expand All @@ -141,7 +139,7 @@ class DynamicDataLoader
* @throws std::exception on all kind of errors.
*/
/*@{*/
void load_data_from_path( const cata_path &path, const std::string &src, loading_ui &ui );
void load_data_from_path( const cata_path &path, const std::string &src );
/*@}*/
/**
* Deletes and unloads all the data previously loaded with
Expand All @@ -159,7 +157,6 @@ class DynamicDataLoader
* game should *not* proceed in that case.
*/
/*@{*/
void finalize_loaded_data( loading_ui &ui );
void finalize_loaded_data();
/*@}*/

Expand Down
Loading

0 comments on commit 734ec4c

Please sign in to comment.