Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed May 3, 2024
1 parent 9b8b64f commit a920e3f
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 111 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: true
PointerAlignment: Left
AllowShortFunctionsOnASingleLine: InlineOnly

BreakBeforeBraces: Custom
BraceWrapping:
Expand Down
5 changes: 1 addition & 4 deletions gdext/src/CanvasRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions gdext/src/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,12 @@ enum class RendererType

struct Context
{
// Window* mainWindow = nullptr;
std::unique_ptr<Viewports> viewports;
std::unique_ptr<Fonts> fonts;
std::unique_ptr<Input> input;
std::unique_ptr<Renderer> renderer;
float scale = 1.0f;

// RID svp;
// RID ci;
// Ref<ImageTexture> fontTexture;
// bool headless = false;
// int dpiFactor = 1;
// bool scaleToDPI = false;

Context(Window* mainWindow, RID mainSubViewport, std::unique_ptr<Renderer> r);
~Context();
};
Expand All @@ -75,7 +67,6 @@ void AddFontDefault();
void RebuildFontAtlas();
void SetIniFilename(const String& fn);
void SetVisible(bool visible);
bool IsVisible();

bool SubViewportWidget(SubViewport* svp);

Expand Down
39 changes: 8 additions & 31 deletions gdext/src/DummyRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions gdext/src/Fonts.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <memory>
#include <imgui.h>
#include <godot_cpp/classes/font_file.hpp>
#include <imgui.h>
#include <memory>
using namespace godot;

namespace ImGui::Godot {
Expand Down
2 changes: 1 addition & 1 deletion gdext/src/ImGuiAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ inline Color ToColor(ImVec4 v)
return Color(v.x, v.y, v.z, v.w);
}

std::unordered_map<StringName, std::string> stringname_cache;
const char* sn_to_cstr(const StringName& sn)
{
static std::unordered_map<StringName, std::string> stringname_cache;
if (!stringname_cache.contains(sn))
{
stringname_cache[sn] = std::string(String(sn).utf8().get_data());
Expand Down
34 changes: 7 additions & 27 deletions gdext/src/ImGuiAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <>
Expand All @@ -60,10 +54,7 @@ struct GdsPtr<String>
}
}

operator char*()
{
return buf.data();
}
operator char*() { return buf.data(); }
};

template <class T>
Expand All @@ -88,10 +79,7 @@ struct GdsArray
}
}

operator T*()
{
return buf.data();
}
operator T*() { return buf.data(); }
};

template <>
Expand All @@ -118,24 +106,16 @@ struct GdsArray<const char* const>
}
}

operator const char* const*()
{
return ptrs.data();
}
operator const char* const*() { return ptrs.data(); }
};

struct GdsZeroArray
{
const std::vector<char>& 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<String>(v).utf8().get_data() : nullptr
Expand Down
1 change: 0 additions & 1 deletion gdext/src/RdRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct RdRenderer::Impl
RID sampler;
TypedArray<RID> srcBuffers;
TypedArray<RDUniform> uniforms;
// TypedArray<RID> storageTextures;
godot::PackedColorArray clearColors;

std::unordered_map<RID, RID> framebuffers;
Expand Down
13 changes: 3 additions & 10 deletions gdext/src/RdRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions gdext/src/RdRendererThreadSafe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 3 additions & 10 deletions gdext/src/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ namespace ImGui::Godot {
class Renderer
{
public:
Renderer()
{
}

virtual ~Renderer()
{
}
Renderer() {}
virtual ~Renderer() {}

virtual const char* Name() = 0;

Expand All @@ -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
10 changes: 2 additions & 8 deletions gdext/src/Viewports.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@ class ImGuiWindow : public Window

void _input(const Ref<InputEvent>& 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;
Expand Down
5 changes: 1 addition & 4 deletions gdext/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ inline RID make_rid(ImTextureID id)
template <>
struct std::hash<RID>
{
std::size_t operator()(const RID& rid) const noexcept
{
return std::hash<int64_t>{}(rid.get_id());
}
std::size_t operator()(const RID& rid) const noexcept { return std::hash<int64_t>{}(rid.get_id()); }
};

0 comments on commit a920e3f

Please sign in to comment.