diff --git a/README.txt b/README.txt index 8224047..f283b1b 100644 --- a/README.txt +++ b/README.txt @@ -253,6 +253,7 @@ distribution. Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) http://creativecommons.org/licenses/by-sa/3.0/ + License of Minetest-c55 source code ----------------------------------- @@ -372,3 +373,8 @@ DejaVu Sans Mono: Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved. +Additional media attributions +----------------------------- + +Antonio Arjona Melches: Pteranodon model and texture + diff --git a/models/README.txt b/models/README.txt deleted file mode 100644 index f31f2df..0000000 --- a/models/README.txt +++ /dev/null @@ -1 +0,0 @@ -Note: models uploaded here are by tonyka. Proper attribution will be done soon! diff --git a/models/pteranodon.md2 b/models/all/pteranodon.md2 similarity index 100% rename from models/pteranodon.md2 rename to models/all/pteranodon.md2 diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index a9c0de6..047c6e1 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -88,6 +88,7 @@ void set_default_settings(Settings *settings) settings->setDefault("smooth_lighting", "true"); settings->setDefault("enable_texture_atlas", "true"); settings->setDefault("texture_path", ""); + settings->setDefault("model_path", ""); settings->setDefault("video_driver", "opengl"); settings->setDefault("free_move", "false"); settings->setDefault("continuous_forward", "false"); diff --git a/src/mob.cpp b/src/mob.cpp index ab0058e..10fcdca 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -21,9 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "noise.h" #include "constants.h" #include "debug.h" -#include "main.h" // For g_profiler and g_settings +#include "main.h" // For g_profiler and g_settings #include "profiler.h" #include "settings.h" +#include "tile.h" // For getTexturePath and getModelPath Mob::Mob( scene::ISceneNode* parent, @@ -49,29 +50,16 @@ Mob::Mob( m_box = core::aabbox3d(-BS*1000000,m_y-BS,-BS*1000000, BS*1000000,m_y+BS,BS*1000000); - // draw arb mesh - // - m_mesh = mgr->getMesh("/home/leslie/dev/git/minetest/models/Pteranodon/Pteranodon.MD2"); + // load a mesh + m_mesh = mgr->getMesh(getModelPath("pteranodon").c_str()); - m_node = mgr->addMeshSceneNode(m_mesh, NULL); - //m_node = mgr->addAnimatedMeshSceneNode(m_mesh); + m_node = mgr->addMeshSceneNode(m_mesh, NULL); - m_node->setPosition(player_position); + // put it at the player's feet + m_node->setPosition(player_position); - - //m_node->setMD2Animation(scene::EMAT_STAND); - - - m_mesh->drop(); - -/* - m_node->setScale(v3f((m_prop.visual_size.X*BS)/2, - (m_prop.visual_size.Y*BS)/2, - (m_prop.visual_size.X*BS)/2)); - u8 li = m_last_light; - setMeshColor(m_node->getMesh(), video::SColor(255,li,li,li)); -*/ + m_mesh->drop(); } Mob::~Mob() @@ -105,7 +93,7 @@ void Mob::render() if (m_node) { m_node->setMaterialFlag(video::EMF_LIGHTING, false); - m_node->setMaterialTexture(0, driver->getTexture("/home/leslie/dev/git/minetest/models/Pteranodon/maps/mapeado.png")); + m_node->setMaterialTexture(0, driver->getTexture(getTexturePath("pteranodon_map.png").c_str())); } } diff --git a/src/tile.cpp b/src/tile.cpp index 6dbe4c6..e1d01d6 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -38,6 +38,11 @@ with this program; if not, write to the Free Software Foundation, Inc., */ MutexedMap g_texturename_to_path_cache; +/* + A cache from model name to model path +*/ +MutexedMap g_modelname_to_path_cache; + /* Replaces the filename extension. eg: @@ -77,17 +82,12 @@ static bool replace_ext(std::string &path, const char *ext) If failed, return "". */ -static std::string getImagePath(std::string path) +static std::string getExtPath(std::string path, std::string default_ext, const char** extensions) { - // A NULL-ended list of possible image extensions - const char *extensions[] = { - "png", "jpg", "bmp", "tga", - "pcx", "ppm", "psd", "wal", "rgb", - NULL - }; // If there is no extension, add one if(removeStringEnd(path, extensions) == "") - path = path + ".png"; + path = path + "." + default_ext; + // Check paths until something is found to exist const char **ext = extensions; do{ @@ -102,6 +102,30 @@ static std::string getImagePath(std::string path) return ""; } +static std::string getImageExtPath(std::string path) +{ + // A NULL-ended list of possible image extensions + const char *extensions[] = { + "png", "jpg", "bmp", "tga", + "pcx", "ppm", "psd", "wal", "rgb", + NULL + }; + + return getExtPath(path, "png", extensions); +} + +static std::string getModelExtPath(std::string path) +{ + // A NULL-ended list of possible image extensions + const char *extensions[] = { + "md3", "md2", + NULL + }; + + return getExtPath(path, "md2", extensions); +} + + /* Gets the path to a texture by first checking if the texture exists in texture_path and if not, using the data path. @@ -130,7 +154,7 @@ std::string getTexturePath(const std::string &filename) { std::string testpath = texture_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. - fullpath = getImagePath(testpath); + fullpath = getImageExtPath(testpath); } /* @@ -142,7 +166,7 @@ std::string getTexturePath(const std::string &filename) + "textures" + DIR_DELIM + "all"; std::string testpath = texture_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. - fullpath = getImagePath(testpath); + fullpath = getImageExtPath(testpath); } /* @@ -154,7 +178,7 @@ std::string getTexturePath(const std::string &filename) + DIR_DELIM + "base" + DIR_DELIM + "pack"; std::string testpath = base_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. - fullpath = getImagePath(testpath); + fullpath = getImageExtPath(testpath); } // Add to cache (also an empty result is cached) @@ -164,6 +188,72 @@ std::string getTexturePath(const std::string &filename) return fullpath; } +/* + Gets the path to a model by first checking if the model exists + in model_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 getModelPath(const std::string &filename) +{ + std::string fullpath = ""; + /* + Check from cache + */ + bool incache = g_modelname_to_path_cache.get(filename, &fullpath); + if(incache) + return fullpath; + + /* + Check from model_path + */ + std::string model_path = g_settings->get("model_path"); + if(model_path != "") + { + std::string testpath = model_path + DIR_DELIM + filename; + // Check all filename extensions. Returns "" if not found. + fullpath = getModelExtPath(testpath); + } + + /* + Check from $user/models/all + */ + if(fullpath == "") + { + std::string path = porting::path_user + DIR_DELIM + + "models" + DIR_DELIM + "all"; + std::string testpath = path + DIR_DELIM + filename; + // Check all filename extensions. Returns "" if not found. + fullpath = getModelExtPath(testpath); + } + + /* + Check from default data directory + */ + if(fullpath == "") + { + std::string base_path = porting::path_share + DIR_DELIM + "models" + + DIR_DELIM + "base" + DIR_DELIM + "pack"; + std::string testpath = base_path + DIR_DELIM + filename; + // Check all filename extensions. Returns "" if not found. + fullpath = getModelExtPath(testpath); + } + + // Add to cache (also an empty result is cached) + g_modelname_to_path_cache.set(filename, fullpath); + + // Finally return it + return fullpath; +} + + + + /* An internal variant of AtlasPointer with more data. (well, more like a wrapper) diff --git a/src/tile.h b/src/tile.h index ae986e7..9b05c28 100644 --- a/src/tile.h +++ b/src/tile.h @@ -46,6 +46,18 @@ class IGameDef; */ std::string getTexturePath(const std::string &filename); +/* + Gets the path to a model by first checking if the model exists + in model_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 getModelPath(const std::string &filename); + /* Specifies a texture in an atlas. diff --git a/textures/base/pack/pteranodon_map.png b/textures/base/pack/pteranodon_map.png new file mode 100644 index 0000000..9beb8b8 Binary files /dev/null and b/textures/base/pack/pteranodon_map.png differ