diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f7b1352..b7276d1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,9 +2,9 @@ name: Release on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] env: BUILD_TYPE: Release @@ -13,7 +13,7 @@ jobs: build: strategy: matrix: - os: [ macos-14, ubuntu-latest, windows-latest ] + os: [macos-14, ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v4 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWARNINGS_AS_ERRORS=FALSE - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} diff --git a/.gitignore b/.gitignore index 3185ed1..1faa45a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Application build output build/ distribution/ +.cache/ # Created by CPack when executing tests. Testing/ @@ -14,3 +15,4 @@ profile.json # User defined CMake preset file. CMakeUserPresets.json +*.sublime-workspace diff --git a/CMakePresets.json b/CMakePresets.json index 94e2693..86090e6 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -16,7 +16,8 @@ "generator": "Ninja", "binaryDir": "build/release", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "Release", + "WARNINGS_AS_ERRORS": "FALSE" } }, { @@ -41,7 +42,8 @@ "binaryDir": "build/xcode-release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "CMAKE_OSX_ARCHITECTURES": "x86_64;arm64" + "CMAKE_OSX_ARCHITECTURES": "x86_64;arm64", + "WARNINGS_AS_ERRORS": "FALSE" }, "condition": { "type": "equals", @@ -62,9 +64,7 @@ "displayName": "Build Release", "configurePreset": "release", "configuration": "Release", - "targets": [ - "App" - ] + "targets": ["App"] }, { "name": "xcode-debug", @@ -82,9 +82,7 @@ "displayName": "Build Release (Xcode)", "configurePreset": "xcode-release", "configuration": "Release", - "targets": [ - "App" - ], + "targets": ["App"], "condition": { "type": "equals", "lhs": "${hostSystemName}", @@ -97,17 +95,13 @@ "name": "release", "displayName": "Distribute Release", "configurePreset": "release", - "configurations": [ - "Release" - ] + "configurations": ["Release"] }, { "name": "xcode-release", "displayName": "Distribute Release (Xcode)", "configurePreset": "xcode-release", - "configurations": [ - "Release" - ], + "configurations": ["Release"], "condition": { "type": "equals", "lhs": "${hostSystemName}", diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 4c7aa5c..cb314f6 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -2,7 +2,6 @@ function(set_project_warnings project_name) option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE) - message(STATUS "Treat compiler warnings as errors") set(MSVC_WARNINGS /W4 # Baseline reasonable warnings @@ -59,6 +58,7 @@ function(set_project_warnings project_name) ) if (WARNINGS_AS_ERRORS) + message(STATUS "Treat compiler warnings as errors") set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) endif () diff --git a/docs/Profiling.md b/docs/Profiling.md index f395182..b1942a5 100644 --- a/docs/Profiling.md +++ b/docs/Profiling.md @@ -68,8 +68,7 @@ int Application::run() { ## Show results -The resulting JSON file uses -the [Trace Event Format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview). Any +The resulting JSON file (`profile.json`) uses the [Trace Event Format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview). Any tool that can read this format can visualize the profiler data. For example the web tool [Perfetto](https://ui.perfetto.dev/) or Chromes built in [chrome://tracing](chrome://tracing). Just drag&drop the generated profiler JSON file onto the tool to load it. @@ -78,6 +77,6 @@ This is roughly how this looks like on Chrome. ![chrome-trace.png](assets/chrome-trace.png) -*** +--- Next up: [Logging](Logging.md) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 684caad..032de6d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -5,7 +5,8 @@ include(${PROJECT_SOURCE_DIR}/cmake/StaticAnalyzers.cmake) add_library(${NAME} STATIC Core/Log.cpp Core/Log.hpp Core/Debug/Instrumentor.hpp Core/Application.cpp Core/Application.hpp Core/Window.cpp Core/Window.hpp - Core/Resources.hpp Core/DPIHandler.hpp) + Core/Resources.hpp Core/Resources.cpp + Core/DPIHandler.hpp) # Define set of OS specific files to include if (CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/src/core/Core/Application.cpp b/src/core/Core/Application.cpp index 73a3cea..af0edd2 100644 --- a/src/core/Core/Application.cpp +++ b/src/core/Core/Application.cpp @@ -66,8 +66,13 @@ ExitStatus App::Application::run() { const float font_size{18.0F * font_scaling_factor}; const std::string font_path{Resources::font_path("Manrope.ttf").generic_string()}; - io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); - io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); + if (Resources::exists(font_path)) { + io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); + io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); + } else { + APP_WARN("Could not find font file under: {}", font_path.c_str()); + } + DPIHandler::set_global_font_scaling(&io); // Setup Platform/Renderer backends diff --git a/src/core/Core/Resources.cpp b/src/core/Core/Resources.cpp new file mode 100644 index 0000000..f07f4d2 --- /dev/null +++ b/src/core/Core/Resources.cpp @@ -0,0 +1,18 @@ +#include "Core/Resources.hpp" + +#include + +#include + +#include "Core/Debug/Instrumentor.hpp" + +namespace App { + +bool Resources::exists(const std::filesystem::path& pathname) { + APP_PROFILE_FUNCTION(); + + struct stat buffer; + return (stat(pathname.generic_string().c_str(), &buffer) == 0); +} + +} // namespace App diff --git a/src/core/Core/Resources.hpp b/src/core/Core/Resources.hpp index 96c49b4..2881317 100644 --- a/src/core/Core/Resources.hpp +++ b/src/core/Core/Resources.hpp @@ -9,6 +9,7 @@ class Resources { public: [[nodiscard]] static std::filesystem::path resource_path(const std::filesystem::path& file_path); [[nodiscard]] static std::filesystem::path font_path(const std::string_view& font_file); + [[nodiscard]] static bool exists(const std::filesystem::path& pathname); }; } // namespace App diff --git a/src/core/Core/Window.cpp b/src/core/Core/Window.cpp index 6965079..f469711 100644 --- a/src/core/Core/Window.cpp +++ b/src/core/Core/Window.cpp @@ -11,8 +11,6 @@ namespace App { Window::Window(const Settings& settings) { APP_PROFILE_FUNCTION(); - const auto window_flags{ - static_cast(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI)}; const WindowSize size{DPIHandler::get_dpi_aware_window_size(settings)}; m_window = SDL_CreateWindow(settings.title.c_str(), @@ -20,7 +18,7 @@ Window::Window(const Settings& settings) { SDL_WINDOWPOS_CENTERED, size.width, size.height, - window_flags); + SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); Uint32 renderer_flags{SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED}; m_renderer = SDL_CreateRenderer(m_window, -1, renderer_flags); diff --git a/template.sublime-project b/template.sublime-project new file mode 100644 index 0000000..a97a8da --- /dev/null +++ b/template.sublime-project @@ -0,0 +1,124 @@ +{ + "folders": [ + { + "path": ".", + } + ], + "settings": { + "cmake": { + "build_folder": "$folder/build", + "command_line_overrides": { + "CMAKE_POLICY_VERSION_MINIMUM": "3.5", + }, + }, + "LSP": { + "clangd": { + "initializationOptions": { + "clangd.clang-tidy": true, + }, + }, + }, + }, + "build_systems": + [ + { + "config": "Debug", + "env": + { + }, + "generator": "Unix Makefiles", + "name": "Debug", + "target": "cmake_build", + "variants": + [ + { + "build_target": "App", + "name": "App" + }, + { + "artifact": "src/app/App.app/Contents/MacOS/App", + "build_target": "App", + "name": "Run: App", + "target": "cmake_run" + }, + { + "artifact": "src/app/App.app/Contents/MacOS/App", + "build_target": "App", + "debug": true, + "name": "Run under LLDB: App", + "target": "cmake_run" + }, + { + "build_target": "Core", + "name": "Core" + }, + { + "build_target": "ResourcesTest", + "name": "ResourcesTest" + }, + { + "artifact": "src/core/Tests/ResourcesTest", + "build_target": "ResourcesTest", + "name": "Run: ResourcesTest", + "target": "cmake_run" + }, + { + "artifact": "src/core/Tests/ResourcesTest", + "build_target": "ResourcesTest", + "debug": true, + "name": "Run under LLDB: ResourcesTest", + "target": "cmake_run" + }, + { + "build_target": "SDL2", + "name": "SDL2" + }, + { + "build_target": "SDL2-static", + "name": "SDL2-static" + }, + { + "build_target": "SDL2_test", + "name": "SDL2_test" + }, + { + "build_target": "Settings", + "name": "Settings" + }, + { + "build_target": "TestRunner", + "name": "TestRunner" + }, + { + "build_target": "doctest_with_main", + "name": "doctest_with_main" + }, + { + "build_target": "fmt", + "name": "fmt" + }, + { + "build_target": "imgui", + "name": "imgui" + }, + { + "build_target": "sdl_headers_copy", + "name": "sdl_headers_copy" + }, + { + "build_target": "spdlog", + "name": "spdlog" + }, + { + "build_target": "uninstall", + "name": "uninstall" + }, + { + "name": "ctest", + "target": "ctest_run" + } + ], + "working_dir": "$folder/build" + } + ], +} diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index e2515c4..1e7719f 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -5,31 +5,31 @@ include(FetchContent) FetchContent_Declare( doctest GIT_REPOSITORY "https://github.com/onqtam/doctest.git" - GIT_TAG v2.4.11 + GIT_TAG v2.4.12 ) FetchContent_Declare( fmt GIT_REPOSITORY "https://github.com/fmtlib/fmt.git" - GIT_TAG 11.0.2 + GIT_TAG 11.2.0 ) FetchContent_Declare( imgui GIT_REPOSITORY "https://github.com/ocornut/imgui.git" - GIT_TAG 368123ab06b2b573d585e52f84cd782c5c006697 # Branch: docking, date: 07.11.2024, 07:58 GMT+1 + GIT_TAG b4311141947de17763d88f680c84c14379538388 # Branch: docking, date: 08.08.2024, 06:37 GMT+3 ) FetchContent_Declare( SDL2 GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" - GIT_TAG release-2.30.9 + GIT_TAG release-2.32.8 ) FetchContent_Declare( spdlog GIT_REPOSITORY "https://github.com/gabime/spdlog.git" - GIT_TAG v1.15.0 + GIT_TAG v1.15.3 ) # Settings