X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftile.cpp;h=366f2dfb798d6b66b54115d74deb9c3dbcb9279a;hb=fe98fe342a65c995bbc59470549417f38311366b;hp=d4244bd42045aa475c8ad1095da1ececa7b29b6f;hpb=310fa10035568f517de0f45ff5dfa544bbdfe9de;p=minetest.git diff --git a/src/tile.cpp b/src/tile.cpp index d4244bd42..366f2dfb7 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -22,6 +22,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "main.h" // for g_settings #include "filesys.h" #include "utility.h" +#include "settings.h" +#include +#include "log.h" +#include "mapnode.h" // For texture atlas making +#include "mineral.h" // For texture atlas making /* A cache from texture name to texture path @@ -112,10 +117,10 @@ std::string getTexturePath(const std::string &filename) /* Check from texture_path */ - std::string texture_path = g_settings.get("texture_path"); + std::string texture_path = g_settings->get("texture_path"); if(texture_path != "") { - std::string testpath = texture_path + '/' + filename; + std::string testpath = texture_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. fullpath = getImagePath(testpath); } @@ -157,10 +162,10 @@ TextureSource::TextureSource(IrrlichtDevice *device): m_name_to_id[""] = 0; // Build main texture atlas - if(g_settings.getBool("enable_texture_atlas")) + if(g_settings->getBool("enable_texture_atlas")) buildMainAtlas(); else - dstream<<"INFO: Not building texture atlas."< request = m_get_texture_queue.pop(); - dstream<<"INFO: TextureSource::processQueue(): " + infostream<<"TextureSource::processQueue(): " <<"got texture request with " <<"name=\""< result_queue; @@ -226,7 +231,7 @@ u32 TextureSource::getTextureId(const std::string &name) // Throw a request in m_get_texture_queue.add(name, 0, 0, &result_queue); - dstream<<"INFO: Waiting for texture from main thread, name=\"" + infostream<<"Waiting for texture from main thread, name=\"" <getValue(); } } - dstream<<"INFO: getTextureIdDirect(): \""<(pos_from, dim) // from ); - /*dstream<<"INFO: getTextureIdDirect(): Loaded \"" + /*infostream<<"getTextureIdDirect(): Loaded \"" <= m_atlaspointer_cache.size()) { - dstream<<"WARNING: TextureSource::getTextureName(): id="<= m_atlaspointer_cache.size()=" < sourcelist; - - sourcelist.push_back("stone.png"); - sourcelist.push_back("mud.png"); - sourcelist.push_back("sand.png"); - sourcelist.push_back("grass.png"); - sourcelist.push_back("grass_footsteps.png"); - sourcelist.push_back("tree.png"); - sourcelist.push_back("tree_top.png"); - sourcelist.push_back("water.png"); - sourcelist.push_back("leaves.png"); - sourcelist.push_back("glass.png"); - sourcelist.push_back("mud.png^grass_side.png"); - sourcelist.push_back("cobble.png"); - sourcelist.push_back("mossycobble.png"); - sourcelist.push_back("gravel.png"); - sourcelist.push_back("jungletree.png"); - - sourcelist.push_back("stone.png^mineral_coal.png"); - sourcelist.push_back("stone.png^mineral_iron.png"); + core::map sourcelist; + + for(u16 j=0; j::Iterator + i = f->used_texturenames.getIterator(); + i.atEnd() == false; i++) + { + std::string name = i.getNode()->getKey(); + sourcelist[name] = true; + + if(f->often_contains_mineral){ + for(int k=1; k::Iterator + i = sourcelist.getIterator(); + i.atEnd() == false; i++) + { + std::string name = i.getNode()->getKey(); + infostream<<"\""< pos_in_atlas(0,0); - pos_in_atlas.Y += padding; + pos_in_atlas.Y = padding; - for(u32 i=0; i::Iterator + i = sourcelist.getIterator(); + i.atEnd() == false; i++) { - std::string name = sourcelist[i]; + std::string name = i.getNode()->getKey(); /*video::IImage *img = driver->createImageFromFile( getTexturePath(name.c_str()).c_str()); @@ -559,7 +582,7 @@ void TextureSource::buildMainAtlas() video::IImage *img2 = generate_image_from_scratch(name, m_device); if(img2 == NULL) { - dstream<<"WARNING: TextureSource::buildMainAtlas(): Couldn't generate texture atlas: Couldn't generate image \""< max_size_in_atlas.Width || dim.Height > max_size_in_atlas.Height) { - dstream<<"INFO: TextureSource::buildMainAtlas(): Not adding " + infostream<<"TextureSource::buildMainAtlas(): Not adding " <<"\""< atlas_dim.Height) { - dstream<<"WARNING: TextureSource::buildMainAtlas(): " - <<"Atlas is full, not adding more textures." - < (s32)atlas_dim.Width - 256 - padding){ + errorstream<<"TextureSource::buildMainAtlas(): " + <<"Atlas is full, not adding more textures." + < 16) // Limit to 16 (more gives no benefit) + xwise_tiling = 16; for(u32 j=0; jgetPixel(x, src_y); atlas_img->setPixel(x,dst_y,c); } @@ -657,27 +686,33 @@ void TextureSource::buildMainAtlas() /* Second pass: set texture pointer in generated AtlasPointers */ - for(u32 i=0; i::Iterator + i = sourcelist.getIterator(); + i.atEnd() == false; i++) { - std::string name = sourcelist[i]; + std::string name = i.getNode()->getKey(); if(m_name_to_id.find(name) == NULL) continue; u32 id = m_name_to_id[name]; - //dstream<<"id of name "<writeImageToFile(atlas_img, - getTexturePath("main_atlas.png").c_str());*/ + /*std::string atlaspath = porting::path_userdata + + DIR_DELIM + "generated_texture_atlas.png"; + infostream<<"Removing and writing texture atlas for inspection to " + <writeImageToFile(atlas_img, atlaspath.c_str());*/ } video::IImage* generate_image_from_scratch(std::string name, IrrlichtDevice *device) { - /*dstream<<"INFO: generate_image_from_scratch(): " + /*infostream<<"generate_image_from_scratch(): " "\""<getVideoDriver(); @@ -702,7 +737,7 @@ video::IImage* generate_image_from_scratch(std::string name, } } - /*dstream<<"INFO: generate_image_from_scratch(): " + /*infostream<<"generate_image_from_scratch(): " <<"last_separator_position="<createImageFromFile(path.c_str()); if(image == NULL) { - dstream<<"WARNING: generate_image(): Could not load image \"" + infostream<<"generate_image(): Could not load image \"" < dim = image->getDimension(); //core::dimension2d dim(16,16); @@ -825,7 +860,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, { // A special texture modification - dstream<<"INFO: generate_image(): generating special " + infostream<<"generate_image(): generating special " <<"modification \""<createImageFromFile( @@ -958,7 +993,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, if(img) { core::dimension2d dim = img->getDimension(); - dstream<<"INFO: Size "< pos_base(x, y); video::IImage *img2 = @@ -973,7 +1008,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, } else { - dstream<<"WARNING: img==NULL"<createImageFromFile(path.c_str()); if(image == NULL) { - dstream<<"WARNING: generate_image(): Loading path \"" + infostream<<"generate_image(): Loading path \"" <drop(); } } + /* + "[makealpha:R,G,B:filename.png" + Use an image with converting one color to transparent. + */ + else if(part_of_name.substr(0,11) == "[makealpha:") + { + if(baseimg != NULL) + { + infostream<<"generate_image(): baseimg!=NULL " + <<"for part_of_name=\""<createImageFromFile(path.c_str()); + + if(image == NULL) + { + infostream<<"generate_image(): Loading path \"" + < dim = image->getDimension(); + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + + // Blit + image->copyTo(baseimg); + + image->drop(); + + for(u32 y=0; ygetPixel(x,y); + u32 r = c.getRed(); + u32 g = c.getGreen(); + u32 b = c.getBlue(); + if(!(r == r1 && g == g1 && b == b1)) + continue; + c.setAlpha(0); + baseimg->setPixel(x,y,c); + } + } + } + /* + "[makealpha2:R,G,B;R2,G2,B2:filename.png" + Use an image with converting two colors to transparent. + */ + else if(part_of_name.substr(0,12) == "[makealpha2:") + { + if(baseimg != NULL) + { + infostream<<"generate_image(): baseimg!=NULL " + <<"for part_of_name=\""<createImageFromFile(path.c_str()); + + if(image == NULL) + { + infostream<<"generate_image(): Loading path \"" + < dim = image->getDimension(); + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + + // Blit + image->copyTo(baseimg); + + image->drop(); + + for(u32 y=0; ygetPixel(x,y); + u32 r = c.getRed(); + u32 g = c.getGreen(); + u32 b = c.getBlue(); + if(!(r == r1 && g == g1 && b == b1) && + !(r == r2 && g == g2 && b == b2)) + continue; + c.setAlpha(0); + baseimg->setPixel(x,y,c); + } + } + } /* [inventorycube{topimage{leftimage{rightimage In every subimage, replace ^ with &. @@ -1056,7 +1207,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, { if(baseimg != NULL) { - dstream<<"WARNING: generate_image(): baseimg!=NULL " + infostream<<"generate_image(): baseimg!=NULL " <<"for part_of_name=\""<queryFeature(video::EVDF_RENDER_TO_TARGET) == false) { - dstream<<"WARNING: generate_image(): EVDF_RENDER_TO_TARGET" + infostream<<"generate_image(): EVDF_RENDER_TO_TARGET" " not supported. Creating fallback image"<