1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Change the preprocessor macro that differs server/client builds

This commit is contained in:
sfan5 2024-10-15 15:47:23 +02:00
parent e2ea359925
commit 37095f3e49
45 changed files with 137 additions and 88 deletions

View file

@ -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

View file

@ -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<std::pair<std::string, lua_CFunction>> 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<Server *>(m_gamedef);
}
#ifndef SERVER
#if CHECK_CLIENT_BUILD()
Client* ScriptApiBase::getClient()
{
return dynamic_cast<Client *>(m_gamedef);

View file

@ -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;

View file

@ -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

View file

@ -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();

View file

@ -30,7 +30,7 @@ extern "C" {
#include <lauxlib.h>
}
#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

View file

@ -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<ServerEnvironment*>(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<bool>(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);

View file

@ -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

View file

@ -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")

View file

@ -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")) {