X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftile.cpp;h=aea9665f5eb69ca3568c12447538a81e7a1b8771;hb=2bb559be826f4f82b56fb7916e206df55337c258;hp=6dbe4c63a606b29ba6b8cef22b8816ebf7e373c6;hpb=48790c0751cb43d45ba5efb33557de8b213d6111;p=minetest.git diff --git a/src/tile.cpp b/src/tile.cpp index 6dbe4c63a..aea9665f5 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1,6 +1,6 @@ /* -Minetest-c55 -Copyright (C) 2010-2011 celeron55, Perttu Ahola +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -206,10 +206,10 @@ class SourceImageCache { assert(img); // Remove old image - core::map::Node *n; + std::map::iterator n; n = m_images.find(name); - if(n){ - video::IImage *oldimg = n->getValue(); + if(n != m_images.end()){ + video::IImage *oldimg = n->second; if(oldimg) oldimg->drop(); } @@ -229,20 +229,20 @@ class SourceImageCache } video::IImage* get(const std::string &name) { - core::map::Node *n; + std::map::iterator n; n = m_images.find(name); - if(n) - return n->getValue(); + if(n != m_images.end()) + return n->second; return NULL; } // Primarily fetches from cache, secondarily tries to read from filesystem video::IImage* getOrLoad(const std::string &name, IrrlichtDevice *device) { - core::map::Node *n; + std::map::iterator n; n = m_images.find(name); - if(n){ - n->getValue()->grab(); // Grab for caller - return n->getValue(); + if(n != m_images.end()){ + n->second->grab(); // Grab for caller + return n->second; } video::IVideoDriver* driver = device->getVideoDriver(); std::string path = getTexturePath(name.c_str()); @@ -263,7 +263,7 @@ class SourceImageCache return img; } private: - core::map m_images; + std::map m_images; }; /* @@ -372,6 +372,18 @@ class TextureSource : public IWritableTextureSource // Update new texture pointer and texture coordinates to an // AtlasPointer based on it's texture id void updateAP(AtlasPointer &ap); + + bool isKnownSourceImage(const std::string &name) + { + bool is_known = false; + bool cache_found = m_source_image_existence.get(name, &is_known); + if(cache_found) + return is_known; + // Not found in cache; find out if a local file exists + is_known = (getTexturePath(name) != ""); + m_source_image_existence.set(name, is_known); + return is_known; + } // Processes queued texture requests from other threads. // Shall be called from the main thread. @@ -400,11 +412,14 @@ class TextureSource : public IWritableTextureSource // This should be only accessed from the main thread SourceImageCache m_sourcecache; + // Thread-safe cache of what source images are known (true = known) + MutexedMap m_source_image_existence; + // A texture id is index in this array. // The first position contains a NULL texture. - core::array m_atlaspointer_cache; + std::vector m_atlaspointer_cache; // Maps a texture name to an index in the former. - core::map m_name_to_id; + std::map m_name_to_id; // The two former containers are behind this mutex JMutex m_atlaspointer_cache_mutex; @@ -450,11 +465,11 @@ u32 TextureSource::getTextureId(const std::string &name) See if texture already exists */ JMutexAutoLock lock(m_atlaspointer_cache_mutex); - core::map::Node *n; + std::map::iterator n; n = m_name_to_id.find(name); - if(n != NULL) + if(n != m_name_to_id.end()) { - return n->getValue(); + return n->second; } } @@ -564,13 +579,13 @@ u32 TextureSource::getTextureIdDirect(const std::string &name) { JMutexAutoLock lock(m_atlaspointer_cache_mutex); - core::map::Node *n; + std::map::iterator n; n = m_name_to_id.find(name); - if(n != NULL) + if(n != m_name_to_id.end()) { /*infostream<<"getTextureIdDirect(): \""<getValue(); + return n->second; } } @@ -709,7 +724,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name) baseimg_dim = baseimg->getDimension(); SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg_dim); m_atlaspointer_cache.push_back(nap); - m_name_to_id.insert(name, id); + m_name_to_id[name] = id; /*infostream<<"getTextureIdDirect(): " <<"Returning id="< 0) + if(!m_get_texture_queue.empty()) { GetRequest request = m_get_texture_queue.pop(); @@ -781,6 +796,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im assert(get_current_thread_id() == m_main_thread); m_sourcecache.insert(name, img, true, m_device->getVideoDriver()); + m_source_image_existence.set(name, true); } void TextureSource::rebuildImagesAndTextures() @@ -856,7 +872,7 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef) main content features */ - core::map sourcelist; + std::set sourcelist; for(u16 j=0; j::Iterator - i = sourcelist.getIterator(); - i.atEnd() == false; i++) + for(std::set::iterator + i = sourcelist.begin(); + i != sourcelist.end(); ++i) { - std::string name = i.getNode()->getKey(); + std::string name = *i; infostream<<"\""<::Iterator - i = sourcelist.getIterator(); - i.atEnd() == false; i++) + for(std::set::iterator + i = sourcelist.begin(); + i != sourcelist.end(); ++i) { - std::string name = i.getNode()->getKey(); + std::string name = *i; // Generate image by name video::IImage *img2 = generate_image_from_scratch(name, m_device, @@ -1010,11 +1026,11 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef) bool reuse_old_id = false; u32 id = m_atlaspointer_cache.size(); // Check old id without fetching a texture - core::map::Node *n; + std::map::iterator n; n = m_name_to_id.find(name); // If it exists, we will replace the old definition - if(n){ - id = n->getValue(); + if(n != m_name_to_id.end()){ + id = n->second; reuse_old_id = true; /*infostream<<"TextureSource::buildMainAtlas(): " <<"Replacing old AtlasPointer"<::Iterator - i = sourcelist.getIterator(); - i.atEnd() == false; i++) + for(std::set::iterator + i = sourcelist.begin(); + i != sourcelist.end(); ++i) { - std::string name = i.getNode()->getKey(); - if(m_name_to_id.find(name) == NULL) + std::string name = *i; + if(m_name_to_id.find(name) == m_name_to_id.end()) continue; u32 id = m_name_to_id[name]; //infostream<<"id of name "< pos_from(0,0); // Blit - image->copyToWithAlpha(baseimg, pos_to, + /*image->copyToWithAlpha(baseimg, pos_to, core::rect(pos_from, dim), video::SColor(255,255,255,255), - NULL); + NULL);*/ + blit_with_alpha(image, baseimg, pos_from, pos_to, dim); // Drop image image->drop(); } @@ -1344,7 +1361,11 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, u32 h0 = stoi(sf.next(":")); infostream<<"combined w="<createImage(video::ECF_A8R8G8B8, dim); img->copyTo(img2); img->drop(); - img2->copyToWithAlpha(baseimg, pos_base, + /*img2->copyToWithAlpha(baseimg, pos_base, core::rect(v2s32(0,0), dim), video::SColor(255,255,255,255), - NULL); + NULL);*/ + blit_with_alpha(img2, baseimg, v2s32(0,0), pos_base, dim); img2->drop(); } else