X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftile.cpp;h=7cad1b83692399392cacbf6ede423d0c543fc014;hb=d5029958b9017ad89775bc4f68c4de3db603e618;hp=e676c56c438c8eb54859e2d4ae1db0d7c22f1aeb;hpb=a0b5605db8ba7f36d868491d2a2274d2bbd8aec5;p=oweals%2Fminetest.git diff --git a/src/tile.cpp b/src/tile.cpp index e676c56c4..7cad1b836 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -372,6 +372,18 @@ public: // 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,6 +412,9 @@ private: // 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; @@ -518,15 +533,6 @@ core::dimension2d imageTransformDimension(u32 transform, core::dimension2d< // Apply transform to image data void imageTransform(u32 transform, video::IImage *src, video::IImage *dst); -/* - Adds a new texture to the video driver and returns a pointer to it. - This pointer should not be dropped. Any texture that was registered - with that name before is removed (this may invalidate some ITexture - pointers). -*/ -video::ITexture* register_texture(video::IVideoDriver *driver, - std::string name, video::IImage *img); - /* Generate image based on a string like "stone.png" or "[crack0". if baseimg is NULL, it is created. Otherwise stuff is made on it. @@ -695,9 +701,11 @@ u32 TextureSource::getTextureIdDirect(const std::string &name) " create texture \""<addTexture(name.c_str(), baseimg); + } /* Add texture to caches (add NULL textures too) @@ -788,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() @@ -816,7 +825,7 @@ void TextureSource::rebuildImagesAndTextures() // Create texture from resulting image video::ITexture *t = NULL; if(img) - t = register_texture(driver, sap->name, img); + t = driver->addTexture(sap->name.c_str(), img); // Replace texture sap->a.atlas = t; @@ -1051,7 +1060,7 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef) /* Make texture */ - video::ITexture *t = register_texture(driver, "__main_atlas__", atlas_img); + video::ITexture *t = driver->addTexture("__main_atlas__", atlas_img); assert(t); /* @@ -1142,15 +1151,6 @@ video::IImage* generate_image_from_scratch(std::string name, return baseimg; } -video::ITexture* register_texture(video::IVideoDriver *driver, - std::string name, video::IImage *img) -{ - video::ITexture *old_texture = driver->findTexture(name.c_str()); - if(old_texture) - driver->removeTexture(old_texture); - return driver->addTexture(name.c_str(), img); -} - bool generate_image(std::string part_of_name, video::IImage *& baseimg, IrrlichtDevice *device, SourceImageCache *sourcecache) { @@ -1557,12 +1557,12 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, assert(img_top && img_left && img_right); // Create textures from images - video::ITexture *texture_top = register_texture(driver, - imagename_top + "__temp1__", img_top); - video::ITexture *texture_left = register_texture(driver, - imagename_left + "__temp2__", img_left); - video::ITexture *texture_right = register_texture(driver, - imagename_right + "__temp3__", img_right); + video::ITexture *texture_top = driver->addTexture( + (imagename_top + "__temp__").c_str(), img_top); + video::ITexture *texture_left = driver->addTexture( + (imagename_left + "__temp__").c_str(), img_left); + video::ITexture *texture_right = driver->addTexture( + (imagename_right + "__temp__").c_str(), img_right); assert(texture_top && texture_left && texture_right); // Drop images