Skip to content

Commit

Permalink
Add support of Visual Studio (#75)
Browse files Browse the repository at this point in the history
* Add support of Visual Studio

* Fix comments
  • Loading branch information
vakomash authored Mar 17, 2024
1 parent b61f841 commit 5fffbff
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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 )
Expand All @@ -30,7 +34,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} )

Expand Down
14 changes: 4 additions & 10 deletions sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CardStatus*> selection_array = fd->selection_array;
for (CardStatus * dst: selection_array)
{
if (dst->m_inhibited > 0 && !src_overloaded)
Expand Down Expand Up @@ -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<skill_id>(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<CardStatus*> selection_array = fd->selection_array;
for (CardStatus * dst: selection_array)
{
if (dst->m_inhibited > 0)
Expand Down Expand Up @@ -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<CardStatus*> selection_array = fd->selection_array;
for (CardStatus * dst: selection_array)
{
// TurningTides
Expand Down Expand Up @@ -3882,9 +3878,7 @@ Results<uint64_t> play(Field* fd,bool skip_init, bool skip_preplay,unsigned turn
// for (unsigned i = 0; i < num_inhibited; ++ i)
{
select_targets<Skill::protect>(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<CardStatus*> selection_array = fd->selection_array;
for (CardStatus * dst: selection_array)
{
if (dst->m_inhibited > 0)
Expand Down
25 changes: 16 additions & 9 deletions tyrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
#include <unordered_map>
#include <tuple>
#include <boost/algorithm/string.hpp>
#include <numeric>

#ifdef _MSC_VER
#define __builtin_expect(x, y) (x)
#define __builtin_unreachable() __assume(0)
#define and &&
#define or ||
#endif

enum Fix
{
Expand Down Expand Up @@ -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

Expand Down
18 changes: 17 additions & 1 deletion tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
// #define NDEBUG
#define BOOST_THREAD_USE_LIB

#ifndef _WIN32
#include <unistd.h>
#else
#include <io.h>
#define F_OK 0
#define access(f, m) _access((f), (m))
#endif
#include <array>
#include <cassert>
#include <chrono>
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -3255,7 +3263,14 @@ 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)
{
//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))
exit(1);
Expand Down Expand Up @@ -3454,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);
Expand Down
1 change: 1 addition & 0 deletions tyrant_optimize.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _USE_MATH_DEFINES
#include "deck.h"
#include <boost/thread/barrier.hpp>
#include <boost/thread/mutex.hpp>
Expand Down

0 comments on commit 5fffbff

Please sign in to comment.