diff --git a/.vscode_MacOS/c_cpp_properties.json b/.vscode_MacOS/c_cpp_properties.json index e5780753..11fa8037 100644 --- a/.vscode_MacOS/c_cpp_properties.json +++ b/.vscode_MacOS/c_cpp_properties.json @@ -35,7 +35,7 @@ "vendor/tracy/include" ], "defines": [ - "MACOSX" + "MACOSX", "PROFILING" ], "cStandard": "c17", "cppStandard": "c++20" diff --git a/application/lucre/gameState.cpp b/application/lucre/gameState.cpp index 522c0268..5a969a63 100644 --- a/application/lucre/gameState.cpp +++ b/application/lucre/gameState.cpp @@ -38,8 +38,8 @@ namespace LucreApp { GameState::GameState() - : m_State{State::SPLASH}, m_NextState{State::SPLASH}, m_LastState{State::SPLASH}, m_InputIdle{false}, - m_UserInputEnabled{false}, m_DeleteScene{State::NULL_STATE}, m_LoadingState{State::NULL_STATE} + : m_State{State::SPLASH}, m_NextState{State::SPLASH}, m_LastState{State::SPLASH}, m_UserInputEnabled{false}, + m_DeleteScene{State::NULL_STATE}, m_LoadingState{State::NULL_STATE} { memset(m_StateLoaded, false, static_cast(State::MAX_STATES) * sizeof(bool)); } diff --git a/application/lucre/gameState.h b/application/lucre/gameState.h index 68ae6625..fb50a254 100644 --- a/application/lucre/gameState.h +++ b/application/lucre/gameState.h @@ -86,7 +86,6 @@ namespace LucreApp State m_State, m_NextState, m_LastState, m_DeleteScene, m_LoadingState; std::shared_ptr m_Scenes[static_cast(State::MAX_STATES)]; bool m_UserInputEnabled; - bool m_InputIdle; bool m_StateLoaded[static_cast(State::MAX_STATES)]; int m_DeleteSceneCounter; }; diff --git a/engine/auxiliary/instrumentation.cpp b/engine/auxiliary/instrumentation.cpp index 17209728..8961387f 100644 --- a/engine/auxiliary/instrumentation.cpp +++ b/engine/auxiliary/instrumentation.cpp @@ -33,7 +33,10 @@ namespace GfxRenderEngine { namespace Instrumentation { - Timer::Timer(const char* name) : m_Name(name) { m_Start = std::chrono::high_resolution_clock::now(); } + Timer::Timer(Profiler& profiler, const char* name) : m_Profiler{profiler}, m_Name(name) + { + m_Start = std::chrono::high_resolution_clock::now(); + } Timer::~Timer() { @@ -42,20 +45,10 @@ namespace GfxRenderEngine auto start = std::chrono::duration{m_Start.time_since_epoch()}; auto elapsedMicroSeconds = std::chrono::time_point_cast(m_End).time_since_epoch() - std::chrono::time_point_cast(m_Start).time_since_epoch(); - SessionManager::Get().CreateEntry({m_Name, start, elapsedMicroSeconds, std::this_thread::get_id()}); + m_Profiler.CreateEntry({m_Name, start, elapsedMicroSeconds, std::this_thread::get_id()}); } - - SessionManager::SessionManager() : m_CurrentSession(nullptr) {} - - SessionManager::~SessionManager() { End(); } - - void SessionManager::Begin(const std::string& name, const std::string& filename) + Profiler::Profiler(const std::string& name, const std::string& filename) { - std::lock_guard lock(m_Mutex); - if (m_CurrentSession) - { - EndInternal(); - } m_StartTime = std::chrono::steady_clock::now(); // this function must be called @@ -85,18 +78,23 @@ namespace GfxRenderEngine } else { - // plain cout because logger might not yet be available - std::cout << "SessionManager could not open output file '" << filepath << "'" << std::endl; + LOG_CORE_CRITICAL("Profiler could not open output file '{0}'", filepath); } } - void SessionManager::End() + Profiler::~Profiler() { std::lock_guard lock(m_Mutex); - EndInternal(); + if (m_CurrentSession) + { + EndJsonFile(); + m_OutputStream.close(); + delete m_CurrentSession; + m_CurrentSession = nullptr; + } } - void SessionManager::CreateEntry(const Result& result) + void Profiler::CreateEntry(const Result& result) { if ((std::chrono::steady_clock::now() - m_StartTime) > 5min) { @@ -111,10 +109,9 @@ namespace GfxRenderEngine outputFile << "\"name\":\"" << result.m_Name << "\","; outputFile << "\"ph\":\"X\","; outputFile << "\"pid\":0,"; - outputFile << "\"tid\":" << result.m_ThreadID << ","; + outputFile << "\"tid\":" << std::hash()(result.m_ThreadID) << ","; outputFile << "\"ts\":" << result.m_Start.count(); outputFile << "}"; - std::lock_guard lock(m_Mutex); if (m_CurrentSession) { @@ -123,28 +120,18 @@ namespace GfxRenderEngine } } - void SessionManager::StartJsonFile() + void Profiler::StartJsonFile() { m_OutputStream << "{\"otherData\": {},\"traceEvents\":[{}"; m_OutputStream.flush(); } - void SessionManager::EndJsonFile() + void Profiler::EndJsonFile() { m_OutputStream << "]}"; m_OutputStream.flush(); } - void SessionManager::EndInternal() - { - if (m_CurrentSession) - { - EndJsonFile(); - m_OutputStream.close(); - delete m_CurrentSession; - m_CurrentSession = nullptr; - } - } } // namespace Instrumentation } // namespace GfxRenderEngine #endif diff --git a/engine/auxiliary/instrumentation.h b/engine/auxiliary/instrumentation.h index bd51264f..2df06a58 100644 --- a/engine/auxiliary/instrumentation.h +++ b/engine/auxiliary/instrumentation.h @@ -44,10 +44,7 @@ namespace GfxRenderEngine #define FUNC_SIGNATURE __PRETTY_FUNCTION__ #endif -#define PROFILE_BEGIN_SESSION(name, filepath) ::GfxRenderEngine::Instrumentation::SessionManager::Get().Begin(name, filepath) -#define PROFILE_END_SESSION() ::GfxRenderEngine::Instrumentation::SessionManager::Get().End() - -#define PROFILE_SCOPE_LINE2(name, line) ::GfxRenderEngine::Instrumentation::Timer timer##line(name) +#define PROFILE_SCOPE_LINE2(name, line) Instrumentation::Timer timer##line(*g_Profiler, name) #define PROFILE_SCOPE_LINE(name, line) PROFILE_SCOPE_LINE2(name, line) #define PROFILE_SCOPE(name) PROFILE_SCOPE_LINE(name, __LINE__) #define PROFILE_FUNCTION() PROFILE_SCOPE(FUNC_SIGNATURE) @@ -68,30 +65,19 @@ namespace GfxRenderEngine std::string m_Name; }; - class SessionManager + class Profiler { public: - SessionManager(const SessionManager&) = delete; - SessionManager(SessionManager&&) = delete; - - void Begin(const std::string& name, const std::string& filename = "results.json"); - void End(); + Profiler(const std::string& name, const std::string& filename = "results.json"); + ~Profiler(); + Profiler(const Profiler&) = delete; + Profiler(Profiler&&) = delete; void CreateEntry(const Result& result); - static SessionManager& Get() - { - static SessionManager instance; - return instance; - } - private: - SessionManager(); - ~SessionManager(); - void StartJsonFile(); void EndJsonFile(); - void EndInternal(); private: std::mutex m_Mutex; @@ -104,10 +90,11 @@ namespace GfxRenderEngine { public: - Timer(const char* name); + Timer(Profiler& Profiler, const char* name); ~Timer(); private: + Profiler& m_Profiler; const char* m_Name; std::chrono::time_point m_Start, m_End; }; diff --git a/engine/auxiliary/threadPool.h b/engine/auxiliary/threadPool.h index ac236164..842c5bb8 100644 --- a/engine/auxiliary/threadPool.h +++ b/engine/auxiliary/threadPool.h @@ -21,6 +21,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #pragma once +#include #include #include "BS_thread_pool/BS_thread_pool.hpp" diff --git a/engine/core.cpp b/engine/core.cpp index 83e8b31f..f14b42b7 100644 --- a/engine/core.cpp +++ b/engine/core.cpp @@ -71,11 +71,6 @@ namespace GfxRenderEngine bool Engine::Start() { - // init logger - if (!Log::Init()) - { - std::cout << "Could not initialize logger" << std::endl; - } InitSettings(); // signal handling diff --git a/engine/engine.cpp b/engine/engine.cpp index 8f83a482..16703c8d 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -25,12 +25,18 @@ #include "core.h" #include "engine.h" -#include "auxiliary/instrumentation.h" #include "application.h" +using Profiler = GfxRenderEngine::Instrumentation::Profiler; +// global logger for the engine and application +std::unique_ptr g_Logger; +// non-owning pointer to the global profiler +std::unique_ptr g_Profiler; + int engine(int argc, char* argv[]) { - PROFILE_BEGIN_SESSION("RunTime", "profiling (open with chrome tracing).json"); + g_Logger = std::make_unique(); + g_Profiler = std::make_unique("RunTime", "profiling (open with chrome tracing).json"); std::unique_ptr engine; std::unique_ptr application; @@ -53,7 +59,6 @@ int engine(int argc, char* argv[]) if (!engine->IsRunning()) { engine->Quit(); - PROFILE_END_SESSION(); exit(0); } std::this_thread::sleep_for(16ms); @@ -103,10 +108,11 @@ int engine(int argc, char* argv[]) engine->Shutdown(); application.reset(); engine->Quit(); + g_Profiler.reset(); + g_Logger.reset(); - PROFILE_END_SESSION(); #ifdef DEBUG - LOG_CORE_INFO("leaving main"); + std::cout << "leaving main" << std::endl; #endif return 0; } diff --git a/engine/engine.h b/engine/engine.h index 9e80b0cb..9c2bc1e4 100644 --- a/engine/engine.h +++ b/engine/engine.h @@ -26,6 +26,10 @@ #include #include "log/log.h" +#include "auxiliary/instrumentation.h" +#ifdef TRACY_ENABLE +#include "tracy/Tracy.hpp" +#endif #define GLM_FORCE_DEPTH_ZERO_TO_ONE #include "glm.hpp" @@ -36,10 +40,6 @@ #define GLM_ENABLE_EXPERIMENTAL #include "gtx/hash.hpp" -#ifdef TRACY_ENABLE -#include "tracy/Tracy.hpp" -#endif - typedef uint8_t uchar; typedef uint16_t uint16; typedef uint32_t uint; @@ -66,11 +66,28 @@ int engine(int argc, char* argv[]); #define BIT(x) (1 << (x)) +// profiling +extern std::unique_ptr g_Profiler; + // logging #ifndef DISTRIBUTION_BUILD #define LOGGING_AND_ASSERTS #endif #ifdef LOGGING_AND_ASSERTS + +extern std::unique_ptr g_Logger; +#define LOG_CORE_TRACE(...) g_Logger->GetLogger().trace(__VA_ARGS__) +#define LOG_CORE_INFO(...) g_Logger->GetLogger().info(__VA_ARGS__) +#define LOG_CORE_WARN(...) g_Logger->GetLogger().warn(__VA_ARGS__) +#define LOG_CORE_ERROR(...) g_Logger->GetLogger().error(__VA_ARGS__) +#define LOG_CORE_CRITICAL(...) g_Logger->GetLogger().critical(__VA_ARGS__) + +#define LOG_APP_TRACE(...) g_Logger->GetAppLogger().trace(__VA_ARGS__) +#define LOG_APP_INFO(...) g_Logger->GetAppLogger().info(__VA_ARGS__) +#define LOG_APP_WARN(...) g_Logger->GetAppLogger().warn(__VA_ARGS__) +#define LOG_APP_ERROR(...) g_Logger->GetAppLogger().error(__VA_ARGS__) +#define LOG_APP_CRITICAL(...) g_Logger->GetAppLogger().critical(__VA_ARGS__) + #define CORE_ASSERT(x, str) \ if (!(x)) \ LOG_CORE_CRITICAL("ASSERT on line number {0} in file {1}: {2} (error)", __LINE__, __FILE__, str) @@ -84,17 +101,6 @@ int engine(int argc, char* argv[]); if (!(x)) \ LOG_APP_CRITICAL("ASSERT on line number {0} in file {1}: {2} (error)", __LINE__, __FILE__, str) -#define LOG_CORE_TRACE(...) GfxRenderEngine::Log::GetLogger()->trace(__VA_ARGS__) -#define LOG_CORE_INFO(...) GfxRenderEngine::Log::GetLogger()->info(__VA_ARGS__) -#define LOG_CORE_WARN(...) GfxRenderEngine::Log::GetLogger()->warn(__VA_ARGS__) -#define LOG_CORE_ERROR(...) GfxRenderEngine::Log::GetLogger()->error(__VA_ARGS__) -#define LOG_CORE_CRITICAL(...) GfxRenderEngine::Log::GetLogger()->critical(__VA_ARGS__) - -#define LOG_APP_TRACE(...) GfxRenderEngine::Log::GetAppLogger()->trace(__VA_ARGS__) -#define LOG_APP_INFO(...) GfxRenderEngine::Log::GetAppLogger()->info(__VA_ARGS__) -#define LOG_APP_WARN(...) GfxRenderEngine::Log::GetAppLogger()->warn(__VA_ARGS__) -#define LOG_APP_ERROR(...) GfxRenderEngine::Log::GetAppLogger()->error(__VA_ARGS__) -#define LOG_APP_CRITICAL(...) GfxRenderEngine::Log::GetAppLogger()->critical(__VA_ARGS__) #else #define CORE_ASSERT(x, str) \ { \ diff --git a/engine/gui/Common/UI/viewGroup.cpp b/engine/gui/Common/UI/viewGroup.cpp index 6d7bf390..82ac7326 100644 --- a/engine/gui/Common/UI/viewGroup.cpp +++ b/engine/gui/Common/UI/viewGroup.cpp @@ -498,9 +498,7 @@ namespace GfxRenderEngine return; } - float sum = 0.0f; float maxOther = 0.0f; - float totalWeight = 0.0f; float weightSum = 0.0f; float weightZeroSum = 0.0f; @@ -520,7 +518,6 @@ namespace GfxRenderEngine if (linLayoutParams) { - totalWeight += linLayoutParams->weight; if (linLayoutParams->HasMargins()) { margins = linLayoutParams->margins; @@ -566,7 +563,6 @@ namespace GfxRenderEngine maxOther = std::max(maxOther, view->GetMeasuredWidth() + margins.horiz()); } - sum += amount; if (linLayoutParams) { if (linLayoutParams->weight == 0.0f) @@ -940,7 +936,6 @@ namespace GfxRenderEngine } const float friction = 0.92f; - const float stop_threshold = 0.1f; void ScrollView::Draw(SCREEN_UIContext& dc) { @@ -1345,7 +1340,7 @@ namespace GfxRenderEngine } TabHolder::TabHolder(Orientation orientation, float stripSize, LayoutParams* layoutParams, float leftMargin) - : LinearLayout(Opposite(orientation), layoutParams), stripSize_(stripSize) + : LinearLayout(Opposite(orientation), layoutParams) { if (orientation == ORIENT_HORIZONTAL) { diff --git a/engine/gui/Common/UI/viewGroup.h b/engine/gui/Common/UI/viewGroup.h index fe851baa..e705aab2 100644 --- a/engine/gui/Common/UI/viewGroup.h +++ b/engine/gui/Common/UI/viewGroup.h @@ -298,9 +298,7 @@ namespace GfxRenderEngine Orientation orientation_; float scrollPos_ = 0.0f; - float scrollStart_ = 0.0f; float scrollTarget_ = 0.0f; - int scrollTouchId_ = -1; bool scrollToTarget_ = false; float inertia_ = 0.0f; float pull_ = 0.0f; @@ -384,7 +382,6 @@ namespace GfxRenderEngine ScrollView* tabScroll_ = nullptr; AnchorLayout* contents_ = nullptr; - float stripSize_; int currentTab_ = 0; std::vector tabs_; std::vector tabTweens_; diff --git a/engine/log/log.cpp b/engine/log/log.cpp index 87aeba2e..7321cda4 100644 --- a/engine/log/log.cpp +++ b/engine/log/log.cpp @@ -35,12 +35,8 @@ namespace GfxRenderEngine { - std::shared_ptr Log::m_Logger; - std::shared_ptr Log::m_AppLogger; - - bool Log::Init() + Log::Log() { - bool ok = false; std::vector logSink; logSink.emplace_back(std::make_shared()); @@ -48,7 +44,6 @@ namespace GfxRenderEngine m_Logger = std::make_shared("Engine", begin(logSink), end(logSink)); if (m_Logger) { - ok = true; spdlog::register_logger(m_Logger); m_Logger->set_level(spdlog::level::trace); m_Logger->flush_on(spdlog::level::trace); @@ -57,12 +52,9 @@ namespace GfxRenderEngine m_AppLogger = std::make_shared("Application", begin(logSink), end(logSink)); if (m_AppLogger) { - ok = true; spdlog::register_logger(m_AppLogger); m_Logger->set_level(spdlog::level::trace); m_Logger->flush_on(spdlog::level::trace); } - - return ok; } } // namespace GfxRenderEngine diff --git a/engine/log/log.h b/engine/log/log.h index 37229096..28e60c0d 100644 --- a/engine/log/log.h +++ b/engine/log/log.h @@ -37,14 +37,14 @@ namespace GfxRenderEngine class Log { public: - static bool Init(); + Log(); - inline static std::shared_ptr& GetLogger() { return m_Logger; } + spdlog::logger& GetLogger() { return *m_Logger; } - inline static std::shared_ptr& GetAppLogger() { return m_AppLogger; } + spdlog::logger& GetAppLogger() { return *m_AppLogger; } private: - static std::shared_ptr m_Logger; - static std::shared_ptr m_AppLogger; + std::shared_ptr m_Logger; + std::shared_ptr m_AppLogger; }; } // namespace GfxRenderEngine