If available, use local textures instead of those sent by server

master
Perttu Ahola 2011-11-26 13:32:23 +02:00
parent b58dc083a9
commit 8bd178c2e5
1 changed files with 14 additions and 4 deletions

View File

@ -183,18 +183,28 @@ class SourceImageCache
{ {
public: public:
void insert(const std::string &name, video::IImage *img, void insert(const std::string &name, video::IImage *img,
bool do_overwrite) bool prefer_local, video::IVideoDriver *driver)
{ {
assert(img); assert(img);
// Remove old image
core::map<std::string, video::IImage*>::Node *n; core::map<std::string, video::IImage*>::Node *n;
n = m_images.find(name); n = m_images.find(name);
if(n){ if(n){
if(!do_overwrite)
return;
video::IImage *oldimg = n->getValue(); video::IImage *oldimg = n->getValue();
if(oldimg) if(oldimg)
oldimg->drop(); oldimg->drop();
} }
// Try to use local texture instead if asked to
if(prefer_local){
std::string path = getTexturePath(name.c_str());
if(path != ""){
video::IImage *img2 = driver->createImageFromFile(path.c_str());
if(img2){
m_images[name] = img2;
return;
}
}
}
img->grab(); img->grab();
m_images[name] = img; m_images[name] = img;
} }
@ -725,7 +735,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im
assert(get_current_thread_id() == m_main_thread); assert(get_current_thread_id() == m_main_thread);
m_sourcecache.insert(name, img, false); m_sourcecache.insert(name, img, true, m_device->getVideoDriver());
} }
void TextureSource::rebuildImagesAndTextures() void TextureSource::rebuildImagesAndTextures()