From 4e9aa7dc77a5039a5696a82ff899a51e1936cca0 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 9 Sep 2024 20:39:35 +0200 Subject: [PATCH] Make itemdef.h safe to include anywhere --- src/CMakeLists.txt | 4 ++-- src/client/client.cpp | 1 + src/client/minimap.cpp | 1 + src/client/particles.cpp | 1 + src/client/renderingengine.cpp | 1 + src/client/sky.cpp | 1 + src/client/wieldmesh.cpp | 1 + src/gui/guiHyperText.cpp | 1 + src/gui/touchcontrols.h | 2 +- src/itemdef.cpp | 5 ++++- src/itemdef.h | 33 ++++++++++++++++++++------------- src/nodedef.cpp | 1 + 12 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2eaeed2d2..93dafa2cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -396,12 +396,14 @@ set(independent_SRCS gettext_plural_form.cpp httpfetch.cpp hud.cpp + inventory.cpp itemstackmetadata.cpp lighting.cpp log.cpp metadata.cpp modchannels.cpp nameidmapping.cpp + nodemetadata.cpp nodetimer.cpp noise.cpp objdef.cpp @@ -429,7 +431,6 @@ set(common_SRCS environment.cpp filesys.cpp gettext.cpp - inventory.cpp inventorymanager.cpp itemdef.cpp light.cpp @@ -440,7 +441,6 @@ set(common_SRCS mapnode.cpp mapsector.cpp nodedef.cpp - nodemetadata.cpp pathfinder.cpp player.cpp porting.cpp diff --git a/src/client/client.cpp b/src/client/client.cpp index 7feb2212d..3da5f777e 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/renderingengine.h" #include "client/sound.h" #include "client/texturepaths.h" +#include "client/texturesource.h" #include "client/mesh_generator_thread.h" #include "client/particles.h" #include "client/localplayer.h" diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index 13dca5fe9..f959d00be 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "shader.h" #include "mapblock.h" #include "client/renderingengine.h" +#include "client/texturesource.h" #include "gettext.h" //// diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 3a2dace12..e197b4f8a 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/content_cao.h" #include "client/clientevent.h" #include "client/renderingengine.h" +#include "client/texturesource.h" #include "util/numeric.h" #include "light.h" #include "localplayer.h" diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index f0d2abddb..2f714e020 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiscalingfilter.h" #include "localplayer.h" #include "client/hud.h" +#include "client/texturesource.h" #include "camera.h" #include "minimap.h" #include "clientmap.h" diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 27640bc28..054c1ace2 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "profiler.h" #include "util/numeric.h" #include "client/renderingengine.h" +#include "client/texturesource.h" #include "settings.h" #include "camera.h" // CameraModes diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index e66214ae6..81ca99b5f 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock_mesh.h" #include "client/meshgen/collector.h" #include "client/tile.h" +#include "client/texturesource.h" #include "log.h" #include "util/numeric.h" #include diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 44019ebe2..393e06cc1 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "IVideoDriver.h" #include "client/client.h" #include "client/renderingengine.h" +#include "client/texturesource.h" #include "hud.h" #include "inventory.h" #include "util/string.h" diff --git a/src/gui/touchcontrols.h b/src/gui/touchcontrols.h index 98ec806bd..2d3d4fbb0 100644 --- a/src/gui/touchcontrols.h +++ b/src/gui/touchcontrols.h @@ -34,13 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemdef.h" #include "client/game.h" #include "util/basic_macros.h" +#include "client/texturesource.h" namespace irr { class IrrlichtDevice; } -using namespace irr; using namespace irr::core; using namespace irr::gui; diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 0bb90929e..773cadaec 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/mesh.h" #include "client/wieldmesh.h" #include "client/client.h" +#include "client/texturesource.h" #endif #include "log.h" #include "settings.h" @@ -448,8 +449,9 @@ public: // Get the definition return m_item_definitions.find(name) != m_item_definitions.cend(); } + #if CHECK_CLIENT_BUILD() -public: +protected: ClientCached* createClientCachedDirect(const ItemStack &item, Client *client) const { // This is not thread-safe @@ -490,6 +492,7 @@ public: return ptr; } +public: // Get item inventory texture virtual video::ITexture* getInventoryTexture(const ItemStack &item, Client *client) const diff --git a/src/itemdef.h b/src/itemdef.h index 1cfd475e5..f0d780173 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -35,11 +35,11 @@ with this program; if not, write to the Free Software Foundation, Inc., class IGameDef; class Client; struct ToolCapabilities; -#if CHECK_CLIENT_BUILD() -#include "client/texturesource.h" struct ItemMesh; struct ItemStack; -#endif +typedef std::vector Palette; // copied from src/client/texturesource.h +namespace irr::video { class ITexture; } +using namespace irr; /* Base item definition @@ -155,25 +155,32 @@ public: virtual void getAll(std::set &result) const=0; // Check if item is known virtual bool isKnown(const std::string &name) const=0; -#if CHECK_CLIENT_BUILD() + + virtual void serialize(std::ostream &os, u16 protocol_version)=0; + + /* Client-specific methods */ + // TODO: should be moved elsewhere in the future + // Get item inventory texture - virtual video::ITexture* getInventoryTexture(const ItemStack &item, Client *client) const=0; + virtual video::ITexture* getInventoryTexture(const ItemStack &item, Client *client) const + { return nullptr; } /** * Get wield mesh - * - * Returns nullptr if there is an inventory image + * @returns nullptr if there is an inventory image */ - virtual ItemMesh* getWieldMesh(const ItemStack &item, Client *client) const = 0; + virtual ItemMesh* getWieldMesh(const ItemStack &item, Client *client) const + { return nullptr; } + // Get item palette - virtual Palette* getPalette(const ItemStack &item, Client *client) const = 0; + virtual Palette* getPalette(const ItemStack &item, Client *client) const + { return nullptr; } + // Returns the base color of an item stack: the color of all // tiles that do not define their own color. virtual video::SColor getItemstackColor(const ItemStack &stack, - Client *client) const = 0; -#endif - - virtual void serialize(std::ostream &os, u16 protocol_version)=0; + Client *client) const + { return video::SColor(0); } }; class IWritableItemDefManager : public IItemDefManager diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 2b3b3b1fb..06a74ccef 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/shader.h" #include "client/client.h" #include "client/renderingengine.h" +#include "client/texturesource.h" #include "client/tile.h" #include #endif