Skip to content

Commit

Permalink
Merge pull request CleverRaven#77041 from sparr/unknown_terrain_tile_…
Browse files Browse the repository at this point in the history
…error

Check `unknown_terrain` instead of `unknown` for overmap tileset
  • Loading branch information
Maleclypse authored Oct 19, 2024
2 parents f1417b4 + 28af8bf commit 08d4771
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
18 changes: 10 additions & 8 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ tile_type &tileset::create_tile_type( const std::string &id, tile_type &&new_til
}

void cata_tiles::load_tileset( const std::string &tileset_id, const bool precheck,
const bool force, const bool pump_events )
const bool force, const bool pump_events, const bool terrain )
{
if( tileset_ptr && tileset_ptr->get_tileset_id() == tileset_id && !force ) {
return;
Expand All @@ -341,7 +341,7 @@ void cata_tiles::load_tileset( const std::string &tileset_id, const bool prechec
// reset the overlay ordering from the previous loaded tileset
tileset_mutation_overlay_ordering.clear();

tileset_ptr = cache.load_tileset( tileset_id, renderer, precheck, force, pump_events );
tileset_ptr = cache.load_tileset( tileset_id, renderer, precheck, force, pump_events, terrain );

set_draw_scale( 16 );

Expand Down Expand Up @@ -625,7 +625,7 @@ void cata_tiles::set_draw_scale( int scale )
}

void tileset_cache::loader::load( const std::string &tileset_id, const bool precheck,
const bool pump_events )
const bool pump_events, const bool terrain )
{
std::string json_conf;
std::string layering;
Expand Down Expand Up @@ -765,8 +765,9 @@ void tileset_cache::loader::load( const std::string &tileset_id, const bool prec
}
}

if( !ts.find_tile_type( "unknown" ) ) {
dbg( D_ERROR ) << "The tileset you're using has no 'unknown' tile defined!";
if( !ts.find_tile_type( terrain ? "unknown_terrain" : "unknown" ) ) {
dbg( D_ERROR ) << "The tileset you're using has no '" << ( terrain ? "unknown_terrain" : "unknown" )
<< "' tile defined!";
}
ensure_default_item_highlight();

Expand Down Expand Up @@ -4411,14 +4412,15 @@ bool cata_tiles::draw_item_highlight( const tripoint &pos, int &height_3d )
}

std::shared_ptr<const tileset> tileset_cache::load_tileset( const std::string &tileset_id,
const SDL_Renderer_Ptr &renderer, const bool precheck, const bool force, const bool pump_events )
const SDL_Renderer_Ptr &renderer, const bool precheck, const bool force, const bool pump_events,
const bool terrain )
{
const auto get_or_create_tileset = [&]() {
const auto it = tilesets_.find( tileset_id );
if( it == tilesets_.end() || it->second.expired() ) {
std::shared_ptr<tileset> new_ts = std::make_shared<tileset>();
loader loader( *new_ts, renderer );
loader.load( tileset_id, precheck, pump_events );
loader.load( tileset_id, precheck, pump_events, terrain );
tilesets_.emplace( tileset_id, new_ts );
return new_ts;
}
Expand All @@ -4429,7 +4431,7 @@ std::shared_ptr<const tileset> tileset_cache::load_tileset( const std::string &t

if( force || ( ts->get_tileset_id().empty() && !precheck ) ) {
loader loader( *ts, renderer );
loader.load( tileset_id, precheck, pump_events );
loader.load( tileset_id, precheck, pump_events, terrain );
}
return ts;
}
Expand Down
9 changes: 6 additions & 3 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class tileset_cache
public:
std::shared_ptr<const tileset> load_tileset( const std::string &tileset_id,
const SDL_Renderer_Ptr &renderer, bool precheck,
bool force, bool pump_events );
bool force, bool pump_events, bool terrain );
private:
class loader;
std::unordered_map<std::string, std::weak_ptr<tileset>> tilesets_;
Expand Down Expand Up @@ -379,8 +379,10 @@ class tileset_cache::loader
* @param pump_events Handle window events and refresh the screen when necessary.
* Please ensure that the tileset is not accessed when this method is
* executing if you set it to true.
* @param terrain If true, this will be an overmap/terrain tileset
*/
void load( const std::string &tileset_id, bool precheck, bool pump_events = false );
void load( const std::string &tileset_id, bool precheck, bool pump_events = false,
bool terrain = false );
};

