Skip to content

Commit b380c7c

Browse files
committed
Add implot
1 parent 8f333c2 commit b380c7c

17 files changed

Lines changed: 89 additions & 40 deletions

File tree

Engine/Engine.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"vendor/imgui/imgui_draw.cpp"
55
"vendor/imgui/imgui_tables.cpp"
66
"vendor/imgui/imgui_widgets.cpp"
7+
"vendor/implot/.github/example_implot.cpp"
8+
"vendor/implot/implot.cpp"
9+
"vendor/implot/implot_demo.cpp"
10+
"vendor/implot/implot_items.cpp"
711
"vendor/sfml-imgui/imgui-SFML.cpp"
812
"Engine/src/EngineCore.h"
913
"Engine/src/EngineMeta.h"
@@ -51,6 +55,8 @@
5155
"Engine/src/engine/systems/Flow.h"
5256
"Engine/src/engine/systems/Input.cpp"
5357
"Engine/src/engine/systems/Input.h"
58+
"Engine/src/engine/systems/InputMac.cpp"
59+
"Engine/src/engine/systems/InputMac.h"
5460
"Engine/src/engine/systems/Reflection.cpp"
5561
"Engine/src/engine/systems/Reflection.h"
5662
"Engine/src/engine/systems/ResourceManager.cpp"
@@ -97,6 +103,7 @@ target_include_directories("Engine" PRIVATE
97103
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../GameTemplates/Game/src>
98104
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor>
99105
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/imgui>
106+
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/implot>
100107
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/sfml-imgui>
101108
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/SFML-3.0.0/include>
102109
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/json/include>
@@ -159,6 +166,7 @@ target_include_directories("Engine" PRIVATE
159166
$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../GameTemplates/Game/src>
160167
$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor>
161168
$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/imgui>
169+
$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/implot>
162170
$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/sfml-imgui>
163171
$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/SFML-3.0.0/include>
164172
$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/json/include>
@@ -220,6 +228,7 @@ target_include_directories("Engine" PRIVATE
220228
$<$<CONFIG:ReleaseNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../GameTemplates/Game/src>
221229
$<$<CONFIG:ReleaseNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor>
222230
$<$<CONFIG:ReleaseNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/imgui>
231+
$<$<CONFIG:ReleaseNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/implot>
223232
$<$<CONFIG:ReleaseNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/sfml-imgui>
224233
$<$<CONFIG:ReleaseNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/SFML-3.0.0/include>
225234
$<$<CONFIG:ReleaseNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/json/include>
@@ -280,6 +289,7 @@ target_include_directories("Engine" PRIVATE
280289
$<$<CONFIG:DebugNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../GameTemplates/Game/src>
281290
$<$<CONFIG:DebugNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor>
282291
$<$<CONFIG:DebugNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/imgui>
292+
$<$<CONFIG:DebugNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/implot>
283293
$<$<CONFIG:DebugNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/sfml-imgui>
284294
$<$<CONFIG:DebugNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/SFML-3.0.0/include>
285295
$<$<CONFIG:DebugNoEditor>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/json/include>
@@ -341,6 +351,7 @@ target_include_directories("Engine" PRIVATE
341351
$<$<CONFIG:Distro>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../GameTemplates/Game/src>
342352
$<$<CONFIG:Distro>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor>
343353
$<$<CONFIG:Distro>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/imgui>
354+
$<$<CONFIG:Distro>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/implot>
344355
$<$<CONFIG:Distro>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/sfml-imgui>
345356
$<$<CONFIG:Distro>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/SFML-3.0.0/include>
346357
$<$<CONFIG:Distro>:${CMAKE_CURRENT_SOURCE_DIR}/Engine/../vendor/json/include>

Engine/premake5.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ project "Engine"
1313
"src/**.h",
1414
"src/**.mm",
1515
"../vendor/imgui/**.cpp",
16+
"../vendor/implot/**.cpp",
1617
"../vendor/sfml-imgui/imgui-SFML.cpp",
1718
}
1819

@@ -28,6 +29,7 @@ project "Engine"
2829
"../GameTemplates/Game/src",
2930
"../vendor",
3031
"../vendor/imgui",
32+
"../vendor/implot",
3133
"../vendor/sfml-imgui",
3234
"../vendor/SFML-3.0.0/include",
3335
"../vendor/json/include",

Engine/src/engine/Engine.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
44
#define IMGUI_DEFINE_MATH_OPERATORS
55
#include "imgui/imgui.h"
6+
#include "implot/implot.h"
67
#include "imgui-SFML.h"
78
#endif
89

@@ -17,6 +18,7 @@
1718
#include "engine/systems/Time.h"
1819
#include "engine/systems/Timer.h"
1920
#include "utils/Wrappers.h"
21+
#include "Engine.h"
2022

2123
namespace Toad
2224
{
@@ -35,8 +37,6 @@ static std::unique_ptr<filewatch::FileWatch<TFILEWATCH_STRTYPE>> dll_file_watch
3537
static Camera editor_cam{ "EditorCamera" };
3638
// multiple windows
3739

38-
static DllHandle curr_dll{};
39-
4040
static std::filesystem::path current_path;
4141
static std::filesystem::path project_path;
4242

@@ -45,6 +45,10 @@ static std::unique_ptr<sf::RenderTexture> window_texture = nullptr;
4545

4646
static Camera* interacting_camera = nullptr;
4747

48+
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
49+
static UICtx ui_ctx;
50+
#endif
51+
4852
void Render(AppWindow& window);
4953
void CleanUp();
5054

@@ -234,10 +238,20 @@ bool Init()
234238

235239
// #TODO: change to a .ini or .json
236240
::AppSettings gsettings;
241+
242+
DllHandle curr_dll = ScriptManager::GetDLLHandle();
243+
244+
LOGDEBUGF("curr_dll: {}", (void*)(curr_dll));
245+
237246
if (curr_dll != nullptr)
238247
{
239248
auto get_game_settings = reinterpret_cast<get_game_settings_t*>(DLibGetAddress(curr_dll, "get_game_settings"));
240-
gsettings = get_game_settings();
249+
LOGDEBUGF("DLGetError: {}", DLGetError());
250+
LOGDEBUGF("get_game_settings: {}", (void*)(get_game_settings));
251+
if (!get_game_settings)
252+
LOGERROR("Couldn't get game settings");
253+
else
254+
gsettings = get_game_settings();
241255
}
242256

243257
#ifdef TOAD_EDITOR
@@ -249,6 +263,8 @@ bool Init()
249263
#endif
250264
AppWindow& window = GetWindow();
251265

266+
LOGDEBUGF("Creating window ({})", gsettings.window_name);
267+
252268
if (!window.Create(gsettings.window_width, gsettings.window_height, gsettings.frame_limit, gsettings.style, gsettings.window_name))
253269
return false;
254270
//window.Create({ (uint32_t)gsettings.window_width, (uint32_t)gsettings.window_height }, "abc", gsettings.style);
@@ -272,6 +288,11 @@ bool Init()
272288
StartGameSession();
273289
#endif
274290

291+
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
292+
ui_ctx.imgui_ctx = ImGui::GetCurrentContext();
293+
ui_ctx.implot_ctx = ImPlot::GetCurrentContext();
294+
#endif
295+
275296
return true;
276297
}
277298

@@ -359,21 +380,20 @@ void Render(AppWindow& window)
359380

360381
for (auto& obj : Scene::current_scene.objects_all)
361382
for (auto& [name, script] : obj->GetAttachedScripts())
362-
script->OnImGui(obj.get(), ImGui::GetCurrentContext());
383+
script->OnImGui(obj.get(), ui_ctx);
363384

364385
ImGui::SFML::Render(window);
365386
#else
366-
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
367387
Scene::current_scene.Render(window);
368388
DrawingCanvas::ClearDrawBuffers();
369389

390+
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
370391
for (auto& obj : Scene::current_scene.objects_all)
371392
for (auto& [name, script] : obj->GetAttachedScripts())
372-
script->OnImGui(obj.get(), ImGui::GetCurrentContext());
393+
script->OnImGui(obj.get(), ui_ctx);
373394

374395
ImGui::SFML::Render(window);
375396
#endif
376-
Scene::current_scene.Render(window);
377397

378398
if (cam != nullptr)
379399
{
@@ -539,6 +559,7 @@ void CleanUp()
539559
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
540560
LOGDEBUG("shutting down imgui");
541561
ImGui::SFML::Shutdown();
562+
ImPlot::DestroyContext();
542563
#endif
543564

544565
LOGDEBUG("closing window");
@@ -552,4 +573,9 @@ Camera& GetEditorCamera()
552573
return editor_cam;
553574
}
554575

576+
const UICtx& GetUIContext()
577+
{
578+
return ui_ctx;
555579
}
580+
581+
} // namespace Toad

Engine/src/engine/Engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace Toad
4747

4848
ENGINE_API Toad::Camera& GetEditorCamera();
4949

50+
ENGINE_API const UICtx& GetUIContext();
51+
5052
ENGINE_API void SetPreUICallback(const FENGINE_PRE_UI_CALLBACK& callback);
5153
ENGINE_API void SetEngineUI(const FENGINE_UI& p_ui);
5254

Engine/src/engine/default_scripts/AnimationController.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ void AnimationController::OnLateUpdate(Object* obj)
4141
}
4242

4343
#ifdef TOAD_EDITOR
44-
void AnimationController::OnEditorUI(Object* obj, ImGuiContext* ctx)
44+
void AnimationController::OnEditorUI(Object* obj, const UICtx& ctx)
4545
{
46+
UI_APPLY_CTX(ctx);
47+
4648
Script::OnEditorUI(obj, ctx);
4749
if (m_attachedAnimation)
4850
{

Engine/src/engine/default_scripts/AnimationController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ENGINE_API AnimationController : public Script
2020
void OnStart(Object* obj) override;
2121
void OnLateUpdate(Object* obj) override;
2222
#ifdef TOAD_EDITOR
23-
void OnEditorUI(Object* obj, ImGuiContext* ctx) override;
23+
void OnEditorUI(Object* obj, const UICtx& ctx) override;
2424
#endif
2525
private:
2626
Animation* m_attachedAnimation = nullptr;

Engine/src/engine/default_scripts/Script.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ void Script::OnRender(Object* obj, sf::RenderTarget& target)
3939
}
4040

4141
#ifdef TOAD_EDITOR
42-
void Script::OnEditorUI(Object* obj, ImGuiContext* ctx)
42+
void Script::OnEditorUI(Object* obj, const UICtx& ctx)
4343
{
4444
}
4545
#endif
4646

4747
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
48-
void Script::OnImGui(Object* obj, ImGuiContext* ctx)
48+
void Script::OnImGui(Object* obj, const UICtx& ctx)
4949
{
5050
}
5151
#endif

Engine/src/engine/default_scripts/Script.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
1010
#include "imgui/imgui.h"
11+
#include "implot/implot.h"
1112
#endif
1213

1314
#define EXPOSE_VAR(T) m_reflection.Add(#T, &(T))
@@ -25,6 +26,17 @@ Script* Clone() override \
2526
return dynamic_cast<Script*>(script); \
2627
}
2728

29+
// gets passed with ui functions
30+
struct UICtx
31+
{
32+
ImGuiContext* imgui_ctx = nullptr;
33+
ImPlotContext* implot_ctx = nullptr;
34+
};
35+
36+
#define UI_APPLY_CTX(ctx) \
37+
ImGui::SetCurrentContext(ctx.imgui_ctx); \
38+
ImPlot::SetCurrentContext(ctx.implot_ctx)
39+
2840
namespace Toad
2941
{
3042
class Object;
@@ -43,10 +55,10 @@ class ENGINE_API Script
4355
virtual void OnStart(Object* obj);
4456
virtual void OnRender(Object* obj, sf::RenderTarget& target);
4557
#ifdef TOAD_EDITOR
46-
virtual void OnEditorUI(Object* obj, ImGuiContext* ctx);
58+
virtual void OnEditorUI(Object* obj, const UICtx& ctx);
4759
#endif
4860
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
49-
virtual void OnImGui(Object* obj, ImGuiContext* ctx);
61+
virtual void OnImGui(Object* obj, const UICtx& ctx);
5062
#endif
5163

5264
virtual void OnEnd(Object* obj, Scene* next_scene);

GameTemplates/Game/src/assets/scripts/TestScript.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ void TestScript::ExposeVars()
8888
#ifdef TOAD_EDITOR
8989
void TestScript::OnEditorUI(Toad::Object* obj, ImGuiContext* ctx)
9090
{
91-
ImGui::SetCurrentContext(ctx);
91+
UI_APPLY_CTX(ctx);
9292

9393
ImGui::Text("Velocity: %f %f", velx, vely);
9494
}
9595
#endif
9696

9797
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
98-
void TestScript::OnImGui(Toad::Object* obj, ImGuiContext* ctx)
98+
void TestScript::OnImGui(Toad::Object* obj, const UICtx& ctx)
9999
{
100-
ImGui::SetCurrentContext(ctx);
100+
UI_APPLY_CTX(ctx);
101101

102102
ImGui::Begin("[TestScript] Controller menu");
103103

GameTemplates/Game/src/assets/scripts/TestScript.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class GAME_API TestScript : public Toad::Script
1818
void ExposeVars() override;
1919

2020
#ifdef TOAD_EDITOR
21-
void OnEditorUI(Toad::Object* obj, ImGuiContext* ctx) override;
21+
void OnEditorUI(Toad::Object* obj, const UICtx& ctx) override;
2222
#endif
2323
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
24-
void OnImGui(Toad::Object* obj, ImGuiContext* ctx) override;
24+
void OnImGui(Toad::Object* obj, const UICtx& ctx) override;
2525
#endif
2626
};

0 commit comments

Comments
 (0)