Skip to content

Commit b5830ac

Browse files
committed
Implementation of a debug console and C# exposing of the Debug method
1 parent 92ec532 commit b5830ac

File tree

8 files changed

+74
-2
lines changed

8 files changed

+74
-2
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
# Agregue un origen al ejecutable de este proyecto.
6-
add_executable (Exeon "main.cpp" "icon.rc" "public/Core/Core.h" "private/Core/Core.cpp" "public/Core/Renderer/Renderer.h" "private/Core/Renderer/Renderer.cpp" "public/Core/Renderer/D3D12.h" "private/Core/Renderer/D3D12.cpp" "public/Util.h" "public/Core/Renderer/DescriptorHeap.h" "private/Core/Renderer/DescriptorHeap.cpp" "public/Core/Renderer/Descriptor.h" "public/Core/Renderer/Shader.h" "private/Core/Renderer/Shader.cpp" "public/Core/Renderer/ScreenQuad.h" "private/Core/Renderer/ScreenQuad.cpp" "public/Core/Scene/SceneManager.h" "private/Core/Scene/SceneManager.cpp" "public/Core/Scene/Scene.h" "private/Core/Scene/Scene.cpp" "public/Core/GameObject/GameObject.h" "private/Core/GameObject/GameObject.cpp" "private/Core/GameObject/Component/Component.cpp" "private/Core/GameObject/Component/Component.cpp" "public/Core/GameObject/Component/Mesh.h" "private/Core/GameObject/Component/Mesh.cpp" "public/Core/Renderer/ResourceManager.h" "private/Core/Renderer/ResourceManager.cpp" "public/Math/Vector3.h" "private/Math/Vector3.cpp" "public/Math/Transform.h" "private/Math/Transform.cpp" "public/Core/Input/Input.h" "private/Core/Input/Input.cpp" "private/Core/GameObject/Camera/Camera.cpp" "public/Core/GameObject/Camera/Camera.h" "private/Core/GameObject/Camera/EditorCamera.cpp" "public/Core/GameObject/Camera/EditorCamera.h" "public/Core/Time.h" "private/Core/Time.cpp" "public/Core/Editor/Editor.h" "private/Core/Editor/Editor.cpp" "public/Core/Editor/Fonts/Roboto.h" "private/Core/Editor/Fonts/Roboto.cpp" "public/Runtime/MonoScript.h" "private/Runtime/MonoScript.cpp")
6+
add_executable (Exeon "main.cpp" "icon.rc" "public/Core/Core.h" "private/Core/Core.cpp" "public/Core/Renderer/Renderer.h" "private/Core/Renderer/Renderer.cpp" "public/Core/Renderer/D3D12.h" "private/Core/Renderer/D3D12.cpp" "public/Util.h" "public/Core/Renderer/DescriptorHeap.h" "private/Core/Renderer/DescriptorHeap.cpp" "public/Core/Renderer/Descriptor.h" "public/Core/Renderer/Shader.h" "private/Core/Renderer/Shader.cpp" "public/Core/Renderer/ScreenQuad.h" "private/Core/Renderer/ScreenQuad.cpp" "public/Core/Scene/SceneManager.h" "private/Core/Scene/SceneManager.cpp" "public/Core/Scene/Scene.h" "private/Core/Scene/Scene.cpp" "public/Core/GameObject/GameObject.h" "private/Core/GameObject/GameObject.cpp" "private/Core/GameObject/Component/Component.cpp" "private/Core/GameObject/Component/Component.cpp" "public/Core/GameObject/Component/Mesh.h" "private/Core/GameObject/Component/Mesh.cpp" "public/Core/Renderer/ResourceManager.h" "private/Core/Renderer/ResourceManager.cpp" "public/Math/Vector3.h" "private/Math/Vector3.cpp" "public/Math/Transform.h" "private/Math/Transform.cpp" "public/Core/Input/Input.h" "private/Core/Input/Input.cpp" "private/Core/GameObject/Camera/Camera.cpp" "public/Core/GameObject/Camera/Camera.h" "private/Core/GameObject/Camera/EditorCamera.cpp" "public/Core/GameObject/Camera/EditorCamera.h" "public/Core/Time.h" "private/Core/Time.cpp" "public/Core/Editor/Editor.h" "private/Core/Editor/Editor.cpp" "public/Core/Editor/Fonts/Roboto.h" "private/Core/Editor/Fonts/Roboto.cpp" "public/Runtime/MonoScript.h" "private/Runtime/MonoScript.cpp" "public/Core/Editor/Console.h" "private/Core/Editor/Console.cpp")
77

