diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-02 19:03:32 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-02 20:25:31 +0100 |
commit | 5a95eb1282e30bd803d7e0b352a8443795842e42 (patch) | |
tree | c97bc43e4d5107a427817c65aa1b0c2eeb64a427 | |
parent | 0fe5336b9a53f20817f54be0bd7cd935db14914c (diff) |
fix build with Linux and/or GCC
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | anim-crop-tool/atlas.hpp | 3 | ||||
-rw-r--r-- | anim-crop-tool/main.cpp | 2 | ||||
-rw-r--r-- | editor/events.cpp | 6 | ||||
-rw-r--r-- | editor/save.cpp | 2 | ||||
-rw-r--r-- | external/CMakeLists.txt | 5 | ||||
-rw-r--r-- | floormat/main.hpp | 2 | ||||
-rw-r--r-- | main/draw.cpp | 2 | ||||
-rw-r--r-- | main/setup.cpp | 2 | ||||
-rw-r--r-- | serialize/anim.hpp | 2 | ||||
-rw-r--r-- | serialize/json-helper.hpp | 3 | ||||
-rw-r--r-- | serialize/world-impl.hpp | 8 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 15 | ||||
-rw-r--r-- | serialize/world-writer.cpp | 19 | ||||
-rw-r--r-- | src/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/random.cpp | 2 | ||||
-rw-r--r-- | src/tile-atlas.hpp | 2 | ||||
-rw-r--r-- | src/tile.hpp | 2 | ||||
-rw-r--r-- | src/world.hpp | 2 |
19 files changed, 50 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 410c0921..f16b8f64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ if(MSVC) add_link_options(-HIGHENTROPYVA) endif() else() - add_compile_options(-fuse-cxa-atexit) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-cxa-atexit") endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang$") @@ -150,7 +150,9 @@ add_subdirectory(src) add_subdirectory(main) add_subdirectory(editor) add_subdirectory(anim-crop-tool) -add_subdirectory(test) +if(WIN32) # TODO + add_subdirectory(test) +endif() install(DIRECTORY images DESTINATION "share/${PROJECT_NAME}") diff --git a/anim-crop-tool/atlas.hpp b/anim-crop-tool/atlas.hpp index 02e7176b..6da8fd63 100644 --- a/anim-crop-tool/atlas.hpp +++ b/anim-crop-tool/atlas.hpp @@ -1,11 +1,10 @@ #pragma once #include <vector> +#include <filesystem> #include <Magnum/Magnum.h> #include <Magnum/Math/Vector2.h> #include <opencv2/core/mat.hpp> -namespace std::filesystem { class path; } - namespace floormat::Serialize { struct anim_frame; diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index e77821f5..430e4b80 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -185,7 +185,7 @@ static char* fix_argv0(char* argv0) noexcept return c+1; } #else - if (auto* c = strrchr(argv[0], '/'); c && c[1]) + if (auto* c = strrchr(argv0, '/'); c && c[1]) return c+1; #endif return argv0; diff --git a/editor/events.cpp b/editor/events.cpp index 86ff4d59..821c9c4d 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -67,7 +67,7 @@ void app::on_mouse_move(const mouse_move_event& event) noexcept void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept { - enum class Button : std::underlying_type_t<mouse_button> { + enum class Button_ : std::underlying_type_t<mouse_button> { Left = mouse_button_left, Right = mouse_button_right, Middle = mouse_button_middle, @@ -76,10 +76,10 @@ void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexce const auto button = std::uint8_t(1 << (event.button-1)); struct ev { - using Button = Button; + using Button = Button_; accessor(Vector2i, position) accessor(Button, button) - } e = {event.position, Button(button)}; + } e = {event.position, Button_(button)}; if (!(cursor.in_imgui = is_down ? _imgui.handleMousePressEvent(e) : _imgui.handleMouseReleaseEvent(e))) do_mouse_up_down(button, is_down, fixup_mods(event.mods)); diff --git a/editor/save.cpp b/editor/save.cpp index 6b6f5ce2..35cdf9e7 100644 --- a/editor/save.cpp +++ b/editor/save.cpp @@ -1,6 +1,8 @@ #include "app.hpp" #include "floormat/main.hpp" #include "src/world.hpp" + +#include <filesystem> #include <Corrade/Utility/Path.h> namespace floormat { diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index d04565c3..f08fe35d 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -26,8 +26,8 @@ else() add_compile_options( -Wno-error -Wno-undef - -Wno-old-style-cast ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-old-style-cast") endif() if(FLOORMAT_SUBMODULE-DEPENDENCIES) @@ -138,6 +138,9 @@ if(FLOORMAT_SUBMODULE-DEPENDENCIES) SDL_WASAPI OFF SDL_XINPUT OFF ) + if(NOT WIN32) + set(MAGNUM_WITH_WINDOWLESSWGLAPPLICATION OFF) + endif() endif() fm_run_hook(fm-userconfig-external-pre) diff --git a/floormat/main.hpp b/floormat/main.hpp index da7e59b9..9347ad40 100644 --- a/floormat/main.hpp +++ b/floormat/main.hpp @@ -36,7 +36,7 @@ struct floormat_main virtual global_coords pixel_to_tile(Vector2d position) const noexcept = 0; - virtual world& world() noexcept = 0; + virtual struct world& world() noexcept = 0; virtual SDL_Window* window() noexcept = 0; [[nodiscard]] static floormat_main* create(floormat_app& app, fm_settings&& options); diff --git a/main/draw.cpp b/main/draw.cpp index 533d09ca..71de7e72 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -147,7 +147,7 @@ void main_impl::drawEvent() constexpr float α = .1f; dt_expected.jitter = std::fmax(dt_expected.jitter + Δt * α, dt_expected.jitter * (1-α) + Δt * α); - dt_expected.jitter = std::copysignf(std::fminf(dt_expected.value, std::fabsf(dt_expected.jitter)), dt_expected.jitter); + dt_expected.jitter = std::copysign(std::fmin(dt_expected.value, std::fabs(dt_expected.jitter)), dt_expected.jitter); } else dt_expected.jitter = 0; diff --git a/main/setup.cpp b/main/setup.cpp index b6488bad..edd95767 100644 --- a/main/setup.cpp +++ b/main/setup.cpp @@ -98,7 +98,7 @@ void main_impl::update_window_state() if (!(flags & SDL_WINDOW_INPUT_FOCUS)) dt_expected.value = 2.f / hz; else - dt_expected.value = std::floorf((1.f/hz - 1e-3f) * 1e3f) * 1e-3f; + dt_expected.value = std::floor((1.f/hz - 1e-3f) * 1e3f) * 1e-3f; } else { diff --git a/serialize/anim.hpp b/serialize/anim.hpp index 957e733e..85d5facd 100644 --- a/serialize/anim.hpp +++ b/serialize/anim.hpp @@ -8,8 +8,6 @@ #include <Magnum/Math/Vector2.h> #include <nlohmann/json_fwd.hpp> -namespace std::filesystem { class path; } - namespace floormat::Serialize { struct anim_frame final diff --git a/serialize/json-helper.hpp b/serialize/json-helper.hpp index 42cd73b3..e0e2c0ca 100644 --- a/serialize/json-helper.hpp +++ b/serialize/json-helper.hpp @@ -1,7 +1,6 @@ #pragma once #include <nlohmann/json.hpp> - -namespace std::filesystem { class path; } +#include <filesystem> namespace floormat { diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index caf5e8a7..4c206a7e 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -9,14 +9,14 @@ namespace floormat::Serialize { -namespace { - using tilemeta = std::uint8_t; using varid = decltype(tile_image_proto::variant); using atlasid = std::uint16_t; using chunksiz = std::uint16_t; using proto_t = std::uint16_t; +namespace { + template<typename T> constexpr inline T int_max = std::numeric_limits<T>::max(); #define file_magic ".floormat.save" @@ -30,6 +30,8 @@ constexpr inline auto chunk_magic = (std::uint16_t)~0xc0d3; constexpr inline std::underlying_type_t<pass_mode> pass_mask = pass_blocked | pass_shoot_through | pass_ok; constexpr inline auto pass_bits = std::bit_width(pass_mask); +} // namespace + enum : tilemeta { meta_ground = 1 << (pass_bits + 0), meta_wall_n = 1 << (pass_bits + 1), @@ -38,8 +40,6 @@ enum : tilemeta { meta_short_variant = 1 << (pass_bits + 4), }; -} // namespace - } // namespace floormat::Serialize namespace floormat { diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index aa156609..e55ea059 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -4,11 +4,10 @@ #include "src/world.hpp" #include "src/loader.hpp" #include "src/tile-atlas.hpp" +#include <cstring> namespace floormat::Serialize { -namespace { - struct reader_state final { explicit reader_state(world& world) noexcept; void deserialize_world(ArrayView<const char> buf); @@ -21,10 +20,10 @@ private: void read_chunks(reader_t& reader); std::unordered_map<atlasid, std::shared_ptr<tile_atlas>> atlases; - struct world* world; + world* _world; }; -reader_state::reader_state(struct world& world) noexcept : world{&world} {} +reader_state::reader_state(world& world) noexcept : _world{&world} {} void reader_state::read_atlases(reader_t& s) { @@ -61,7 +60,7 @@ void reader_state::read_chunks(reader_t& s) chunk_coords coord; s >> coord.x; s >> coord.y; - auto& chunk = (*world)[coord]; + auto& chunk = (*_world)[coord]; for (std::size_t i = 0; i < TILE_COUNT; i++) { const tilemeta flags = s.read<tilemeta>(); @@ -111,8 +110,6 @@ void reader_state::deserialize_world(ArrayView<const char> buf) s.assert_end(); } -} // namespace - } // namespace floormat::Serialize namespace floormat { @@ -121,7 +118,11 @@ world world::deserialize(StringView filename) { char errbuf[128]; constexpr auto strerror = []<std::size_t N> (char (&buf)[N]) -> const char* { +#ifndef _WIN32 + ::strerror_r(errno, buf, std::size(buf)); +#else ::strerror_s(buf, std::size(buf), errno); +#endif return buf; }; fm_assert(filename.flags() & StringViewFlag::NullTerminated); diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index c16dc32a..c33947dc 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -8,6 +8,7 @@ #include "src/world.hpp" #include <vector> #include <algorithm> +#include <cstring> #include <Corrade/Containers/StringView.h> #include <Corrade/Utility/Path.h> @@ -15,8 +16,6 @@ namespace Path = Corrade::Utility::Path; namespace floormat::Serialize { -namespace { - struct interned_atlas final { const tile_atlas* img; atlasid index; @@ -34,7 +33,7 @@ private: void serialize_chunk(const chunk& c, chunk_coords coord); void serialize_atlases(); - const struct world* world; + const world* _world; std::vector<char> atlas_buf, chunk_buf, file_buf; std::vector<std::vector<char>> chunk_bufs; std::unordered_map<const void*, interned_atlas> tile_images; @@ -53,7 +52,7 @@ constexpr auto chunkbuf_size = #pragma warning(disable : 4996) #endif -writer_state::writer_state(const struct world& world) : world{&world} +writer_state::writer_state(const world& world) : _world{&world} { chunk_buf.reserve(chunkbuf_size); chunk_bufs.reserve(world.chunks().size()); @@ -201,7 +200,7 @@ void writer_state::serialize_atlases() ArrayView<const char> writer_state::serialize_world() { - for (const auto& [pos, c] : world->chunks()) + for (const auto& [pos, c] : _world->chunks()) { #ifndef FM_NO_DEBUG if (c.empty(true)) @@ -212,9 +211,9 @@ ArrayView<const char> writer_state::serialize_world() serialize_atlases(); using proto_t = std::decay_t<decltype(proto_version)>; - union { chunksiz x; char bytes[sizeof x]; } c = {.x = maybe_byteswap((chunksiz)world->size())}; + union { chunksiz x; char bytes[sizeof x]; } c = {.x = maybe_byteswap((chunksiz)_world->size())}; union { proto_t x; char bytes[sizeof x]; } p = {.x = maybe_byteswap(proto_version)}; - fm_assert(world->size() <= int_max<chunksiz>); + fm_assert(_world->size() <= int_max<chunksiz>); std::size_t len = 0; len += std::size(file_magic)-1; @@ -248,8 +247,6 @@ ArrayView<const char> writer_state::serialize_world() #pragma warning(pop) #endif -} // namespace - } // namespace floormat::Serialize namespace floormat { @@ -259,7 +256,11 @@ void world::serialize(StringView filename) collect(true); char errbuf[128]; constexpr auto strerror = []<std::size_t N> (char (&buf)[N]) -> const char* { +#ifndef _WIN32 + ::strerror_r(errno, buf, std::size(buf)); +#else ::strerror_s(buf, std::size(buf), errno); +#endif return buf; }; fm_assert(filename.flags() & StringViewFlag::NullTerminated); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c4ac952..85e6bf5b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,10 +6,15 @@ target_link_libraries( Magnum::GL Magnum::Magnum Magnum::Shaders - Magnum::AnyImageImporter - Magnum::TgaImporter nlohmann_json::nlohmann_json ) if(FLOORMAT_PRECOMPILED-HEADERS) target_precompile_headers(${self} PRIVATE precomp.hpp) endif() + +if(WIN32 OR MAGNUM_BUILD_STATIC) + target_link_libraries(${self} PUBLIC + Magnum::AnyImageImporter + Magnum::TgaImporter + ) +endif() diff --git a/src/random.cpp b/src/random.cpp index 4da534a3..d3e45292 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -18,7 +18,7 @@ std::size_t random_engine_impl::operator()() if constexpr(sizeof(std::size_t) > sizeof(std::uint32_t)) { constexpr std::size_t N = (sizeof(std::size_t) + sizeof(std::uint32_t)-1) / sizeof(std::uint32_t); - static_assert(N >= 2); + static_assert(N >= 1); union { std::size_t x; std::uint32_t a[N]; diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp index b46cf686..026d2073 100644 --- a/src/tile-atlas.hpp +++ b/src/tile-atlas.hpp @@ -5,8 +5,6 @@ #include <array> #include <memory> -namespace std::filesystem { class path; } - namespace floormat { struct tile_atlas final diff --git a/src/tile.hpp b/src/tile.hpp index ab55ca11..b7bacc8d 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -25,7 +25,7 @@ struct tile_proto final { std::shared_ptr<tile_atlas> ground_atlas, wall_north_atlas, wall_west_atlas; variant_t ground_variant = 0, wall_north_variant = 0, wall_west_variant = 0; - pass_mode pass_mode = pass_mode::pass_shoot_through; + enum pass_mode pass_mode = pass_mode::pass_shoot_through; tile_image_proto ground_image() const noexcept; tile_image_proto wall_north_image() const noexcept; diff --git a/src/world.hpp b/src/world.hpp index 9b58ff3d..195d4903 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -6,8 +6,6 @@ #include <unordered_map> #include <memory> -namespace std::filesystem { class path; } - namespace floormat { struct world final |