diff --git a/gdext/include/imconfig-godot.h b/gdext/include/imconfig-godot.h index 442129fb..6a032c0c 100644 --- a/gdext/include/imconfig-godot.h +++ b/gdext/include/imconfig-godot.h @@ -2,8 +2,7 @@ #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS // match ImGui.NET -#if __has_include("godot_cpp/godot.hpp") -#pragma warning(push, 0) +#if __has_include("godot_cpp/godot.hpp") // GDExtension #include #include #include @@ -24,8 +23,7 @@ using godot::Vector4; } while (0) #endif #endif -#pragma warning(pop) -#else +#else // module #include "core/math/color.h" #include "core/math/vector2.h" #include "core/math/vector2i.h" diff --git a/gdext/include/imgui-godot.h b/gdext/include/imgui-godot.h index ad15d98e..1de9f571 100644 --- a/gdext/include/imgui-godot.h +++ b/gdext/include/imgui-godot.h @@ -8,7 +8,6 @@ #if __has_include("godot_cpp/godot.hpp") #define IGN_GDEXT // GDExtension -#pragma warning(push, 0) #include #include #include @@ -19,7 +18,6 @@ #include #include #include -#pragma warning(pop) using godot::AtlasTexture; using godot::Callable; diff --git a/gdext/src/CMakeLists.txt b/gdext/src/CMakeLists.txt index caa6a372..c1003e43 100644 --- a/gdext/src/CMakeLists.txt +++ b/gdext/src/CMakeLists.txt @@ -1,12 +1,14 @@ target_sources(imgui-godot-native PRIVATE - common.h CanvasRenderer.cpp CanvasRenderer.h + common.h Context.cpp Context.h DummyRenderer.h Fonts.cpp Fonts.h + GdsCache.cpp + GdsCache.h ImGuiAPI.cpp ImGuiAPI.h ImGuiGD.cpp @@ -15,8 +17,6 @@ target_sources(imgui-godot-native PRIVATE ImGuiLayer.h ImGuiLayerHelper.cpp ImGuiLayerHelper.h - ImGuiRoot.cpp - ImGuiRoot.h Input.cpp Input.h main.cpp @@ -25,8 +25,6 @@ target_sources(imgui-godot-native PRIVATE RdRendererThreadSafe.cpp RdRendererThreadSafe.h Renderer.h - ShortTermCache.cpp - ShortTermCache.h Viewports.cpp Viewports.h ) diff --git a/gdext/src/CanvasRenderer.h b/gdext/src/CanvasRenderer.h index 3b35a7f1..0401f6a0 100644 --- a/gdext/src/CanvasRenderer.h +++ b/gdext/src/CanvasRenderer.h @@ -1,12 +1,9 @@ #pragma once #include "Renderer.h" +#include #include #include -#pragma warning(push, 0) -#include -#pragma warning(pop) - using godot::RID; namespace ImGui::Godot { diff --git a/gdext/src/Context.cpp b/gdext/src/Context.cpp index 2bb0452a..ed1ec38b 100644 --- a/gdext/src/Context.cpp +++ b/gdext/src/Context.cpp @@ -44,8 +44,7 @@ Context::~Context() void Init(godot::Window* mainWindow, RID mainSubViewport, const Ref& cfg) { // re-init not allowed - // if (ctx) - // return; + ERR_FAIL_COND(ctx); DisplayServer* DS = DisplayServer::get_singleton(); RenderingServer* RS = RenderingServer::get_singleton(); @@ -123,90 +122,6 @@ void Init(godot::Window* mainWindow, RID mainSubViewport, const Ref& c if (cfg->get("AddDefaultFont")) AddFontDefault(); RebuildFontAtlas(); - - // ctx = std::make_unique(); - // ctx->mainWindow = mainWindow; - // ctx->ci = canvasItem; - // ctx->input = std::make_unique(ctx->mainWindow); - // - // int32_t screenDPI = DisplayServer::get_singleton()->screen_get_dpi(); - // ctx->dpiFactor = std::max(1, screenDPI / 96); - // ctx->scaleToDPI = ProjectSettings::get_singleton()->get_setting("display/window/dpi/allow_hidpi"); - // - // ImGuiIO& io = ImGui::GetIO(); - // io.DisplaySize = ctx->mainWindow->get_size(); - // - // io.BackendPlatformName = PlatformName; - // - // io.BackendFlags |= ImGuiBackendFlags_HasGamepad; - // io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; - // io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; - // io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; - // io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; - // io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; - // - // Array fonts = cfg->get("Fonts"); - // bool addDefaultFont = cfg->get("AddDefaultFont"); - // float scale = cfg->get("Scale"); - // String iniFilename = cfg->get("IniFilename"); - // String rendererName = cfg->get("Renderer"); - // - // SetIniFilename(iniFilename); - // - // RenderingServer* RS = RenderingServer::get_singleton(); - // - // ctx->headless = DisplayServer::get_singleton()->get_name() == "headless"; - // - // if (!ctx->headless && !RS->get_rendering_device()) - // { - // ctx->headless = true; - // UtilityFunctions::printerr("imgui-godot requires RenderingDevice"); - // } - // - // if (ctx->headless || rendererName == "Dummy") - // { - // ctx->renderer = std::make_unique(); - // } - // else - // { - // int threadModel = ProjectSettings::get_singleton()->get_setting("rendering/driver/threads/thread_model"); - // #ifdef DEBUG_ENABLED - // if (Engine::get_singleton()->is_editor_hint()) - // threadModel = 0; - // #endif - // if (threadModel == 2) - // ctx->renderer = std::make_unique(); - // else - // ctx->renderer = std::make_unique(); - // } - // ctx->renderer = std::make_unique(); - // io.BackendRendererName = ctx->renderer->Name(); - // - // Object* igl = Engine::get_singleton()->get_singleton("ImGuiLayer"); - // RS->connect("frame_pre_draw", Callable(igl, "on_frame_pre_draw")); - // - // ctx->svp = RS->viewport_create(); - // RS->viewport_set_transparent_background(ctx->svp, true); - // RS->viewport_set_update_mode(ctx->svp, RenderingServer::VIEWPORT_UPDATE_ALWAYS); - // RS->viewport_set_clear_mode(ctx->svp, RenderingServer::VIEWPORT_CLEAR_NEVER); - // RS->viewport_set_active(ctx->svp, true); - // RS->viewport_set_parent_viewport(ctx->svp, ctx->mainWindow->get_viewport_rid()); - // - // ctx->fonts = std::make_unique(); - // - // for (int i = 0; i < fonts.size(); ++i) - // { - // Ref fontres = fonts[i]; - // Ref font = fontres->get("FontData"); - // int fontSize = fontres->get("FontSize"); - // bool merge = fontres->get("Merge"); - // AddFont(font, fontSize, i > 0 && merge); - // } - // if (addDefaultFont) - // AddFontDefault(); - // RebuildFontAtlas(scale); - // - // ctx->viewports = std::make_unique(ctx->mainWindow, ctx->svp); } void Update(double delta, Vector2 displaySize) @@ -215,7 +130,6 @@ void Update(double delta, Vector2 displaySize) io.DisplaySize = displaySize; io.DeltaTime = static_cast(delta); - // if (!ctx->headless) ctx->input->Update(); gdscache->OnNewFrame(); @@ -235,14 +149,6 @@ void ProcessNotification(int what) void Render() { - // RenderingServer* RS = RenderingServer::get_singleton(); - // godot::Vector2i winSize = ctx->mainWindow->get_size(); - // RS->viewport_set_size(ctx->svp, winSize.x, winSize.y); - // RID vptex = RS->viewport_get_texture(ctx->svp); - // RS->canvas_item_clear(ctx->ci); - // RS->canvas_item_set_transform(ctx->ci, ctx->mainWindow->get_final_transform().affine_inverse()); - // RS->canvas_item_add_texture_rect(ctx->ci, godot::Rect2(0, 0, winSize.x, winSize.y), vptex); - ImGui::Render(); ImGui::UpdatePlatformWindows(); ctx->renderer->Render(); diff --git a/gdext/src/Context.h b/gdext/src/Context.h index 464688a4..52ad5908 100644 --- a/gdext/src/Context.h +++ b/gdext/src/Context.h @@ -1,6 +1,4 @@ #pragma once - -#pragma warning(push, 0) #include #include #include @@ -19,16 +17,15 @@ #include #include #include -#pragma warning(pop) #include "DummyRenderer.h" #include "Fonts.h" +#include "GdsCache.h" #include "ImGuiGD.h" #include "Input.h" #include "RdRenderer.h" #include "RdRendererThreadSafe.h" #include "Renderer.h" -#include "ShortTermCache.h" #include "Viewports.h" using namespace godot; @@ -72,7 +69,8 @@ void Render(); void Shutdown(); void Connect(const Callable& callable); void ResetFonts(); -void AddFont(const Ref& fontFile, int fontSize, bool merge = false, const ImVector& glyphRanges = {}); +void AddFont(const Ref& fontFile, int fontSize, bool merge = false, + const ImVector& glyphRanges = {}); void AddFontDefault(); void RebuildFontAtlas(float scale = 1.0f); void SetIniFilename(const String& fn); diff --git a/gdext/src/ShortTermCache.cpp b/gdext/src/GdsCache.cpp similarity index 81% rename from gdext/src/ShortTermCache.cpp rename to gdext/src/GdsCache.cpp index a09896a7..9d3c05e3 100644 --- a/gdext/src/ShortTermCache.cpp +++ b/gdext/src/GdsCache.cpp @@ -1,4 +1,4 @@ -#include "ShortTermCache.h" +#include "GdsCache.h" #include #include #include @@ -9,9 +9,9 @@ using namespace godot; namespace ImGui::Godot { -std::unique_ptr gdscache = std::make_unique(); +std::unique_ptr gdscache = std::make_unique(); -struct ShortTermCache::Impl +struct GdsCache::Impl { std::unordered_map> bufs; std::unordered_map used; @@ -27,15 +27,15 @@ struct ShortTermCache::Impl } }; -ShortTermCache::ShortTermCache() : impl(std::make_unique()) +GdsCache::GdsCache() : impl(std::make_unique()) { } -ShortTermCache::~ShortTermCache() +GdsCache::~GdsCache() { } -void ShortTermCache::OnNewFrame() +void GdsCache::OnNewFrame() { for (auto it = impl->used.begin(); it != impl->used.end();) { @@ -52,7 +52,7 @@ void ShortTermCache::OnNewFrame() } } -std::vector& ShortTermCache::GetTextBuf(const StringName& label, size_t size, const Array& a) +std::vector& GdsCache::GetTextBuf(const StringName& label, size_t size, const Array& a) { int64_t hash = ImGui::GetID((void*)label.hash()); impl->used[hash] = true; @@ -73,7 +73,7 @@ std::vector& ShortTermCache::GetTextBuf(const StringName& label, size_t si } } -const std::vector& ShortTermCache::GetZeroArray(const Array& a) +const std::vector& GdsCache::GetZeroArray(const Array& a) { int64_t hash = a.hash(); impl->used[hash] = true; diff --git a/gdext/src/ShortTermCache.h b/gdext/src/GdsCache.h similarity index 71% rename from gdext/src/ShortTermCache.h rename to gdext/src/GdsCache.h index 1b5c681d..1ffb24a2 100644 --- a/gdext/src/ShortTermCache.h +++ b/gdext/src/GdsCache.h @@ -1,9 +1,5 @@ #pragma once - -#pragma warning(push, 0) #include -#pragma warning(pop) - #include #include @@ -11,11 +7,11 @@ using namespace godot; namespace ImGui::Godot { -class ShortTermCache +class GdsCache { public: - ShortTermCache(); - ~ShortTermCache(); + GdsCache(); + ~GdsCache(); void OnNewFrame(); std::vector& GetTextBuf(const StringName& label, size_t size, const Array& a); @@ -26,6 +22,6 @@ class ShortTermCache std::unique_ptr impl; }; -extern std::unique_ptr gdscache; +extern std::unique_ptr gdscache; } // namespace ImGui::Godot diff --git a/gdext/src/ImGuiAPI.cpp b/gdext/src/ImGuiAPI.cpp index 16708795..826b74d3 100644 --- a/gdext/src/ImGuiAPI.cpp +++ b/gdext/src/ImGuiAPI.cpp @@ -1,10 +1,7 @@ #include "ImGuiAPI.h" - -#pragma warning(push, 0) #include #include #include -#pragma warning(pop) using namespace godot; diff --git a/gdext/src/ImGuiAPI.h b/gdext/src/ImGuiAPI.h index b3a58be0..6ff02724 100644 --- a/gdext/src/ImGuiAPI.h +++ b/gdext/src/ImGuiAPI.h @@ -1,18 +1,13 @@ #pragma once - -#pragma warning(push, 0) +#include "GdsCache.h" #include #include #include #include #include -#pragma warning(pop) - -#include #include #include -#include "ShortTermCache.h" #include "imgui_bindings.gen.h" using namespace godot; diff --git a/gdext/src/ImGuiGD.cpp b/gdext/src/ImGuiGD.cpp index 2d469a24..b878713b 100644 --- a/gdext/src/ImGuiGD.cpp +++ b/gdext/src/ImGuiGD.cpp @@ -1,7 +1,6 @@ #include "ImGuiGD.h" #include "Context.h" #include "ImGuiLayer.h" -#include "ImGuiRoot.h" #include "common.h" #include #include @@ -41,25 +40,6 @@ void ImGuiGD::_bind_methods() ClassDB::bind_method(D_METHOD("GetFontPtrs"), &ImGuiGD::GetFontPtrs); } -// void ImGuiGD::InitEditor(Node* parent) -//{ -// #ifdef DEBUG_ENABLED -// if (!Engine::get_singleton()->is_editor_hint()) -// return; -// -// if (!Engine::get_singleton()->has_singleton("ImGuiRoot")) -// { -// String resPath = "res://addons/imgui-godot-native/ImGuiGodot.tscn"; -// if (ResourceLoader::get_singleton()->exists(resPath)) -// { -// Ref scene = ResourceLoader::get_singleton()->load(resPath); -// if (scene.is_valid()) -// parent->add_child(scene->instantiate()); -// } -// } -// #endif -// } - bool ImGuiGD::ToolInit() { #ifdef DEBUG_ENABLED @@ -135,7 +115,9 @@ bool ImGuiGD::_GetVisible() void ImGuiGD::_SetJoyAxisDeadZone(float zone) { - ImGui::Godot::GetContext()->input->SetJoyAxisDeadZone(zone); + Context* ctx = ImGui::Godot::GetContext(); + ERR_FAIL_COND(!ctx); + ctx->input->SetJoyAxisDeadZone(zone); } float ImGuiGD::_GetJoyAxisDeadZone() diff --git a/gdext/src/ImGuiGD.h b/gdext/src/ImGuiGD.h index f62e2de3..bb024243 100644 --- a/gdext/src/ImGuiGD.h +++ b/gdext/src/ImGuiGD.h @@ -1,13 +1,9 @@ #pragma once - -#pragma warning(push, 0) #include #include #include #include #include -#pragma warning(pop) - #include using namespace godot; diff --git a/gdext/src/ImGuiLayer.cpp b/gdext/src/ImGuiLayer.cpp index 2318f311..baf89f78 100644 --- a/gdext/src/ImGuiLayer.cpp +++ b/gdext/src/ImGuiLayer.cpp @@ -2,7 +2,6 @@ #include "Context.h" #include "ImGuiLayerHelper.h" -#pragma warning(push, 0) #include #include #include @@ -11,8 +10,6 @@ #include #include #include -#pragma warning(pop) - #include #include @@ -75,8 +72,6 @@ void ImGuiLayer::_enter_tree() Node* parent = get_parent(); if (!parent) return; - // if (parent->get_class() != "ImGuiRoot") - // return; if (Engine::get_singleton()->has_singleton("ImGuiLayer")) return; @@ -115,7 +110,7 @@ void ImGuiLayer::_enter_tree() void ImGuiLayer::_ready() { set_process_priority(std::numeric_limits::max()); - set_physics_process(false); + set_process_mode(Node::PROCESS_MODE_ALWAYS); connect("visibility_changed", Callable(this, "on_visibility_changed")); } @@ -150,7 +145,8 @@ void ImGuiLayer::_process(double delta) Vector2i winSize = impl->window->get_size(); Transform2D ft = impl->window->get_final_transform(); - if (impl->subViewportSize != winSize || impl->finalTransform != ft + if (impl->subViewportSize != winSize || + impl->finalTransform != ft #ifdef DEBUG_ENABLED // force redraw on every frame in editor || Engine::get_singleton()->is_editor_hint() diff --git a/gdext/src/ImGuiLayer.h b/gdext/src/ImGuiLayer.h index d325d32c..91b24b37 100644 --- a/gdext/src/ImGuiLayer.h +++ b/gdext/src/ImGuiLayer.h @@ -1,10 +1,6 @@ #pragma once - -#pragma warning(push, 0) #include #include -#pragma warning(pop) - #include using namespace godot; diff --git a/gdext/src/ImGuiLayerHelper.cpp b/gdext/src/ImGuiLayerHelper.cpp index 34d4437c..81885837 100644 --- a/gdext/src/ImGuiLayerHelper.cpp +++ b/gdext/src/ImGuiLayerHelper.cpp @@ -1,13 +1,9 @@ #include "ImGuiLayerHelper.h" #include "Context.h" #include "imgui-godot.h" - -#pragma warning(push, 0) #include #include #include -#pragma warning(pop) - #include using namespace godot; diff --git a/gdext/src/ImGuiLayerHelper.h b/gdext/src/ImGuiLayerHelper.h index ccfb4411..8d0a562e 100644 --- a/gdext/src/ImGuiLayerHelper.h +++ b/gdext/src/ImGuiLayerHelper.h @@ -1,9 +1,5 @@ #pragma once - -#pragma warning(push, 0) #include -#pragma warning(pop) - #include using godot::InputEvent; diff --git a/gdext/src/ImGuiRoot.cpp b/gdext/src/ImGuiRoot.cpp deleted file mode 100644 index b017f10b..00000000 --- a/gdext/src/ImGuiRoot.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "ImGuiRoot.h" -#include "ImGuiLayer.h" -#include -#include -#include - -namespace ImGui::Godot { - -struct ImGuiRoot::Impl -{ - Ref cfg; -}; - -ImGuiRoot::ImGuiRoot() : impl(std::make_unique()) -{ -} - -ImGuiRoot::~ImGuiRoot() -{ -} - -void ImGuiRoot::_bind_methods() -{ - ClassDB::bind_method(D_METHOD("SetConfig", "cfg"), &ImGuiRoot::SetConfig); - ClassDB::bind_method(D_METHOD("GetConfig"), &ImGuiRoot::GetConfig); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Config", PROPERTY_HINT_RESOURCE_TYPE, "ImGuiConfig"), - "SetConfig", - "GetConfig"); -} - -void ImGuiRoot::_get_property_list(List* p_list) const -{ -} - -void ImGuiRoot::_enter_tree() -{ - Node* parent = get_parent(); - if (parent == get_window() || parent->get_name() == StringName("ImGuiGodotNativeEditorPlugin")) - { - Engine::get_singleton()->register_singleton("ImGuiRoot", this); - ImGuiLayer* igl = memnew(ImGuiLayer); - add_child(igl); - } -} - -void ImGuiRoot::SetConfig(Ref cfg) -{ - impl->cfg = cfg; -} - -Ref ImGuiRoot::GetConfig() -{ - return impl->cfg; -} - -} // namespace ImGui::Godot diff --git a/gdext/src/ImGuiRoot.h b/gdext/src/ImGuiRoot.h deleted file mode 100644 index 0b5de2a1..00000000 --- a/gdext/src/ImGuiRoot.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#pragma warning(push, 0) -#include -#include -#pragma warning(pop) - -#include - -using namespace godot; - -namespace ImGui::Godot { - -class ImGuiRoot : public Node -{ - GDCLASS(ImGuiRoot, Node); - -protected: - static void _bind_methods(); - void _get_property_list(List* p_list) const; - -public: - ImGuiRoot(); - ~ImGuiRoot(); - - void _enter_tree() override; - - void SetConfig(Ref cfg); - Ref GetConfig(); - -private: - struct Impl; - std::unique_ptr impl; -}; - -} // namespace ImGui::Godot diff --git a/gdext/src/RdRenderer.cpp b/gdext/src/RdRenderer.cpp index 7d24d045..a1c493ad 100644 --- a/gdext/src/RdRenderer.cpp +++ b/gdext/src/RdRenderer.cpp @@ -1,11 +1,6 @@ #include "RdRenderer.h" #include "common.h" #include -#include -#include -#include - -#pragma warning(push, 0) #include #include #include @@ -21,7 +16,9 @@ #include #include #include -#pragma warning(pop) +#include +#include +#include using namespace godot; diff --git a/gdext/src/RdRenderer.h b/gdext/src/RdRenderer.h index 592c24aa..40349862 100644 --- a/gdext/src/RdRenderer.h +++ b/gdext/src/RdRenderer.h @@ -1,12 +1,9 @@ #pragma once #include "Renderer.h" +#include #include #include -#pragma warning(push, 0) -#include -#pragma warning(pop) - using godot::RID; namespace ImGui::Godot { @@ -32,7 +29,6 @@ class RdRenderer : public Renderer { } - protected: void Render(RID fb, ImDrawData* drawData); static void ReplaceTextureRIDs(ImDrawData* drawData); diff --git a/gdext/src/RdRendererThreadSafe.h b/gdext/src/RdRendererThreadSafe.h index 0905cb49..1890c54d 100644 --- a/gdext/src/RdRendererThreadSafe.h +++ b/gdext/src/RdRendererThreadSafe.h @@ -1,12 +1,9 @@ #pragma once #include "RdRenderer.h" +#include #include #include -#pragma warning(push, 0) -#include -#pragma warning(pop) - using godot::RID; namespace ImGui::Godot { diff --git a/gdext/src/Renderer.h b/gdext/src/Renderer.h index 11cc5c8a..0fe4c894 100644 --- a/gdext/src/Renderer.h +++ b/gdext/src/Renderer.h @@ -1,11 +1,8 @@ #pragma once +#include #include #include -#pragma warning(push, 0) -#include -#pragma warning(pop) - using godot::RID; namespace ImGui::Godot { diff --git a/gdext/src/Viewports.cpp b/gdext/src/Viewports.cpp index ebb622d8..b4b82add 100644 --- a/gdext/src/Viewports.cpp +++ b/gdext/src/Viewports.cpp @@ -47,11 +47,6 @@ static void Godot_CreateWindow(ImGuiViewport* vp) vd->window->set_transparent_background(true); vd->window->set_flag(Window::FLAG_TRANSPARENT, true); - // Callable::bind is not yet implemented... - // vd->window->connect("window_input", Callable(vd->signalProxy, "window_input")); - // vd->window->connect("close_requested", Callable(vd->signalProxy, "close_requested")); - // vd->window->connect("size_changed", Callable(vd->signalProxy, "size_changed")); - Node* root = Object::cast_to(Engine::get_singleton()->get_singleton("ImGuiLayer")); root->add_child(vd->window); diff --git a/gdext/src/common.h b/gdext/src/common.h index ab28fe48..cbebb5d1 100644 --- a/gdext/src/common.h +++ b/gdext/src/common.h @@ -1,9 +1,5 @@ #pragma once - -#pragma warning(push, 0) #include -#pragma warning(pop) - #include using godot::RID; diff --git a/gdext/src/main.cpp b/gdext/src/main.cpp index 0c4530cd..4efc6b2d 100644 --- a/gdext/src/main.cpp +++ b/gdext/src/main.cpp @@ -1,4 +1,3 @@ -#pragma warning(push, 0) #include #include #include @@ -8,7 +7,6 @@ #include #include #include -#pragma warning(pop) static_assert(GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR >= 2); @@ -17,7 +15,6 @@ static_assert(GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR >= 2); #include "ImGuiGD.h" #include "ImGuiLayer.h" #include "ImGuiLayerHelper.h" -#include "ImGuiRoot.h" #include "Viewports.h" // avoid including cimgui.h elsewhere