Skip to content

Commit

Permalink
Textures: Load base pack only as last fallback (#8974)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Sep 29, 2019
1 parent c2458d3 commit 61e9c1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/client/tile.cpp
Expand Up @@ -122,9 +122,14 @@ std::string getImagePath(std::string path)
Utilizes a thread-safe cache.
*/
std::string getTexturePath(const std::string &filename)
std::string getTexturePath(const std::string &filename, bool *is_base_pack)
{
std::string fullpath;

// This can set a wrong value on cached textures, but is irrelevant because
// is_base_pack is only passed when initializing the textures the first time
if (is_base_pack)
*is_base_pack = false;
/*
Check from cache
*/
Expand Down Expand Up @@ -154,6 +159,8 @@ std::string getTexturePath(const std::string &filename)
std::string testpath = base_path + DIR_DELIM + filename;
// Check all filename extensions. Returns "" if not found.
fullpath = getImagePath(testpath);
if (is_base_pack && !fullpath.empty())
*is_base_pack = true;
}

// Add to cache (also an empty result is cached)
Expand Down Expand Up @@ -215,9 +222,11 @@ class SourceImageCache
bool need_to_grab = true;

// Try to use local texture instead if asked to
if (prefer_local){
std::string path = getTexturePath(name);
if (!path.empty()) {
if (prefer_local) {
bool is_base_pack;
std::string path = getTexturePath(name, &is_base_pack);
// Ignore base pack
if (!path.empty() && !is_base_pack) {
video::IImage *img2 = RenderingEngine::get_video_driver()->
createImageFromFile(path.c_str());
if (img2){
Expand Down
2 changes: 1 addition & 1 deletion src/client/tile.h
Expand Up @@ -64,7 +64,7 @@ std::string getImagePath(std::string path);
Utilizes a thread-safe cache.
*/
std::string getTexturePath(const std::string &filename);
std::string getTexturePath(const std::string &filename, bool *is_base_pack = nullptr);

void clearTextureNameCache();

Expand Down

0 comments on commit 61e9c1b

Please sign in to comment.