diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 0c6b96933..d750f3a92 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -39,7 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., /* A cache from texture name to texture path */ -MutexedMap g_texturename_to_path_cache; +static MutexedMap g_texturename_to_path_cache; /* Replaces the filename extension. @@ -186,11 +186,11 @@ struct TextureInfo TextureInfo( const std::string &name_, video::ITexture *texture_, - std::set &sourceImages_ + std::set &&sourceImages_ ): name(name_), texture(texture_), - sourceImages(sourceImages_) + sourceImages(std::move(sourceImages_)) { } }; @@ -487,8 +487,6 @@ TextureSource::~TextureSource() u32 TextureSource::getTextureId(const std::string &name) { - //infostream<<"getTextureId(): \""<::iterator n; - n = m_name_to_id.find(name); + auto n = m_name_to_id.find(name); if (n != m_name_to_id.end()) { return n->second; } @@ -661,8 +656,8 @@ u32 TextureSource::generateTexture(const std::string &name) MutexAutoLock lock(m_textureinfo_cache_mutex); u32 id = m_textureinfo_cache.size(); - TextureInfo ti(name, tex, source_image_names); - m_textureinfo_cache.push_back(ti); + TextureInfo ti(name, tex, std::move(source_image_names)); + m_textureinfo_cache.emplace_back(std::move(ti)); m_name_to_id[name] = id; return id; @@ -780,19 +775,12 @@ void TextureSource::processQueue() GetRequest request = m_get_texture_queue.pop(); - /*infostream<<"TextureSource::processQueue(): " - <<"got texture request with " - <<"name=\""<= 0xffff || (h) >= 0xffff) { \ + errorstream << "generateImagePart(): invalid width or height " \ + << "for part_of_name=\"" << part_of_name \ + << "\", cancelling." << std::endl; \ + return false; \ + } \ + } while(0) + bool TextureSource::generateImagePart(std::string part_of_name, video::IImage *& baseimg, std::set &source_image_names) { @@ -1210,28 +1217,16 @@ bool TextureSource::generateImagePart(std::string part_of_name, } // Just create a dummy image - //core::dimension2d dim(2,2); core::dimension2d dim(1,1); image = driver->createImage(video::ECF_A8R8G8B8, dim); sanity_check(image != NULL); - /*image->setPixel(0,0, video::SColor(255,255,0,0)); - image->setPixel(1,0, video::SColor(255,0,255,0)); - image->setPixel(0,1, video::SColor(255,0,0,255)); - image->setPixel(1,1, video::SColor(255,255,0,255));*/ image->setPixel(0,0, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); - /*image->setPixel(1,0, video::SColor(255,myrand()%256, - myrand()%256,myrand()%256)); - image->setPixel(0,1, video::SColor(255,myrand()%256, - myrand()%256,myrand()%256)); - image->setPixel(1,1, video::SColor(255,myrand()%256, - myrand()%256,myrand()%256));*/ } // If base image is NULL, load as base. if (baseimg == NULL) { - //infostream<<"Setting "<drop(); } else { // A special texture modification - /*infostream<<"generateImage(): generating special " - <<"modification \""<]:: @@ -1318,6 +1304,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, sf.next(":"); u32 w0 = stoi(sf.next("x")); u32 h0 = stoi(sf.next(":")); + CHECK_DIM(w0, h0); core::dimension2d dim(w0,h0); if (baseimg == NULL) { baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); @@ -1338,10 +1325,6 @@ bool TextureSource::generateImagePart(std::string part_of_name, driver->createImage(video::ECF_A8R8G8B8, dim); img->copyTo(img2); img->drop(); - /*img2->copyToWithAlpha(baseimg, pos_base, - core::rect(v2s32(0,0), dim), - video::SColor(255,255,255,255), - NULL);*/ blit_with_alpha(img2, baseimg, v2s32(0,0), pos_base, dim); img2->drop(); } else { @@ -1378,6 +1361,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, } core::dimension2d dim(width, height); + CHECK_DIM(dim.Width, dim.Height); video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim); img->fill(color); @@ -1393,12 +1377,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, */ else if (str_starts_with(part_of_name, "[brighten")) { - if (baseimg == NULL) { - errorstream<<"generateImagePart(): baseimg==NULL " - <<"for part_of_name=\""< dim = baseimg->getDimension(); // Set alpha to full @@ -1435,12 +1408,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, */ else if (str_starts_with(part_of_name, "[makealpha:")) { - if (baseimg == NULL) { - errorstream<<"generateImagePart(): baseimg == NULL " - <<"for part_of_name=\""< dim = baseimg->getDimension(); - /*video::IImage *oldbaseimg = baseimg; - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - oldbaseimg->copyTo(baseimg); - oldbaseimg->drop();*/ - - // Set alpha to full for (u32 y=0; y dim = imageTransformDimension( @@ -1517,7 +1474,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, */ else if (str_starts_with(part_of_name, "[inventorycube")) { - if (baseimg != NULL){ + if (baseimg) { errorstream<<"generateImagePart(): baseimg != NULL " <<"for part_of_name=\""<getDimension(); frame_size.Y /= frame_count; video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, frame_size); - if (!img){ - errorstream<<"generateImagePart(): Could not create image " - <<"for part_of_name=\""<fill(video::SColor(0,0,0,0)); @@ -1645,12 +1591,8 @@ bool TextureSource::generateImagePart(std::string part_of_name, */ else if (str_starts_with(part_of_name, "[mask:")) { - if (baseimg == NULL) { - errorstream << "generateImage(): baseimg == NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); + Strfnd sf(part_of_name); sf.next(":"); std::string filename = unescape_string(sf.next_esc(":", escape), escape); @@ -1681,12 +1623,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, sf.next(":"); std::string color_str = sf.next(":"); - if (baseimg == NULL) { - errorstream << "generateImagePart(): baseimg != NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); video::SColor color; @@ -1712,12 +1649,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, std::string color_str = sf.next(":"); std::string ratio_str = sf.next(":"); - if (baseimg == NULL) { - errorstream << "generateImagePart(): baseimg != NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); video::SColor color; int ratio = -1; @@ -1742,12 +1674,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, /* IMPORTANT: When changing this, getTextureForMesh() needs to be * updated too. */ - if (!baseimg) { - errorstream << "generateImagePart(): baseimg == NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); // Apply the "clean transparent" filter, if needed if (m_setting_mipmap || m_setting_bilinear_filter || @@ -1769,12 +1696,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, * equal to the target minimum. If e.g. this is a vertical frames * animation, the short dimension will be the real size. */ - if (dim.Width == 0 || dim.Height == 0) { - errorstream << "generateImagePart(): Illegal 0 dimension " - << "for part_of_name=\""<< part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_DIM(dim.Width, dim.Height); u32 xscale = scaleto / dim.Width; u32 yscale = scaleto / dim.Height; const s32 scale = std::max(xscale, yscale); @@ -1798,21 +1720,16 @@ bool TextureSource::generateImagePart(std::string part_of_name, */ else if (str_starts_with(part_of_name, "[resize")) { - if (baseimg == NULL) { - errorstream << "generateImagePart(): baseimg == NULL " - << "for part_of_name=\""<< part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); Strfnd sf(part_of_name); sf.next(":"); u32 width = stoi(sf.next("x")); u32 height = stoi(sf.next("")); - core::dimension2d dim(width, height); + CHECK_DIM(width, height); video::IImage *image = RenderingEngine::get_video_driver()-> - createImage(video::ECF_A8R8G8B8, dim); + createImage(video::ECF_A8R8G8B8, {width, height}); baseimg->copyToScaling(image); baseimg->drop(); baseimg = image; @@ -1825,12 +1742,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, 255 means totally opaque. */ else if (str_starts_with(part_of_name, "[opacity:")) { - if (baseimg == NULL) { - errorstream << "generateImagePart(): baseimg == NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); Strfnd sf(part_of_name); sf.next(":"); @@ -1855,12 +1767,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, will be inverted. */ else if (str_starts_with(part_of_name, "[invert:")) { - if (baseimg == NULL) { - errorstream << "generateImagePart(): baseimg == NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); Strfnd sf(part_of_name); sf.next(":"); @@ -1892,13 +1799,8 @@ bool TextureSource::generateImagePart(std::string part_of_name, from the base image it assumes to be a tilesheet with dimensions W,H (in tiles). */ - else if (part_of_name.substr(0,7) == "[sheet:") { - if (baseimg == NULL) { - errorstream << "generateImagePart(): baseimg != NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + else if (str_starts_with(part_of_name, "[sheet:")) { + CHECK_BASEIMG(); Strfnd sf(part_of_name); sf.next(":"); @@ -1907,24 +1809,13 @@ bool TextureSource::generateImagePart(std::string part_of_name, u32 x0 = stoi(sf.next(",")); u32 y0 = stoi(sf.next(":")); - if (w0 == 0 || h0 == 0) { - errorstream << "generateImagePart(): invalid width or height " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_DIM(w0, h0); core::dimension2d img_dim = baseimg->getDimension(); core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); video::IImage *img = driver->createImage( video::ECF_A8R8G8B8, tile_dim); - if (!img) { - errorstream << "generateImagePart(): Could not create image " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } img->fill(video::SColor(0,0,0,0)); v2u32 vdim(tile_dim); @@ -1996,12 +1887,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, else if (str_starts_with(part_of_name, "[hsl:") || str_starts_with(part_of_name, "[colorizehsl:")) { - if (baseimg == nullptr) { - errorstream << "generateImagePart(): baseimg == NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); bool colorize = str_starts_with(part_of_name, "[colorizehsl:"); @@ -2038,12 +1924,8 @@ bool TextureSource::generateImagePart(std::string part_of_name, else if (str_starts_with(part_of_name, "[overlay:") || str_starts_with(part_of_name, "[hardlight:")) { - if (baseimg == nullptr) { - errorstream << "generateImage(): baseimg == NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); + Strfnd sf(part_of_name); sf.next(":"); std::string filename = unescape_string(sf.next_esc(":", escape), escape); @@ -2072,12 +1954,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, */ else if (str_starts_with(part_of_name, "[contrast:")) { - if (baseimg == nullptr) { - errorstream << "generateImagePart(): baseimg == NULL " - << "for part_of_name=\"" << part_of_name - << "\", cancelling." << std::endl; - return false; - } + CHECK_BASEIMG(); Strfnd sf(part_of_name); sf.next(":"); @@ -2105,7 +1982,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, pixel with alpha=64 drawn atop a pixel with alpha=128 should yield a pixel with alpha=160, while getInterpolated would yield alpha=96. */ -static inline video::SColor blitPixel(const video::SColor &src_c, const video::SColor &dst_c, u32 ratio) +static inline video::SColor blitPixel(const video::SColor src_c, const video::SColor dst_c, u32 ratio) { if (dst_c.getAlpha() == 0) return src_c; @@ -2198,7 +2075,7 @@ static void blit_with_interpolate_overlay(video::IImage *src, video::IImage *dst Apply color to destination, using a weighted interpolation blend */ static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor &color, int ratio, bool keep_alpha) + const video::SColor color, int ratio, bool keep_alpha) { u32 alpha = color.getAlpha(); video::SColor dst_c; @@ -2236,7 +2113,7 @@ static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, Apply color to destination, using a Multiply blend mode */ static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor &color) + const video::SColor color) { video::SColor dst_c; @@ -2257,7 +2134,7 @@ static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, Apply color to destination, using a Screen blend mode */ static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor &color) + const video::SColor color) { video::SColor dst_c; @@ -2479,7 +2356,7 @@ video::IImage *create_crack_image(video::IImage *crack, s32 frame_index, core::rect frame(v2s32(0, frame_index * frame_size.Height), frame_size); video::IImage *result = nullptr; -// extract crack frame + // extract crack frame video::IImage *crack_tile = driver->createImage(video::ECF_A8R8G8B8, tile_size); if (!crack_tile) return nullptr; @@ -2496,7 +2373,7 @@ video::IImage *create_crack_image(video::IImage *crack, s32 frame_index, if (tiles == 1) return crack_tile; -// tile it + // tile it result = driver->createImage(video::ECF_A8R8G8B8, size); if (!result) goto exit__has_tile; @@ -2700,7 +2577,7 @@ namespace { return v / 12.92f; } - v3f srgb_to_linear(const video::SColor &col_srgb) + v3f srgb_to_linear(const video::SColor col_srgb) { v3f col(col_srgb.getRed(), col_srgb.getGreen(), col_srgb.getBlue()); col /= 255.0f; @@ -2710,7 +2587,7 @@ namespace { return col; } - video::SColor linear_to_srgb(const v3f &col_linear) + video::SColor linear_to_srgb(const v3f col_linear) { v3f col; col.X = linear_to_srgb_component(col_linear.X);