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 {'] 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: diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index 2f909d5d0..3d71ad4ec 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,55 @@ 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 + { +#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 + } + } + } + + // 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) diff --git a/src/game/client/components/background.cpp b/src/game/client/components/background.cpp index 6b28d8297..8a894eee3 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(); } @@ -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) == 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) { @@ -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 c4186fc57..af1a08d25 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -2017,7 +2017,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); @@ -2173,6 +2173,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_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_MAP, 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)) {