enum class text_alignment : int {
Expand Down Expand Up @@ -682,10 +684,11 @@ class cata_tiles
* @param pump_events Handle window events and refresh the screen when necessary.
* Please ensure that the tileset is not accessed when this method is
* executing if you set it to true.
* @param terrain If true, this will be an overmap/terrain tileset
* @throw std::exception On any error.
*/
void load_tileset( const std::string &tileset_id, bool precheck = false,
bool force = false, bool pump_events = false );
bool force = false, bool pump_events = false, bool terrain = false );
/**
* Reinitializes the current tileset, like @ref init, but using the original screen information.
* @throw std::exception On any error.
Expand Down
6 changes: 3 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ void game::reload_tileset()
closetilecontext->reinit();
closetilecontext->load_tileset( get_option<std::string>( "TILES" ),
/*precheck=*/false, /*force=*/true,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
closetilecontext->do_tile_loading_report();

tilecontext = closetilecontext;
Expand All @@ -741,7 +741,7 @@ void game::reload_tileset()
}
fartilecontext->load_tileset( get_option<std::string>( "DISTANT_TILES" ),
/*precheck=*/false, /*force=*/true,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
fartilecontext->do_tile_loading_report();
} catch( const std::exception &err ) {
popup( _( "Loading the zoomed out tileset failed: %s" ), err.what() );
Expand All @@ -751,7 +751,7 @@ void game::reload_tileset()
overmap_tilecontext->reinit();
overmap_tilecontext->load_tileset( get_option<std::string>( "OVERMAP_TILES" ),
/*precheck=*/false, /*force=*/true,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/true );
overmap_tilecontext->do_tile_loading_report();
} catch( const std::exception &err ) {
popup( _( "Loading the overmap tileset failed: %s" ), err.what() );
Expand Down
6 changes: 3 additions & 3 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3273,7 +3273,7 @@ static void refresh_tiles( bool used_tiles_changed, bool pixel_minimap_height_ch
closetilecontext->reinit();
closetilecontext->load_tileset( get_option<std::string>( "TILES" ),
/*precheck=*/false, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
//game_ui::init_ui is called when zoom is changed
g->reset_zoom();
g->mark_main_ui_adaptor_resize();
Expand All @@ -3290,7 +3290,7 @@ static void refresh_tiles( bool used_tiles_changed, bool pixel_minimap_height_ch
}
fartilecontext->load_tileset( get_option<std::string>( "DISTANT_TILES" ),
/*precheck=*/false, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
//game_ui::init_ui is called when zoom is changed
g->reset_zoom();
g->mark_main_ui_adaptor_resize();
Expand All @@ -3305,7 +3305,7 @@ static void refresh_tiles( bool used_tiles_changed, bool pixel_minimap_height_ch
overmap_tilecontext->reinit();
overmap_tilecontext->load_tileset( get_option<std::string>( "OVERMAP_TILES" ),
/*precheck=*/false, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/true );
//game_ui::init_ui is called when zoom is changed
g->reset_zoom();
g->mark_main_ui_adaptor_resize();
Expand Down
12 changes: 6 additions & 6 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3680,7 +3680,7 @@ void catacurses::init_interface()
ui_adaptor dummy( ui_adaptor::disable_uis_below{} );
fartilecontext->load_tileset( get_option<std::string>( "DISTANT_TILES" ),
/*precheck=*/true, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
} catch( const std::exception &err ) {
dbg( D_ERROR ) << "failed to check for tileset: " << err.what();
// use_tiles is the cached value of the USE_TILES option.
Expand All @@ -3695,7 +3695,7 @@ void catacurses::init_interface()
ui_adaptor dummy( ui_adaptor::disable_uis_below{} );
closetilecontext->load_tileset( get_option<std::string>( "TILES" ),
/*precheck=*/true, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
tilecontext = closetilecontext;
} catch( const std::exception &err ) {
dbg( D_ERROR ) << "failed to check for tileset: " << err.what();
Expand All @@ -3710,7 +3710,7 @@ void catacurses::init_interface()
ui_adaptor dummy( ui_adaptor::disable_uis_below{} );
overmap_tilecontext->load_tileset( get_option<std::string>( "OVERMAP_TILES" ),
/*precheck=*/true, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/true );
} catch( const std::exception &err ) {
dbg( D_ERROR ) << "failed to check for overmap tileset: " << err.what();
// use_tiles is the cached value of the USE_TILES option.
Expand Down Expand Up @@ -3755,19 +3755,19 @@ void load_tileset()
}
closetilecontext->load_tileset( get_option<std::string>( "TILES" ),
/*precheck=*/false, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
if( use_far_tiles ) {
fartilecontext->load_tileset( get_option<std::string>( "DISTANT_TILES" ),
/*precheck=*/false, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/false );
}
tilecontext = closetilecontext;
tilecontext->do_tile_loading_report();

if( overmap_tilecontext ) {
overmap_tilecontext->load_tileset( get_option<std::string>( "OVERMAP_TILES" ),
/*precheck=*/false, /*force=*/false,
/*pump_events=*/true );
/*pump_events=*/true, /*terrain=*/true );
overmap_tilecontext->do_tile_loading_report();
}
}
Expand Down

0 comments on commit 08d4771

Please sign in to comment.