Split up tile.cpp/h

This commit is contained in:
cx384 2024-02-27 10:56:22 +01:00 committed by SmallJoker
parent cdce33dd05
commit aaf77025b6
34 changed files with 2851 additions and 2801 deletions

View File

@ -67,6 +67,8 @@ set(client_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/shader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sky.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/texturepaths.cpp
${CMAKE_CURRENT_SOURCE_DIR}/texturesource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wieldmesh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadows.cpp
${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadowsrender.cpp

View File

@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "inventory.h"
#include "client/tile.h"
#include "util/numeric.h"
#include "client/localplayer.h"
#include <ICameraSceneNode.h>
#include <ISceneNode.h>

View File

@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/gameui.h"
#include "client/renderingengine.h"
#include "client/sound.h"
#include "client/tile.h"
#include "client/texturepaths.h"
#include "client/mesh_generator_thread.h"
#include "client/particles.h"
#include "client/localplayer.h"

View File

@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/client.h"
#include "client/renderingengine.h"
#include "client/sound.h"
#include "client/tile.h"
#include "client/texturesource.h"
#include "client/mapblock_mesh.h"
#include "util/basic_macros.h"
#include "util/numeric.h"

View File

@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_cso.h"
#include <IBillboardSceneNode.h>
#include "client/tile.h"
#include "clientenvironment.h"
#include "client.h"
#include "map.h"

View File

@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/clientevent.h"
#include "client/gameui.h"
#include "client/inputhandler.h"
#include "client/tile.h" // For TextureSource
#include "client/texturepaths.h"
#include "client/keys.h"
#include "client/joystick_controller.h"
#include "client/mapblock_mesh.h"
@ -1383,7 +1383,7 @@ void Game::copyServerClientCache()
{
// It would be possible to let the client directly read the media files
// from where the server knows they are. But aside from being more complicated
// it would also *not* fill the media cache and cause slower joining of
// it would also *not* fill the media cache and cause slower joining of
// remote servers.
// (Imagine that you launch a game once locally and then connect to a server.)

View File

@ -272,3 +272,40 @@ void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::I
dest->setPixel(dx, dy, pxl);
}
}
/**
* Check and align image to npot2 if required by hardware
* @param image image to check for npot2 alignment
* @param driver driver to use for image operations
* @return image or copy of image aligned to npot2
*/
video::IImage *Align2Npot2(video::IImage *image,
video::IVideoDriver *driver)
{
if (image == NULL)
return image;
if (driver->queryFeature(video::EVDF_TEXTURE_NPOT))
return image;
core::dimension2d<u32> dim = image->getDimension();
unsigned int height = npot2(dim.Height);
unsigned int width = npot2(dim.Width);
if (dim.Height == height && dim.Width == width)
return image;
if (dim.Height > height)
height *= 2;
if (dim.Width > width)
width *= 2;
video::IImage *targetimage =
driver->createImage(video::ECF_A8R8G8B8,
core::dimension2d<u32>(width, height));
if (targetimage != NULL)
image->copyToScaling(targetimage);
image->drop();
return targetimage;
}

View File

@ -41,3 +41,11 @@ void imageCleanTransparent(video::IImage *src, u32 threshold);
* and downscaling.
*/
void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::IImage *dest);
/* Check and align image to npot2 if required by hardware
* @param image image to check for npot2 alignment
* @param driver driver to use for image operations
* @return image or copy of image aligned to npot2
*/
video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver);

View File

