From a090a1b47e542f1142ce36fe59e45146b07d5c67 Mon Sep 17 00:00:00 2001 From: vakomash <97990688+vakomash@users.noreply.github.com> Date: Sun, 25 Feb 2024 17:45:48 +0200 Subject: [PATCH 1/2] Add support of Visual Studio --- CMakeLists.txt | 10 ++++++++-- sim.cpp | 14 ++++---------- tyrant.h | 25 ++++++++++++++++--------- tyrant_optimize.cpp | 15 ++++++++++++++- tyrant_optimize.h | 1 + 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22ee248d..fc9816a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,17 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.12) # partial module - included by src/cmake/CMakeLists.txt #set(TGT test-${PKG}-cmake) set( CMAKE_CXX_STANDARD 14 ) +if (CMAKE_GENERATOR MATCHES "Visual Studio") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /W3 /wd4061 /wd4100 /wd4820 /wd4514") +else() set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Ofast") +endif() if(STATIC) set( BUILD_SHARED_LIBRARIES OFF) +set( BOOST_USE_STATIC_LIBS ON ) set( Boost_USE_STATIC_LIBS ON ) set( CMAKE_EXE_LINKER_FLAGS "-static") endif() @@ -30,7 +35,8 @@ if (OPENMP_FOUND) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") endif() endif() -find_package(Boost EXACT COMPONENTS system thread filesystem regex timer REQUIRED) +find_package(Boost COMPONENTS system thread filesystem regex timer REQUIRED) +INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) target_link_libraries(tuo ${Boost_LIBRARIES} ) diff --git a/sim.cpp b/sim.cpp index 9e8bff9c..c089f143 100644 --- a/sim.cpp +++ b/sim.cpp @@ -3154,9 +3154,7 @@ void perform_targetted_allied_fast(Field* fd, CardStatus* src, const SkillSpec& bool has_counted_quest = false; #endif bool src_overloaded = src->m_overloaded; - unsigned selection_array_len = fd->selection_array.size(); - CardStatus * selection_array[selection_array_len]; - std::memcpy(selection_array, &fd->selection_array[0], selection_array_len * sizeof(CardStatus *)); + std::vector selection_array = fd->selection_array; for (CardStatus * dst: selection_array) { if (dst->m_inhibited > 0 && !src_overloaded) @@ -3186,8 +3184,7 @@ void perform_targetted_allied_fast(Field* fd, CardStatus* src, const SkillSpec& for (unsigned i = 0; i < num_inhibited; ++ i) { select_targets(fd, &fd->tip->commander, diverted_ss); - selection_array_len = fd->selection_array.size(); - std::memcpy(selection_array, &fd->selection_array[0], selection_array_len * sizeof(CardStatus *)); + std::vector selection_array = fd->selection_array; for (CardStatus * dst: selection_array) { if (dst->m_inhibited > 0) @@ -3237,8 +3234,7 @@ void perform_targetted_hostile_fast(Field* fd, CardStatus* src, const SkillSpec& // apply skill to each target(dst) unsigned selection_array_len = fd->selection_array.size(); - CardStatus * selection_array[selection_array_len]; - std::memcpy(selection_array, &fd->selection_array[0], selection_array_len * sizeof(CardStatus *)); + std::vector selection_array = fd->selection_array; for (CardStatus * dst: selection_array) { // TurningTides @@ -3882,9 +3878,7 @@ Results play(Field* fd,bool skip_init, bool skip_preplay,unsigned turn // for (unsigned i = 0; i < num_inhibited; ++ i) { select_targets(fd, &fd->tip->commander, diverted_ss); - unsigned selection_array_len = fd->selection_array.size(); - CardStatus * selection_array[selection_array_len]; - std::memcpy(selection_array, &fd->selection_array[0], selection_array_len * sizeof(CardStatus *)); + std::vector selection_array = fd->selection_array; for (CardStatus * dst: selection_array) { if (dst->m_inhibited > 0) diff --git a/tyrant.h b/tyrant.h index f99e22dc..f090c244 100644 --- a/tyrant.h +++ b/tyrant.h @@ -12,7 +12,14 @@ #include #include #include +#include +#ifdef _MSC_VER +#define __builtin_expect(x, y) (x) +#define __builtin_unreachable() __assume(0) +#define and && +#define or || +#endif enum Fix { @@ -461,33 +468,33 @@ extern unsigned debug_cached; extern bool debug_line; extern std::string debug_str; #ifndef NDEBUG -#define _DEBUG_MSG(v, format, args...) \ +#define _DEBUG_MSG(v, format, ...) \ { \ if(__builtin_expect(debug_print >= v, false)) \ { \ if(debug_cached) { \ char buf[4096]; \ - if(debug_line){ snprintf(buf, sizeof(buf), "%i - " format, __LINE__, ##args);} \ - else { snprintf(buf, sizeof(buf), format, ##args); } \ + if(debug_line){ snprintf(buf, sizeof(buf), "%i - " format, __LINE__, ##__VA_ARGS__);} \ + else { snprintf(buf, sizeof(buf), format, ##__VA_ARGS__); } \ debug_str += buf; \ } \ - else { if(debug_line){ printf("%i - " format, __LINE__ , ##args);} \ - else {printf(format, ##args);} \ + else { if(debug_line){ printf("%i - " format, __LINE__ , ##__VA_ARGS__);} \ + else {printf(format, ##__VA_ARGS__);} \ std::cout << std::flush; } \ } \ } -#define _DEBUG_SELECTION(format, args...) \ +#define _DEBUG_SELECTION(format, ...) \ { \ if(__builtin_expect(debug_print >= 2, 0)) \ { \ - _DEBUG_MSG(2, "Possible targets of " format ":\n", ##args); \ + _DEBUG_MSG(2, "Possible targets of " format ":\n", ##__VA_ARGS__); \ fd->print_selection_array(); \ } \ } #define _DEBUG_ASSERT(expr) { assert(expr); } #else -#define _DEBUG_MSG(v, format, args...) -#define _DEBUG_SELECTION(format, args...) +#define _DEBUG_MSG(v, format, ...) +#define _DEBUG_SELECTION(format, ...) #define _DEBUG_ASSERT(expr) #endif diff --git a/tyrant_optimize.cpp b/tyrant_optimize.cpp index 50afd8d7..b7373842 100644 --- a/tyrant_optimize.cpp +++ b/tyrant_optimize.cpp @@ -14,7 +14,13 @@ // #define NDEBUG #define BOOST_THREAD_USE_LIB +#ifndef _WIN32 #include +#else +#include +#define F_OK 0 +#define access(f, m) _access((f), (m)) +#endif #include #include #include @@ -2530,6 +2536,8 @@ DeckResults run(int argc, const char **argv) for (int argIndex = 3; argIndex < argc; ++argIndex) { + //bypass MSVS issue: Nesting of code blocks exceeds the limit of 128 nesting levels + bool tokenParsed = true; if (strcmp(argv[argIndex], "deck") == 0) { your_deck_list = std::string(argv[argIndex + 1]); @@ -3255,7 +3263,12 @@ DeckResults run(int argc, const char **argv) opt_multi_optimization = true; argIndex += 3; } - else if (strcmp(argv[argIndex], "genetic") == 0) + else { + tokenParsed = false; + } + + if (!tokenParsed) + if (strcmp(argv[argIndex], "genetic") == 0) { if (check_input_amount(argc, argv, argIndex, 1)) exit(1); diff --git a/tyrant_optimize.h b/tyrant_optimize.h index f4d8c5fe..5ac05dac 100644 --- a/tyrant_optimize.h +++ b/tyrant_optimize.h @@ -1,3 +1,4 @@ +#define _USE_MATH_DEFINES #include "deck.h" #include #include From 4431f9c4fa1f1e8c0f50f98c2a2a7d71155cee58 Mon Sep 17 00:00:00 2001 From: vakomash <97990688+vakomash@users.noreply.github.com> Date: Sun, 17 Mar 2024 20:05:27 +0200 Subject: [PATCH 2/2] Fix comments --- CMakeLists.txt | 3 +-- tyrant_optimize.cpp | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc9816a3..a873f165 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Ofast") endif() if(STATIC) set( BUILD_SHARED_LIBRARIES OFF) -set( BOOST_USE_STATIC_LIBS ON ) set( Boost_USE_STATIC_LIBS ON ) set( CMAKE_EXE_LINKER_FLAGS "-static") endif() @@ -36,7 +35,7 @@ if (OPENMP_FOUND) endif() endif() find_package(Boost COMPONENTS system thread filesystem regex timer REQUIRED) -INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) +include_directories( ${Boost_INCLUDE_DIR} ) target_link_libraries(tuo ${Boost_LIBRARIES} ) diff --git a/tyrant_optimize.cpp b/tyrant_optimize.cpp index b7373842..030ce569 100644 --- a/tyrant_optimize.cpp +++ b/tyrant_optimize.cpp @@ -3268,6 +3268,8 @@ DeckResults run(int argc, const char **argv) } if (!tokenParsed) + { + //no indent: keep two parts of a nested if at the same level if (strcmp(argv[argIndex], "genetic") == 0) { if (check_input_amount(argc, argv, argIndex, 1)) @@ -3467,6 +3469,7 @@ DeckResults run(int argc, const char **argv) std::cerr << "Error: Unknown option " << argv[argIndex] << std::endl; exit(1); } + } // if (tokenParsed) } load_db(prefix); load_ml(prefix);