Improve precaching of terrain images existence...

...by also skipping any image cache record.

This reduces the index numbers used.

Also temporary disable a log::wml_error about missing ".png" extension
This commit is contained in:
Ali El Gariani 2010-06-27 17:07:11 +00:00
parent 5115841054
commit c2f75aba4e
3 changed files with 23 additions and 21 deletions

View file

@ -322,15 +322,17 @@ bool terrain_builder::rule_valid(const building_rule &rule) const
for(variant = image->variants.begin(); variant != image->variants.end(); ++variant) {
std::string s = variant->second.image_string;
s = s.substr(0, s.find_first_of(",:~"));
// we already precached file existence in the constructor
// but only for filenames not using ".."
if(!image::exists("terrain/" + s, s.find("..") == std::string::npos)){
// This warning can be removed after 1.9.2
if(image::exists("terrain/" + s + ".png", s.find("..") == std::string::npos))
lg::wml_error << "Terrain image '" << s << "' misses the '.png' extension\n";
// printf("%s\n",s.c_str());
return false;
bool precached = s.find("..") == std::string::npos;
s = "terrain/" + s;
if(precached) {
//TODO reactivate this (costly) warning
//if precached_file_exists(s+".png")
// lg::wml_error << "Terrain image '" << s << "' misses the '.png' extension\n";
return image::precached_file_exists(s);
} else {
return image::exists(s);
}
}
}

View file

@ -55,7 +55,7 @@ image::bool_cache in_hex_info_;
// const int cache_version_ = 0;
std::map<image::locator,bool> image_existence_map;
std::map<std::string,bool> image_existence_map;
// directories where we already cached file existence
std::set<std::string> precached_dirs;
@ -1054,24 +1054,16 @@ surface reverse_image(const surface& surf)
return rev;
}
bool exists(const image::locator& i_locator, bool precached)
bool exists(const image::locator& i_locator)
{
typedef image::locator loc;
loc::type type = i_locator.get_type();
if (type != loc::FILE && type != loc::SUB_FILE)
return false;
if (precached) {
std::map<image::locator,bool>::const_iterator b = image_existence_map.find(i_locator);
if (b != image_existence_map.end())
return b->second;
else
return false;
}
// The insertion will fail if there is already an element in the cache
std::pair< std::map< image::locator, bool >::iterator, bool >
it = image_existence_map.insert(std::make_pair(i_locator, false));
std::pair< std::map< std::string, bool >::iterator, bool >
it = image_existence_map.insert(std::make_pair(i_locator.get_filename(), false));
bool &cache = it.first->second;
if (it.second)
cache = !get_binary_file_location("images", i_locator.get_filename()).empty();
@ -1113,6 +1105,14 @@ void precache_file_existence(const std::string& subdir)
}
}
bool precached_file_exists(const std::string& file)
{
std::map<std::string, bool>::const_iterator b = image_existence_map.find(file);
if (b != image_existence_map.end())
return b->second;
else
return false;
}
template<typename T>
cache_item<T>& cache_type<T>::get_element(int index){

View file

@ -272,11 +272,11 @@ namespace image {
surface reverse_image(const surface &surf);
///returns true if the given image actually exists, without loading it.
/// precached : if we already have precached the directory containing the file
bool exists(const locator& i_locator, bool precached = false);
bool exists(const locator& i_locator);
/// precache the existence of files in the subdir (ex: "terrain/")
void precache_file_existence(const std::string& subdir = "");
bool precached_file_exists(const std::string& file);
}
#endif