From ca9a0fb7d1f4713cfa3ab6e552ddcbc84439a5fa Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 23 Mar 2023 17:29:39 -0700 Subject: [PATCH 01/11] progress towards cpp20 --- CMakeLists.txt | 13 ++++++------- depends/CMakeLists.txt | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed92b1eca..d031c8784 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,9 +35,10 @@ option(REMOVE_SYMBOLS_FROM_DF_STUBS "Remove debug symbols from DF stubs. (Reduce macro(CHECK_GCC compiler_path) execute_process(COMMAND ${compiler_path} -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT) string(STRIP "${GCC_VERSION_OUT}" GCC_VERSION_OUT) - if(${GCC_VERSION_OUT} VERSION_LESS "4.8") - message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 4.8 or later") - elseif(${GCC_VERSION_OUT} VERSION_GREATER "4.9.9") + if(${GCC_VERSION_OUT} VERSION_LESS "10") + message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 10 or later") + # TODO: this may need to be removed when DF linux actually comes out + # TODO: and we can test # GCC 5 changes ABI name mangling to enable C++11 changes. # This must be disabled to enable linking against DF. # http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/ @@ -66,8 +67,8 @@ if(WIN32) endif() endif() -# Ask for C++11 standard from compilers -set(CMAKE_CXX_STANDARD 11) +# Ask for C++-20 standard from compilers +set(CMAKE_CXX_STANDARD 20) # Require the standard support from compilers. set(CMAKE_CXX_STANDARD_REQUIRED ON) # Use only standard c++ to keep code portable @@ -226,9 +227,7 @@ if(UNIX) ## flags for GCC # default to hidden symbols # ensure compatibility with older CPUs - # enable C++11 features add_definitions(-DLINUX_BUILD) - add_definitions(-D_GLIBCXX_USE_C99) set(GCC_COMMON_FLAGS "-fvisibility=hidden -mtune=generic -Wall -Werror") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMMON_FLAGS}") diff --git a/depends/CMakeLists.txt b/depends/CMakeLists.txt index 15ff52488..566965f8a 100644 --- a/depends/CMakeLists.txt +++ b/depends/CMakeLists.txt @@ -1,14 +1,26 @@ # list depends here. add_subdirectory(lodepng) -add_subdirectory(lua) add_subdirectory(md5) + +add_subdirectory(lua) add_subdirectory(protobuf) +if(UNIX) + set_target_properties(lua PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion") + target_compile_options(protoc + PUBLIC -Wno-deprecated-declarations -Wno-restrict) + target_compile_options(protoc-bin + PUBLIC -Wno-deprecated-declarations -Wno-restrict) + target_compile_options(protobuf-lite + PUBLIC -Wno-deprecated-declarations -Wno-restrict) + target_compile_options(protobuf + PUBLIC -Wno-deprecated-declarations -Wno-restrict) +endif() if(UNIX AND NOT APPLE) # remove this once our MSVC build env has been updated option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" OFF) add_subdirectory(googletest) if(UNIX) - set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-sign-compare") + set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-sign-compare -Wno-restrict") endif() endif() From 9dba18124eb1dd6f25b592fec46e85a8595f6896 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 17 Jun 2023 10:00:54 -0700 Subject: [PATCH 02/11] attach compile options to dfhack that allow protobuf headers to be included --- library/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 8681c9c90..1db78c24e 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -377,6 +377,9 @@ if(WIN32) set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) else() set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "-include Export.h" ) + # required because of protobuf headers + target_compile_options(dfhack + PUBLIC -Wno-deprecated-declarations -Wno-restrict) set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "-include Export.h" ) add_library(dfhooks SHARED Hooks.cpp) target_link_libraries(dfhooks dfhack) From 2efef75b4e4ca368f866bd104f123aaf79c8e568 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 17 Jun 2023 10:46:56 -0700 Subject: [PATCH 03/11] re-constify --- library/modules/DFSteam.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/DFSteam.cpp b/library/modules/DFSteam.cpp index 1fd064d56..103e2dfee 100644 --- a/library/modules/DFSteam.cpp +++ b/library/modules/DFSteam.cpp @@ -108,7 +108,7 @@ static bool is_running_on_wine() { return !!pwine_get_version; } -static DWORD findProcess(LPWSTR name) { +static DWORD findProcess(const LPWSTR name) { PROCESSENTRY32W entry; entry.dwSize = sizeof(PROCESSENTRY32W); From 8a079e1ae755b46822a0e88df09ce9c354f6557d Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 17 Jun 2023 22:14:11 -0700 Subject: [PATCH 04/11] get compiling on windows --- library/CMakeLists.txt | 4 ++-- library/modules/DFSteam.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 1db78c24e..48ebdb986 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -377,9 +377,9 @@ if(WIN32) set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) else() set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "-include Export.h" ) - # required because of protobuf headers + # required because of transitively-included protobuf headers target_compile_options(dfhack - PUBLIC -Wno-deprecated-declarations -Wno-restrict) + INTERFACE -Wno-deprecated-declarations -Wno-restrict) set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "-include Export.h" ) add_library(dfhooks SHARED Hooks.cpp) target_link_libraries(dfhooks dfhack) diff --git a/library/modules/DFSteam.cpp b/library/modules/DFSteam.cpp index 103e2dfee..9aab53466 100644 --- a/library/modules/DFSteam.cpp +++ b/library/modules/DFSteam.cpp @@ -108,7 +108,7 @@ static bool is_running_on_wine() { return !!pwine_get_version; } -static DWORD findProcess(const LPWSTR name) { +static DWORD findProcess(LPCWSTR name) { PROCESSENTRY32W entry; entry.dwSize = sizeof(PROCESSENTRY32W); @@ -150,11 +150,14 @@ static bool launchDFHack(color_ostream& out) { si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); - // note that the enviornment must be explicitly zeroed out and not NULL, + static LPCWSTR procname = L"hack/launchdf.exe"; + static const char * env = "\0"; + + // note that the environment must be explicitly zeroed out and not NULL, // otherwise the launched process will inherit this process's environment, // and the Steam API in the launchdf process will think it is in DF's context. - BOOL res = CreateProcessW(L"hack/launchdf.exe", - NULL, NULL, NULL, FALSE, 0, "\0", NULL, &si, &pi); + BOOL res = CreateProcessW(procname, + NULL, NULL, NULL, FALSE, 0, (LPVOID)env, NULL, &si, &pi); return !!res; } From 8f413628c2342c3639d6c44959bd663bcabfb4a0 Mon Sep 17 00:00:00 2001 From: Myk Date: Mon, 19 Jun 2023 17:40:40 -0700 Subject: [PATCH 05/11] reinstate alphabetical ordering --- depends/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/depends/CMakeLists.txt b/depends/CMakeLists.txt index 566965f8a..9ec71646a 100644 --- a/depends/CMakeLists.txt +++ b/depends/CMakeLists.txt @@ -1,9 +1,9 @@ # list depends here. add_subdirectory(lodepng) -add_subdirectory(md5) - add_subdirectory(lua) +add_subdirectory(md5) add_subdirectory(protobuf) + if(UNIX) set_target_properties(lua PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion") target_compile_options(protoc From 8f1efcd8a38fe1f484d416f1eaf18182307c006e Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 25 Jun 2023 17:44:06 -0700 Subject: [PATCH 06/11] remove need to ignore warnings for dfhack-dependent targets --- library/CMakeLists.txt | 3 --- library/Debug.cpp | 1 + library/include/Core.h | 2 -- library/include/Export.h | 14 ++++++++++++++ library/include/PluginManager.h | 2 -- library/include/RemoteClient.h | 11 ----------- library/include/modules/Buildings.h | 8 +++++++- plugins/channel-safely/channel-manager.cpp | 4 ++-- plugins/channel-safely/include/inlines.h | 2 +- plugins/confirm.cpp | 2 +- plugins/hotkeys.cpp | 2 +- 11 files changed, 27 insertions(+), 24 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 48ebdb986..8681c9c90 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -377,9 +377,6 @@ if(WIN32) set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) else() set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "-include Export.h" ) - # required because of transitively-included protobuf headers - target_compile_options(dfhack - INTERFACE -Wno-deprecated-declarations -Wno-restrict) set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "-include Export.h" ) add_library(dfhooks SHARED Hooks.cpp) target_link_libraries(dfhooks dfhack) diff --git a/library/Debug.cpp b/library/Debug.cpp index 9b13af168..dafbeb5ce 100644 --- a/library/Debug.cpp +++ b/library/Debug.cpp @@ -26,6 +26,7 @@ redistribute it freely, subject to the following restrictions: #include "Debug.h" #include "DebugManager.h" +#include #include #include #include diff --git a/library/include/Core.h b/library/include/Core.h index 696be4ead..c9f49cbb3 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -40,8 +40,6 @@ distribution. #include #include -#include "RemoteClient.h" - #define DFH_MOD_SHIFT 1 #define DFH_MOD_CTRL 2 #define DFH_MOD_ALT 4 diff --git a/library/include/Export.h b/library/include/Export.h index 9e2a78d4b..ad2b4ceec 100644 --- a/library/include/Export.h +++ b/library/include/Export.h @@ -69,3 +69,17 @@ distribution. #else #define Wformat(type, fmtstr, vararg) #endif + +namespace DFHack +{ + enum command_result + { + CR_LINK_FAILURE = -3, // RPC call failed due to I/O or protocol error + CR_NEEDS_CONSOLE = -2, // Attempt to call interactive command without console + CR_NOT_IMPLEMENTED = -1, // Command not implemented, or plugin not loaded + CR_OK = 0, // Success + CR_FAILURE = 1, // Failure + CR_WRONG_USAGE = 2, // Wrong arguments or ui state + CR_NOT_FOUND = 3 // Target object not found (for RPC mainly) + }; +} diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index 78c5e5dc8..f67023f93 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -35,8 +35,6 @@ distribution. #include "Core.h" #include "DataFuncs.h" -#include "RemoteClient.h" - typedef struct lua_State lua_State; namespace tthread diff --git a/library/include/RemoteClient.h b/library/include/RemoteClient.h index e71b985cd..17e296a2e 100644 --- a/library/include/RemoteClient.h +++ b/library/include/RemoteClient.h @@ -39,17 +39,6 @@ namespace DFHack using dfproto::IntMessage; using dfproto::StringMessage; - enum command_result - { - CR_LINK_FAILURE = -3, // RPC call failed due to I/O or protocol error - CR_NEEDS_CONSOLE = -2, // Attempt to call interactive command without console - CR_NOT_IMPLEMENTED = -1, // Command not implemented, or plugin not loaded - CR_OK = 0, // Success - CR_FAILURE = 1, // Failure - CR_WRONG_USAGE = 2, // Wrong arguments or ui state - CR_NOT_FOUND = 3 // Target object not found (for RPC mainly) - }; - enum DFHackReplyCode : int16_t { RPC_REPLY_RESULT = -1, RPC_REPLY_FAIL = -2, diff --git a/library/include/modules/Buildings.h b/library/include/modules/Buildings.h index 78163108e..22dbb0370 100644 --- a/library/include/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -237,7 +237,7 @@ DFHACK_EXPORT std::string getRoomDescription(df::building *building, df::unit *u * starting at the top left and moving right, row by row, * the block's items are checked for anything on the ground within that stockpile. */ -class DFHACK_EXPORT StockpileIterator : public std::iterator +class DFHACK_EXPORT StockpileIterator { df::building_stockpilest* stockpile; df::map_block* block; @@ -245,6 +245,12 @@ class DFHACK_EXPORT StockpileIterator : public std::iteratorblock_events) { if (auto evT = virtual_cast(event)) { // we want to let the user keep some designations free of being managed - auto b = max(0, cavein_candidates[pos] - least_access); + auto b = std::max(0, cavein_candidates[pos] - least_access); auto v = 1000 + (b * 1700); DEBUG(manager).print("(" COORD ") 1000+1000(%d) -> %d {least-access: %d}\n",COORDARGS(pos), b, v, least_access); evT->priority[Coord(local)] = v; diff --git a/plugins/channel-safely/include/inlines.h b/plugins/channel-safely/include/inlines.h index a29f5a04d..362fd927a 100644 --- a/plugins/channel-safely/include/inlines.h +++ b/plugins/channel-safely/include/inlines.h @@ -23,7 +23,7 @@ namespace CSP { inline uint32_t calc_distance(df::coord p1, df::coord p2) { // calculate chebyshev (chessboard) distance uint32_t distance = abs(p2.z - p1.z); - distance += max(abs(p2.x - p1.x), abs(p2.y - p1.y)); + distance += std::max(abs(p2.x - p1.x), abs(p2.y - p1.y)); return distance; } diff --git a/plugins/confirm.cpp b/plugins/confirm.cpp index 1dfb6809d..bd6e41b64 100644 --- a/plugins/confirm.cpp +++ b/plugins/confirm.cpp @@ -411,7 +411,7 @@ public: Screen::paintTile(corner_ur, x2, y1); Screen::paintTile(corner_dl, x1, y2); Screen::paintTile(corner_dr, x2, y2); - string title = " " + get_title() + " "; + string title = ' ' + get_title() + ' '; Screen::paintString(Screen::Pen(' ', COLOR_DARKGREY, COLOR_BLACK), x2 - 6, y1, "DFHack"); Screen::paintString(Screen::Pen(' ', COLOR_BLACK, COLOR_GREY), diff --git a/plugins/hotkeys.cpp b/plugins/hotkeys.cpp index 136ad7a9d..ef2ca9422 100644 --- a/plugins/hotkeys.cpp +++ b/plugins/hotkeys.cpp @@ -103,7 +103,7 @@ static void find_active_keybindings(color_ostream &out, df::viewscreen *screen, } for (int i = 1; i <= 12; i++) { - valid_keys.push_back("F" + int_to_string(i)); + valid_keys.push_back('F' + int_to_string(i)); } valid_keys.push_back("`"); From 78448f438d5386b773afe28e859468dff87a57a6 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 25 Jun 2023 17:53:16 -0700 Subject: [PATCH 07/11] don't leak warning suppression out of protobuf --- depends/CMakeLists.txt | 12 ++++------- .../protobuf/google/protobuf/repeated_field.h | 4 ++++ library/DataDefs.cpp | 4 ++-- library/modules/Gui.cpp | 20 +++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/depends/CMakeLists.txt b/depends/CMakeLists.txt index 9ec71646a..0756519ef 100644 --- a/depends/CMakeLists.txt +++ b/depends/CMakeLists.txt @@ -6,14 +6,10 @@ add_subdirectory(protobuf) if(UNIX) set_target_properties(lua PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion") - target_compile_options(protoc - PUBLIC -Wno-deprecated-declarations -Wno-restrict) - target_compile_options(protoc-bin - PUBLIC -Wno-deprecated-declarations -Wno-restrict) - target_compile_options(protobuf-lite - PUBLIC -Wno-deprecated-declarations -Wno-restrict) - target_compile_options(protobuf - PUBLIC -Wno-deprecated-declarations -Wno-restrict) + set_target_properties(protoc PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict") + set_target_properties(protoc-bin PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict") + set_target_properties(protobuf-lite PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict") + set_target_properties(protobuf PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict") endif() if(UNIX AND NOT APPLE) # remove this once our MSVC build env has been updated diff --git a/depends/protobuf/google/protobuf/repeated_field.h b/depends/protobuf/google/protobuf/repeated_field.h index aed4ce9f2..637708254 100644 --- a/depends/protobuf/google/protobuf/repeated_field.h +++ b/depends/protobuf/google/protobuf/repeated_field.h @@ -46,6 +46,10 @@ #ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_H__ #define GOOGLE_PROTOBUF_REPEATED_FIELD_H__ +#ifdef __GNUC__ +#pragma GCC system_header +#endif + #include #include #include diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index f376edc6a..cd261d50f 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -213,12 +213,12 @@ std::string pointer_identity::getFullName() std::string container_identity::getFullName(type_identity *item) { - return "<" + (item ? item->getFullName() : std::string("void")) + ">"; + return '<' + (item ? item->getFullName() : std::string("void")) + '>'; } std::string ptr_container_identity::getFullName(type_identity *item) { - return "<" + (item ? item->getFullName() : std::string("void")) + "*>"; + return '<' + (item ? item->getFullName() : std::string("void")) + std::string("*>"); } std::string bit_container_identity::getFullName(type_identity *) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index d03bcce09..01fbdddf3 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -182,23 +182,23 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode) if (game->main_interface.info.open) { newFocusString = baseFocus; newFocusString += "/Info"; - newFocusString += "/" + enum_item_key(game->main_interface.info.current_mode); + newFocusString += '/' + enum_item_key(game->main_interface.info.current_mode); switch(game->main_interface.info.current_mode) { case df::enums::info_interface_mode_type::CREATURES: - newFocusString += "/" + enum_item_key(game->main_interface.info.creatures.current_mode); + newFocusString += '/' + enum_item_key(game->main_interface.info.creatures.current_mode); break; case df::enums::info_interface_mode_type::BUILDINGS: - newFocusString += "/" + enum_item_key(game->main_interface.info.buildings.mode); + newFocusString += '/' + enum_item_key(game->main_interface.info.buildings.mode); break; case df::enums::info_interface_mode_type::LABOR: - newFocusString += "/" + enum_item_key(game->main_interface.info.labor.mode); + newFocusString += '/' + enum_item_key(game->main_interface.info.labor.mode); break; case df::enums::info_interface_mode_type::ARTIFACTS: - newFocusString += "/" + enum_item_key(game->main_interface.info.artifacts.mode); + newFocusString += '/' + enum_item_key(game->main_interface.info.artifacts.mode); break; case df::enums::info_interface_mode_type::JUSTICE: - newFocusString += "/" + enum_item_key(game->main_interface.info.justice.current_mode); + newFocusString += '/' + enum_item_key(game->main_interface.info.justice.current_mode); break; default: break; @@ -209,7 +209,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode) if (game->main_interface.view_sheets.open) { newFocusString = baseFocus; newFocusString += "/ViewSheets"; - newFocusString += "/" + enum_item_key(game->main_interface.view_sheets.active_sheet); + newFocusString += '/' + enum_item_key(game->main_interface.view_sheets.active_sheet); focusStrings.push_back(newFocusString); } @@ -233,7 +233,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode) newFocusString += "/Zone"; if (game->main_interface.civzone.cur_bld) { newFocusString += "/Some"; - newFocusString += "/" + enum_item_key(game->main_interface.civzone.cur_bld->type); + newFocusString += '/' + enum_item_key(game->main_interface.civzone.cur_bld->type); } break; case df::enums::main_bottom_mode_type::ZONE_PAINT: @@ -499,7 +499,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dungeonmode) if (!adventure) return; - focus += "/" + enum_item_key(adventure->menu); + focus += '/' + enum_item_key(adventure->menu); } */ @@ -1427,7 +1427,7 @@ DFHACK_EXPORT int Gui::makeAnnouncement(df::announcement_type type, df::announce if (flags.bits.D_DISPLAY) { world->status.display_timer = ANNOUNCE_DISPLAY_TIME; - Gui::writeToGamelog("x" + to_string(repeat_count + 1)); + Gui::writeToGamelog('x' + to_string(repeat_count + 1)); } return -1; } From e7f5b1f949fe6903d3e0fd34a603302687a1dae7 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 3 Jul 2023 11:53:46 -0700 Subject: [PATCH 08/11] move command_result enum from Export to Core --- library/include/Core.h | 11 +++++++++++ library/include/Export.h | 14 -------------- library/include/RemoteClient.h | 1 + 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/library/include/Core.h b/library/include/Core.h index 92bf63d93..a574b029a 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -72,6 +72,17 @@ namespace DFHack struct Hide; } + enum command_result + { + CR_LINK_FAILURE = -3, // RPC call failed due to I/O or protocol error + CR_NEEDS_CONSOLE = -2, // Attempt to call interactive command without console + CR_NOT_IMPLEMENTED = -1, // Command not implemented, or plugin not loaded + CR_OK = 0, // Success + CR_FAILURE = 1, // Failure + CR_WRONG_USAGE = 2, // Wrong arguments or ui state + CR_NOT_FOUND = 3 // Target object not found (for RPC mainly) + }; + enum state_change_event { SC_UNKNOWN = -1, diff --git a/library/include/Export.h b/library/include/Export.h index ad2b4ceec..9e2a78d4b 100644 --- a/library/include/Export.h +++ b/library/include/Export.h @@ -69,17 +69,3 @@ distribution. #else #define Wformat(type, fmtstr, vararg) #endif - -namespace DFHack -{ - enum command_result - { - CR_LINK_FAILURE = -3, // RPC call failed due to I/O or protocol error - CR_NEEDS_CONSOLE = -2, // Attempt to call interactive command without console - CR_NOT_IMPLEMENTED = -1, // Command not implemented, or plugin not loaded - CR_OK = 0, // Success - CR_FAILURE = 1, // Failure - CR_WRONG_USAGE = 2, // Wrong arguments or ui state - CR_NOT_FOUND = 3 // Target object not found (for RPC mainly) - }; -} diff --git a/library/include/RemoteClient.h b/library/include/RemoteClient.h index 17e296a2e..921d351c3 100644 --- a/library/include/RemoteClient.h +++ b/library/include/RemoteClient.h @@ -26,6 +26,7 @@ distribution. #include "Pragma.h" #include "Export.h" #include "ColorText.h" +#include "Core.h" class CPassiveSocket; class CActiveSocket; From 9ddb3813c1ea14e5be99d59c11d871ba7a53359a Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 3 Jul 2023 11:18:14 -0700 Subject: [PATCH 09/11] add new linkage dependency on dfhack --- library/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5d2698bb0..40006a432 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -408,8 +408,8 @@ endif() target_link_libraries(dfhack protobuf-lite clsocket lua jsoncpp_static dfhack-version ${PROJECT_LIBS}) set_target_properties(dfhack PROPERTIES INTERFACE_LINK_LIBRARIES "") -target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static) -target_link_libraries(dfhack-run dfhack-client) +target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static dfhack) +target_link_libraries(dfhack-run dfhack-client dfhack) if(APPLE) add_custom_command(TARGET dfhack-run COMMAND ${dfhack_SOURCE_DIR}/package/darwin/fix-libs.sh WORKING_DIRECTORY ../ COMMENT "Fixing library dependencies...") From e3d3affdbc9d4c91940a72fa448a7bd0f267733c Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 5 Jul 2023 10:25:07 -0700 Subject: [PATCH 10/11] Revert "add new linkage dependency on dfhack" This reverts commit 9ddb3813c1ea14e5be99d59c11d871ba7a53359a. --- library/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 40006a432..5d2698bb0 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -408,8 +408,8 @@ endif() target_link_libraries(dfhack protobuf-lite clsocket lua jsoncpp_static dfhack-version ${PROJECT_LIBS}) set_target_properties(dfhack PROPERTIES INTERFACE_LINK_LIBRARIES "") -target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static dfhack) -target_link_libraries(dfhack-run dfhack-client dfhack) +target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static) +target_link_libraries(dfhack-run dfhack-client) if(APPLE) add_custom_command(TARGET dfhack-run COMMAND ${dfhack_SOURCE_DIR}/package/darwin/fix-libs.sh WORKING_DIRECTORY ../ COMMENT "Fixing library dependencies...") From 125e4c623b9a13048e698af2f4b4b16587091837 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 5 Jul 2023 11:07:51 -0700 Subject: [PATCH 11/11] avoid inducing link dependency on dfhack --- library/Core.cpp | 9 +++++++++ library/include/Core.h | 8 ++------ library/modules/Gui.cpp | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 4b036a83e..8d632e107 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1471,6 +1471,10 @@ std::string Core::getHackPath() #endif } +df::viewscreen * Core::getTopViewscreen() { + return getInstance().top_viewscreen; +} + bool Core::InitMainThread() { Filesystem::init(); @@ -1855,6 +1859,11 @@ void *Core::GetData( std::string key ) } } +Core& Core::getInstance() { + static Core instance; + return instance; +} + bool Core::isSuspended(void) { return ownerThread.load() == std::this_thread::get_id(); diff --git a/library/include/Core.h b/library/include/Core.h index a574b029a..a41aff927 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -125,11 +125,7 @@ namespace DFHack friend bool ::dfhooks_ncurses_key(int key); public: /// Get the single Core instance or make one. - static Core& getInstance() - { - static Core instance; - return instance; - } + static Core& getInstance(); /// check if the activity lock is owned by this thread bool isSuspended(void); /// Is everything OK? @@ -177,7 +173,7 @@ namespace DFHack bool isWorldLoaded() { return (last_world_data_ptr != NULL); } bool isMapLoaded() { return (last_local_map_ptr != NULL && last_world_data_ptr != NULL); } - static df::viewscreen *getTopViewscreen() { return getInstance().top_viewscreen; } + static df::viewscreen *getTopViewscreen(); DFHack::Console &getConsole() { return con; } diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 39f600bbf..102fef9d6 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -1709,7 +1709,7 @@ bool Gui::autoDFAnnouncement(df::report_init r, string message) if (a_flags.bits.D_DISPLAY) { world->status.display_timer = r.display_timer; - Gui::writeToGamelog("x" + to_string(repeat_count + 1)); + Gui::writeToGamelog('x' + to_string(repeat_count + 1)); } DEBUG(gui).print("Announcement succeeded as repeat:\n%s\n", message.c_str()); return true;