Cleaned up a bit, took out absolute paths

master
Leslie Viljoen 2012-07-14 11:56:03 +12:00
parent 63fd4d9b7f
commit 9d4609d6e5
8 changed files with 129 additions and 33 deletions

View File

@ -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

View File

@ -1 +0,0 @@
Note: models uploaded here are by tonyka. Proper attribution will be done soon!

View File

@ -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");

View File

@ -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<f32>(-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()));
}
}

View File

@ -38,6 +38,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
MutexedMap<std::string, std::string> g_texturename_to_path_cache;
/*
A cache from model name to model path
*/
MutexedMap<std::string, std::string> 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)

View File

@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB