From 37095f3e49acd6fa35389b69c417b981fb9c4e6e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 15 Oct 2024 15:47:23 +0200 Subject: [PATCH] Change the preprocessor macro that differs server/client builds --- src/CMakeLists.txt | 4 +-- src/benchmark/benchmark_mapblock.cpp | 2 +- src/client/client.h | 3 +- src/client/clientenvironment.h | 3 +- src/client/game.h | 3 +- src/client/renderingengine.h | 3 +- src/client/sound.h | 3 +- src/clientdynamicinfo.cpp | 4 +-- src/clientdynamicinfo.h | 3 +- src/collision.cpp | 4 +-- src/config.h | 42 ++++++++++++++++++++++++++++ src/content/subgames.cpp | 4 +-- src/filesys.cpp | 4 +-- src/filesys.h | 3 +- src/gettext.cpp | 2 +- src/irrlichttypes_extrabloated.h | 3 +- src/itemdef.cpp | 10 +++---- src/itemdef.h | 4 +-- src/light.cpp | 2 +- src/light.h | 5 ++-- src/main.cpp | 8 +++--- src/mapblock.cpp | 4 +-- src/mapblock.h | 2 +- src/nodedef.cpp | 14 +++++----- src/nodedef.h | 8 +++--- src/player.cpp | 2 +- src/player.h | 2 +- src/porting.cpp | 2 +- src/porting_android.cpp | 2 -- src/porting_android.h | 2 -- src/script/common/c_content.cpp | 2 +- src/script/cpp_api/s_base.cpp | 10 +++---- src/script/cpp_api/s_base.h | 12 ++++---- src/script/cpp_api/s_security.cpp | 6 ++-- src/script/lua_api/l_base.cpp | 4 +-- src/script/lua_api/l_base.h | 4 +-- src/script/lua_api/l_env.cpp | 10 +++---- src/script/lua_api/l_http.cpp | 2 +- src/script/lua_api/l_internal.h | 2 +- src/script/lua_api/l_settings.cpp | 2 +- src/translation.cpp | 2 +- src/translation.h | 3 +- src/util/string.cpp | 2 +- src/util/string.h | 5 ++-- src/version.cpp | 2 +- 45 files changed, 137 insertions(+), 88 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6dd4c05d2..153a45dae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -602,6 +602,7 @@ if(BUILD_CLIENT) # on other platforms, only IrrlichtMt depends on SDL2 "$<$:${SDL2_LIBRARIES}>" ) + target_compile_definitions(${PROJECT_NAME} PRIVATE "MT_BUILDTARGET=1") if(NOT USE_LUAJIT) set_target_properties(${PROJECT_NAME} PROPERTIES # This is necessary for dynamic Lua modules @@ -679,8 +680,7 @@ if(BUILD_SERVER) ${GMP_LIBRARY} ${PLATFORM_LIBS} ) - set_target_properties(${PROJECT_NAME}server PROPERTIES - COMPILE_DEFINITIONS "SERVER") + target_compile_definitions(${PROJECT_NAME}server PRIVATE "MT_BUILDTARGET=2") if(NOT USE_LUAJIT) set_target_properties(${PROJECT_NAME}server PROPERTIES # This is necessary for dynamic Lua modules diff --git a/src/benchmark/benchmark_mapblock.cpp b/src/benchmark/benchmark_mapblock.cpp index 0b3f7c921..0f52c1d96 100644 --- a/src/benchmark/benchmark_mapblock.cpp +++ b/src/benchmark/benchmark_mapblock.cpp @@ -49,7 +49,7 @@ static inline void freeAll(MBContainer &vec) { freeSome(vec, vec.size()); } static void workOnMetadata(const MBContainer &vec) { for (MapBlock *block : vec) { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() bool foo = !!block->mesh; #else bool foo = true; diff --git a/src/client/client.h b/src/client/client.h index 0b26ff94d..0f9a8dafe 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -36,8 +36,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "script/common/c_types.h" // LuaError #include "util/numeric.h" #include "util/string.h" // StringMap +#include "config.h" -#ifdef SERVER +#if !IS_CLIENT_BUILD #error Do not include in server builds #endif diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index db31e69f2..a47cb7b5b 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -23,9 +23,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" // IntervalLimiter #include "activeobjectmgr.h" // client::ActiveObjectMgr #include "irr_ptr.h" +#include "config.h" #include -#ifdef SERVER +#if !IS_CLIENT_BUILD #error Do not include in server builds #endif diff --git a/src/client/game.h b/src/client/game.h index 0282e5ea9..a487d12f4 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -20,9 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes.h" +#include "config.h" #include -#ifdef SERVER +#if !IS_CLIENT_BUILD #error Do not include in server builds #endif diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index ffdda636c..5aa630350 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -26,13 +26,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/inputhandler.h" #include "irrlichttypes_extrabloated.h" #include "debug.h" +#include "config.h" #include "client/shader.h" #include "client/render/core.h" // include the shadow mapper classes too #include "client/shadows/dynamicshadowsrender.h" #include -#ifdef SERVER +#if !IS_CLIENT_BUILD #error Do not include in server builds #endif diff --git a/src/client/sound.h b/src/client/sound.h index 8b19f7761..294a0db7d 100644 --- a/src/client/sound.h +++ b/src/client/sound.h @@ -20,13 +20,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irr_v3d.h" +#include "config.h" #include #include #include #include #include -#ifdef SERVER +#if !IS_CLIENT_BUILD #error Do not include in server builds #endif diff --git a/src/clientdynamicinfo.cpp b/src/clientdynamicinfo.cpp index 12bc23abd..d0930c15c 100644 --- a/src/clientdynamicinfo.cpp +++ b/src/clientdynamicinfo.cpp @@ -17,10 +17,10 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef SERVER - #include "clientdynamicinfo.h" +#if CHECK_CLIENT_BUILD() + #include "settings.h" #include "client/renderingengine.h" #include "gui/guiFormSpecMenu.h" diff --git a/src/clientdynamicinfo.h b/src/clientdynamicinfo.h index c43fcb8d8..ae10ef745 100644 --- a/src/clientdynamicinfo.h +++ b/src/clientdynamicinfo.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_bloated.h" +#include "config.h" struct ClientDynamicInfo @@ -38,7 +39,7 @@ public: touch_controls == other.touch_controls; } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() static ClientDynamicInfo getCurrent(); private: diff --git a/src/collision.cpp b/src/collision.cpp index f554dac80..47a03fba9 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "nodedef.h" #include "gamedef.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/clientenvironment.h" #include "client/localplayer.h" #endif @@ -285,7 +285,7 @@ static void add_object_boxes(Environment *env, const f32 distance = speed_f.getLength() * dtime + box_0.getExtent().getLength() + 1.5f * BS; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() ClientEnvironment *c_env = dynamic_cast(env); if (c_env) { std::vector clientobjects; diff --git a/src/config.h b/src/config.h index 30e290acf..d573a0fab 100644 --- a/src/config.h +++ b/src/config.h @@ -5,3 +5,45 @@ #else #warning Missing configuration #endif + +/* + * There are three ways a Minetest source file can be built: + * 1) we are currently building it for exclusively linking into the client + * 2) we are currently building it for exclusively linking into the server + * 3) we are building it only once for linking into both the client and server + * In case of 1 and 2 that means a single source file may be built twice if + * both a client and server build was requested. + * + * These options map to the following macros: + * 1) IS_CLIENT_BUILD = 1 and CHECK_CLIENT_BUILD() = 1 + * 2) IS_CLIENT_BUILD = 0 and CHECK_CLIENT_BUILD() = 0 + * 3) IS_CLIENT_BUILD = 0 and CHECK_CLIENT_BUILD() undefined + * As a function style macro CHECK_CLIENT_BUILD() has the special property that it + * cause a compile error if it used but not defined. + * + * v v v v v v v v v READ THIS PART v v v v v v v v v + * So that object files can be safely shared, these macros need to be used like so: + * - use IS_CLIENT_BUILD to exclude optional helpers in header files or similar + * - use CHECK_CLIENT_BUILD() in all source files, or in headers where it + * influences program behavior or e.g. class structure + * In practice this means any shared object files (case 3) cannot include any + * code that references CHECK_CLIENT_BUILD(), because a compiler error will occur. + * ^ ^ ^ ^ ^ ^ ^ ^ ^ READ THIS PART ^ ^ ^ ^ ^ ^ ^ ^ ^ + * + * The background is that for any files built only once, we need to ensure that + * they are perfectly ABI-compatible between client/server or it will not work. + * This manifests either as a linker error (good case) or insidious memory corruption + * that causes obscure runtime behavior (bad case). + * Finally, note that the best option is to split code in such a way that usage + * of these macros is not necessary. + */ +#if MT_BUILDTARGET == 1 +#define IS_CLIENT_BUILD 1 +#define CHECK_CLIENT_BUILD() 1 +#elif MT_BUILDTARGET == 2 +#define IS_CLIENT_BUILD 0 +#define CHECK_CLIENT_BUILD() 0 +#else +#define IS_CLIENT_BUILD 0 +#endif +#undef MT_BUILDTARGET diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp index 9d5d528a8..f522ec5c5 100644 --- a/src/content/subgames.cpp +++ b/src/content/subgames.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map_settings_manager.h" #include "util/string.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/texturepaths.h" #endif @@ -192,7 +192,7 @@ SubgameSpec findSubgame(const std::string &id) } std::string menuicon_path; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() menuicon_path = getImagePath( game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png"); #endif diff --git a/src/filesys.cpp b/src/filesys.cpp index b0a1f318e..ad0b4b49e 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "config.h" #include "porting.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "irr_ptr.h" #include #include @@ -945,7 +945,7 @@ bool safeWriteToFile(const std::string &path, std::string_view content) return true; } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() bool extractZipFile(io::IFileSystem *fs, const char *filename, const std::string &destination) { // Be careful here not to touch the global file hierarchy in Irrlicht diff --git a/src/filesys.h b/src/filesys.h index bb71f22e5..c36428c9c 100644 --- a/src/filesys.h +++ b/src/filesys.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "config.h" #include #include #include @@ -154,7 +155,7 @@ const char *GetFilenameFromPath(const char *path); // logs and returns false on error bool safeWriteToFile(const std::string &path, std::string_view content); -#ifndef SERVER +#if IS_CLIENT_BUILD bool extractZipFile(irr::io::IFileSystem *fs, const char *filename, const std::string &destination); #endif diff --git a/src/gettext.cpp b/src/gettext.cpp index bb99e39bc..f60eaae23 100644 --- a/src/gettext.cpp +++ b/src/gettext.cpp @@ -184,7 +184,7 @@ void init_gettext(const char *path, const std::string &configured_language, setenv("LANGUAGE", configured_language.c_str(), 1); SetEnvironmentVariableA("LANGUAGE", configured_language.c_str()); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // Hack to force gettext to see the right environment if (current_language != configured_language) MSVC_LocaleWorkaround(argc, argv); diff --git a/src/irrlichttypes_extrabloated.h b/src/irrlichttypes_extrabloated.h index a3de2c3c8..35e33d9ce 100644 --- a/src/irrlichttypes_extrabloated.h +++ b/src/irrlichttypes_extrabloated.h @@ -20,8 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_bloated.h" +#include "config.h" // IS_CLIENT_BUILD -#ifndef SERVER +#if IS_CLIENT_BUILD #include #include #include diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 220c6fbb6..0bb90929e 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "tool.h" #include "inventory.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/mapblock_mesh.h" #include "client/mesh.h" #include "client/wieldmesh.h" @@ -374,7 +374,7 @@ void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version) class CItemDefManager: public IWritableItemDefManager { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() struct ClientCached { video::ITexture *inventory_texture; @@ -399,7 +399,7 @@ public: CItemDefManager() { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() m_main_thread = std::this_thread::get_id(); #endif clear(); @@ -448,7 +448,7 @@ public: // Get the definition return m_item_definitions.find(name) != m_item_definitions.cend(); } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() public: ClientCached* createClientCachedDirect(const ItemStack &item, Client *client) const { @@ -678,7 +678,7 @@ private: std::map m_item_definitions; // Aliases StringMap m_aliases; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // The id of the thread that is allowed to use irrlicht directly std::thread::id m_main_thread; // Cached textures and meshes diff --git a/src/itemdef.h b/src/itemdef.h index 44fab8d91..1cfd475e5 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class IGameDef; class Client; struct ToolCapabilities; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/texturesource.h" struct ItemMesh; struct ItemStack; @@ -155,7 +155,7 @@ public: virtual void getAll(std::set &result) const=0; // Check if item is known virtual bool isKnown(const std::string &name) const=0; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // Get item inventory texture virtual video::ITexture* getInventoryTexture(const ItemStack &item, Client *client) const=0; diff --git a/src/light.cpp b/src/light.cpp index d5389b450..f159a2bed 100644 --- a/src/light.cpp +++ b/src/light.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "settings.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() static u8 light_LUT[LIGHT_SUN + 1]; diff --git a/src/light.h b/src/light.h index 44082a163..285ea4d9b 100644 --- a/src/light.h +++ b/src/light.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include +#include "config.h" #include "irrlichttypes.h" /* @@ -35,7 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // This brightness is reserved for sunlight #define LIGHT_SUN 15 -#ifndef SERVER +#if IS_CLIENT_BUILD /** * \internal @@ -67,7 +68,7 @@ float decode_light_f(float light_f); void set_light_table(float gamma); -#endif // ifndef SERVER +#endif // 0 <= daylight_factor <= 1000 // 0 <= lightday, lightnight <= LIGHT_SUN diff --git a/src/main.cpp b/src/main.cpp index 803f3c6b0..6928b5c74 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,7 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #if USE_CURSES #include "terminal_chat_console.h" #endif -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "gui/guiMainMenu.h" #include "client/clientlauncher.h" #include "gui/guiEngine.h" @@ -243,7 +243,7 @@ int main(int argc, char *argv[]) } GameStartData game_params; -#ifdef SERVER +#if !CHECK_CLIENT_BUILD() porting::attachOrCreateConsole(); game_params.is_dedicated_server = true; #else @@ -261,7 +261,7 @@ int main(int argc, char *argv[]) if (game_params.is_dedicated_server) return run_dedicated_server(game_params, cmd_args) ? 0 : 1; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() retval = ClientLauncher().run(game_params, cmd_args) ? 0 : 1; #else retval = 0; @@ -377,7 +377,7 @@ static void set_allowed_options(OptionList *allowed_options) _("Feature an interactive terminal (Only works when using minetestserver or with --server)")))); allowed_options->insert(std::make_pair("recompress", ValueSpec(VALUETYPE_FLAG, _("Recompress the blocks of the given map database.")))); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() allowed_options->insert(std::make_pair("address", ValueSpec(VALUETYPE_STRING, _("Address to connect to. ('' = local game)")))); allowed_options->insert(std::make_pair("random-input", ValueSpec(VALUETYPE_FLAG, diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 714b47ec1..04e2a56dc 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_mapnode.h" // For legacy name-id mapping #include "content_nodemeta.h" // For legacy deserialization #include "serialization.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/mapblock_mesh.h" #endif #include "porting.h" @@ -77,7 +77,7 @@ MapBlock::MapBlock(v3s16 pos, IGameDef *gamedef): MapBlock::~MapBlock() { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() { delete mesh; mesh = nullptr; diff --git a/src/mapblock.h b/src/mapblock.h index 044c104bc..a9e6386e1 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -460,7 +460,7 @@ private: */ public: -#ifndef SERVER // Only on client +#if CHECK_CLIENT_BUILD() // Only on client MapBlockMesh *mesh = nullptr; // marks the sides which are opaque: 00+Z-Z+Y-Y+X-X diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 811753c89..2b3b3b1fb 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "itemdef.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/mesh.h" #include "client/shader.h" #include "client/client.h" @@ -332,7 +332,7 @@ ContentFeatures::ContentFeatures() ContentFeatures::~ContentFeatures() { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() for (u16 j = 0; j < 6; j++) { delete tiles[j].layers[0].frames; delete tiles[j].layers[1].frames; @@ -347,7 +347,7 @@ void ContentFeatures::reset() /* Cached stuff */ -#ifndef SERVER +#if CHECK_CLIENT_BUILD() solidness = 2; visual_solidness = 0; backface_culling = true; @@ -370,7 +370,7 @@ void ContentFeatures::reset() groups["dig_immediate"] = 2; drawtype = NDT_NORMAL; mesh.clear(); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() for (auto &i : mesh_ptr) i = NULL; minimap_color = video::SColor(0, 0, 0, 0); @@ -686,7 +686,7 @@ void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version) } catch (SerializationError &e) {}; } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer, const TileSpec &tile, const TileDef &tiledef, video::SColor color, u8 material_type, u32 shader_id, bool backface_culling, @@ -1026,7 +1026,7 @@ NodeDefManager::NodeDefManager() NodeDefManager::~NodeDefManager() { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() for (ContentFeatures &f : m_content_features) { for (auto &j : f.mesh_ptr) { if (j) @@ -1479,7 +1479,7 @@ void NodeDefManager::applyTextureOverrides(const std::vector &o void NodeDefManager::updateTextures(IGameDef *gamedef, void *progress_callback_args) { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() infostream << "NodeDefManager::updateTextures(): Updating " "textures in node definitions" << std::endl; diff --git a/src/nodedef.h b/src/nodedef.h index de713a1ad..ac583dfd3 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "mapnode.h" #include "nameidmapping.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/tile.h" #include class Client; @@ -315,7 +315,7 @@ struct ContentFeatures /* Cached stuff */ -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // 0 1 2 3 4 5 // up down right left back front TileSpec tiles[6]; @@ -351,7 +351,7 @@ struct ContentFeatures enum NodeDrawType drawtype; std::string mesh; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() scene::IMesh *mesh_ptr[24]; video::SColor minimap_color; #endif @@ -530,7 +530,7 @@ struct ContentFeatures return itemgroup_get(groups, group); } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc, scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings); #endif diff --git a/src/player.cpp b/src/player.cpp index 7361549e0..d784b0c12 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -209,7 +209,7 @@ void PlayerControl::setMovementFromKeys() movement_direction = std::atan2(x, y); } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() u32 PlayerControl::getKeysPressed() const { diff --git a/src/player.h b/src/player.h index c729f98a0..d2687a099 100644 --- a/src/player.h +++ b/src/player.h @@ -91,7 +91,7 @@ struct PlayerControl // joystick input. void setMovementFromKeys(); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // For client use u32 getKeysPressed() const; inline bool isMoving() const { return movement_speed > 0.001f; } diff --git a/src/porting.cpp b/src/porting.cpp index f6409c56c..6b7952836 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -80,7 +80,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#if !defined(SERVER) && defined(_WIN32) +#if CHECK_CLIENT_BUILD() && defined(_WIN32) // On Windows export some driver-specific variables to encourage Minetest to be // executed on the discrete GPU in case of systems with two. Portability is fun. extern "C" { diff --git a/src/porting_android.cpp b/src/porting_android.cpp index 760feedfe..142aeb652 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -249,7 +249,6 @@ int getInputDialogSelection() return jnienv->CallIntMethod(activity, dialogvalue); } -#ifndef SERVER float getDisplayDensity() { static bool firstrun = true; @@ -325,5 +324,4 @@ bool hasPhysicalKeyboardAndroid() return result; } -#endif // ndef SERVER } diff --git a/src/porting_android.h b/src/porting_android.h index 8b015553b..efc1a19c2 100644 --- a/src/porting_android.h +++ b/src/porting_android.h @@ -97,9 +97,7 @@ int getInputDialogSelection(); bool hasPhysicalKeyboardAndroid(); -#ifndef SERVER float getDisplayDensity(); v2u32 getDisplaySize(); -#endif } diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 65525eed5..1016f373e 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -998,7 +998,7 @@ void push_content_features(lua_State *L, const ContentFeatures &c) lua_pushstring(L, c.mesh.c_str()); lua_setfield(L, -2, "mesh"); } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() push_ARGB8(L, c.minimap_color); // I know this is not set-able w/ register_node, lua_setfield(L, -2, "minimap_color"); // but the people need to know! #endif diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index cd74b7cfd..0c287be67 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "porting.h" #include "util/string.h" #include "server.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/client.h" #endif @@ -185,7 +185,7 @@ int ScriptApiBase::luaPanic(lua_State *L) return 0; } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() void ScriptApiBase::clientOpenLibs(lua_State *L) { static const std::vector> m_libs = { @@ -305,7 +305,7 @@ void ScriptApiBase::loadScript(const std::string &script_path) lua_pop(L, 1); // Pop error handler } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() void ScriptApiBase::loadModFromMemory(const std::string &mod_name) { ModNameStorer mod_name_storer(getStack(), mod_name); @@ -351,7 +351,7 @@ void ScriptApiBase::loadModFromMemory(const std::string &mod_name) void ScriptApiBase::runCallbacksRaw(int nargs, RunCallbacksMode mode, const char *fxn) { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // Hard fail for bad guarded callbacks // Only run callbacks when the scripting enviroment is loaded FATAL_ERROR_IF(m_type == ScriptingType::Client && @@ -565,7 +565,7 @@ Server* ScriptApiBase::getServer() return dynamic_cast(m_gamedef); } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() Client* ScriptApiBase::getClient() { return dynamic_cast(m_gamedef); diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h index ac74c2e68..d232edc64 100644 --- a/src/script/cpp_api/s_base.h +++ b/src/script/cpp_api/s_base.h @@ -66,7 +66,7 @@ enum class ScriptingType: u8 { }; class Server; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() class Client; #endif class EmergeThread; @@ -91,7 +91,7 @@ public: void loadMod(const std::string &script_path, const std::string &mod_name); void loadScript(const std::string &script_path); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() void loadModFromMemory(const std::string &mod_name); #endif @@ -106,7 +106,7 @@ public: IGameDef *getGameDef() { return m_gamedef; } Server* getServer(); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() Client* getClient(); #endif @@ -128,7 +128,7 @@ public: // returns "" on error static std::string getCurrentModName(lua_State *L); -#ifdef SERVER +#if !CHECK_CLIENT_BUILD() inline void clientOpenLibs(lua_State *L) { assert(false); } #else void clientOpenLibs(lua_State *L); @@ -172,7 +172,7 @@ protected: Environment* getEnv() { return m_environment; } void setEnv(Environment* env) { m_environment = env; } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() GUIEngine* getGuiEngine() { return m_guiengine; } void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; } #endif @@ -199,7 +199,7 @@ private: IGameDef *m_gamedef = nullptr; Environment *m_environment = nullptr; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() GUIEngine *m_guiengine = nullptr; #endif EmergeThread *m_emerge = nullptr; diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index 9a4b0763b..11db1c0ef 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "porting.h" #include "server.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/client.h" #endif #include "settings.h" @@ -423,7 +423,7 @@ void ScriptApiSecurity::setLuaEnv(lua_State *L, int thread) bool ScriptApiSecurity::isSecure(lua_State *L) { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() auto script = ModApiBase::getScriptApiBase(L); // CSM keeps no globals backup but is always secure if (script->getType() == ScriptingType::Client) @@ -743,7 +743,7 @@ int ScriptApiSecurity::sl_g_load(lua_State *L) int ScriptApiSecurity::sl_g_loadfile(lua_State *L) { -#ifndef SERVER +#if CHECK_CLIENT_BUILD() ScriptApiBase *script = ModApiBase::getScriptApiBase(L); // Client implementation diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 962b262a1..162f7d9f9 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -51,7 +51,7 @@ ServerInventoryManager *ModApiBase::getServerInventoryMgr(lua_State *L) return getScriptApiBase(L)->getServer()->getInventoryMgr(); } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() Client *ModApiBase::getClient(lua_State *L) { return getScriptApiBase(L)->getClient(); @@ -68,7 +68,7 @@ Environment *ModApiBase::getEnv(lua_State *L) return getScriptApiBase(L)->getEnv(); } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() GUIEngine *ModApiBase::getGuiEngine(lua_State *L) { return getScriptApiBase(L)->getGuiEngine(); diff --git a/src/script/lua_api/l_base.h b/src/script/lua_api/l_base.h index 37132426a..ded9db371 100644 --- a/src/script/lua_api/l_base.h +++ b/src/script/lua_api/l_base.h @@ -30,7 +30,7 @@ extern "C" { #include } -#ifndef SERVER +#if CHECK_CLIENT_BUILD() class Client; class GUIEngine; #endif @@ -45,7 +45,7 @@ public: static ScriptApiBase* getScriptApiBase(lua_State *L); static Server* getServer(lua_State *L); static ServerInventoryManager *getServerInventoryMgr(lua_State *L); - #ifndef SERVER + #if CHECK_CLIENT_BUILD() static Client* getClient(lua_State *L); static GUIEngine* getGuiEngine(lua_State *L); #endif // !SERVER diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 726300b07..7e8b44da9 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -43,7 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server/player_sao.h" #include "util/string.h" #include "translation.h" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() #include "client/client.h" #endif @@ -71,7 +71,7 @@ int LuaRaycast::l_next(lua_State *L) ServerEnvironment *senv = dynamic_cast(env); bool csm = false; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() csm = getClient(L) != nullptr; #endif @@ -847,7 +847,7 @@ int ModApiEnv::l_find_node_near(lua_State *L) int start_radius = (lua_isboolean(L, 4) && readParam(L, 4)) ? 0 : 1; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // Client API limitations if (Client *client = getClient(L)) radius = client->CSMClampRadius(pos, radius); @@ -959,7 +959,7 @@ int ModApiEnv::l_find_nodes_in_area(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); Map &map = env->getMap(); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() if (Client *client = getClient(L)) { minp = client->CSMClampPos(minp); maxp = client->CSMClampPos(maxp); @@ -1021,7 +1021,7 @@ int ModApiEnv::l_find_nodes_in_area_under_air(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); Map &map = env->getMap(); -#ifndef SERVER +#if CHECK_CLIENT_BUILD() if (Client *client = getClient(L)) { minp = client->CSMClampPos(minp); maxp = client->CSMClampPos(maxp); diff --git a/src/script/lua_api/l_http.cpp b/src/script/lua_api/l_http.cpp index 57f632291..ea965c921 100644 --- a/src/script/lua_api/l_http.cpp +++ b/src/script/lua_api/l_http.cpp @@ -222,7 +222,7 @@ void ModApiHttp::Initialize(lua_State *L, int top) #if USE_CURL bool isMainmenu = false; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() isMainmenu = ModApiBase::getGuiEngine(L) != nullptr; #endif diff --git a/src/script/lua_api/l_internal.h b/src/script/lua_api/l_internal.h index de73ff42a..fb20c061a 100644 --- a/src/script/lua_api/l_internal.h +++ b/src/script/lua_api/l_internal.h @@ -47,7 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc., /* In debug mode ensure no code tries to retrieve the server env when it isn't * actually available (in CSM) */ -#if !defined(SERVER) && !defined(NDEBUG) +#if CHECK_CLIENT_BUILD() && !defined(NDEBUG) #define DEBUG_ASSERT_NO_CLIENTAPI \ FATAL_ERROR_IF(getClient(L) != nullptr, "Tried " \ "to retrieve ServerEnvironment on client") diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index ee46c3fdd..cde337b1a 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -46,7 +46,7 @@ static inline int checkSettingSecurity(lua_State* L, const std::string &name) throw LuaError("Attempted to set secure setting."); bool is_mainmenu = false; -#ifndef SERVER +#if CHECK_CLIENT_BUILD() is_mainmenu = ModApiBase::getGuiEngine(L) != nullptr; #endif if (!is_mainmenu && (name == "mg_name" || name == "mg_flags")) { diff --git a/src/translation.cpp b/src/translation.cpp index 728789acc..069ab3441 100644 --- a/src/translation.cpp +++ b/src/translation.cpp @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include -#ifndef SERVER +#if CHECK_CLIENT_BUILD() // Client translations static Translations client_translations; Translations *g_client_translations = &client_translations; diff --git a/src/translation.h b/src/translation.h index 972cdafef..3471f5789 100644 --- a/src/translation.h +++ b/src/translation.h @@ -25,9 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "config.h" class Translations; -#ifndef SERVER +#if IS_CLIENT_BUILD extern Translations *g_client_translations; #endif diff --git a/src/util/string.cpp b/src/util/string.cpp index b05d993a5..dc06681dc 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -935,7 +935,7 @@ std::wstring translate_string(std::wstring_view s, Translations *translations) // Translate string client side std::wstring translate_string(std::wstring_view s) { -#ifdef SERVER +#if !CHECK_CLIENT_BUILD() return translate_string(s, nullptr); #else return translate_string(s, g_client_translations); diff --git a/src/util/string.h b/src/util/string.h index 50e208966..90f0417ab 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -20,7 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_bloated.h" -#ifndef SERVER +#include "config.h" // IS_CLIENT_BUILD +#if IS_CLIENT_BUILD #include "irrString.h" #endif #include @@ -755,7 +756,7 @@ inline std::string str_join(const std::vector &list, return oss.str(); } -#ifndef SERVER +#if IS_CLIENT_BUILD /** * Create a UTF8 std::string from an irr::core::stringw. */ diff --git a/src/version.cpp b/src/version.cpp index 46c9d1520..8af1bb6d7 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -37,7 +37,7 @@ const char *g_build_info = "BUILD_TYPE=" BUILD_TYPE "\n" "RUN_IN_PLACE=" STR(RUN_IN_PLACE) "\n" "USE_CURL=" STR(USE_CURL) "\n" -#ifndef SERVER +#if CHECK_CLIENT_BUILD() "USE_GETTEXT=" STR(USE_GETTEXT) "\n" "USE_SOUND=" STR(USE_SOUND) "\n" #endif