]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/tile.cpp
Use project name for mo files
[dragonfireclient.git] / src / tile.cpp
index 237491aa8fba286379ec21b6063afce31e8f86de..23fa1129da78bca05411aadacdacca0f2f99816e 100644 (file)
@@ -1,6 +1,6 @@
 /*
 Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -21,6 +21,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "debug.h"
 #include "main.h" // for g_settings
 #include "filesys.h"
+#include "utility.h"
+
+/*
+       A cache from texture name to texture path
+*/
+MutexedMap<std::string, std::string> g_texturename_to_path_cache;
 
 /*
        Replaces the filename extension.
@@ -30,8 +36,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                -> image = "a/image.jpg"
        Returns true on success.
 */
-inline bool replace_ext(std::string &path, const char *ext)
+static bool replace_ext(std::string &path, const char *ext)
 {
+       if(ext == NULL)
+               return false;
        // Find place of last dot, fail if \ or / found.
        s32 last_dot_i = -1;
        for(s32 i=path.size()-1; i>=0; i--)
@@ -59,11 +67,11 @@ inline bool replace_ext(std::string &path, const char *ext)
 
        If failed, return "".
 */
-inline std::string getImagePath(std::string path)
+static std::string getImagePath(std::string path)
 {
        // A NULL-ended list of possible image extensions
        const char *extensions[] = {
-               "png", "jpg", "bmp", "tga", "bmp",
+               "png", "jpg", "bmp", "tga",
                "pcx", "ppm", "psd", "wal", "rgb",
                NULL
        };
@@ -84,25 +92,55 @@ inline std::string getImagePath(std::string path)
 /*
        Gets the path to a texture by first checking if the texture exists
        in texture_path and if not, using the data path.
+
+       Checks all supported extensions by replacing the original extension.
+
+       If not found, returns "".
+
+       Utilizes a thread-safe cache.
 */
-inline std::string getTexturePath(std::string filename)
+std::string getTexturePath(const std::string &filename)
 {
+       std::string fullpath = "";
+       /*
+               Check from cache
+       */
+       bool incache = g_texturename_to_path_cache.get(filename, &fullpath);
+       if(incache)
+               return fullpath;
+       
+       /*
+               Check from texture_path
+       */
        std::string texture_path = g_settings.get("texture_path");
        if(texture_path != "")
        {
-               std::string fullpath = texture_path + '/' + filename;
-               // Check all filename extensions
-               fullpath = getImagePath(fullpath);
-               // If found, return it
-               if(fullpath != "")
-                       return fullpath;
+               std::string testpath = texture_path + '/' + filename;
+               // Check all filename extensions. Returns "" if not found.
+               fullpath = getImagePath(testpath);
        }
-       std::string fullpath = porting::getDataPath(filename.c_str());
-       // Check all filename extensions
-       fullpath = getImagePath(fullpath);
+       
+       /*
+               Check from default data directory
+       */
+       if(fullpath == "")
+       {
+               std::string testpath = porting::getDataPath(filename.c_str());
+               // Check all filename extensions. Returns "" if not found.
+               fullpath = getImagePath(testpath);
+       }
+       
+       // Add to cache (also an empty result is cached)
+       g_texturename_to_path_cache.set(filename, fullpath);
+       
+       // Finally return it
        return fullpath;
 }
 
+/*
+       TextureSource
+*/
+
 TextureSource::TextureSource(IrrlichtDevice *device):
                m_device(device),
                m_main_atlas_image(NULL),
@@ -474,7 +512,11 @@ void TextureSource::buildMainAtlas()
        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("stone.png^mineral_coal.png");
        sourcelist.push_back("stone.png^mineral_iron.png");
@@ -484,7 +526,7 @@ void TextureSource::buildMainAtlas()
        sourcelist.push_back("sand.png^mineral_iron.png");
        
        // Padding to disallow texture bleeding
-       s32 padding = 8;
+       s32 padding = 16;
 
        /*
                First pass: generate almost everything
@@ -1098,6 +1140,8 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
                        /*scene::ILightSceneNode *light =*/ smgr->addLightSceneNode(0,
                                        v3f(-50, 100, 0), video::SColorf(0.5,0.5,0.5), 1000);
 
+                       smgr->setAmbientLight(video::SColorf(0.2,0.2,0.2));
+
                        // Render scene
                        driver->beginScene(true, true, video::SColor(0,0,0,0));
                        smgr->drawAll();