Make itemdef.h safe to include anywhere

This commit is contained in:
sfan5 2024-09-09 20:39:35 +02:00
parent a18355e7e8
commit 4e9aa7dc77
12 changed files with 35 additions and 17 deletions

@ -396,12 +396,14 @@ set(independent_SRCS
gettext_plural_form.cpp gettext_plural_form.cpp
httpfetch.cpp httpfetch.cpp
hud.cpp hud.cpp
inventory.cpp
itemstackmetadata.cpp itemstackmetadata.cpp
lighting.cpp lighting.cpp
log.cpp log.cpp
metadata.cpp metadata.cpp
modchannels.cpp modchannels.cpp
nameidmapping.cpp nameidmapping.cpp
nodemetadata.cpp
nodetimer.cpp nodetimer.cpp
noise.cpp noise.cpp
objdef.cpp objdef.cpp
@ -429,7 +431,6 @@ set(common_SRCS
environment.cpp environment.cpp
filesys.cpp filesys.cpp
gettext.cpp gettext.cpp
inventory.cpp
inventorymanager.cpp inventorymanager.cpp
itemdef.cpp itemdef.cpp
light.cpp light.cpp
@ -440,7 +441,6 @@ set(common_SRCS
mapnode.cpp mapnode.cpp
mapsector.cpp mapsector.cpp
nodedef.cpp nodedef.cpp
nodemetadata.cpp
pathfinder.cpp pathfinder.cpp
player.cpp player.cpp
porting.cpp porting.cpp

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

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "shader.h" #include "shader.h"
#include "mapblock.h" #include "mapblock.h"
#include "client/renderingengine.h" #include "client/renderingengine.h"
#include "client/texturesource.h"
#include "gettext.h" #include "gettext.h"
//// ////

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/content_cao.h" #include "client/content_cao.h"
#include "client/clientevent.h" #include "client/clientevent.h"
#include "client/renderingengine.h" #include "client/renderingengine.h"
#include "client/texturesource.h"
#include "util/numeric.h" #include "util/numeric.h"
#include "light.h" #include "light.h"
#include "localplayer.h" #include "localplayer.h"

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiscalingfilter.h" #include "guiscalingfilter.h"
#include "localplayer.h" #include "localplayer.h"
#include "client/hud.h" #include "client/hud.h"
#include "client/texturesource.h"
#include "camera.h" #include "camera.h"
#include "minimap.h" #include "minimap.h"
#include "clientmap.h" #include "clientmap.h"

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h" #include "profiler.h"
#include "util/numeric.h" #include "util/numeric.h"
#include "client/renderingengine.h" #include "client/renderingengine.h"
#include "client/texturesource.h"
#include "settings.h" #include "settings.h"
#include "camera.h" // CameraModes #include "camera.h" // CameraModes

@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock_mesh.h" #include "mapblock_mesh.h"
#include "client/meshgen/collector.h" #include "client/meshgen/collector.h"
#include "client/tile.h" #include "client/tile.h"
#include "client/texturesource.h"
#include "log.h" #include "log.h"
#include "util/numeric.h" #include "util/numeric.h"
#include <map> #include <map>

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "client/client.h" #include "client/client.h"
#include "client/renderingengine.h" #include "client/renderingengine.h"
#include "client/texturesource.h"
#include "hud.h" #include "hud.h"
#include "inventory.h" #include "inventory.h"
#include "util/string.h" #include "util/string.h"

@ -34,13 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "itemdef.h" #include "itemdef.h"
#include "client/game.h" #include "client/game.h"
#include "util/basic_macros.h" #include "util/basic_macros.h"
#include "client/texturesource.h"
namespace irr namespace irr
{ {
class IrrlichtDevice; class IrrlichtDevice;
} }
using namespace irr;
using namespace irr::core; using namespace irr::core;
using namespace irr::gui; using namespace irr::gui;

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/mesh.h" #include "client/mesh.h"
#include "client/wieldmesh.h" #include "client/wieldmesh.h"
#include "client/client.h" #include "client/client.h"
#include "client/texturesource.h"
#endif #endif
#include "log.h" #include "log.h"
#include "settings.h" #include "settings.h"
@ -448,8 +449,9 @@ public:
// Get the definition // Get the definition
return m_item_definitions.find(name) != m_item_definitions.cend(); return m_item_definitions.find(name) != m_item_definitions.cend();
} }
#if CHECK_CLIENT_BUILD() #if CHECK_CLIENT_BUILD()
public: protected:
ClientCached* createClientCachedDirect(const ItemStack &item, Client *client) const ClientCached* createClientCachedDirect(const ItemStack &item, Client *client) const
{ {
// This is not thread-safe // This is not thread-safe
@ -490,6 +492,7 @@ public:
return ptr; return ptr;
} }
public:
// Get item inventory texture // Get item inventory texture
virtual video::ITexture* getInventoryTexture(const ItemStack &item, virtual video::ITexture* getInventoryTexture(const ItemStack &item,
Client *client) const Client *client) const

@ -35,11 +35,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class IGameDef; class IGameDef;
class Client; class Client;
struct ToolCapabilities; struct ToolCapabilities;
#if CHECK_CLIENT_BUILD()
#include "client/texturesource.h"
struct ItemMesh; struct ItemMesh;
struct ItemStack; struct ItemStack;
#endif typedef std::vector<video::SColor> Palette; // copied from src/client/texturesource.h
namespace irr::video { class ITexture; }
using namespace irr;
/* /*
Base item definition Base item definition
@ -155,25 +155,32 @@ public:
virtual void getAll(std::set<std::string> &result) const=0; virtual void getAll(std::set<std::string> &result) const=0;
// Check if item is known // Check if item is known
virtual bool isKnown(const std::string &name) const=0; 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 // 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 * 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 // 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 // Returns the base color of an item stack: the color of all
// tiles that do not define their own color. // tiles that do not define their own color.
virtual video::SColor getItemstackColor(const ItemStack &stack, virtual video::SColor getItemstackColor(const ItemStack &stack,
Client *client) const = 0; Client *client) const
#endif { return video::SColor(0); }
virtual void serialize(std::ostream &os, u16 protocol_version)=0;
}; };
class IWritableItemDefManager : public IItemDefManager class IWritableItemDefManager : public IItemDefManager

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/shader.h" #include "client/shader.h"
#include "client/client.h" #include "client/client.h"
#include "client/renderingengine.h" #include "client/renderingengine.h"
#include "client/texturesource.h"
#include "client/tile.h" #include "client/tile.h"
#include <IMeshManipulator.h> #include <IMeshManipulator.h>
#endif #endif