@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <array>
#include <algorithm>
#include <cmath>
#include "client/texturesource.h"
/*
MeshMakeData

View File

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "irrlichttypes_extrabloated.h"
#include "util/numeric.h"
#include "client/tile.h"
#include "voxel.h"
#include <array>
@ -29,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class Client;
class NodeDefManager;
class IShaderSource;
class ITextureSource;
/*
Mesh making stuff

View File

@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
#include "irrlichttypes_extrabloated.h"
#include "client/tile.h"
#include "localplayer.h"
#include "../particles.h"

View File

@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_bloated.h"
#include <IMaterialRendererServices.h>
#include <string>
#include "tile.h"
#include "nodedef.h"
class IGameDef;

154
src/client/texturepaths.cpp Normal file
View File

@ -0,0 +1,154 @@
/*
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 "texturepaths.h"
#include "util/container.h"
#include "settings.h"
#include "filesys.h"
#include "porting.h"
/*
A cache from texture name to texture path
*/
static MutexedMap<std::string, std::string> g_texturename_to_path_cache;
/*
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)
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.
If failed, return "".
*/
std::string getImagePath(std::string path)
{
// A NULL-ended list of possible image extensions
const char *extensions[] = { "png", "jpg", "bmp", "tga", NULL };
// If there is no extension, assume PNG
if (removeStringEnd(path, extensions).empty())
path = path + ".png";
// Check paths until something is found to exist
const char **ext = extensions;
do{
bool r = replace_ext(path, *ext);
if (!r)
return "";
if (fs::PathExists(path))
return path;
}
while((++ext) != NULL);
return "";
}
/*
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, bool *is_base_pack)
{
std::string fullpath;
// This can set a wrong value on cached textures, but is irrelevant because
// is_base_pack is only passed when initializing the textures the first time
if (is_base_pack)
*is_base_pack = false;
/*
Check from cache
*/
bool incache = g_texturename_to_path_cache.get(filename, &fullpath);
if (incache)
return fullpath;
/*
Check from texture_path
*/
for (const auto &path : getTextureDirs()) {
std::string testpath = path + DIR_DELIM;
testpath.append(filename);
// Check all filename extensions. Returns "" if not found.
fullpath = getImagePath(testpath);
if (!fullpath.empty())
break;
}
/*
Check from default data directory
*/
if (fullpath.empty())
{
std::string base_path = porting::path_share + DIR_DELIM + "textures"
+ 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);
if (is_base_pack && !fullpath.empty())
*is_base_pack = true;
}
// Add to cache (also an empty result is cached)
g_texturename_to_path_cache.set(filename, fullpath);
// Finally return it
return fullpath;
}
void clearTextureNameCache()
{
g_texturename_to_path_cache.clear();
}
std::vector<std::string> getTextureDirs()
{
return fs::GetRecursiveDirs(g_settings->get("texture_path"));
}

44
src/client/texturepaths.h Normal file
View File

@ -0,0 +1,44 @@
/*
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.
*/
#pragma once
#include <string>
#include <vector>
// Texture paths get cached and this clears the Cache.
void clearTextureNameCache();
// Find out the full path of an image by trying different filename extensions.
// If failed, return "".
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.
*/
std::string getTexturePath(const std::string &filename, bool *is_base_pack = nullptr);
// Returns all dictionaries found from the "texture_path" setting.
std::vector<std::string> getTextureDirs();

2493
src/client/texturesource.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,93 @@
/*
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.
*/
#pragma once
#include "irrlichttypes.h"
#include <ITexture.h>
#include <string>
#include <vector>
typedef std::vector<video::SColor> Palette;
/*
TextureSource creates and caches textures.
*/
class ISimpleTextureSource
{
public:
ISimpleTextureSource() = default;
virtual ~ISimpleTextureSource() = default;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr) = 0;
};
class ITextureSource : public ISimpleTextureSource
{
public:
ITextureSource() = default;
virtual ~ITextureSource() = default;
virtual u32 getTextureId(const std::string &name)=0;
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr)=0;
virtual video::ITexture* getTextureForMesh(
const std::string &name, u32 *id = nullptr) = 0;
/*!
* Returns a palette from the given texture name.
* The pointer is valid until the texture source is
* destructed.
* Should be called from the main thread.
*/
virtual Palette* getPalette(const std::string &name) = 0;
virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
};
class IWritableTextureSource : public ITextureSource
{
public:
IWritableTextureSource() = default;
virtual ~IWritableTextureSource() = default;
virtual u32 getTextureId(const std::string &name)=0;
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr)=0;
virtual bool isKnownSourceImage(const std::string &name)=0;
virtual void processQueue()=0;
virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
virtual void rebuildImagesAndTextures()=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
};
IWritableTextureSource *createTextureSource();

File diff suppressed because it is too large Load Diff

View File

