Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Apr 26, 2024
1 parent 47f68a0 commit 1ff8885
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 307 deletions.
6 changes: 2 additions & 4 deletions gdext/include/imconfig-godot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <godot_cpp/variant/color.hpp>
#include <godot_cpp/variant/vector2.hpp>
#include <godot_cpp/variant/vector2i.hpp>
Expand All @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions gdext/include/imgui-godot.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#if __has_include("godot_cpp/godot.hpp")
#define IGN_GDEXT
// GDExtension
#pragma warning(push, 0)
#include <godot_cpp/classes/atlas_texture.hpp>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/font_file.hpp>
Expand All @@ -19,7 +18,6 @@
#include <godot_cpp/classes/window.hpp>
#include <godot_cpp/variant/callable.hpp>
#include <godot_cpp/variant/typed_array.hpp>
#pragma warning(pop)

using godot::AtlasTexture;
using godot::Callable;
Expand Down
8 changes: 3 additions & 5 deletions gdext/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -25,8 +25,6 @@ target_sources(imgui-godot-native PRIVATE
RdRendererThreadSafe.cpp
RdRendererThreadSafe.h
Renderer.h
ShortTermCache.cpp
ShortTermCache.h
Viewports.cpp
Viewports.h
)
5 changes: 1 addition & 4 deletions gdext/src/CanvasRenderer.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#pragma once
#include "Renderer.h"
#include <godot_cpp/variant/rid.hpp>
#include <imgui.h>
#include <memory>

#pragma warning(push, 0)
#include <godot_cpp/variant/rid.hpp>
#pragma warning(pop)

using godot::RID;

