From ba2df71c17f204efd3ae9f843c5d8d4f31935a5c Mon Sep 17 00:00:00 2001 From: Martin Helmut Fieber Date: Mon, 1 Apr 2024 20:34:16 +0200 Subject: [PATCH] Update SDL2 header usage --- .clang-tidy | 1 + docs/Dependencies.md | 2 +- src/core/Core/Application.cpp | 17 +++++++++++------ src/core/Core/Application.hpp | 2 +- src/core/Core/DPIHandler.hpp | 2 +- src/core/Core/Window.cpp | 7 +++++-- src/core/Core/Window.hpp | 2 +- src/core/Platform/Linux/DPIHandler.cpp | 3 +-- src/core/Platform/Linux/Resources.cpp | 8 +++++++- src/core/Platform/Mac/DPIHandler.cpp | 3 +-- src/core/Platform/Mac/Resources.cpp | 8 +++++++- src/core/Platform/Windows/DPIHandler.cpp | 3 +-- src/core/Platform/Windows/Resources.cpp | 8 +++++++- 13 files changed, 45 insertions(+), 21 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 74c9bae..da143e9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -49,3 +49,4 @@ CheckOptions: - { key: readability-identifier-length.MinimumVariableNameLength, value: 2 } - { key: readability-identifier-length.MinimumParameterNameLength, value: 2 } - { key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors, value: '1' } + - { key: misc-include-cleaner.IgnoreHeaders, value: "SDL2/SDL\.h" } diff --git a/docs/Dependencies.md b/docs/Dependencies.md index 3018664..1c432bf 100644 --- a/docs/Dependencies.md +++ b/docs/Dependencies.md @@ -74,7 +74,7 @@ add_library(imgui ${imgui_SOURCE_DIR}/imstb_rectpack.h ${imgui_SOURCE_DIR}/imstb_textedit.h ${imgui_SOURCE_DIR}/imstb_truetype.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer.cpp) + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer2.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer2.cpp) # Set include directory based in populated variable `imgui_SOURCE_DIR`. target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) diff --git a/src/core/Core/Application.cpp b/src/core/Core/Application.cpp index 51c579f..02a870f 100644 --- a/src/core/Core/Application.cpp +++ b/src/core/Core/Application.cpp @@ -1,11 +1,6 @@ #include "Application.hpp" -#include -#include -#include -#include -#include -#include +#include #include #include #include @@ -162,10 +157,14 @@ ExitStatus App::Application::run() { } void App::Application::stop() { + APP_PROFILE_FUNCTION(); + m_running = false; } void Application::on_event(const SDL_WindowEvent& event) { + APP_PROFILE_FUNCTION(); + switch (event.event) { case SDL_WINDOWEVENT_CLOSE: return on_close(); @@ -180,14 +179,20 @@ void Application::on_event(const SDL_WindowEvent& event) { } void Application::on_minimize() { + APP_PROFILE_FUNCTION(); + m_minimized = true; } void Application::on_shown() { + APP_PROFILE_FUNCTION(); + m_minimized = false; } void Application::on_close() { + APP_PROFILE_FUNCTION(); + stop(); } diff --git a/src/core/Core/Application.hpp b/src/core/Core/Application.hpp index f7c9f1b..34c1d0b 100644 --- a/src/core/Core/Application.hpp +++ b/src/core/Core/Application.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/src/core/Core/DPIHandler.hpp b/src/core/Core/DPIHandler.hpp index 524cf49..e2513ea 100644 --- a/src/core/Core/DPIHandler.hpp +++ b/src/core/Core/DPIHandler.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include "Core/Window.hpp" diff --git a/src/core/Core/Window.cpp b/src/core/Core/Window.cpp index c5789f5..12a8201 100644 --- a/src/core/Core/Window.cpp +++ b/src/core/Core/Window.cpp @@ -1,7 +1,6 @@ #include "Window.hpp" -#include -#include +#include #include "Core/DPIHandler.hpp" #include "Core/Debug/Instrumentor.hpp" @@ -47,10 +46,14 @@ Window::~Window() { } SDL_Window* Window::get_native_window() const { + APP_PROFILE_FUNCTION(); + return m_window; } SDL_Renderer* Window::get_native_renderer() const { + APP_PROFILE_FUNCTION(); + return m_renderer; } diff --git a/src/core/Core/Window.hpp b/src/core/Core/Window.hpp index cd0a123..5bff306 100644 --- a/src/core/Core/Window.hpp +++ b/src/core/Core/Window.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/core/Platform/Linux/DPIHandler.cpp b/src/core/Platform/Linux/DPIHandler.cpp index f731318..707ba1d 100644 --- a/src/core/Platform/Linux/DPIHandler.cpp +++ b/src/core/Platform/Linux/DPIHandler.cpp @@ -1,7 +1,6 @@ #include "Core/DPIHandler.hpp" -#include -#include +#include #include #include "Core/Debug/Instrumentor.hpp" diff --git a/src/core/Platform/Linux/Resources.cpp b/src/core/Platform/Linux/Resources.cpp index 8d8f944..f274f1f 100644 --- a/src/core/Platform/Linux/Resources.cpp +++ b/src/core/Platform/Linux/Resources.cpp @@ -1,16 +1,20 @@ #include "Core/Resources.hpp" -#include +#include #include #include #include +#include "Core/Debug/Instrumentor.hpp" + namespace App { static const std::string BASE_PATH{SDL_GetBasePath()}; std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) { + APP_PROFILE_FUNCTION(); + std::filesystem::path font_path{BASE_PATH}; font_path /= "../share"; font_path /= "fonts" / file_path; @@ -18,6 +22,8 @@ std::filesystem::path Resources::resource_path(const std::filesystem::path& file } std::filesystem::path Resources::font_path(const std::string_view& font_file) { + APP_PROFILE_FUNCTION(); + return resource_path(font_file); } diff --git a/src/core/Platform/Mac/DPIHandler.cpp b/src/core/Platform/Mac/DPIHandler.cpp index e4cd803..eb86229 100644 --- a/src/core/Platform/Mac/DPIHandler.cpp +++ b/src/core/Platform/Mac/DPIHandler.cpp @@ -1,7 +1,6 @@ #include "Core/DPIHandler.hpp" -#include -#include +#include #include #include diff --git a/src/core/Platform/Mac/Resources.cpp b/src/core/Platform/Mac/Resources.cpp index 6e2f076..cd77d2b 100644 --- a/src/core/Platform/Mac/Resources.cpp +++ b/src/core/Platform/Mac/Resources.cpp @@ -1,22 +1,28 @@ #include "Core/Resources.hpp" -#include +#include #include #include #include +#include "Core/Debug/Instrumentor.hpp" + namespace App { static const std::string BASE_PATH{SDL_GetBasePath()}; std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) { + APP_PROFILE_FUNCTION(); + std::filesystem::path font_path{BASE_PATH}; font_path /= file_path; return font_path; } std::filesystem::path Resources::font_path(const std::string_view& font_file) { + APP_PROFILE_FUNCTION(); + return resource_path(font_file); } diff --git a/src/core/Platform/Windows/DPIHandler.cpp b/src/core/Platform/Windows/DPIHandler.cpp index fd94939..0d7e52d 100644 --- a/src/core/Platform/Windows/DPIHandler.cpp +++ b/src/core/Platform/Windows/DPIHandler.cpp @@ -1,7 +1,6 @@ #include "Core/DPIHandler.hpp" -#include -#include +#include #include #include "Core/Debug/Instrumentor.hpp" diff --git a/src/core/Platform/Windows/Resources.cpp b/src/core/Platform/Windows/Resources.cpp index 0226643..b72f21e 100644 --- a/src/core/Platform/Windows/Resources.cpp +++ b/src/core/Platform/Windows/Resources.cpp @@ -1,22 +1,28 @@ #include "Core/Resources.hpp" -#include +#include #include #include #include +#include "Core/Debug/Instrumentor.hpp" + namespace App { static const std::string BASE_PATH{SDL_GetBasePath()}; std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) { + APP_PROFILE_FUNCTION(); + std::filesystem::path font_path{BASE_PATH}; font_path /= "../share" / file_path; return font_path; } std::filesystem::path Resources::font_path(const std::string_view& font_file) { + APP_PROFILE_FUNCTION(); + return resource_path("fonts") / font_file; }