@ -20,118 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "irrlichttypes.h"
#include "irr_v3d.h"
#include <ITexture.h>
#include <string>
#include <vector>
#include <SMaterial.h>
#include "util/numeric.h"
#include "config.h"
class IGameDef;
struct TileSpec;
struct TileDef;
namespace irr::video { class IVideoDriver; }
typedef std::vector<video::SColor> Palette;
/*
tile.{h,cpp}: Texture handling stuff.
*/
/*
Find out the full path of an image by trying different filename
extensions.
If failed, return "".
TODO: Should probably be moved out from here, because things needing
this function do not need anything else from this header
*/
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.
*/
std::string getTexturePath(const std::string &filename, bool *is_base_pack = nullptr);
void clearTextureNameCache();
/*
TextureSource creates and caches textures.
*/
class ISimpleTextureSource
{
public:
ISimpleTextureSource() = default;
virtual ~ISimpleTextureSource() = default;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr) = 0;
};
class ITextureSource : public ISimpleTextureSource
{
public:
ITextureSource() = default;
virtual ~ITextureSource() = default;
virtual u32 getTextureId(const std::string &name)=0;
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr)=0;
virtual video::ITexture* getTextureForMesh(
const std::string &name, u32 *id = nullptr) = 0;
/*!
* Returns a palette from the given texture name.
* The pointer is valid until the texture source is
* destructed.
* Should be called from the main thread.
*/
virtual Palette* getPalette(const std::string &name) = 0;
virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
};
class IWritableTextureSource : public ITextureSource
{
public:
IWritableTextureSource() = default;
virtual ~IWritableTextureSource() = default;
virtual u32 getTextureId(const std::string &name)=0;
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr)=0;
virtual bool isKnownSourceImage(const std::string &name)=0;
virtual void processQueue()=0;
virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
virtual void rebuildImagesAndTextures()=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
};
IWritableTextureSource *createTextureSource();
video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver);
enum MaterialType{
TILE_MATERIAL_BASIC,
@ -318,5 +209,3 @@ struct TileSpec
//! The first is base texture, the second is overlay.
TileLayer layers[MAX_TILE_LAYERS];
};
std::vector<std::string> getTextureDirs();

View File

@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/string.h"
#ifndef SERVER
#include "client/tile.h" // getImagePath
#include "client/texturepaths.h"
#endif
// The maximum number of identical world names allowed

View File

@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "client/tile.h" // ITextureSource
#include "client/texturesource.h"
#include "client/fontengine.h"
#include "debug.h"
#include "irrlichttypes_extrabloated.h"

View File

@ -1,7 +1,6 @@
#include "guiAnimatedImage.h"
#include "client/guiscalingfilter.h"
#include "client/tile.h" // ITextureSource
#include "log.h"
#include "porting.h"
#include "util/string.h"

View File

@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "guiBackgroundImage.h"
#include "client/guiscalingfilter.h"
#include "log.h"
#include "client/texturesource.h"
GUIBackgroundImage::GUIBackgroundImage(gui::IGUIEnvironment *env,
gui::IGUIElement *parent, s32 id, const core::rect<s32> &rectangle,

View File

@ -19,7 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "irrlichttypes_extrabloated.h"
#include "util/string.h"
#include "client/tile.h" // ITextureSource
class ISimpleTextureSource;
class GUIBackgroundImage : public gui::IGUIElement
{

View File

@ -6,7 +6,6 @@
#include "client/guiscalingfilter.h"
#include "client/tile.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"

View File

@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/keycode.h"
#include "settings.h"
#include "porting.h"
#include "client/tile.h"
#include "client/texturesource.h"
#include "client/fontengine.h"
#include "log.h"
#include "gettext.h"

View File

@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "version.h"
#include <ICameraSceneNode.h>
#include <IGUIStaticText.h>
#include "client/imagefilters.h"
#if USE_SOUND
#include "client/sound/sound_openal.h"

View File

@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiFormSpecMenu.h"
#include "client/clouds.h"
#include "client/sound.h"
#include "client/tile.h"
#include "util/enriched_string.h"
#include "translation.h"

View File

@ -39,7 +39,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IAnimatedMeshSceneNode.h>
#include "client/renderingengine.h"
#include "log.h"
#include "client/tile.h" // ITextureSource
#include "client/hud.h" // drawItemStack
#include "filesys.h"
#include "gettime.h"

View File

@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiHyperText.h"
#include "guiScrollBar.h"
#include "client/fontengine.h"
#include "client/tile.h"
#include "IVideoDriver.h"
#include "client/client.h"
#include "client/renderingengine.h"

View File

@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/renderingengine.h"
#include "debug.h"
#include "log.h"
#include "client/tile.h"
#include "client/texturesource.h"
#include "gettime.h"
#include "util/string.h"
#include "util/numeric.h"

View File

@ -32,7 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <vector>
#include "itemdef.h"
#include "client/tile.h"
#include "client/game.h"
using namespace irr;

View File

@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/mapblock_mesh.h"
#include "client/mesh.h"
#include "client/wieldmesh.h"
#include "client/tile.h"
#include "client/client.h"
#endif
#include "log.h"

View File

@ -35,7 +35,7 @@ class Client;
struct ToolCapabilities;
struct PointedThing;
#ifndef SERVER
#include "client/tile.h"
#include "client/texturesource.h"
struct ItemMesh;
struct ItemStack;
#endif

View File

@ -357,7 +357,7 @@ void ContentFeatures::reset()
has_on_destruct = false;
has_after_destruct = false;
floats = false;
/*
Actual data