namespace ImGui::Godot {
Expand Down
96 changes: 1 addition & 95 deletions gdext/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ Context::~Context()
void Init(godot::Window* mainWindow, RID mainSubViewport, const Ref<Resource>& cfg)
{
// re-init not allowed
// if (ctx)
// return;
ERR_FAIL_COND(ctx);

DisplayServer* DS = DisplayServer::get_singleton();
RenderingServer* RS = RenderingServer::get_singleton();
Expand Down Expand Up @@ -123,90 +122,6 @@ void Init(godot::Window* mainWindow, RID mainSubViewport, const Ref<Resource>& c
if (cfg->get("AddDefaultFont"))
AddFontDefault();
RebuildFontAtlas();

// ctx = std::make_unique<Context>();
// ctx->mainWindow = mainWindow;
// ctx->ci = canvasItem;
// ctx->input = std::make_unique<Input>(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<DummyRenderer>();
// }
// 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<RdRendererThreadSafe>();
// else
// ctx->renderer = std::make_unique<RdRenderer>();
// }
// ctx->renderer = std::make_unique<CanvasRenderer>();
// 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<Fonts>();
//
// for (int i = 0; i < fonts.size(); ++i)
// {
// Ref<Resource> fontres = fonts[i];
// Ref<FontFile> 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<Viewports>(ctx->mainWindow, ctx->svp);
}

void Update(double delta, Vector2 displaySize)
Expand All @@ -215,7 +130,6 @@ void Update(double delta, Vector2 displaySize)
io.DisplaySize = displaySize;
io.DeltaTime = static_cast<float>(delta);

// if (!ctx->headless)
ctx->input->Update();

gdscache->OnNewFrame();
Expand All @@ -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();
Expand Down
8 changes: 3 additions & 5 deletions gdext/src/Context.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once

#pragma warning(push, 0)
#include <godot_cpp/classes/canvas_layer.hpp>
#include <godot_cpp/classes/display_server.hpp>
#include <godot_cpp/classes/engine.hpp>
Expand All @@ -19,16 +17,15 @@
#include <godot_cpp/variant/packed_byte_array.hpp>
#include <godot_cpp/variant/typed_array.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#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;
Expand Down Expand Up @@ -72,7 +69,8 @@ void Render();
void Shutdown();
void Connect(const Callable& callable);
void ResetFonts();
void AddFont(const Ref<FontFile>& fontFile, int fontSize, bool merge = false, const ImVector<ImWchar>& glyphRanges = {});
void AddFont(const Ref<FontFile>& fontFile, int fontSize, bool merge = false,
const ImVector<ImWchar>& glyphRanges = {});
void AddFontDefault();
void RebuildFontAtlas(float scale = 1.0f);
void SetIniFilename(const String& fn);
Expand Down
16 changes: 8 additions & 8 deletions gdext/src/ShortTermCache.cpp → gdext/src/GdsCache.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ShortTermCache.h"
#include "GdsCache.h"
#include <godot_cpp/variant/utility_functions.hpp>
#include <imgui.h>
#include <iterator>
Expand All @@ -9,9 +9,9 @@ using namespace godot;

namespace ImGui::Godot {

std::unique_ptr<ShortTermCache> gdscache = std::make_unique<ShortTermCache>();
std::unique_ptr<GdsCache> gdscache = std::make_unique<GdsCache>();

struct ShortTermCache::Impl
struct GdsCache::Impl
{
std::unordered_map<int64_t, std::vector<char>> bufs;
std::unordered_map<int64_t, bool> used;
Expand All @@ -27,15 +27,15 @@ struct ShortTermCache::Impl
}
};

ShortTermCache::ShortTermCache() : impl(std::make_unique<Impl>())
GdsCache::GdsCache() : impl(std::make_unique<Impl>())
{
}

ShortTermCache::~ShortTermCache()
GdsCache::~GdsCache()
{
}

void ShortTermCache::OnNewFrame()
void GdsCache::OnNewFrame()
{
for (auto it = impl->used.begin(); it != impl->used.end();)
{
Expand All @@ -52,7 +52,7 @@ void ShortTermCache::OnNewFrame()
}
}

std::vector<char>& ShortTermCache::GetTextBuf(const StringName& label, size_t size, const Array& a)
std::vector<char>& GdsCache::GetTextBuf(const StringName& label, size_t size, const Array& a)
{
int64_t hash = ImGui::GetID((void*)label.hash());
impl->used[hash] = true;
Expand All @@ -73,7 +73,7 @@ std::vector<char>& ShortTermCache::GetTextBuf(const StringName& label, size_t si
}
}

const std::vector<char>& ShortTermCache::GetZeroArray(const Array& a)
const std::vector<char>& GdsCache::GetZeroArray(const Array& a)
{
int64_t hash = a.hash();
impl->used[hash] = true;
Expand Down
12 changes: 4 additions & 8 deletions gdext/src/ShortTermCache.h → gdext/src/GdsCache.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#pragma once

#pragma warning(push, 0)
#include <godot_cpp/variant/variant.hpp>
#pragma warning(pop)

#include <memory>
#include <vector>

using namespace godot;

namespace ImGui::Godot {

class ShortTermCache
class GdsCache
{
public:
ShortTermCache();
~ShortTermCache();
GdsCache();
~GdsCache();

void OnNewFrame();
std::vector<char>& GetTextBuf(const StringName& label, size_t size, const Array& a);
Expand All @@ -26,6 +22,6 @@ class ShortTermCache
std::unique_ptr<Impl> impl;
};

extern std::unique_ptr<ShortTermCache> gdscache;
extern std::unique_ptr<GdsCache> gdscache;

} // namespace ImGui::Godot
3 changes: 0 additions & 3 deletions gdext/src/ImGuiAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "ImGuiAPI.h"

#pragma warning(push, 0)
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#pragma warning(pop)

using namespace godot;

Expand Down
7 changes: 1 addition & 6 deletions gdext/src/ImGuiAPI.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#pragma once

#pragma warning(push, 0)
#include "GdsCache.h"
#include <godot_cpp/classes/object.hpp>
#include <godot_cpp/classes/ref_counted.hpp>
#include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/variant/variant.hpp>
#pragma warning(pop)

#include <cimgui.h>
#include <memory>
#include <string_view>

#include "ShortTermCache.h"
#include "imgui_bindings.gen.h"

using namespace godot;
Expand Down
Loading

0 comments on commit 1ff8885

Please sign in to comment.