From 71b7391bc8bc233beb4c217a1c02ec6538208224 Mon Sep 17 00:00:00 2001 From: Robin Quint Date: Thu, 7 Mar 2024 17:07:16 +0100 Subject: [PATCH 01/20] Made cmake building on windows somewhat possible --- .gitignore | 1 + CMakeLists.txt | 130 ++++++++++++++++++++------------- cmake/FindTHEORA.cmake | 2 +- collective.h | 2 +- collective_config.cpp | 2 +- content_factory.h | 10 +-- directory_path.cpp | 59 +++++++++++++-- extern/iomanip.h | 2 +- extern/variant.hpp | 1 + file_path.cpp | 14 +++- file_sharing.cpp | 2 +- fx_factory.cpp | 2 +- fx_math.h | 7 ++ gen_variant_serialize_pretty.h | 6 +- gui_builder.cpp | 6 +- indexed_vector.h | 3 + item.h | 2 +- item_attributes.h | 2 +- level_maker.h | 2 +- main_loop.h | 4 +- map_layouts.h | 2 +- miniunz.cpp | 9 ++- model_builder.h | 2 +- my_containers.h | 10 +-- opengl.cpp | 8 +- opengl.h | 2 +- player_control.h | 2 +- pretty_archive.cpp | 6 +- renderer.cpp | 2 +- scripted_ui.cpp | 3 +- sdl.h | 8 +- sound_library.cpp | 2 +- stdafx.h | 4 +- steam_friends.h | 1 + steam_ugc.cpp | 2 +- task.h | 2 +- video.cpp | 12 +-- village_behaviour.h | 2 +- 38 files changed, 228 insertions(+), 110 deletions(-) diff --git a/.gitignore b/.gitignore index f40599b4e..0ed8324a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ extern/steamworks/ +extern/deps/ mods/ build/ build_kde/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 125a07b45..a2d563f9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,25 +1,31 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 3.20) + project(keeper) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -# set default cxxflags -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++1y -Wno-sign-compare -Wno-unused-variable -Wno-shift-count-overflow -ftemplate-depth=512 -DUSE_STEAMWORKS -I /home/michal/keeperrl/extern/steamworks/public") -# clang specific cflags -if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-tautological-constant-out-of-range-compare -Wno-mismatched-tags") + +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_CXX_STANDARD 17) +else() + set(CMAKE_CXX_STANDARD 14) endif() +set(CMAKE_CXX_STANDARD_REQUIRED on) -set(STDAFX_H "${CMAKE_CURRENT_SOURCE_DIR}/stdafx.h") -set(STDAFX_H_GCH "${CMAKE_CURRENT_BINARY_DIR}/stdagx.h.gch") +option(ENABLE_STEAMWORKS "Enable steamworks integration" off) -# set debug cxxflags -set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wimplicit-fallthrough -Wno-unused-function") -#if ((${CMAKE_BUILD_TYPE} MATCHES "Debug") AND (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")) -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -L ${CMAKE_CURRENT_SOURCE_DIR}/extern/steamworks/redistributable_bin/linux64/ -L /usr/local/lib -lsteam_api -Wl,-rpath=. -Wl,--gdb-index") - #endif() +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(STDAFX_H "${CMAKE_CURRENT_SOURCE_DIR}/stdafx.h") +set(STDAFX_H_GCH "${CMAKE_CURRENT_BINARY_DIR}/stdafx.h.gch") # additional cmake modules directory set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") +if(ENABLE_STEAMWORKS) + add_library(steamworks SHARED IMPORTED) + set_target_properties(steamworks PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/extern/steamworks/redistributable_bin/win64/steam_api64.dll") + set_target_properties(steamworks PROPERTIES IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/extern/steamworks/redistributable_bin/win64/steam_api64.lib") + target_include_directories(steamworks INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/extern/steamworks/public") +endif() + # find required libraries find_package(SDL2 REQUIRED) find_package(SDL2_image REQUIRED) @@ -43,27 +49,31 @@ find_package(VorbisFile REQUIRED) find_package(THEORA REQUIRED) # generate version.h -file(GLOB GENERATE_VERSION_SH "gen_version.sh") -set(KEEPER_VERSION_H "${CMAKE_CURRENT_SOURCE_DIR}/version.h") -add_custom_command( - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/ - COMMAND ${GENERATE_VERSION_SH} - DEPENDS ${GENERATE_VERSION_SH} - OUTPUT ${KEEPER_VERSION_H} - COMMENT "Generating version.h" -) +if(ENABLE_GEN_VERSION) + file(GLOB GENERATE_VERSION_SH "gen_version.sh") + set(KEEPER_VERSION_H "${CMAKE_CURRENT_SOURCE_DIR}/version.h") + add_custom_command( + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/ + COMMAND ${GENERATE_VERSION_SH} + DEPENDS ${GENERATE_VERSION_SH} + OUTPUT ${KEEPER_VERSION_H} + COMMENT "Generating version.h" + ) +endif() # check member serialization # the stamp file is not actually generated, but it doesn't seem to matter -file(GLOB CHECK_SERIAL_SH "check_serial.sh") -set(CHECK_SERIAL_STAMP "${CMAKE_CURRENT_SOURCE_DIR}/check_serial.stamp") -add_custom_command( - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/ - COMMAND bash ${CHECK_SERIAL_SH} - DEPENDS ${CHECK_SERIAL_SH} - OUTPUT ${CHECK_SERIAL_STAMP} - COMMENT "Checking serialization" -) +if(ENABLE_CHECK_SERIAL) + file(GLOB CHECK_SERIAL_SH "check_serial.sh") + set(CHECK_SERIAL_STAMP "${CMAKE_CURRENT_SOURCE_DIR}/check_serial.stamp") + add_custom_command( + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/ + COMMAND bash ${CHECK_SERIAL_SH} + DEPENDS ${CHECK_SERIAL_SH} + OUTPUT ${CHECK_SERIAL_STAMP} + COMMENT "Checking serialization" + ) +endif() # rules to create `keeper` binary file(GLOB SOURCES "*.cpp" "extern/*.cpp") @@ -71,12 +81,13 @@ add_executable(keeper ${SOURCES} ${KEEPER_VERSION_H} ${CHECK_SERIAL_STAMP}) target_include_directories(keeper PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(keeper PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/extern) target_include_directories(keeper PRIVATE ${SDL2_INCLUDE_DIRS}) +target_include_directories(keeper PRIVATE ${OPENAL_INCLUDE_DIRS}) target_link_libraries(keeper PRIVATE - ${SDL2_LIBRARIES} + SDL2::SDL2 ${SDL2_IMAGE_LIBRARY} - ${OPENGL_gl_LIBRARY} + OpenGL::GL ${CMAKE_THREAD_LIBS_INIT} - ${CURL_LIBRARIES} + CURL::libcurl ${ZLIB_LIBRARIES} ${OPENAL_LIBRARY} ${VORBIS_LIBRARIES} @@ -84,26 +95,45 @@ target_link_libraries(keeper PRIVATE ${THEORA_dec_LIBRARY} ${VorbisFile_LIBRARIES} ) +if(ENABLE_STEAMWORKS) + target_link_libraries(keeper PRIVATE steamworks) + target_compile_definitions(keeper PRIVATE USE_STEAMWORKS) +endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_compile_definitions(keeper PRIVATE WINDOWS) + target_link_libraries(keeper PRIVATE dbghelp) +endif() +target_compile_options(keeper PRIVATE $<$:/w>) +target_compile_definitions(keeper PRIVATE $<$:_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING>) +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set_source_files_properties( + content_factory.cpp + player_control.cpp + gui_builder.cpp + pretty_printing.cpp + task.cpp + PROPERTIES + COMPILE_FLAGS /bigobj + ) + else() + set_source_files_properties( + content_factory.cpp + player_control.cpp + gui_builder.cpp + pretty_printing.cpp + task.cpp + PROPERTIES + COMPILE_FLAGS -Wa,-mbig-obj + ) + endif() +endif() # set up definitions if ((${CMAKE_BUILD_TYPE} MATCHES "Release")) target_compile_definitions(keeper PRIVATE RELEASE=1) else() -# generate stdafx.h.gch for debug build -# workaround to unquote the cxxflags -set(CXX_FLAGS_LIST ${CMAKE_CXX_FLAGS}) -separate_arguments(CXX_FLAGS_LIST) -add_custom_command( - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/ - COMMAND ${CMAKE_CXX_COMPILER} ${CXX_FLAGS_LIST} -x c++-header ${STDAFX_H} -MMD -o ${STDAFX_H_GCH} - DEPENDS ${STDAFX_H} - OUTPUT ${STDAFX_H_GCH} - COMMENT "Generating ${STDAFX_H_GCH}" -) -if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include-pch ${STDAFX_H_GCH}") -endif() -target_sources(keeper PRIVATE ${STDAFX_H_GCH}) + target_precompile_headers(keeper PRIVATE ${STDAFX_H}) endif() if(ENABLE_LOCAL_USER_DIR) diff --git a/cmake/FindTHEORA.cmake b/cmake/FindTHEORA.cmake index 2a5d1f43d..a7f0dc260 100644 --- a/cmake/FindTHEORA.cmake +++ b/cmake/FindTHEORA.cmake @@ -38,7 +38,7 @@ mark_as_advanced(THEORA_dec_LIBRARY) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(THEORA - REQUIRED_VARS THEORA_LIBRARY THEORA_enc_LIBRARY THEORA_dec_LIBRARY THEORA_INCLUDE_DIR) + REQUIRED_VARS THEORA_dec_LIBRARY THEORA_INCLUDE_DIR) if (THEORA_FOUND) set(THEORA_LIBRARIES "${THEORA_LIBRARY}" "${THEORA_enc_LIBRARY}" "${THEORA_dec_LIBRARY}") diff --git a/collective.h b/collective.h index 5074515ee..b086c543b 100644 --- a/collective.h +++ b/collective.h @@ -50,7 +50,7 @@ class CollectiveWarnings; class Immigration; class PositionMatching; class MinionActivities; -class ResourceInfo; +struct ResourceInfo; class StoragePositions; class Furnace; class Dancing; diff --git a/collective_config.cpp b/collective_config.cpp index 95d3d3e2c..da0b67cbe 100644 --- a/collective_config.cpp +++ b/collective_config.cpp @@ -95,7 +95,7 @@ void CollectiveConfig::addBedRequirementToImmigrants(vector& immi [&](const auto&) {} )); if (!hasBed) { - info.addRequirement(AttractionInfo(1, factory->furniture.getBedFurniture(*bedType)[0])); + info.addRequirement(AttractionInfo(1, AttractionType(factory->furniture.getBedFurniture(*bedType)[0]))); } } } diff --git a/content_factory.h b/content_factory.h index 54e19ab38..2f54a2e4c 100644 --- a/content_factory.h +++ b/content_factory.h @@ -32,12 +32,12 @@ class KeyVerifier; class BuildInfo; -class ExternalEnemy; -class ResourceDistribution; -class EnemyInfo; +struct ExternalEnemy; +struct ResourceDistribution; +struct EnemyInfo; class ImmigrantInfo; -class ZLevelInfo; -class BuildingInfo; +struct ZLevelInfo; +struct BuildingInfo; struct LayoutGenerator; struct TileGasInfo; struct PromotionInfo; diff --git a/directory_path.cpp b/directory_path.cpp index 32d8d26e9..69d454ad5 100644 --- a/directory_path.cpp +++ b/directory_path.cpp @@ -1,10 +1,14 @@ #include "stdafx.h" #include "directory_path.h" #include "file_path.h" -#include -#include -#include -#include "dirent.h" +#ifndef _MSC_VER +# include +# include +# include +# include "dirent.h" +#else +#include +#endif DirectoryPath::DirectoryPath(string p) : path(std::move(p)) { } @@ -17,6 +21,7 @@ DirectoryPath DirectoryPath::subdirectory(const std::string& s) const { return DirectoryPath(path + "/" + s); } +#ifndef _MSC_VER static bool isDirectory(const string& path) { struct stat path_stat; if (stat(path.c_str(), &path_stat)) @@ -24,6 +29,12 @@ static bool isDirectory(const string& path) { else return S_ISDIR(path_stat.st_mode); } +#else +static bool isDirectory(const string& path) { + std::error_code err; + return std::filesystem::is_directory(path, err); +} +#endif bool DirectoryPath::exists() const { return isDirectory(getPath()); @@ -31,7 +42,10 @@ bool DirectoryPath::exists() const { void DirectoryPath::createIfDoesntExist() const { if (!exists()) { -#ifndef WINDOWS +#ifdef _MSC_VER + std::error_code err; + USER_CHECK(!std::filesystem::create_directory(path.data(), err)); +#elif !defined(WINDOWS) USER_CHECK(!mkdir(path.data(), 0750)) << "Unable to create directory \"" + path + "\": " + strerror(errno); #else USER_CHECK(!mkdir(path.data())) << "Unable to create directory \"" + path + "\": " + strerror(errno); @@ -45,19 +59,30 @@ void DirectoryPath::removeRecursively() const { remove(file.getPath()); for (auto subdir : getSubDirs()) subdirectory(subdir).removeRecursively(); - rmdir(getPath()); + #ifdef _MSC_VER + std::error_code err; + std::filesystem::remove(getPath(), err); + #else + rmdir(getPath()); + #endif } } static bool isRegularFile(const string& path) { +#ifndef _MSC_VER struct stat path_stat; if (stat(path.c_str(), &path_stat)) return false; else return S_ISREG(path_stat.st_mode); +#else + std::error_code err; + return std::filesystem::is_regular_file(path, err); +#endif } vector DirectoryPath::getFiles() const { +#ifndef _MSC_VER vector ret; if (DIR* dir = opendir(path.data())) { while (dirent* ent = readdir(dir)) @@ -66,9 +91,18 @@ vector DirectoryPath::getFiles() const { closedir(dir); } return ret; +#else + vector res; + for(const auto& entry : std::filesystem::directory_iterator{path.data()}) { + if(entry.is_regular_file()) + res.push_back(FilePath(entry.path().filename().string(), entry.path().string())); + } + return res; +#endif } vector DirectoryPath::getSubDirs() const { +#ifndef _MSC_VER vector ret; if (DIR* dir = opendir(path.data())) { while (dirent* ent = readdir(dir)) @@ -77,6 +111,15 @@ vector DirectoryPath::getSubDirs() const { closedir(dir); } return ret; +#else + vector res; + std::error_code err; + for(const auto& entry : std::filesystem::directory_iterator{path.data(), err}) { + if(entry.is_directory()) + res.push_back(entry.path().filename().string()); + } + return res; +#endif } const char* DirectoryPath::getPath() const { @@ -107,10 +150,14 @@ string getAbsolute(const char* path) { } DirectoryPath DirectoryPath::current() { +#ifndef _MSC_VER char buffer[2048]; char* name = getcwd(buffer, sizeof(buffer) - 1); CHECK(name && "getcwd error"); return DirectoryPath(name); +#else + return DirectoryPath(std::filesystem::current_path().string()); +#endif } optional DirectoryPath::copyRecursively(DirectoryPath to) { diff --git a/extern/iomanip.h b/extern/iomanip.h index dd7815c80..1c16f8a3b 100644 --- a/extern/iomanip.h +++ b/extern/iomanip.h @@ -2,7 +2,7 @@ #include -#ifdef _LIBCPP_VERSION +#if defined(_LIBCPP_VERSION) || defined(_WIN32) #include #else diff --git a/extern/variant.hpp b/extern/variant.hpp index 746acaac8..bc907e4de 100644 --- a/extern/variant.hpp +++ b/extern/variant.hpp @@ -43,6 +43,7 @@ #if defined(__has_include) && !defined(STX_NO_STD_VARIANT) # if __has_include() && (__cplusplus > 201402) + #include namespace STX_NAMESPACE_NAME { using std::variant; using std::visit; diff --git a/file_path.cpp b/file_path.cpp index ceadbe05f..5f7b52b58 100644 --- a/file_path.cpp +++ b/file_path.cpp @@ -2,8 +2,13 @@ #include "file_path.h" #include "debug.h" #include "util.h" -#include -#include + +#ifndef _MSC_VER +# include +# include +#else +# include +#endif FilePath FilePath::fromFullPath(const std::string& path) { return FilePath(split(path, {'/'}).back(), path); @@ -28,7 +33,10 @@ time_t FilePath::getModificationTime() const { } bool FilePath::exists() const { -#ifdef WINDOWS +#ifdef _MSC_VER + std::error_code err; + return std::filesystem::is_regular_file(fullPath.c_str(), err); +#elif defined(WINDOWS) struct _stat buf; _stat(fullPath.c_str(), &buf); return S_ISREG(buf.st_mode); diff --git a/file_sharing.cpp b/file_sharing.cpp index 4b5d12c4b..b8a951603 100644 --- a/file_sharing.cpp +++ b/file_sharing.cpp @@ -395,7 +395,7 @@ static string firstLines(string text, int max_lines = 3) { } } } - while (text.back() == '\n') + while (!text.empty() && text.back() == '\n') text.pop_back(); return text; } diff --git a/fx_factory.cpp b/fx_factory.cpp index 06b7d4a7c..749d81720 100644 --- a/fx_factory.cpp +++ b/fx_factory.cpp @@ -619,7 +619,7 @@ static void addMagicMissileEffect(FXManager& mgr) { pdef.textureName = TextureName::MISSILE_CORE; SubSystemDef ssdef(pdef, edef, 0.0f, 0.1f); - ssdef.emitFunc = [](AnimationContext& ctx, EmissionState& em, Particle& pinst) { + ssdef.emitFunc = [=](AnimationContext& ctx, EmissionState& em, Particle& pinst) { em.direction = ctx.ps.targetDirAngle; em.directionSpread = 0.0f; em.strength = ctx.ps.targetTileDist * 24.0f / flightTime; diff --git a/fx_math.h b/fx_math.h index cf4aab705..14262c4f7 100644 --- a/fx_math.h +++ b/fx_math.h @@ -29,9 +29,16 @@ inline float degToRad(float v) { return v * (2.0f * fconstant::pi / 360.0f); } inline float radToDeg(float v) { return v * (360.0 / (2.0 * fconstant::pi)); } inline std::pair sincos(float radians) { +#ifndef _WIN32 std::pair out; ::sincosf(radians, &out.first, &out.second); return out; +#else + std::pair out; + out.first = std::sin(radians); + out.second = std::cos(radians); + return out; +#endif } // Return angle in range (0; 2 * PI) diff --git a/gen_variant_serialize_pretty.h b/gen_variant_serialize_pretty.h index 5496e14a7..fa9f24dc6 100644 --- a/gen_variant_serialize_pretty.h +++ b/gen_variant_serialize_pretty.h @@ -9,7 +9,8 @@ void serialize(PrettyInputArchive& ar1, VARIANT_NAME& v) { v.index = Index; \ new(&v.elem##Index) Type;\ ar1(v.elem##Index); \ - } else + return; \ + } VARIANT_TYPES_LIST #undef X #ifdef DEFAULT_ELEM @@ -19,7 +20,8 @@ void serialize(PrettyInputArchive& ar1, VARIANT_NAME& v) { new(&v.elem##Index) Type;\ ar1.seek(bookmark);\ ar1(v.elem##Index); \ - } else + return; \ + } VARIANT_TYPES_LIST #undef X ar1.error("Bad default elem"); diff --git a/gui_builder.cpp b/gui_builder.cpp index c11a7cebf..8ebebadb7 100644 --- a/gui_builder.cpp +++ b/gui_builder.cpp @@ -1775,7 +1775,7 @@ SGuiElem GuiBuilder::drawSpellsList(const vector& spells, GenericId c list.addElem(line.buildHorizontalList()); auto ret = list.buildVerticalList(); if (active) { - auto getNextSpell = [spells](int curIndex, int inc) -> optional { + auto getNextSpell = [spells, spellsPerRow](int curIndex, int inc) -> optional { int module = abs(inc) == 1 ? spells.size() : (spells.size() + spellsPerRow - 1) / spellsPerRow * spellsPerRow; for (int i : All(spells)) { int index = (curIndex + (i + 1) * inc + module) % module; @@ -4379,7 +4379,7 @@ SGuiElem GuiBuilder::drawMinionPage(const PlayerInfo& minion, const optional& queue, View:: SGuiElem GuiBuilder::drawCampaignMenu(SyncQueue& queue, View::CampaignOptions campaignOptions, View::CampaignMenuState& menuState) { if (menuState.index == CampaignMenuElems::None{} && hasController()) - menuState.index = CampaignMenuElems::Help{}; + menuState.index = CampaignMenuElems::CampaignMenuIndexVariant(CampaignMenuElems::Help{}); const auto& campaign = campaignOptions.campaign; auto& retiredGames = campaignOptions.retired; auto lines = WL(getListBuilder, getStandardLineHeight()); diff --git a/indexed_vector.h b/indexed_vector.h index 075c446b6..351f7088d 100644 --- a/indexed_vector.h +++ b/indexed_vector.h @@ -11,6 +11,9 @@ class IndexedVector { indexes.emplace(elems[i]->getUniqueId(), i); } + IndexedVector(const IndexedVector&) = default; + IndexedVector& operator=(const IndexedVector&) = default; + IndexedVector(IndexedVector&&) = default; IndexedVector& operator = (IndexedVector&&) = default; diff --git a/item.h b/item.h index cfe68d6f5..6026cda7f 100644 --- a/item.h +++ b/item.h @@ -30,7 +30,7 @@ class Fire; class ItemAttributes; class Effect; struct CorpseInfo; -class WeaponInfo; +struct WeaponInfo; struct ItemUpgradeInfo; class ItemPrefix; class ItemType; diff --git a/item_attributes.h b/item_attributes.h index d431df60e..85d6fde44 100644 --- a/item_attributes.h +++ b/item_attributes.h @@ -107,6 +107,6 @@ class ItemAttributes { string SERIAL(equipWarning) = "This item may potentially hurt your minion. Continue?"; }; -static_assert(std::is_nothrow_move_constructible::value, "T should be noexcept MoveConstructible"); +// static_assert(std::is_nothrow_move_constructible::value, "T should be noexcept MoveConstructible"); CEREAL_CLASS_VERSION(ItemAttributes, 1) \ No newline at end of file diff --git a/level_maker.h b/level_maker.h index a0abfe0f6..8c545450b 100644 --- a/level_maker.h +++ b/level_maker.h @@ -31,7 +31,7 @@ class LevelGenException { }; class FilePath; -class CreatureList; +struct CreatureList; class TribeId; class ContentFactory;; struct BiomeInfo; diff --git a/main_loop.h b/main_loop.h index 148f364b7..bbadb8914 100644 --- a/main_loop.h +++ b/main_loop.h @@ -19,7 +19,7 @@ class SokobanInput; struct CampaignSetup; class ModelBuilder; class ItemType; -class CreatureList; +struct CreatureList; class GameConfig; class AvatarInfo; class NameGenerator; @@ -32,7 +32,7 @@ struct ModDetails; class TribeId; struct RetiredModelInfo; class Unlocks; -class SteamAchievements; +struct SteamAchievements; class MainLoop { public: diff --git a/map_layouts.h b/map_layouts.h index b0677030b..abe369167 100644 --- a/map_layouts.h +++ b/map_layouts.h @@ -33,4 +33,4 @@ class MapLayouts { map> SERIAL(layouts); }; -static_assert(std::is_nothrow_move_constructible::value, "T should be noexcept MoveConstructible"); +// static_assert(std::is_nothrow_move_constructible::value, "T should be noexcept MoveConstructible"); diff --git a/miniunz.cpp b/miniunz.cpp index f640e8414..af9318dc5 100644 --- a/miniunz.cpp +++ b/miniunz.cpp @@ -16,8 +16,12 @@ #include //#ifdef unix +#ifndef _WIN32 # include # include +#else +# include +#endif /*#else # include # include @@ -96,7 +100,10 @@ void change_file_date( optional mymkdir( const char* dirname) { -#ifndef WINDOWS +#ifdef _MSC_VER + std::error_code err; + if(!std::filesystem::create_directory(dirname, err)) +#elif !defined(WINDOWS) if (mkdir (dirname,0775) != 0) #else if (mkdir (dirname) != 0) diff --git a/model_builder.h b/model_builder.h index 83d3de3a7..29528f98e 100644 --- a/model_builder.h +++ b/model_builder.h @@ -17,7 +17,7 @@ class ExternalEnemies; struct EnemyEvent; class Tutorial; class FilePath; -class CreatureList; +struct CreatureList; class GameConfig; class ContentFactory; struct LevelConnection; diff --git a/my_containers.h b/my_containers.h index af9e3371a..e5c8ae8ec 100644 --- a/my_containers.h +++ b/my_containers.h @@ -51,7 +51,7 @@ class vector { } void push_back(T t) { -#ifndef RELEASE // due to compile errors on older clang +#if !defined(RELEASE) && !defined(_WIN32) // due to compile errors on older clang static_assert(std::is_nothrow_move_constructible::value, "T should be noexcept MoveConstructible"); #endif impl.push_back(std::move(t)); @@ -419,19 +419,19 @@ class vector { friend class Iterator; auto begin() const { - return const_iterator(&*impl.begin(), this); + return const_iterator(impl.data(), this); } auto end() const { - return const_iterator(&*impl.end(), this); + return const_iterator(impl.data() + impl.size(), this); } auto begin() { - return iterator(&*impl.begin(), this); + return iterator(impl.data(), this); } auto end() { - return iterator(&*impl.end(), this); + return iterator(impl.data() + impl.size(), this); } std::vector impl; diff --git a/opengl.cpp b/opengl.cpp index c9216e2d8..538a38a0a 100644 --- a/opengl.cpp +++ b/opengl.cpp @@ -181,7 +181,7 @@ void glQuad(float x, float y, float ex, float ey) { SDL::glEnd(); } -#ifdef WINDOWS +#if defined(WINDOWS) || defined(_WIN32) void *winLoadFunction(const char *name) { auto ret = SDL::SDL_GL_GetProcAddress(name); //USER_CHECK(!!ret) << "Unable to load OpenGL function: " << name << ". Please update your video card driver."; @@ -208,7 +208,7 @@ namespace SDL { #endif bool isOpenglFeatureAvailable(OpenglFeature feature) { -#ifdef WINDOWS +#if defined(WINDOWS) || defined(_WIN32) #define ON_WINDOWS(check) check #else #define ON_WINDOWS(check) @@ -228,7 +228,7 @@ bool isOpenglFeatureAvailable(OpenglFeature feature) { } void initializeGLExtensions() { -#ifdef WINDOWS +#if defined(WINDOWS) || defined(_WIN32) #define LOAD(func) SDL::func = (decltype(SDL::func))winLoadFunction(#func); LOAD(glBindFramebuffer); LOAD(glDeleteFramebuffers); @@ -237,6 +237,8 @@ void initializeGLExtensions() { LOAD(glFramebufferTexture2D); LOAD(glDrawBuffers); LOAD(glBlendFuncSeparate); + LOAD(glDebugMessageCallback); + LOAD(glDebugMessageControl); #undef LOAD #endif } diff --git a/opengl.h b/opengl.h index 4c7ca8f2d..e9c3663ec 100644 --- a/opengl.h +++ b/opengl.h @@ -24,7 +24,7 @@ void initializeGLExtensions(); enum class OpenglFeature { FRAMEBUFFER, SEPARATE_BLEND_FUNC, DEBUG }; bool isOpenglFeatureAvailable(OpenglFeature); -#ifdef WINDOWS +#if defined(_WIN32) || defined(WINDOWS) namespace SDL { #define EXT_ENTRY __stdcall diff --git a/player_control.h b/player_control.h index a652ddb5d..1443636aa 100644 --- a/player_control.h +++ b/player_control.h @@ -50,7 +50,7 @@ class Tutorial; struct BuildInfo; class MoveInfo; class UnknownLocations; -class AttackTrigger; +struct AttackTrigger; class ImmigrantInfo; struct WorkshopOptionInfo; struct FurnaceOptionInfo; diff --git a/pretty_archive.cpp b/pretty_archive.cpp index 93ff000a3..37ab4f4da 100644 --- a/pretty_archive.cpp +++ b/pretty_archive.cpp @@ -28,7 +28,7 @@ static bool contains(const vector& a, const string& substring, int i } static void eatWhitespace(const vector& s, int& index) { - while (index < s.size() && isspace(s[index].c)) + while (index < s.size() && isspace((unsigned char)s[index].c)) ++index; } @@ -107,9 +107,9 @@ void eatArgument(const vector& s, int& index) { optional scanWord(const vector& s, int& index) { string ret; int origIndex = index; - while (index < s.size() && isspace(s[index].c)) + while (index < s.size() && isspace((unsigned char)s[index].c)) ++index; - while (index < s.size() && (isalnum(s[index].c) || s[index].c == '_')) + while (index < s.size() && (isalnum((unsigned char)s[index].c) || s[index].c == '_')) ret += s[index++].c; if (ret.empty()) { index = origIndex; diff --git a/renderer.cpp b/renderer.cpp index d7407aa68..c9d36537d 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -14,7 +14,7 @@ If not, see http://www.gnu.org/licenses/ . */ #include "stdafx.h" -#include "dirent.h" +// #include "dirent.h" #include "extern/lodepng.h" #include "renderer.h" diff --git a/scripted_ui.cpp b/scripted_ui.cpp index 2680e2f1b..6f825b5d2 100644 --- a/scripted_ui.cpp +++ b/scripted_ui.cpp @@ -366,9 +366,10 @@ struct Container : ScriptedUIInterface { vector getError(const string& s) const { static map errors; + static ScriptedUIData defUiData; if (!errors.count(s)) errors[s] = ScriptedUI{make_unique