Move some more sources to shared target

This commit is contained in:
sfan5 2024-09-09 21:34:56 +02:00
parent 16fef8f479
commit 0a8eb2c71c
10 changed files with 40 additions and 49 deletions

View File

@ -391,7 +391,10 @@ add_subdirectory(server)
# a compiler error and you need to instead add it to client_SRCS or common_SRCS.
set(independent_SRCS
chat.cpp
content_nodemeta.cpp
convert_json.cpp
craftdef.cpp
debug.cpp
face_position_cache.cpp
httpfetch.cpp
hud.cpp
@ -410,11 +413,17 @@ set(independent_SRCS
particles.cpp
profiler.cpp
serialization.cpp
settings.cpp
staticobject.cpp
terminal_chat_console.cpp
texture_override.cpp
tileanimation.cpp
tool.cpp
${common_network_SRCS}
${content_SRCS}
${database_SRCS}
${threading_SRCS}
${util_SRCS}
)
# /!\ Consider carefully before adding files here /!\
@ -422,9 +431,6 @@ set(common_SRCS
clientdynamicinfo.cpp
collision.cpp
content_mapnode.cpp
content_nodemeta.cpp
craftdef.cpp
debug.cpp
defaultsettings.cpp
emerge.cpp
environment.cpp
@ -450,19 +456,14 @@ set(common_SRCS
server.cpp
serverenvironment.cpp
servermap.cpp
settings.cpp
tool.cpp
translation.cpp
version.cpp
voxel.cpp
voxelalgorithms.cpp
${common_network_SRCS}
${common_SCRIPT_SRCS}
${common_server_SRCS}
${content_SRCS}
${database_SRCS}
${mapgen_SRCS}
${UTIL_SRCS}
${server_network_SRCS}
)
if(ANDROID)
@ -586,6 +587,9 @@ add_library(EngineCommon OBJECT
${independent_SRCS}
)
add_dependencies(EngineCommon GenerateVersion)
target_link_libraries(EngineCommon
sha256
)
get_target_property(
IRRLICHT_INCLUDES IrrlichtMt::IrrlichtMt INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(EngineCommon PRIVATE ${IRRLICHT_INCLUDES})

View File

@ -28,10 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map_settings_manager.h"
#include "util/string.h"
#if CHECK_CLIENT_BUILD()
#include "client/texturepaths.h"
#endif
// The maximum number of identical world names allowed
#define MAX_WORLD_NAMES 100
@ -96,8 +92,7 @@ std::string getSubgamePathEnv()
static SubgameSpec getSubgameSpec(const std::string &game_id,
const std::string &game_path,
const std::unordered_map<std::string, std::string> &mods_paths,
const std::string &menuicon_path)
const std::unordered_map<std::string, std::string> &mods_paths)
{
const auto gamemods_path = game_path + DIR_DELIM + "mods";
// Get meta
@ -130,7 +125,7 @@ static SubgameSpec getSubgameSpec(const std::string &game_id,
last_mod = conf.get("last_mod");
SubgameSpec spec(game_id, game_path, gamemods_path, mods_paths, game_title,
menuicon_path, game_author, game_release, first_mod, last_mod);
game_author, game_release, first_mod, last_mod);
if (conf.exists("name") && !conf.exists("title"))
spec.deprecation_msgs.push_back("\"name\" setting in game.conf is deprecated, please use \"title\" instead");
@ -191,13 +186,7 @@ SubgameSpec findSubgame(const std::string &id)
mods_paths[fs::AbsolutePath(mod_path)] = mod_path;
}
std::string menuicon_path;
#if CHECK_CLIENT_BUILD()
menuicon_path = getImagePath(
game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
#endif
return getSubgameSpec(id, game_path, mods_paths, menuicon_path);
return getSubgameSpec(id, game_path, mods_paths);
}
SubgameSpec findWorldSubgame(const std::string &world_path)
@ -206,7 +195,7 @@ SubgameSpec findWorldSubgame(const std::string &world_path)
// See if world contains an embedded game; if so, use it.
std::string world_gamepath = world_path + DIR_DELIM + "game";
if (fs::PathExists(world_gamepath))
return getSubgameSpec(world_gameid, world_gamepath, {}, "");
return getSubgameSpec(world_gameid, world_gamepath, {});
return findSubgame(world_gameid);
}

View File

@ -41,7 +41,6 @@ struct SubgameSpec
* Map from virtual path to mods path
*/
std::unordered_map<std::string, std::string> addon_mods_paths;
std::string menuicon_path;
// For logging purposes
std::vector<const char *> deprecation_msgs;
@ -50,7 +49,6 @@ struct SubgameSpec
const std::string &gamemods_path = "",
const std::unordered_map<std::string, std::string> &addon_mods_paths = {},
const std::string &title = "",
const std::string &menuicon_path = "",
const std::string &author = "", int release = 0,
const std::string &first_mod = "",
const std::string &last_mod = "") :
@ -60,8 +58,7 @@ struct SubgameSpec
last_mod(last_mod),
path(path),
gamemods_path(gamemods_path),
addon_mods_paths(addon_mods_paths),
menuicon_path(menuicon_path)
addon_mods_paths(addon_mods_paths)
{
}