88
if (CMAKE_VERSION VERSION_GREATER 3.12)
99
set_property(TARGET Exeon PROPERTY CXX_STANDARD 20)

src/Managed/ExeonScript.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
using System;
2+
using System.Runtime.CompilerServices;
23

34
namespace Exeon
45
{
56
public class ExeonScript
67
{
8+
[MethodImpl(MethodImplOptions.InternalCall)]
9+
public static extern void Debug(string msg);
10+
711
public static void Init()
812
{
9-
Console.WriteLine("Debug");
13+
Debug("ASD");
1014
}
1115
}
1216
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "Core/Editor/Console.h"
2+
3+
Console* Console::m_instance;
4+
5+
Console::Console() {
6+
7+
}
8+
9+
void Console::Init() {
10+
this->Debug("Test for logs");
11+
this->Debug("Test #2");
12+
}
13+
14+
void Console::Update() {
15+
ImGui::SetNextWindowPos(ImVec2{ 370.f, 694.f });
16+
ImGui::SetNextWindowSize(ImVec2{ 1200.f, 280.f });
17+
ImGui::Begin("Console");
18+
ImGui::Text(this->m_log.c_str());
19+
ImGui::End();
20+
}
21+
22+
void Console::Debug(std::string msg) {
23+
std::string log = this->m_log + "\n" + msg;
24+
this->m_log = log;
25+
return;
26+
}
27+
28+
Console* Console::GetInstance() {
29+
if (Console::m_instance == nullptr)
30+
Console::m_instance = new Console();
31+
return Console::m_instance;
32+
}

src/private/Core/Editor/Editor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ Editor::Editor() {
1313
this->m_bRotation = false;
1414
this->m_bScale = false;
1515
this->m_guizmoOp = ImGuizmo::OPERATION::TRANSLATE;
16+
this->m_console = nullptr;
1617
}
1718

1819
void Editor::Init(UINT nWidth, UINT nHeight) {
1920
this->m_sceneMgr = SceneManager::GetInstance();
21+
this->m_console = Console::GetInstance();
22+
this->m_console->Init();
2023

2124
ImGuiIO& io = ImGui::GetIO();
2225

@@ -243,6 +246,8 @@ void Editor::Update() {
243246
ImGui::End();
244247
}
245248

249+
250+
this->m_console->Update();
246251
}
247252

248253
Editor* Editor::GetInstance() {

src/private/Runtime/MonoScript.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ MonoScript::MonoScript() {
1212
this->m_filename = "Managed/ExeonScript.dll";
1313
}
1414

15+
extern "C" void Console_Debug(MonoString* msg) {
16+
const char* nativeMsg = mono_string_to_utf8(msg);
17+
18+
Console::GetInstance()->Debug(nativeMsg);
19+
mono_free((void*)nativeMsg);
20+
}
21+
1522
void MonoScript::Init() {
1623
mono_set_dirs("C:/Program Files/Mono/lib", "C:/Program Files/Mono/etc");
1724
this->m_domain = mono_jit_init("ExeonDomain");
@@ -43,6 +50,7 @@ void MonoScript::Init() {
4350
return;
4451
}
4552

53+
mono_add_internal_call("Exeon.ExeonScript::Debug", (const void*)Console_Debug);
4654
mono_runtime_invoke(initMethod, nullptr, nullptr, nullptr);
4755
}
4856

src/public/Core/Editor/Console.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
#include <iostream>
3+
#include <imgui/imgui.h>
4+
5+
class Console {
6+
private:
7+
static Console* m_instance;
8+
std::string m_log;
9+
public:
10+
Console();
11+
12+
void Init();
13+
void Update();
14+
15+
void Debug(std::string msg);
16+
17+
static Console* GetInstance();
18+
};
19+

src/public/Core/Editor/Editor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <DXMath/DirectXMath.h>
66
#include "Fonts/Roboto.h"
77
#include "Core/Scene/SceneManager.h"
8+
#include "Console.h"
89
#include "Util.h"
910

1011
class Editor {
@@ -19,6 +20,8 @@ class Editor {
1920

2021
WVP m_wvp;
2122

23+
Console* m_console;
24+
2225
bool m_bLocation;
2326
bool m_bRotation;
2427
bool m_bScale;

src/public/Runtime/MonoScript.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <mono/metadata/assembly.h>
55
#include <mono/metadata/debug-helpers.h>
66
#include <spdlog/spdlog.h>
7+
#include "Core/Editor/Editor.h"
78

89
class MonoScript {
910
private:

0 commit comments

Comments
 (0)