#include "constants.h"
#include "utility.h"
#include "environment.h"
+#include "tile.h"
/*
ClientActiveObject
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
buf->getMaterial().setTexture
- (0, driver->getTexture(porting::getDataPath("rat.png").c_str()));
+ (0, driver->getTexture(getTexturePath("rat.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
//buf->getMaterial().setTexture(0, NULL);
// Initialize with the stick texture
buf->getMaterial().setTexture
- (0, driver->getTexture(porting::getDataPath("stick.png").c_str()));
+ (0, driver->getTexture(getTexturePath("stick.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
//buf->getMaterial().setTexture(0, NULL);
buf->getMaterial().setTexture
- (0, driver->getTexture(porting::getDataPath("rat.png").c_str()));
+ (0, driver->getTexture(getTexturePath("rat.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
//buf->getMaterial().setTexture(0, NULL);
buf->getMaterial().setTexture
- (0, driver->getTexture(porting::getDataPath("oerkki1.png").c_str()));
+ (0, driver->getTexture(getTexturePath("oerkki1.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
*/
{
video::ITexture *heart_texture =
- driver->getTexture(porting::getDataPath("heart.png").c_str());
+ driver->getTexture(getTexturePath("heart.png").c_str());
v2s32 p = pos + v2s32(0, -20);
for(s32 i=0; i<halfheartcount/2; i++)
{
if(brightness >= 0.5)
{
skybox = smgr->addSkyBoxSceneNode(
- driver->getTexture(porting::getDataPath("skybox2.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox3.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()));
+ driver->getTexture(getTexturePath("skybox2.png").c_str()),
+ driver->getTexture(getTexturePath("skybox3.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()));
}
else if(brightness >= 0.2)
{
skybox = smgr->addSkyBoxSceneNode(
- driver->getTexture(porting::getDataPath("skybox2_dawn.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox3_dawn.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()));
+ driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
}
else
{
skybox = smgr->addSkyBoxSceneNode(
- driver->getTexture(porting::getDataPath("skybox2_night.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox3_night.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()));
+ driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
}
}
core::dimension2d<u32> screensize = driver->getScreenSize();\r
\r
video::ITexture *bgtexture =\r
- driver->getTexture(porting::getDataPath("mud.png").c_str());\r
+ driver->getTexture(getTexturePath("mud.png").c_str());\r
if(bgtexture)\r
{\r
s32 texturesize = 128;\r
}\r
\r
video::ITexture *logotexture =\r
- driver->getTexture(porting::getDataPath("menulogo.png").c_str());\r
+ driver->getTexture(getTexturePath("menulogo.png").c_str());\r
if(logotexture)\r
{\r
v2s32 logosize(logotexture->getOriginalSize().Width,\r
\r
guienv = device->getGUIEnvironment();\r
gui::IGUISkin* skin = guienv->getSkin();\r
- gui::IGUIFont* font = guienv->getFont(porting::getDataPath("fontlucida.png").c_str());\r
+ gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());\r
if(font)\r
skin->setFont(font);\r
else\r
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
buf->getMaterial().setTexture
- (0, driver->getTexture(porting::getDataPath("rat.png").c_str()));
+ (0, driver->getTexture(getTexturePath("rat.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
// Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
- buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player.png").c_str()));
+ buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
//buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
// Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
- buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player_back.png").c_str()));
+ buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player_back.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
buf->getMaterial().setTexture
- (0, driver->getTexture(porting::getDataPath("sign.png").c_str()));
+ (0, driver->getTexture(getTexturePath("sign.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
buf->getMaterial().setTexture
- (0, driver->getTexture(porting::getDataPath("sign_back.png").c_str()));
+ (0, driver->getTexture(getTexturePath("sign_back.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
"mineral_iron.png"
};
-//textureid_t mineral_textures[MINERAL_COUNT] = {0};
std::string mineral_textures[MINERAL_COUNT];
void init_mineral()
}
}
-//textureid_t mineral_block_texture(u8 mineral)
std::string mineral_block_texture(u8 mineral)
{
if(mineral >= MINERAL_COUNT)
#define MINERAL_HEADER
#include "inventory.h"
-#include "texture.h"
+#include "tile.h"
/*
Minerals
#define MINERAL_COUNT 3
-//textureid_t mineral_block_texture(u8 mineral);
std::string mineral_block_texture(u8 mineral);
inline CraftItem * getDiggedMineralItem(u8 mineral)
// Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
- buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player.png").c_str()));
+ buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
//buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
// Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
- buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player_back.png").c_str()));
+ buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player_back.png").c_str()));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+++ /dev/null
-/*
-Minetest-c55
-Copyright (C) 2010 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
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#ifndef TEXTURE_HEADER
-#define TEXTURE_HEADER
-
-// This file now contains all that was here
-#include "tile.h"
-
-// TODO: Remove this
-typedef u16 textureid_t;
-
-#if 0
-
-#include "common_irrlicht.h"
-//#include "utility.h"
-#include "debug.h"
-
-/*
- All textures are given a "texture id".
- 0 = nothing (a NULL pointer texture)
-*/
-typedef u16 textureid_t;
-
-/*
- Every texture in the game can be specified by this.
-
- It exists instead of specification strings because arbitary
- texture combinations for map nodes are handled using this,
- and strings are too slow for that purpose.
-
- Plain texture pointers are not used because they don't contain
- content information by themselves. A texture can be completely
- reconstructed by just looking at this, while this also is a
- fast unique key to containers.
-*/
-
-#define TEXTURE_SPEC_TEXTURE_COUNT 4
-
-struct TextureSpec
-{
- TextureSpec()
- {
- clear();
- }
-
- TextureSpec(textureid_t id0)
- {
- clear();
- tids[0] = id0;
- }
-
- TextureSpec(textureid_t id0, textureid_t id1)
- {
- clear();
- tids[0] = id0;
- tids[1] = id1;
- }
-
- void clear()
- {
- for(u32 i=0; i<TEXTURE_SPEC_TEXTURE_COUNT; i++)
- {
- tids[i] = 0;
- }
- }
-
- bool empty() const
- {
- for(u32 i=0; i<TEXTURE_SPEC_TEXTURE_COUNT; i++)
- {
- if(tids[i] != 0)
- return false;
- }
- return true;
- }
-
- void addTid(textureid_t tid)
- {
- for(u32 i=0; i<TEXTURE_SPEC_TEXTURE_COUNT; i++)
- {
- if(tids[i] == 0)
- {
- tids[i] = tid;
- return;
- }
- }
- // Too many textures
- assert(0);
- }
-
- bool operator==(const TextureSpec &other) const
- {
- for(u32 i=0; i<TEXTURE_SPEC_TEXTURE_COUNT; i++)
- {
- if(tids[i] != other.tids[i])
- return false;
- }
- return true;
- }
-
- bool operator<(const TextureSpec &other) const
- {
- for(u32 i=0; i<TEXTURE_SPEC_TEXTURE_COUNT; i++)
- {
- if(tids[i] >= other.tids[i])
- return false;
- }
- return true;
- }
-
- // Ids of textures. They are blit on each other.
- textureid_t tids[TEXTURE_SPEC_TEXTURE_COUNT];
-};
-
-#endif
-
-#endif
/*
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
#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.
-> 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;
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[] = {
/*
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),
/*
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
#include "utility.h"
#include <string>
+/*
+ tile.{h,cpp}: Texture handling stuff.
+*/
+
+/*
+ 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.
+*/
+std::string getTexturePath(const std::string &filename);
+
/*
Specifies a texture in an atlas.
core::list<Value> m_list;
};
-#if 0
+#if 1
template<typename Key, typename Value>
-class MutexedCache
+class MutexedMap
{
public:
- MutexedCache()
+ MutexedMap()
{
m_mutex.Init();
assert(m_mutex.IsInitialized());
if(n == NULL)
return false;
-
- *result = n->getValue();
+
+ if(result != NULL)
+ *result = n->getValue();
+
return true;
}