mirror of https://github.com/minetest/minetest.git
Refactor tile.cpp/h parts except texturesource.cpp
This commit is contained in:
parent
aaf77025b6
commit
879f7e9f03
|
@ -273,16 +273,14 @@ void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::I
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Check and align image to npot2 if required by hardware
|
||||||
* Check and align image to npot2 if required by hardware
|
|
||||||
* @param image image to check for npot2 alignment
|
* @param image image to check for npot2 alignment
|
||||||
* @param driver driver to use for image operations
|
* @param driver driver to use for image operations
|
||||||
* @return image or copy of image aligned to npot2
|
* @return image or copy of image aligned to npot2
|
||||||
*/
|
*/
|
||||||
video::IImage *Align2Npot2(video::IImage *image,
|
video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver)
|
||||||
video::IVideoDriver *driver)
|
|
||||||
{
|
{
|
||||||
if (image == NULL)
|
if (image == nullptr)
|
||||||
return image;
|
return image;
|
||||||
|
|
||||||
if (driver->queryFeature(video::EVDF_TEXTURE_NPOT))
|
if (driver->queryFeature(video::EVDF_TEXTURE_NPOT))
|
||||||
|
@ -304,7 +302,7 @@ video::IImage *Align2Npot2(video::IImage *image,
|
||||||
driver->createImage(video::ECF_A8R8G8B8,
|
driver->createImage(video::ECF_A8R8G8B8,
|
||||||
core::dimension2d<u32>(width, height));
|
core::dimension2d<u32>(width, height));
|
||||||
|
|
||||||
if (targetimage != NULL)
|
if (targetimage != nullptr)
|
||||||
image->copyToScaling(targetimage);
|
image->copyToScaling(targetimage);
|
||||||
image->drop();
|
image->drop();
|
||||||
return targetimage;
|
return targetimage;
|
||||||
|
|
|
@ -23,77 +23,51 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
#include "porting.h"
|
#include "porting.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/*
|
// A cache from texture name to texture path
|
||||||
A cache from texture name to texture path
|
|
||||||
*/
|
|
||||||
static MutexedMap<std::string, std::string> g_texturename_to_path_cache;
|
static MutexedMap<std::string, std::string> g_texturename_to_path_cache;
|
||||||
|
|
||||||
/*
|
void clearTextureNameCache()
|
||||||
Replaces the filename extension.
|
|
||||||
eg:
|
|
||||||
std::string image = "a/image.png"
|
|
||||||
replace_ext(image, "jpg")
|
|
||||||
-> image = "a/image.jpg"
|
|
||||||
Returns true on success.
|
|
||||||
*/
|
|
||||||
static bool replace_ext(std::string &path, const char *ext)
|
|
||||||
{
|
{
|
||||||
if (ext == NULL)
|
g_texturename_to_path_cache.clear();
|
||||||
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--)
|
|
||||||
{
|
|
||||||
if (path[i] == '.')
|
|
||||||
{
|
|
||||||
last_dot_i = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path[i] == '\\' || path[i] == '/')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// If not found, return an empty string
|
|
||||||
if (last_dot_i == -1)
|
|
||||||
return false;
|
|
||||||
// Else make the new path
|
|
||||||
path = path.substr(0, last_dot_i+1) + ext;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Find out the full path of an image by trying different filename extensions.
|
||||||
Find out the full path of an image by trying different filename
|
// If failed, return "".
|
||||||
extensions.
|
std::string getImagePath(std::string_view path)
|
||||||
If failed, return "".
|
|
||||||
*/
|
|
||||||
std::string getImagePath(std::string path)
|
|
||||||
{
|
{
|
||||||
// A NULL-ended list of possible image extensions
|
// A NULL-ended list of possible image extensions
|
||||||
const char *extensions[] = { "png", "jpg", "bmp", "tga", NULL };
|
// (In newer C++ versions a fixed size array and ranges::subrange could be used
|
||||||
// If there is no extension, assume PNG
|
// or just modernise removeStringEnd.)
|
||||||
if (removeStringEnd(path, extensions).empty())
|
static const char *extensions[] = {".png", ".jpg", ".bmp", ".tga", nullptr};
|
||||||
path = path + ".png";
|
|
||||||
// Check paths until something is found to exist
|
// Remove present extension
|
||||||
const char **ext = extensions;
|
std::string_view stripped_path = removeStringEnd(path, extensions);
|
||||||
do{
|
// If there is no known extension, assume it has been omitted.
|
||||||
bool r = replace_ext(path, *ext);
|
if (stripped_path.empty())
|
||||||
if (!r)
|
stripped_path = path;
|
||||||
return "";
|
|
||||||
if (fs::PathExists(path))
|
for (const char *ext : extensions) {
|
||||||
return path;
|
if (!ext)
|
||||||
|
break;
|
||||||
|
std::string extended_path(stripped_path);
|
||||||
|
extended_path.append(ext);
|
||||||
|
if (fs::PathExists(extended_path))
|
||||||
|
return extended_path;
|
||||||
}
|
}
|
||||||
while((++ext) != NULL);
|
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Gets the path to a texture by first checking if the texture exists
|
||||||
Gets the path to a texture by first checking if the texture exists
|
* in texture_path and if not, using the data path.
|
||||||
in texture_path and if not, using the data path.
|
*
|
||||||
Checks all supported extensions by replacing the original extension.
|
* Checks all supported extensions by replacing the original extension.
|
||||||
If not found, returns "".
|
*
|
||||||
Utilizes a thread-safe cache.
|
* If not found, returns "".
|
||||||
|
*
|
||||||
|
* Utilizes a thread-safe cache.
|
||||||
*/
|
*/
|
||||||
std::string getTexturePath(const std::string &filename, bool *is_base_pack)
|
std::string getTexturePath(const std::string &filename, bool *is_base_pack)
|
||||||
{
|
{
|
||||||
|
@ -103,35 +77,26 @@ std::string getTexturePath(const std::string &filename, bool *is_base_pack)
|
||||||
// is_base_pack is only passed when initializing the textures the first time
|
// is_base_pack is only passed when initializing the textures the first time
|
||||||
if (is_base_pack)
|
if (is_base_pack)
|
||||||
*is_base_pack = false;
|
*is_base_pack = false;
|
||||||
/*
|
|
||||||
Check from cache
|
// Check from cache
|
||||||
*/
|
|
||||||
bool incache = g_texturename_to_path_cache.get(filename, &fullpath);
|
bool incache = g_texturename_to_path_cache.get(filename, &fullpath);
|
||||||
if (incache)
|
if (incache)
|
||||||
return fullpath;
|
return fullpath;
|
||||||
|
|
||||||
/*
|
// Check from texture_path setting
|
||||||
Check from texture_path
|
|
||||||
*/
|
|
||||||
for (const auto &path : getTextureDirs()) {
|
for (const auto &path : getTextureDirs()) {
|
||||||
std::string testpath = path + DIR_DELIM;
|
|
||||||
testpath.append(filename);
|
|
||||||
// Check all filename extensions. Returns "" if not found.
|
// Check all filename extensions. Returns "" if not found.
|
||||||
fullpath = getImagePath(testpath);
|
fullpath = getImagePath(path + DIR_DELIM + filename);
|
||||||
if (!fullpath.empty())
|
if (!fullpath.empty())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Check from default data directory i.e. .../minetest/textures/base/pack
|
||||||
Check from default data directory
|
if (fullpath.empty()) {
|
||||||
*/
|
|
||||||
if (fullpath.empty())
|
|
||||||
{
|
|
||||||
std::string base_path = porting::path_share + DIR_DELIM + "textures"
|
std::string base_path = porting::path_share + DIR_DELIM + "textures"
|
||||||
+ DIR_DELIM + "base" + DIR_DELIM + "pack";
|
+ DIR_DELIM + "base" + DIR_DELIM + "pack";
|
||||||
std::string testpath = base_path + DIR_DELIM + filename;
|
|
||||||
// Check all filename extensions. Returns "" if not found.
|
// Check all filename extensions. Returns "" if not found.
|
||||||
fullpath = getImagePath(testpath);
|
fullpath = getImagePath(base_path + DIR_DELIM + filename);
|
||||||
if (is_base_pack && !fullpath.empty())
|
if (is_base_pack && !fullpath.empty())
|
||||||
*is_base_pack = true;
|
*is_base_pack = true;
|
||||||
}
|
}
|
||||||
|
@ -143,11 +108,6 @@ std::string getTexturePath(const std::string &filename, bool *is_base_pack)
|
||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearTextureNameCache()
|
|
||||||
{
|
|
||||||
g_texturename_to_path_cache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> getTextureDirs()
|
std::vector<std::string> getTextureDirs()
|
||||||
{
|
{
|
||||||
return fs::GetRecursiveDirs(g_settings->get("texture_path"));
|
return fs::GetRecursiveDirs(g_settings->get("texture_path"));
|
||||||
|
|
|
@ -27,7 +27,7 @@ void clearTextureNameCache();
|
||||||
|
|
||||||
// Find out the full path of an image by trying different filename extensions.
|
// Find out the full path of an image by trying different filename extensions.
|
||||||
// If failed, return "".
|
// If failed, return "".
|
||||||
std::string getImagePath(std::string path);
|
std::string getImagePath(std::string_view path);
|
||||||
|
|
||||||
/* Gets the path to a texture by first checking if the texture exists
|
/* Gets the path to a texture by first checking if the texture exists
|
||||||
* in texture_path and if not, using the data path.
|
* in texture_path and if not, using the data path.
|
||||||
|
|
|
@ -1 +1,66 @@
|
||||||
// Empty after splitting tile.h
|
/*
|
||||||
|
Minetest
|
||||||
|
Copyright (C) 2010-2013 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 Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tile.h"
|
||||||
|
|
||||||
|
// Sets everything else except the texture in the material
|
||||||
|
void TileLayer::applyMaterialOptions(video::SMaterial &material) const
|
||||||
|
{
|
||||||
|
switch (material_type) {
|
||||||
|
case TILE_MATERIAL_OPAQUE:
|
||||||
|
case TILE_MATERIAL_LIQUID_OPAQUE:
|
||||||
|
case TILE_MATERIAL_WAVING_LIQUID_OPAQUE:
|
||||||
|
material.MaterialType = video::EMT_SOLID;
|
||||||
|
break;
|
||||||
|
case TILE_MATERIAL_BASIC:
|
||||||
|
case TILE_MATERIAL_WAVING_LEAVES:
|
||||||
|
case TILE_MATERIAL_WAVING_PLANTS:
|
||||||
|
case TILE_MATERIAL_WAVING_LIQUID_BASIC:
|
||||||
|
material.MaterialTypeParam = 0.5;
|
||||||
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
|
||||||
|
break;
|
||||||
|
case TILE_MATERIAL_ALPHA:
|
||||||
|
case TILE_MATERIAL_LIQUID_TRANSPARENT:
|
||||||
|
case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT:
|
||||||
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
|
||||||
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
||||||
|
material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
||||||
|
}
|
||||||
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) {
|
||||||
|
material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileLayer::applyMaterialOptionsWithShaders(video::SMaterial &material) const
|
||||||
|
{
|
||||||
|
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
|
||||||
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
||||||
|
material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
||||||
|
material.TextureLayers[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
||||||
|
}
|
||||||
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) {
|
||||||
|
material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
||||||
|
material.TextureLayers[1].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -96,50 +96,9 @@ struct TileLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets everything else except the texture in the material
|
// Sets everything else except the texture in the material
|
||||||
void applyMaterialOptions(video::SMaterial &material) const
|
void applyMaterialOptions(video::SMaterial &material) const;
|
||||||
{
|
|
||||||
switch (material_type) {
|
|
||||||
case TILE_MATERIAL_OPAQUE:
|
|
||||||
case TILE_MATERIAL_LIQUID_OPAQUE:
|
|
||||||
case TILE_MATERIAL_WAVING_LIQUID_OPAQUE:
|
|
||||||
material.MaterialType = video::EMT_SOLID;
|
|
||||||
break;
|
|
||||||
case TILE_MATERIAL_BASIC:
|
|
||||||
case TILE_MATERIAL_WAVING_LEAVES:
|
|
||||||
case TILE_MATERIAL_WAVING_PLANTS:
|
|
||||||
case TILE_MATERIAL_WAVING_LIQUID_BASIC:
|
|
||||||
material.MaterialTypeParam = 0.5;
|
|
||||||
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
|
|
||||||
break;
|
|
||||||
case TILE_MATERIAL_ALPHA:
|
|
||||||
case TILE_MATERIAL_LIQUID_TRANSPARENT:
|
|
||||||
case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT:
|
|
||||||
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
|
|
||||||
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
|
||||||
material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
|
||||||
}
|
|
||||||
if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) {
|
|
||||||
material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void applyMaterialOptionsWithShaders(video::SMaterial &material) const
|
void applyMaterialOptionsWithShaders(video::SMaterial &material) const;
|
||||||
{
|
|
||||||
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
|
|
||||||
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
|
||||||
material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
|
||||||
material.TextureLayers[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
|
||||||
}
|
|
||||||
if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) {
|
|
||||||
material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
|
||||||
material.TextureLayers[1].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isTransparent() const
|
bool isTransparent() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue