Skip to content

Commit

Permalink
🏂 Debug Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
wobbier committed Sep 2, 2024
1 parent 99675e2 commit db01837
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Modules/Dementia/Source/Dementia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
#define ME_BASIC_PROFILER USE_IF( USING( ME_IMGUI ) && USING( ME_PROFILING ) )
#define ME_GAME_TOOLS USE_IF( USING( ME_TOOLS ) && !USING( ME_EDITOR ) )
3 changes: 2 additions & 1 deletion Modules/Dementia/Source/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Path::Path( const std::string& InFile, bool Raw /*= false*/ )
#endif
LocalPos = static_cast<int8_t>( FullPath.rfind( LocalPath ) );
DirectoryPos = static_cast<int8_t>( FullPath.find_last_of( "/" ) + 1 );
DirectoryPos = (int8_t)( FullPath.size() - DirectoryPos );

#if USING( ME_PLATFORM_UWP )
//std::replace(LocalPath.begin(), LocalPath.end(), '/', '\\');
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Source/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ void Engine::Init( Game* game )
}
} );

#if USING( ME_GAME_TOOLS )
m_debugTools.Init();
#endif

InitGame();

ResizeFunc( engineConfig.WindowSize );
Expand Down Expand Up @@ -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...
Expand Down
7 changes: 7 additions & 0 deletions Source/Engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <Work/Worker.h>
#include "Core/ISystem.h"

#if USING( ME_GAME_TOOLS )
#include "Tools/DebugTools.h"
#endif

class Game;
class IWindow;
class BGFXRenderer;
Expand Down Expand Up @@ -100,6 +104,9 @@ class Engine
public:
Input& GetEditorInput();
#endif
#if USING( ME_GAME_TOOLS )
DebugTools m_debugTools;
#endif
};

Engine& GetEngine();
81 changes: 81 additions & 0 deletions Source/Tools/DebugTools.cpp
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions Source/Tools/DebugTools.h
Original file line number Diff line number Diff line change
@@ -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<SharedPtr<HavanaWidget>> CustomRegisteredWidgets;
};

#endif
3 changes: 0 additions & 3 deletions Source/Window/SDLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions Tools/BaseProject.sharpmake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 )
{
Expand Down

0 comments on commit db01837

Please sign in to comment.