From 0f177bad46df523e8b58070e238ed76cf010e097 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Fri, 2 Oct 2020 16:16:16 +0200 Subject: [PATCH 1/8] Add explicit button for current map as BG --- src/game/client/components/menus_settings.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 1eb11caf3..d264e056b 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -2013,7 +2013,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) } } - MainView.HSplitTop(310.0f, &Gameplay, &MainView); + MainView.HSplitTop(330.0f, &Gameplay, &MainView); Gameplay.HSplitTop(30.0f, &Label, &Gameplay); UI()->DoLabelScaled(&Label, Localize("Gameplay"), 20.0f, -1); @@ -2177,6 +2177,16 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) UI()->DoLabelScaled(&Label, Localize("Map"), 14.0f, -1); DoEditBox(g_Config.m_ClBackgroundEntities, &Left, g_Config.m_ClBackgroundEntities, sizeof(g_Config.m_ClBackgroundEntities), 14.0f, &s_Map); + aRects[1].HSplitTop(20.0f, &Button, &aRects[1]); + bool UseCurrentMap = str_comp(g_Config.m_ClBackgroundEntities, CURRENT) == 0; + if(DoButton_CheckBox(&UseCurrentMap, Localize("Use current map as background"), UseCurrentMap, &Button)) + { + if(UseCurrentMap) + g_Config.m_ClBackgroundEntities[0] = '\0'; + else + str_copy(g_Config.m_ClBackgroundEntities, CURRENT, sizeof(g_Config.m_ClBackgroundEntities)); + } + aRects[1].HSplitTop(20.0f, &Button, 0); if(DoButton_CheckBox(&g_Config.m_ClBackgroundShowTilesLayers, Localize("Show tiles layers from BG map"), g_Config.m_ClBackgroundShowTilesLayers, &Button)) { From 2dc725e0f6238efdb4e93c04a3a0f94da68807ab Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Fri, 2 Oct 2020 16:21:18 +0200 Subject: [PATCH 2/8] Rename CURRENT to CURRENT_MAP --- src/game/client/components/background.cpp | 6 +++--- src/game/client/components/background.h | 2 +- src/game/client/components/menus_settings.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game/client/components/background.cpp b/src/game/client/components/background.cpp index 6b28d8297..bfdb6e69d 100644 --- a/src/game/client/components/background.cpp +++ b/src/game/client/components/background.cpp @@ -39,7 +39,7 @@ void CBackground::OnInit() { m_pImages->m_pClient = GameClient(); Kernel()->RegisterInterface(m_pBackgroundMap); - if(g_Config.m_ClBackgroundEntities[0] != '\0' && str_comp(g_Config.m_ClBackgroundEntities, CURRENT)) + if(g_Config.m_ClBackgroundEntities[0] != '\0' && str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP)) LoadBackground(); } @@ -68,7 +68,7 @@ void CBackground::LoadBackground() NeedImageLoading = true; m_Loaded = true; } - else if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT) == 0) + else if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0) { m_pMap = Kernel()->RequestInterface(); if(m_pMap->IsLoaded()) @@ -91,7 +91,7 @@ void CBackground::LoadBackground() void CBackground::OnMapLoad() { - if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT) == 0 || str_comp(g_Config.m_ClBackgroundEntities, m_aMapName)) + if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0 || str_comp(g_Config.m_ClBackgroundEntities, m_aMapName)) { m_LastLoad = 0; LoadBackground(); diff --git a/src/game/client/components/background.h b/src/game/client/components/background.h index 941e09c4f..ba61ede1a 100644 --- a/src/game/client/components/background.h +++ b/src/game/client/components/background.h @@ -5,7 +5,7 @@ #include // Special value to use background of current map -#define CURRENT "%current%" +#define CURRENT_MAP "%current%" class CBackgroundEngineMap : public CMap { diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index d264e056b..024633a2e 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -2178,13 +2178,13 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) DoEditBox(g_Config.m_ClBackgroundEntities, &Left, g_Config.m_ClBackgroundEntities, sizeof(g_Config.m_ClBackgroundEntities), 14.0f, &s_Map); aRects[1].HSplitTop(20.0f, &Button, &aRects[1]); - bool UseCurrentMap = str_comp(g_Config.m_ClBackgroundEntities, CURRENT) == 0; + bool UseCurrentMap = str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0; if(DoButton_CheckBox(&UseCurrentMap, Localize("Use current map as background"), UseCurrentMap, &Button)) { if(UseCurrentMap) g_Config.m_ClBackgroundEntities[0] = '\0'; else - str_copy(g_Config.m_ClBackgroundEntities, CURRENT, sizeof(g_Config.m_ClBackgroundEntities)); + str_copy(g_Config.m_ClBackgroundEntities, CURRENT_MAP, sizeof(g_Config.m_ClBackgroundEntities)); } aRects[1].HSplitTop(20.0f, &Button, 0); From 317bf6bba41cb6ddb650b6de53b85616a09915c7 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Fri, 2 Oct 2020 16:23:16 +0200 Subject: [PATCH 3/8] Don't try to load %current% as a normal map --- src/game/client/components/background.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/game/client/components/background.cpp b/src/game/client/components/background.cpp index bfdb6e69d..8a894eee3 100644 --- a/src/game/client/components/background.cpp +++ b/src/game/client/components/background.cpp @@ -61,14 +61,7 @@ void CBackground::LoadBackground() str_copy(m_aMapName, g_Config.m_ClBackgroundEntities, sizeof(m_aMapName)); char aBuf[128]; str_format(aBuf, sizeof(aBuf), "maps/%s", g_Config.m_ClBackgroundEntities); - if(m_pMap->Load(aBuf)) - { - m_pLayers->InitBackground(m_pMap); - RenderTools()->RenderTilemapGenerateSkip(m_pLayers); - NeedImageLoading = true; - m_Loaded = true; - } - else if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0) + if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0) { m_pMap = Kernel()->RequestInterface(); if(m_pMap->IsLoaded()) @@ -78,6 +71,13 @@ void CBackground::LoadBackground() m_Loaded = true; } } + else if(m_pMap->Load(aBuf)) + { + m_pLayers->InitBackground(m_pMap); + RenderTools()->RenderTilemapGenerateSkip(m_pLayers); + NeedImageLoading = true; + m_Loaded = true; + } if(m_Loaded) { From 6a79cc3e591e88bc38daa801f9d8269b3e0cfb25 Mon Sep 17 00:00:00 2001 From: def Date: Mon, 21 Sep 2020 00:07:31 +0200 Subject: [PATCH 4/8] Determine binary dir independently of data dir (fixes #2891) @Learath2 Could you check if this can be extended to also find the DDNet-Server executable on Mac? --- src/engine/shared/storage.cpp | 82 +++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 14 deletions(-) diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index 2f909d5d0..69c8fd511 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -3,6 +3,7 @@ #include "linereader.h" #include #include +#include #include class CStorage : public IStorage @@ -31,6 +32,9 @@ public: // get datadir FindDatadir(ppArguments[0]); + // get binarydir + FindBinarydir(ppArguments[0]); + // get currentdir if(!fs_getcwd(m_aCurrentdir, sizeof(m_aCurrentdir))) m_aCurrentdir[0] = 0; @@ -166,7 +170,6 @@ public: if(fs_is_dir("data/mapres")) { str_copy(m_aDatadir, "data", sizeof(m_aDatadir)); - str_copy(m_aBinarydir, "", sizeof(m_aBinarydir)); return; } @@ -175,11 +178,6 @@ public: if(fs_is_dir(DATA_DIR "/mapres")) { str_copy(m_aDatadir, DATA_DIR, sizeof(m_aDatadir)); -#if defined(BINARY_DIR) - str_copy(m_aBinarydir, BINARY_DIR, sizeof(m_aBinarydir)); -#else - str_copy(m_aBinarydir, DATA_DIR "/..", sizeof(m_aBinarydir)); -#endif return; } #endif @@ -194,15 +192,14 @@ public: if(Pos < MAX_PATH_LENGTH) { char aBuf[MAX_PATH_LENGTH]; - str_copy(m_aBinarydir, pArgv0, Pos + 1); - str_format(aBuf, sizeof(aBuf), "%s/data/mapres", m_aBinarydir); + char aDir[MAX_PATH_LENGTH]; + str_copy(aDir, pArgv0, Pos + 1); + str_format(aBuf, sizeof(aBuf), "%s/data/mapres", aDir); if(fs_is_dir(aBuf)) { - str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", m_aBinarydir); + str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aDir); return; } - else - m_aBinarydir[0] = 0; } } @@ -226,7 +223,6 @@ public: str_format(aBuf, sizeof(aBuf), "%s/data/mapres", aDirs[i]); if(fs_is_dir(aBuf)) { - str_copy(m_aBinarydir, aDirs[i], sizeof(m_aDatadir)); str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aDirs[i]); return; } @@ -234,8 +230,66 @@ public: } #endif - // no data-dir found - dbg_msg("storage", "warning no data directory found"); + dbg_msg("storage", "warning: no data directory found"); + } + + void FindBinarydir(const char *pArgv0) + { +#if defined(BINARY_DIR) + str_copy(m_aBinarydir, BINARY_DIR, sizeof(m_aBinarydir)); + return; +#endif + + // check for usable path in argv[0] + { + unsigned int Pos = ~0U; + for(unsigned i = 0; pArgv0[i]; i++) + if(pArgv0[i] == '/' || pArgv0[i] == '\\') + Pos = i; + + if(Pos < MAX_PATH_LENGTH) + { + char aBuf[MAX_PATH_LENGTH]; + str_copy(m_aBinarydir, pArgv0, Pos + 1); + str_format(aBuf, sizeof(aBuf), "%s/" PLAT_SERVER_EXEC, m_aBinarydir); + IOHANDLE File = io_open(aBuf, IOFLAG_READ); + if(File) + { + io_close(File); + return; + } + else + m_aBinarydir[0] = 0; + } + } + +#if defined(CONF_FAMILY_UNIX) + // check for all default locations + { + const char *aDirs[] = { + "/usr/bin", + "/usr/local/bin", + "/usr/pkg/bin", + "/opt/ddnet"}; + const int DirsCount = sizeof(aDirs) / sizeof(aDirs[0]); + + int i; + for(i = 0; i < DirsCount; i++) + { + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "%s/" PLAT_SERVER_EXEC, aDirs[i]); + IOHANDLE File = io_open(aBuf, IOFLAG_READ); + if(File) + { + io_close(File); + str_copy(m_aBinarydir, aDirs[i], sizeof(m_aDatadir)); + return; + } + } + } +#endif + + dbg_msg("storage", "warning: no binary directory found"); } virtual void ListDirectoryInfo(int Type, const char *pPath, FS_LISTDIR_INFO_CALLBACK pfnCallback, void *pUser) From db01e068d9b3d5555117fe9ff80c878ae46e9ad7 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 24 Sep 2020 10:46:19 +0200 Subject: [PATCH 5/8] Add Mac OSX standalone client handling to find server executable --- src/engine/shared/storage.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index 69c8fd511..c565000a0 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -259,7 +259,22 @@ public: return; } else + { +#if defined(CONF_PLATFORM_MACOSX) + str_append(m_aBinarydir, "/../../../DDNet-Server.app/Contents/MacOS", sizeof(m_aBinarydir)); + str_format(aBuf, sizeof(aBuf), "%s/" PLAT_SERVER_EXEC, m_aBinarydir); + IOHANDLE File = io_open(aBuf, IOFLAG_READ); + if(File) + { + io_close(File); + return; + } + else + m_aBinarydir[0] = 0; +#else m_aBinarydir[0] = 0; +#endif + } } } From 606701abff72d5fbcdb20d44f97259a791236844 Mon Sep 17 00:00:00 2001 From: def Date: Fri, 2 Oct 2020 18:24:40 +0200 Subject: [PATCH 6/8] No more hardcoded binary paths for POSIX --- src/engine/shared/storage.cpp | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index c565000a0..3d71ad4ec 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -278,33 +278,7 @@ public: } } -#if defined(CONF_FAMILY_UNIX) - // check for all default locations - { - const char *aDirs[] = { - "/usr/bin", - "/usr/local/bin", - "/usr/pkg/bin", - "/opt/ddnet"}; - const int DirsCount = sizeof(aDirs) / sizeof(aDirs[0]); - - int i; - for(i = 0; i < DirsCount; i++) - { - char aBuf[128]; - str_format(aBuf, sizeof(aBuf), "%s/" PLAT_SERVER_EXEC, aDirs[i]); - IOHANDLE File = io_open(aBuf, IOFLAG_READ); - if(File) - { - io_close(File); - str_copy(m_aBinarydir, aDirs[i], sizeof(m_aDatadir)); - return; - } - } - } -#endif - - dbg_msg("storage", "warning: no binary directory found"); + // no binary directory found, use $PATH on Posix, $PWD on Windows } virtual void ListDirectoryInfo(int Type, const char *pPath, FS_LISTDIR_INFO_CALLBACK pfnCallback, void *pUser) From 343e30f7a647d4ca048afa5d5bbc4459ea3bdafe Mon Sep 17 00:00:00 2001 From: def Date: Thu, 1 Oct 2020 00:09:38 +0200 Subject: [PATCH 7/8] Fix protocol.h/protocol7.h to compile on their own (fixes #2962 in another way) --- datasrc/compile.py | 4 +++- datasrc/seven/compile.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/datasrc/compile.py b/datasrc/compile.py index ae71b866a..ef2d52a49 100644 --- a/datasrc/compile.py +++ b/datasrc/compile.py @@ -98,6 +98,8 @@ if gen_network_header: print("#ifndef GAME_GENERATED_PROTOCOL_H") print("#define GAME_GENERATED_PROTOCOL_H") + print("#include ") + print("#include ") print(network.RawHeader) for e in network.Enums: @@ -167,9 +169,9 @@ if gen_network_source: # create names lines = [] + lines += ['#include "protocol.h"'] lines += ['#include '] lines += ['#include '] - lines += ['#include "protocol.h"'] lines += ['#include '] lines += ['CNetObjHandler::CNetObjHandler()'] diff --git a/datasrc/seven/compile.py b/datasrc/seven/compile.py index 33f53bc34..df3ace984 100644 --- a/datasrc/seven/compile.py +++ b/datasrc/seven/compile.py @@ -99,6 +99,8 @@ if gen_network_header: print("#ifndef GAME_GENERATED_PROTOCOL7_H") print("#define GAME_GENERATED_PROTOCOL7_H") + print("#include ") + print("#include ") print("namespace protocol7 {") print(network.RawHeader) @@ -177,9 +179,9 @@ if gen_network_source: # create names lines = [] + lines += ['#include "protocol7.h"'] lines += ['#include '] lines += ['#include '] - lines += ['#include "protocol7.h"'] lines += ['namespace protocol7 {'] From 8427e996723714bb17cbd22cc61425b38d3e837d Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Fri, 2 Oct 2020 19:30:05 +0200 Subject: [PATCH 8/8] Don't run the style fixer for generated files Fixes #2962. --- scripts/fix_style.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/fix_style.py b/scripts/fix_style.py index 27e69780a..1c5abf76c 100755 --- a/scripts/fix_style.py +++ b/scripts/fix_style.py @@ -8,14 +8,21 @@ import sys os.chdir(os.path.dirname(__file__) + "/..") -ignore_files = ["src/engine/keys.h", "src/engine/client/keynames.h"] - def recursive_file_list(path): result = [] for dirpath, dirnames, filenames in os.walk(path): - result += filter(lambda p: p not in ignore_files, [os.path.join(dirpath, filename) for filename in filenames]) + result += [os.path.join(dirpath, filename) for filename in filenames] return result +IGNORE_FILES = [ + "src/engine/client/keynames.h", + "src/engine/keys.h", +] +def filter_ignored(filenames): + return [filename for filename in filenames + if filename not in IGNORE_FILES + and not filename.startswith("src/game/generated/")] + def filter_cpp(filenames): return [filename for filename in filenames if any(filename.endswith(ext) for ext in ".c .cpp .h".split())] @@ -31,7 +38,7 @@ def main(): p = argparse.ArgumentParser(description="Check and fix style of changed files") p.add_argument("-n", "--dry-run", action="store_true", help="Don't fix, only warn") args = p.parse_args() - filenames = filter_cpp(recursive_file_list("src")) + filenames = filter_ignored(filter_cpp(recursive_file_list("src"))) if not args.dry_run: reformat(filenames) else: