From a920e3f82178640ae501e99c752b3b4f10fa023d Mon Sep 17 00:00:00 2001 From: Patrick Dawson Date: Sat, 4 May 2024 01:24:48 +0200 Subject: [PATCH] Minor cleanup --- .clang-format | 1 + gdext/src/CanvasRenderer.h | 5 +--- gdext/src/Context.h | 9 -------- gdext/src/DummyRenderer.h | 39 +++++++------------------------- gdext/src/Fonts.h | 4 ++-- gdext/src/ImGuiAPI.cpp | 2 +- gdext/src/ImGuiAPI.h | 34 ++++++---------------------- gdext/src/RdRenderer.cpp | 1 - gdext/src/RdRenderer.h | 13 +++-------- gdext/src/RdRendererThreadSafe.h | 5 +--- gdext/src/Renderer.h | 13 +++-------- gdext/src/Viewports.h | 10 ++------ gdext/src/common.h | 5 +--- 13 files changed, 30 insertions(+), 111 deletions(-) diff --git a/.clang-format b/.clang-format index c6eaef45..d8664a56 100644 --- a/.clang-format +++ b/.clang-format @@ -7,6 +7,7 @@ AlwaysBreakTemplateDeclarations: Yes BinPackArguments: false BinPackParameters: true PointerAlignment: Left +AllowShortFunctionsOnASingleLine: InlineOnly BreakBeforeBraces: Custom BraceWrapping: diff --git a/gdext/src/CanvasRenderer.h b/gdext/src/CanvasRenderer.h index 0401f6a0..91e8a3c7 100644 --- a/gdext/src/CanvasRenderer.h +++ b/gdext/src/CanvasRenderer.h @@ -14,10 +14,7 @@ class CanvasRenderer : public Renderer CanvasRenderer(); virtual ~CanvasRenderer(); - virtual const char* Name() override - { - return "godot4_canvas"; - } + virtual const char* Name() override { return "godot4_canvas"; } bool Init() override; void InitViewport(RID vprid) override; diff --git a/gdext/src/Context.h b/gdext/src/Context.h index a33cb6df..ab2a9ffa 100644 --- a/gdext/src/Context.h +++ b/gdext/src/Context.h @@ -41,20 +41,12 @@ enum class RendererType struct Context { - // Window* mainWindow = nullptr; std::unique_ptr viewports; std::unique_ptr fonts; std::unique_ptr input; std::unique_ptr renderer; float scale = 1.0f; - // RID svp; - // RID ci; - // Ref fontTexture; - // bool headless = false; - // int dpiFactor = 1; - // bool scaleToDPI = false; - Context(Window* mainWindow, RID mainSubViewport, std::unique_ptr r); ~Context(); }; @@ -75,7 +67,6 @@ void AddFontDefault(); void RebuildFontAtlas(); void SetIniFilename(const String& fn); void SetVisible(bool visible); -bool IsVisible(); bool SubViewportWidget(SubViewport* svp); diff --git a/gdext/src/DummyRenderer.h b/gdext/src/DummyRenderer.h index 8b791d6b..77dbe83f 100644 --- a/gdext/src/DummyRenderer.h +++ b/gdext/src/DummyRenderer.h @@ -6,39 +6,16 @@ namespace ImGui::Godot { class DummyRenderer : public Renderer { public: - DummyRenderer() - { - } + DummyRenderer() {} + ~DummyRenderer() {} - ~DummyRenderer() - { - } + const char* Name() override { return "godot4_dummy"; } - const char* Name() override - { - return "godot4_dummy"; - } - - bool Init() override - { - return true; - } - - void InitViewport(RID vprid) override - { - } - - void CloseViewport(RID vprid) override - { - } - - void Render() override - { - } - - void OnHide() override - { - } + bool Init() override { return true; } + void InitViewport(RID vprid) override {} + void CloseViewport(RID vprid) override {} + void Render() override {} + void OnHide() override {} }; } // namespace ImGui::Godot diff --git a/gdext/src/Fonts.h b/gdext/src/Fonts.h index 21772b0b..86c4d291 100644 --- a/gdext/src/Fonts.h +++ b/gdext/src/Fonts.h @@ -1,7 +1,7 @@ #pragma once -#include -#include #include +#include +#include using namespace godot; namespace ImGui::Godot { diff --git a/gdext/src/ImGuiAPI.cpp b/gdext/src/ImGuiAPI.cpp index 826b74d3..853dcc6a 100644 --- a/gdext/src/ImGuiAPI.cpp +++ b/gdext/src/ImGuiAPI.cpp @@ -16,9 +16,9 @@ inline Color ToColor(ImVec4 v) return Color(v.x, v.y, v.z, v.w); } -std::unordered_map stringname_cache; const char* sn_to_cstr(const StringName& sn) { + static std::unordered_map stringname_cache; if (!stringname_cache.contains(sn)) { stringname_cache[sn] = std::string(String(sn).utf8().get_data()); diff --git a/gdext/src/ImGuiAPI.h b/gdext/src/ImGuiAPI.h index 6ff02724..8cfa7a37 100644 --- a/gdext/src/ImGuiAPI.h +++ b/gdext/src/ImGuiAPI.h @@ -29,15 +29,9 @@ struct GdsPtr val = arr[0]; } - ~GdsPtr() - { - arr[0] = val; - } + ~GdsPtr() { arr[0] = val; } - operator T*() - { - return &val; - } + operator T*() { return &val; } }; template <> @@ -60,10 +54,7 @@ struct GdsPtr } } - operator char*() - { - return buf.data(); - } + operator char*() { return buf.data(); } }; template @@ -88,10 +79,7 @@ struct GdsArray } } - operator T*() - { - return buf.data(); - } + operator T*() { return buf.data(); } }; template <> @@ -118,24 +106,16 @@ struct GdsArray } } - operator const char* const*() - { - return ptrs.data(); - } + operator const char* const*() { return ptrs.data(); } }; struct GdsZeroArray { const std::vector& buf; - GdsZeroArray(const Array& a) : buf(gdscache->GetZeroArray(a)) - { - } + GdsZeroArray(const Array& a) : buf(gdscache->GetZeroArray(a)) {} - operator const char*() - { - return buf.data(); - } + operator const char*() { return buf.data(); } }; #define VARIANT_CSTR(v) v.get_type() == Variant::STRING ? static_cast(v).utf8().get_data() : nullptr diff --git a/gdext/src/RdRenderer.cpp b/gdext/src/RdRenderer.cpp index ccc2df08..e4ecee0f 100644 --- a/gdext/src/RdRenderer.cpp +++ b/gdext/src/RdRenderer.cpp @@ -32,7 +32,6 @@ struct RdRenderer::Impl RID sampler; TypedArray srcBuffers; TypedArray uniforms; - // TypedArray storageTextures; godot::PackedColorArray clearColors; std::unordered_map framebuffers; diff --git a/gdext/src/RdRenderer.h b/gdext/src/RdRenderer.h index 6c2c778b..2a4ade66 100644 --- a/gdext/src/RdRenderer.h +++ b/gdext/src/RdRenderer.h @@ -14,20 +14,13 @@ class RdRenderer : public Renderer RdRenderer(); virtual ~RdRenderer(); - virtual const char* Name() override - { - return "godot4_rd"; - } + virtual const char* Name() override { return "godot4_rd"; } bool Init() override; void InitViewport(RID vprid) override; - void CloseViewport(RID vprid) override - { - } + void CloseViewport(RID vprid) override {} virtual void Render() override; - void OnHide() override - { - } + void OnHide() override {} protected: void Render(RID fb, ImDrawData* drawData); diff --git a/gdext/src/RdRendererThreadSafe.h b/gdext/src/RdRendererThreadSafe.h index 1890c54d..6e29fe23 100644 --- a/gdext/src/RdRendererThreadSafe.h +++ b/gdext/src/RdRendererThreadSafe.h @@ -14,10 +14,7 @@ class RdRendererThreadSafe : public RdRenderer RdRendererThreadSafe(); virtual ~RdRendererThreadSafe(); - const char* Name() override - { - return "godot4_rd_mt"; - } + const char* Name() override { return "godot4_rd_mt"; } void Render() override; void OnFramePreDraw() override; diff --git a/gdext/src/Renderer.h b/gdext/src/Renderer.h index 0fe4c894..c3e89d3d 100644 --- a/gdext/src/Renderer.h +++ b/gdext/src/Renderer.h @@ -10,13 +10,8 @@ namespace ImGui::Godot { class Renderer { public: - Renderer() - { - } - - virtual ~Renderer() - { - } + Renderer() {} + virtual ~Renderer() {} virtual const char* Name() = 0; @@ -25,9 +20,7 @@ class Renderer virtual void CloseViewport(RID vprid) = 0; virtual void Render() = 0; virtual void OnHide() = 0; - virtual void OnFramePreDraw() - { - } + virtual void OnFramePreDraw() {} }; } // namespace ImGui::Godot diff --git a/gdext/src/Viewports.h b/gdext/src/Viewports.h index 0cc4c5da..9f209066 100644 --- a/gdext/src/Viewports.h +++ b/gdext/src/Viewports.h @@ -29,15 +29,9 @@ class ImGuiWindow : public Window void _input(const Ref& evt) override; - void _close_requested() - { - _vp->PlatformRequestClose = true; - } + void _close_requested() { _vp->PlatformRequestClose = true; } - void _size_changed() - { - _vp->PlatformRequestResize = true; - } + void _size_changed() { _vp->PlatformRequestResize = true; } private: ImGuiViewport* _vp = nullptr; diff --git a/gdext/src/common.h b/gdext/src/common.h index cbebb5d1..0c0e8894 100644 --- a/gdext/src/common.h +++ b/gdext/src/common.h @@ -25,8 +25,5 @@ inline RID make_rid(ImTextureID id) template <> struct std::hash { - std::size_t operator()(const RID& rid) const noexcept - { - return std::hash{}(rid.get_id()); - } + std::size_t operator()(const RID& rid) const noexcept { return std::hash{}(rid.get_id()); } };