From db0183776a8f910b32806b3001018729384b57a2 Mon Sep 17 00:00:00 2001 From: Mitch Andrews Date: Sun, 1 Sep 2024 23:18:41 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=82=20Debug=20Tools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/Dementia/Source/Dementia.h | 3 +- Modules/Dementia/Source/Path.cpp | 3 +- Source/Engine/Engine.cpp | 8 +++ Source/Engine/Engine.h | 7 +++ Source/Tools/DebugTools.cpp | 81 ++++++++++++++++++++++++++++++ Source/Tools/DebugTools.h | 17 +++++++ Source/Window/SDLWindow.cpp | 3 -- Tools/BaseProject.sharpmake.cs | 2 + 8 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 Source/Tools/DebugTools.cpp create mode 100644 Source/Tools/DebugTools.h diff --git a/Modules/Dementia/Source/Dementia.h b/Modules/Dementia/Source/Dementia.h index be422d63..c6e0b61b 100644 --- a/Modules/Dementia/Source/Dementia.h +++ b/Modules/Dementia/Source/Dementia.h @@ -161,4 +161,5 @@ Class& operator=(Class&&) = delete; #define ME_PROFILING USE_IF( USING( ME_DEBUG ) || USING( ME_RELEASE ) ) // I'm currently using some ImGui stuff in debug for profiling, TOOLS needs it even that it's currently bundled with the editor. #define ME_IMGUI USE_IF( USING( ME_EDITOR ) || USING( ME_TOOLS ) || USING( ME_PROFILING ) ) -#define ME_BASIC_PROFILER USE_IF( USING( ME_IMGUI ) && USING( ME_PROFILING ) ) \ No newline at end of file +#define ME_BASIC_PROFILER USE_IF( USING( ME_IMGUI ) && USING( ME_PROFILING ) ) +#define ME_GAME_TOOLS USE_IF( USING( ME_TOOLS ) && !USING( ME_EDITOR ) ) \ No newline at end of file diff --git a/Modules/Dementia/Source/Path.cpp b/Modules/Dementia/Source/Path.cpp index e9cb5b2f..f9f016fd 100644 --- a/Modules/Dementia/Source/Path.cpp +++ b/Modules/Dementia/Source/Path.cpp @@ -129,6 +129,7 @@ Path::Path( const std::string& InFile, bool Raw /*= false*/ ) #endif LocalPos = static_cast( FullPath.rfind( LocalPath ) ); DirectoryPos = static_cast( FullPath.find_last_of( "/" ) + 1 ); + DirectoryPos = (int8_t)( FullPath.size() - DirectoryPos ); #if USING( ME_PLATFORM_UWP ) //std::replace(LocalPath.begin(), LocalPath.end(), '/', '\\'); @@ -149,7 +150,7 @@ const char* Path::GetExtension() const std::string_view Path::GetDirectory() const { - return std::string_view( FullPath.c_str(), DirectoryPos ); + return std::string_view( FullPath.c_str(), FullPath.size() - DirectoryPos ); } std::string Path::GetDirectoryString() const diff --git a/Source/Engine/Engine.cpp b/Source/Engine/Engine.cpp index c921b798..95287705 100644 --- a/Source/Engine/Engine.cpp +++ b/Source/Engine/Engine.cpp @@ -174,6 +174,10 @@ void Engine::Init( Game* game ) } } ); +#if USING( ME_GAME_TOOLS ) + m_debugTools.Init(); +#endif + InitGame(); ResizeFunc( engineConfig.WindowSize ); @@ -284,6 +288,10 @@ void Engine::Run() GetEditorInput().Update(); #endif +#if USING( ME_GAME_TOOLS ) + m_debugTools.Render(); +#endif + // Update Loaded Cores { // TODO: This is wrong?? There's more than just physics in loaded cores... diff --git a/Source/Engine/Engine.h b/Source/Engine/Engine.h index dca64175..f243b56b 100644 --- a/Source/Engine/Engine.h +++ b/Source/Engine/Engine.h @@ -16,6 +16,10 @@ #include #include "Core/ISystem.h" +#if USING( ME_GAME_TOOLS ) +#include "Tools/DebugTools.h" +#endif + class Game; class IWindow; class BGFXRenderer; @@ -100,6 +104,9 @@ class Engine public: Input& GetEditorInput(); #endif +#if USING( ME_GAME_TOOLS ) + DebugTools m_debugTools; +#endif }; Engine& GetEngine(); diff --git a/Source/Tools/DebugTools.cpp b/Source/Tools/DebugTools.cpp new file mode 100644 index 00000000..925825e5 --- /dev/null +++ b/Source/Tools/DebugTools.cpp @@ -0,0 +1,81 @@ +#include "PCH.h" +#include "DebugTools.h" + +#if USING( ME_GAME_TOOLS ) + +#include "imgui.h" +#include "Window\SDLWindow.h" +#include "Window\PlatformWindowHooks.h" +#include "Engine\Engine.h" +#include "Renderer.h" + +static SDL_Cursor* g_imgui_to_sdl_cursor[ImGuiMouseCursor_COUNT]; + +DebugTools::DebugTools() +{ + +} + + +DebugTools::~DebugTools() +{ + +} + +void DebugTools::Init() +{ + auto registry = GetWidgetRegistry(); + + for( auto it : registry ) + { + auto customWidget = it.second.CreateFunc(); + CustomRegisteredWidgets.push_back( customWidget ); + customWidget->Init(); + } + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; + io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; + + g_imgui_to_sdl_cursor[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor( SDL_SYSTEM_CURSOR_ARROW ); + g_imgui_to_sdl_cursor[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor( SDL_SYSTEM_CURSOR_IBEAM ); + g_imgui_to_sdl_cursor[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor( SDL_SYSTEM_CURSOR_HAND ); + g_imgui_to_sdl_cursor[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor( SDL_SYSTEM_CURSOR_SIZENS ); + g_imgui_to_sdl_cursor[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor( SDL_SYSTEM_CURSOR_SIZEWE ); + g_imgui_to_sdl_cursor[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor( SDL_SYSTEM_CURSOR_SIZENESW ); + g_imgui_to_sdl_cursor[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor( SDL_SYSTEM_CURSOR_SIZENWSE ); + + ImGui::InitHooks( (SDLWindow*)GetEngine().GetWindow(), GetEngine().GetRenderer().GetImGuiRenderer() ); +} + +void DebugTools::Render() +{ + ImGui::Begin( "Debug Tools" ); + + if( ImGui::BeginMenu( "View" ) ) + { + { + for( auto& i : CustomRegisteredWidgets ) + { + if( ImGui::MenuItem( i->Name.c_str(), i->Hotkey.c_str(), &i->IsOpen ) ) + { + } + } + } + ImGui::EndMenu(); + } + ImGui::End(); + // Custom User Widgets + { + OPTICK_CATEGORY( "Custom User Widgets", Optick::Category::UI ); + for( auto customWidget : CustomRegisteredWidgets ) + { + if( customWidget->IsOpen ) + { + customWidget->Render(); + } + } + } +} + +#endif \ No newline at end of file diff --git a/Source/Tools/DebugTools.h b/Source/Tools/DebugTools.h new file mode 100644 index 00000000..0831cf6a --- /dev/null +++ b/Source/Tools/DebugTools.h @@ -0,0 +1,17 @@ +#pragma once + +#if USING( ME_GAME_TOOLS ) +#include "Editor\WidgetRegistry.h" + +class DebugTools +{ +public: + DebugTools(); + ~DebugTools(); + + void Init(); + void Render(); + std::vector> CustomRegisteredWidgets; +}; + +#endif \ No newline at end of file diff --git a/Source/Window/SDLWindow.cpp b/Source/Window/SDLWindow.cpp index b1774a55..fab37dff 100644 --- a/Source/Window/SDLWindow.cpp +++ b/Source/Window/SDLWindow.cpp @@ -921,9 +921,6 @@ void SDLWindow::HandleWindowEvent( const SDL_WindowEvent& event ) break; case SDL_WINDOWEVENT_SIZE_CHANGED: ResizeCB( GetSize() ); - SDL_Log( "Window %d size changed to %dx%d", - event.windowID, event.data1, - event.data2 ); break; case SDL_WINDOWEVENT_MINIMIZED: SDL_Log( "Window %d minimized", event.windowID ); diff --git a/Tools/BaseProject.sharpmake.cs b/Tools/BaseProject.sharpmake.cs index 20d3b07d..dfef5efb 100644 --- a/Tools/BaseProject.sharpmake.cs +++ b/Tools/BaseProject.sharpmake.cs @@ -203,6 +203,7 @@ public virtual void ConfigureDebug(Configuration conf, CommonTarget target) conf.Options.Add(Sharpmake.Options.Vc.Compiler.RuntimeLibrary.MultiThreadedDebugDLL); conf.Options.Add(Options.Vc.Compiler.Inline.Disable); conf.Defines.Add("DEFINE_ME_DEBUG"); + conf.Defines.Add("DEFINE_ME_TOOLS"); } [ConfigurePriority(ConfigurePriorities.Optimization)] @@ -214,6 +215,7 @@ public virtual void ConfigureRelease(Configuration conf, CommonTarget target) conf.Options.Add(Options.Vc.General.DebugInformation.ProgramDatabase); conf.Options.Add(Options.Vc.Compiler.Inline.OnlyInline); conf.Defines.Add("DEFINE_ME_RELEASE"); + conf.Defines.Add("DEFINE_ME_TOOLS"); if (conf.Platform == Platform.win64 ) {