View File

@ -4,9 +4,13 @@ set(common_network_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/mtp/impl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mtp/threads.cpp
${CMAKE_CURRENT_SOURCE_DIR}/networkpacket.cpp
${CMAKE_CURRENT_SOURCE_DIR}/socket.cpp
PARENT_SCOPE
)
set(server_network_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/serveropcodes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serverpackethandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/socket.cpp
PARENT_SCOPE
)

View File

@ -31,7 +31,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <tuple>
bool is_valid_player_name(std::string_view name) {
bool is_valid_player_name(std::string_view name)
{
return !name.empty() && name.size() <= PLAYERNAME_SIZE && string_allowed(name, PLAYERNAME_ALLOWED_CHARS);
}
@ -173,8 +174,6 @@ u16 Player::getMaxHotbarItemcount()
return mainlist ? std::min(mainlist->getSize(), (u32) hud_hotbar_itemcount) : 0;
}
#if CHECK_CLIENT_BUILD()
u32 PlayerControl::getKeysPressed() const
{
u32 keypress_bits =
@ -218,7 +217,6 @@ u32 PlayerControl::getKeysPressed() const
return keypress_bits;
}
#endif
void PlayerControl::unpackKeysPressed(u32 keypress_bits)
{

View File

@ -86,11 +86,9 @@ struct PlayerControl
movement_direction = a_movement_direction;
}
#if CHECK_CLIENT_BUILD()
// For client use
u32 getKeysPressed() const;
inline bool isMoving() const { return movement_speed > 0.001f; }
#endif
// For server use
void unpackKeysPressed(u32 keypress_bits);

View File

@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientdynamicinfo.h"
#include "client/client.h"
#include "client/renderingengine.h"
#include "client/texturepaths.h"
#include "network/networkprotocol.h"
#include "content/mod_configuration.h"
#include "threading/mutex_auto_lock.h"
@ -329,8 +330,9 @@ int ModApiMainMenu::l_get_games(lua_State *L)
lua_pushinteger(L, game.release);
lua_settable(L, top_lvl2);
auto menuicon = getImagePath(game.path + DIR_DELIM "menu" DIR_DELIM "icon.png");
lua_pushstring(L, "menuicon_path");
lua_pushstring(L, game.menuicon_path.c_str());
lua_pushstring(L, menuicon.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L, "addon_mods_paths");

View File

@ -1,4 +1,4 @@
set(UTIL_SRCS
set(util_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/areastore.cpp
${CMAKE_CURRENT_SOURCE_DIR}/auth.cpp
${CMAKE_CURRENT_SOURCE_DIR}/colorize.cpp

View File

@ -856,16 +856,6 @@ std::wstring translate_string(std::wstring_view s, Translations *translations)
return res;
}
// Translate string client side
std::wstring translate_string(std::wstring_view s)
{
#if !CHECK_CLIENT_BUILD()
return translate_string(s, nullptr);
#else
return translate_string(s, g_client_translations);
#endif
}
static const std::array<std::wstring_view, 30> disallowed_dir_names = {
// Problematic filenames from here:
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#file-and-directory-names

View File

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "config.h" // IS_CLIENT_BUILD
#if IS_CLIENT_BUILD
#include "irrString.h"
#include "translation.h"
#endif
#include <cstdlib>
#include <string>
@ -634,9 +635,17 @@ std::vector<std::basic_string<T> > split(const std::basic_string<T> &s, T delim)
std::wstring translate_string(std::wstring_view s, Translations *translations);
std::wstring translate_string(std::wstring_view s);
inline std::wstring translate_string(std::wstring_view s)
{
#if IS_CLIENT_BUILD
return translate_string(s, g_client_translations);
#else
return translate_string(s, nullptr);
#endif
}
inline std::wstring unescape_translate(std::wstring_view s) {
inline std::wstring unescape_translate(std::wstring_view s)
{
return unescape_enriched(translate_string(s));
}