diff options
-rw-r--r-- | CMakeLists.txt | 106 | ||||
-rw-r--r-- | compat/assert.hpp | 9 | ||||
-rw-r--r-- | external/CMakeLists.txt | 26 | ||||
-rw-r--r-- | main/CMakeLists.txt | 5 | ||||
-rw-r--r-- | main/app.hpp | 2 | ||||
-rw-r--r-- | main/draw.cpp | 5 | ||||
-rw-r--r-- | main/imgui-raii.hpp | 2 | ||||
-rw-r--r-- | main/imgui.cpp | 4 | ||||
-rw-r--r-- | main/loader-impl.cpp | 1 | ||||
-rw-r--r-- | shaders/tile-shader.cpp | 2 | ||||
-rw-r--r-- | shaders/tile-shader.hpp | 1 | ||||
-rw-r--r-- | shaders/tile-shader.vert | 3 | ||||
-rw-r--r-- | src/random.cpp | 3 | ||||
-rw-r--r-- | src/random.hpp | 4 |
14 files changed, 111 insertions, 62 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 49d207b9..7986654b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -cmake_minimum_required(VERSION 3.16 FATAL_ERROR) +cmake_minimum_required(VERSION 3.18 FATAL_ERROR) project(floormat) set(CMAKE_CXX_STANDARD 23) @@ -22,26 +22,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set(CMAKE_INSTALL_MESSAGE LAZY) -if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR CMAKE_INSTALL_PREFIX STREQUAL "") - set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "" FORCE) -endif() - -if(WIN32) - add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DWIN32_LEAN_AND_MEAN) -endif() - -if(MSVC) - add_definitions(-D_USE_MATH_DEFINES=1) -endif() - -if(COMMAND fm_hook_pre_external) - fm_hook_pre_external() -endif() - -set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS OFF) -set_directory_properties(PROPERTIES CORRADE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) -set_directory_properties(PROPERTIES INTERFACE_CORRADE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) - function(sets type) set(i 0) list(LENGTH ARGN max) @@ -58,24 +38,11 @@ function(sets type) endwhile() endfunction() -cmake_policy(SET CMP0063 NEW) - -if(MSVC) - add_compile_options(-permissive-) - add_compile_options( - -wd4244 # warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data - -wd4312 # warning C4312: 'reinterpret_cast': conversion from 'GLenum' to 'void *' of greater size - -wd4251 # warning C4251: 't::f': class 'x' needs to have dll-interface to be used by clients of class 'y' - -wd4456 # warning C4456: declaration of 'x' hides previous local declaration - ) - add_compile_options(-external:W0 -external:anglebrackets) - if(CMAKE_SIZEOF_VOID_P GREATER_EQUAL 8) - add_link_options(-HIGHENTROPYVA) +function(fm_run_hook str) + if(COMMAND "${str}") + cmake_language(CALL "${str}") endif() -endif() - -set(FLOORMAT_SUBMODULE_DEPENDENCIES ON CACHE BOOL - "Use dependencies included in the source directory (needs git submodule update --init).") +endfunction() function(fm_load_userconfig) if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") @@ -85,17 +52,53 @@ function(fm_load_userconfig) endif() set(_fm_userconfig "userconfig-${_fm_username}@${CMAKE_CXX_COMPILER_ID}.cmake") if(EXISTS "${CMAKE_SOURCE_DIR}/${_fm_userconfig}") + message(STATUS "loading user config '${_fm_userconfig}'") include("${CMAKE_SOURCE_DIR}/${_fm_userconfig}") else() message(STATUS "user config '${_fm_userconfig}' not found") endif() endfunction() -fm_load_userconfig() -add_subdirectory(external) +if(NOT "$ENV{FLOORMAT_NO_USERCONFIG}" AND NOT FLOORMAT_NO_USERCONFIG) + fm_load_userconfig() +endif() -include_directories(.) -include_directories(src) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR CMAKE_INSTALL_PREFIX STREQUAL "") + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "" FORCE) +endif() + +if(WIN32) + add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DWIN32_LEAN_AND_MEAN) +endif() + +if(MSVC) + add_definitions(-D_USE_MATH_DEFINES=1) + add_compile_options(-permissive-) + add_compile_options( + -wd4244 # warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data + -wd4312 # warning C4312: 'reinterpret_cast': conversion from 'GLenum' to 'void *' of greater size + -wd4251 # warning C4251: 't::f': class 'x' needs to have dll-interface to be used by clients of class 'y' + -wd4456 # warning C4456: declaration of 'x' hides previous local declaration + ) + add_compile_options(-external:W0 -external:anglebrackets) + if(CMAKE_SIZEOF_VOID_P GREATER_EQUAL 8) + add_link_options(-HIGHENTROPYVA) + endif() +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang$") + add_compile_options(-Wno-reserved-macro-identifier) +endif() + +cmake_policy(SET CMP0063 NEW) + +set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS OFF) +set_directory_properties(PROPERTIES CORRADE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) +set_directory_properties(PROPERTIES INTERFACE_CORRADE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) + +fm_run_hook(fm-userconfig-init) + +add_subdirectory(external) if(MSVC) add_definitions(/FI"compat/prelude.hpp") @@ -103,9 +106,19 @@ else() add_definitions(-include compat/prelude.hpp) endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang$") - set_property(DIRECTORY APPEND PROPERTY COMPILE_FLAGS -Wignored-attributes -Werror -ferror-limit=5) -endif() +fm_run_hook(fm-userconfig-src) + +include_directories(.) +include_directories(src) + +#get_property(_fm-sdl2-include-dirs TARGET SDL2::SDL2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +include_directories(SYSTEM + "${CORRADE_INCLUDE_DIR}" + "${MAGNUM_INCLUDE_DIR}" + "${MAGNUMPLUGINS_INCLUDE_DIR}" + "${MAGNUMINTEGRATION_INCLUDE_DIR}" + #${_fm-sdl2-include-dirs} +) add_subdirectory(src) add_subdirectory(draw) @@ -114,3 +127,6 @@ add_subdirectory(anim-crop-tool) add_subdirectory(test) install(DIRECTORY images DESTINATION "share/${PROJECT_NAME}") + +fm_run_hook(fm-userconfig-post) +get_cmake_property(_variableNames VARIABLES) diff --git a/compat/assert.hpp b/compat/assert.hpp index 04c5acbe..24070b15 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -6,6 +6,11 @@ namespace floormat::detail { +#ifdef __GNUG__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + template<std::size_t N, std::size_t M, typename... Xs> constexpr void emit_debug(const char(&pfx)[M], const char(&fmt)[N], Xs... xs) noexcept { @@ -20,6 +25,10 @@ constexpr void emit_debug(const char(&pfx)[M], const char(&fmt)[N], Xs... xs) no } } +#ifdef __GNUG__ +# pragma GCC diagnostic pop +#endif + template<std::size_t N, typename...Xs> [[noreturn]] constexpr inline void abort(const char (&fmt)[N], Xs... xs) noexcept diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index d70503a0..3b4110b7 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,16 +1,25 @@ project(floormat-external) +set(FLOORMAT_SUBMODULE-DEPENDENCIES ON CACHE BOOL + "Use dependencies included in the source directory (needs git submodule update --init).") + foreach(_module corrade magnum magnum-integration magnum-plugins) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${_module}/modules") endforeach() if(MSVC) add_link_options(-WX:NO) + set_property(DIRECTORY APPEND PROPERTY STATIC_LIBRARY_OPTIONS + -IGNORE:4006 #warning LNK4006: main already defined in x.cpp.obj; second definition ignored + ) else() - add_compile_options(-Wno-error) + add_compile_options( + -Wno-error + -Wno-undef + ) endif() -if(FLOORMAT_SUBMODULE_DEPENDENCIES) +if(FLOORMAT_SUBMODULE-DEPENDENCIES) sets(BOOL CORRADE_BUILD_STATIC OFF CORRADE_BUILD_TESTS OFF @@ -114,7 +123,9 @@ if(FLOORMAT_SUBMODULE_DEPENDENCIES) ) endif() -if(FLOORMAT_SUBMODULE_DEPENDENCIES) +fm_run_hook(fm-userconfig-external-pre) + +if(FLOORMAT_SUBMODULE-DEPENDENCIES) sets(PATH IMGUI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/imgui") add_subdirectory(json) add_subdirectory(sdl2) @@ -124,18 +135,19 @@ if(FLOORMAT_SUBMODULE_DEPENDENCIES) add_subdirectory(magnum-integration) endif() -if(FLOORMAT_SUBMODULE_DEPENDENCIES) +if(FLOORMAT_SUBMODULE-DEPENDENCIES) if(MSVC) target_compile_options(CorradeTestSuite PRIVATE -EHsc) - set_property(DIRECTORY APPEND PROPERTY STATIC_LIBRARY_OPTIONS - -IGNORE:4006 #warning LNK4006: main already defined in x.cpp.obj; second definition ignored - ) endif() endif() +fm_run_hook(fm-userconfig-external) + find_package(SDL2 QUIET REQUIRED) find_package(Corrade QUIET REQUIRED) find_package(ImGui QUIET REQUIRED) find_package(Magnum QUIET REQUIRED) find_package(MagnumPlugins QUIET REQUIRED) find_package(MagnumIntegration QUIET REQUIRED ImGui) + +fm_run_hook(fm-userconfig-external-post) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 1da8afa5..9780ad4c 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -6,6 +6,11 @@ link_libraries(Magnum::Sdl2Application Magnum::Trade) link_libraries(MagnumIntegration::ImGui) corrade_add_resource(res ../resources.conf) +if(MSVC) + set_property(SOURCE "${res}" APPEND PROPERTY COMPILE_OPTIONS "-W0") +else() + set_property(SOURCE "${res}" APPEND PROPERTY COMPILE_OPTIONS "-w") +endif() add_executable(${self} "${sources}" "${res}") set_property(TARGET ${self} PROPERTY OUTPUT_NAME "${PROJECT_NAME}") install(TARGETS ${self} RUNTIME DESTINATION bin) diff --git a/main/app.hpp b/main/app.hpp index 60b9a607..96400cda 100644 --- a/main/app.hpp +++ b/main/app.hpp @@ -27,7 +27,7 @@ struct app final : private Platform::Application private: struct app_settings; - [[maybe_unused]] static void usage(const Utility::Arguments& args); + [[maybe_unused]] [[noreturn]] static void usage(const Utility::Arguments& args); explicit app(const Arguments& arguments, app_settings opts); using dpi_policy = Platform::Implementation::Sdl2DpiScalingPolicy; diff --git a/main/draw.cpp b/main/draw.cpp index 92fa8b9d..ddeccc23 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -19,7 +19,10 @@ void app::drawEvent() _frame_time = dt; } else - swapBuffers(), timeline.nextFrame(); + { + swapBuffers(); + timeline.nextFrame(); + } { const float dt = std::clamp(timeline.previousFrameDuration(), 1e-3f, 1e-1f); diff --git a/main/imgui-raii.hpp b/main/imgui-raii.hpp index 931b5189..85512b2d 100644 --- a/main/imgui-raii.hpp +++ b/main/imgui-raii.hpp @@ -2,7 +2,7 @@ #include <Corrade/Containers/StringView.h> #include <Magnum/Math/Color.h> -#include <ImGui.h> +#include <imgui.h> namespace floormat::imgui { diff --git a/main/imgui.cpp b/main/imgui.cpp index 13a09a8b..e1790968 100644 --- a/main/imgui.cpp +++ b/main/imgui.cpp @@ -154,7 +154,7 @@ void app::draw_fps() auto c6 = push_style_color(ImGuiCol_Text, {0, 1, 0, 1}); char buf[16]; - const double dt = _frame_time > 1e-6 ? std::round(1/double(_frame_time)*10.)*.1 + 0.05 : 999; + const double dt = _frame_time > 1e-6f ? std::round(1/double(_frame_time)*10.)*.1 + 0.05 : 999; snprintf(buf, sizeof(buf), "%.1f FPS", dt); const ImVec2 size = ImGui::CalcTextSize(buf); @@ -179,7 +179,7 @@ void app::draw_cursor_coord() auto c3 = push_style_var(ImGuiStyleVar_WindowBorderSize, 0); auto c4 = push_style_var(ImGuiStyleVar_WindowMinSize, {1, 1}); auto c5 = push_style_var(ImGuiStyleVar_ScrollbarSize, 0); - auto c6 = push_style_color(ImGuiCol_Text, {.9, .9, .9, 1}); + auto c6 = push_style_color(ImGuiCol_Text, {.9f, .9f, .9f, 1}); char buf[64]; const auto coord = *_cursor_tile; diff --git a/main/loader-impl.cpp b/main/loader-impl.cpp index 0fe5befa..8112b350 100644 --- a/main/loader-impl.cpp +++ b/main/loader-impl.cpp @@ -66,6 +66,7 @@ std::shared_ptr<tile_atlas> loader_impl::tile_atlas(Containers::StringView name, Trade::ImageData2D loader_impl::tile_texture(Containers::StringView filename_) { static_assert(IMAGE_PATH[sizeof(IMAGE_PATH)-2] == '/'); + ASSERT(filename_.size() < 4096); char* const filename = (char*)alloca(filename_.size() + sizeof(IMAGE_PATH)); std::memcpy(filename, IMAGE_PATH, sizeof(IMAGE_PATH)-1); diff --git a/shaders/tile-shader.cpp b/shaders/tile-shader.cpp index 12bc0a6d..87238f5a 100644 --- a/shaders/tile-shader.cpp +++ b/shaders/tile-shader.cpp @@ -30,6 +30,8 @@ tile_shader::tile_shader() set_tint({1, 1, 1, 1}); } +tile_shader::~tile_shader() = default; + tile_shader& tile_shader::set_scale(const Vector2& scale) { if (scale != _scale) diff --git a/shaders/tile-shader.hpp b/shaders/tile-shader.hpp index 93f78a1c..6cb81c7e 100644 --- a/shaders/tile-shader.hpp +++ b/shaders/tile-shader.hpp @@ -12,6 +12,7 @@ struct tile_shader : GL::AbstractShaderProgram typedef GL::Attribute<1, Vector2> TextureCoordinates; explicit tile_shader(); + ~tile_shader() override; Vector2 scale() const { return _scale; } tile_shader& set_scale(const Vector2& scale); diff --git a/shaders/tile-shader.vert b/shaders/tile-shader.vert index 8b3f2dba..2b622317 100644 --- a/shaders/tile-shader.vert +++ b/shaders/tile-shader.vert @@ -5,11 +5,12 @@ layout (location = 1) uniform vec2 offset; layout (location = 0) in vec4 position; layout (location = 1) in vec2 texcoords; +layout (location = 2) in float foo = 1; noperspective out vec2 frag_texcoords; void main() { float cx = 1/scale.x, cy = 1/scale.y; float x = -position.y, y = -position.x, z = position.z; - gl_Position = vec4((x-y+offset.x)*cx, (x+y+z*2)*cy*.59-offset.y*cy, 0, 1); + gl_Position = vec4((x-y+offset.x)*cx, (x+y+z*2)*cy*.59-offset.y*cy*foo, 0, 1); frag_texcoords = texcoords; } diff --git a/src/random.cpp b/src/random.cpp index 82c47ff9..4da534a3 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -6,6 +6,8 @@ namespace floormat { static thread_local auto g = std::independent_bits_engine<decltype(std::ranlux48{}), 32, std::uint32_t>{std::ranlux48{}}; +random_engine::~random_engine() = default; + struct random_engine_impl final : random_engine { std::size_t operator()() override; float operator()(float min, float max) override; @@ -21,7 +23,6 @@ std::size_t random_engine_impl::operator()() std::size_t x; std::uint32_t a[N]; } ret; -#pragma omp unroll full for (std::size_t i = 0; i < N; i++) ret.a[i] = g(); return ret.x; diff --git a/src/random.hpp b/src/random.hpp index 3616aabf..84d8ca2a 100644 --- a/src/random.hpp +++ b/src/random.hpp @@ -7,7 +7,7 @@ namespace floormat { struct random_engine { - virtual inline ~random_engine(); + virtual ~random_engine(); virtual std::common_type_t<std::size_t, std::uintptr_t, std::ptrdiff_t> operator()() = 0; template<std::integral T> @@ -25,8 +25,6 @@ struct random_engine virtual float operator()(float min, float max) = 0; }; -random_engine::~random_engine() = default; - [[maybe_unused]] extern random_engine& random; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) } // namespace floormat |