diff --git a/gdext/src/Context.cpp b/gdext/src/Context.cpp index 56307b0..d8032ac 100644 --- a/gdext/src/Context.cpp +++ b/gdext/src/Context.cpp @@ -50,7 +50,7 @@ void Init(const Ref& cfg) RenderingServer* RS = RenderingServer::get_singleton(); ProjectSettings* PS = ProjectSettings::get_singleton(); - RendererType rendererType; + RendererType rendererType = RendererType::Dummy; String rendererName = cfg->get("Renderer"); if (rendererName == "Dummy") @@ -68,7 +68,7 @@ void Init(const Ref& cfg) rendererType = RendererType::Canvas; // there's no way to get the actual current thread model, eg if --render-thread is used - int threadModel = PS->get_setting("rendering/driver/threads/thread_model"); + const int threadModel = PS->get_setting("rendering/driver/threads/thread_model"); std::unique_ptr renderer; switch (rendererType) @@ -110,8 +110,8 @@ void Init(const Ref& cfg) { Ref fontres = fonts[i]; Ref fontData = fontres->get("FontData"); - int fontSize = fontres->get("FontSize"); - bool merge = fontres->get("Merge"); + const int fontSize = fontres->get("FontSize"); + const bool merge = fontres->get("Merge"); if (i == 0) AddFont(fontData, fontSize); else @@ -178,8 +178,8 @@ void RebuildFontAtlas() ERR_FAIL_COND(!ctx); ERR_FAIL_COND(ctx->inProcessFrame); - bool scaleToDpi = ProjectSettings::get_singleton()->get_setting("display/window/dpi/allow_hidpi"); - int dpiFactor = std::max(1, DisplayServer::get_singleton()->screen_get_dpi() / 96); + const bool scaleToDpi = ProjectSettings::get_singleton()->get_setting("display/window/dpi/allow_hidpi"); + const int dpiFactor = std::max(1, DisplayServer::get_singleton()->screen_get_dpi() / 96); ctx->fonts->RebuildFontAtlas(scaleToDpi ? dpiFactor * ctx->scale : ctx->scale); } @@ -200,9 +200,9 @@ void SetIniFilename(const String& fn) bool SubViewportWidget(SubViewport* svp) { - ImVec2 vpSize = svp->get_size(); - ImVec2 pos = ImGui::GetCursorScreenPos(); - ImVec2 pos_max = {pos.x + vpSize.x, pos.y + vpSize.y}; + const ImVec2 vpSize = svp->get_size(); + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const ImVec2 pos_max = {pos.x + vpSize.x, pos.y + vpSize.y}; ImGui::GetWindowDrawList()->AddImage((ImTextureID)svp->get_texture()->get_rid().get_id(), pos, pos_max); ImGui::PushID(svp->get_instance_id()); diff --git a/gdext/src/Fonts.cpp b/gdext/src/Fonts.cpp index 8e1fc43..f92dcfc 100644 --- a/gdext/src/Fonts.cpp +++ b/gdext/src/Fonts.cpp @@ -43,7 +43,7 @@ struct Fonts::Impl static void ResetStyle() { - ImGuiStyle defaultStyle; + const ImGuiStyle defaultStyle; ImGuiStyle& style = ImGui::GetStyle(); style.WindowPadding = defaultStyle.WindowPadding; @@ -79,7 +79,7 @@ struct Fonts::Impl void Fonts::Impl::AddFontToAtlas(const FontParams& fp, float scale) { auto& io = ImGui::GetIO(); - int fontSize = fp.fontSize * scale; + const int fontSize = fp.fontSize * scale; ImFontConfig fc; if (fp.merge) @@ -106,7 +106,7 @@ void Fonts::Impl::AddFontToAtlas(const FontParams& fp, float scale) std::copy(fontdesc.begin(), fontdesc.end(), fc.Name); fc.Name[fontdesc.length()] = '\0'; - int64_t len = fp.font->get_data().size(); + const int64_t len = fp.font->get_data().size(); // let ImGui manage this memory void* p = ImGui::MemAlloc(len); memcpy(p, fp.font->get_data().ptr(), len); diff --git a/gdext/src/GdsCache.cpp b/gdext/src/GdsCache.cpp index 9d3c05e..25b4131 100644 --- a/gdext/src/GdsCache.cpp +++ b/gdext/src/GdsCache.cpp @@ -19,7 +19,7 @@ struct GdsCache::Impl static void CopyInput(std::vector& buf, const Array& a) { CharString cs = String(a[0]).utf8(); - std::string_view sv = cs.get_data(); + const std::string_view sv = cs.get_data(); if (sv.size() >= buf.size()) return; std::copy(sv.begin(), sv.end(), buf.begin()); @@ -54,7 +54,7 @@ void GdsCache::OnNewFrame() std::vector& GdsCache::GetTextBuf(const StringName& label, size_t size, const Array& a) { - int64_t hash = ImGui::GetID((void*)label.hash()); + const int64_t hash = ImGui::GetID((void*)label.hash()); impl->used[hash] = true; auto it = impl->bufs.find(hash); if (it == impl->bufs.end()) @@ -75,7 +75,7 @@ std::vector& GdsCache::GetTextBuf(const StringName& label, size_t size, co const std::vector& GdsCache::GetZeroArray(const Array& a) { - int64_t hash = a.hash(); + const int64_t hash = a.hash(); impl->used[hash] = true; if (auto it = impl->bufs.find(hash); it != impl->bufs.end()) { @@ -87,7 +87,7 @@ const std::vector& GdsCache::GetZeroArray(const Array& a) for (int i = 0; i < a.size(); ++i) { CharString cs = String(a[i]).utf8(); - std::string_view sv = cs.get_data(); + const std::string_view sv = cs.get_data(); std::copy(sv.begin(), sv.end(), std::back_inserter(buf)); buf.push_back('\0'); } diff --git a/gdext/src/ImGuiController.cpp b/gdext/src/ImGuiController.cpp index 1d3f0dd..6d2d278 100644 --- a/gdext/src/ImGuiController.cpp +++ b/gdext/src/ImGuiController.cpp @@ -17,7 +17,7 @@ ImGuiController* instance = nullptr; struct ImGuiController::Impl { - Window* window; + Window* window = nullptr; ImGuiControllerHelper* helper = nullptr; void CheckContentScale() const; @@ -168,7 +168,8 @@ void ImGuiController::SetMainViewport(Viewport* vp) add_child(newLayer); else vp->add_child(newLayer); - ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport; + ImGui::GetIO().BackendFlags |= + ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport; } else { diff --git a/gdext/src/ImGuiLayer.cpp b/gdext/src/ImGuiLayer.cpp index 3d61ba0..1fe2703 100644 --- a/gdext/src/ImGuiLayer.cpp +++ b/gdext/src/ImGuiLayer.cpp @@ -117,7 +117,7 @@ void ImGuiLayer::UpdateViewport() vpSize = Object::cast_to(impl->parentViewport)->get_size(); GetContext()->viewportSize = vpSize; - Transform2D ft = impl->parentViewport->get_final_transform(); + const Transform2D ft = impl->parentViewport->get_final_transform(); if (impl->subViewportSize != vpSize || impl->finalTransform != ft @@ -133,7 +133,7 @@ void ImGuiLayer::UpdateViewport() RenderingServer* RS = RenderingServer::get_singleton(); RS->viewport_set_size(impl->subViewportRid, impl->subViewportSize.x, impl->subViewportSize.y); - RID vptex = RS->viewport_get_texture(impl->subViewportRid); + const RID vptex = RS->viewport_get_texture(impl->subViewportRid); RS->canvas_item_clear(impl->canvasItem); RS->canvas_item_set_transform(impl->canvasItem, ft.affine_inverse()); RS->canvas_item_add_texture_rect(impl->canvasItem, diff --git a/gdext/src/Input.cpp b/gdext/src/Input.cpp index d15b033..0200a0d 100644 --- a/gdext/src/Input.cpp +++ b/gdext/src/Input.cpp @@ -27,7 +27,7 @@ struct Input::Impl Vector2 currentSubViewportPos; Vector2 mouseWheel; ImGuiMouseCursor currentCursor = ImGuiMouseCursor_None; - bool hasMouse; + bool hasMouse = false; }; namespace { diff --git a/gdext/src/RdRenderer.cpp b/gdext/src/RdRenderer.cpp index cb6ead4..a21be0f 100644 --- a/gdext/src/RdRenderer.cpp +++ b/gdext/src/RdRenderer.cpp @@ -61,7 +61,7 @@ RID RdRenderer::GetFramebuffer(RID vprid) if (!vprid.is_valid()) return RID(); - RenderingServer* RS = RenderingServer::get_singleton(); + const RenderingServer* RS = RenderingServer::get_singleton(); RenderingDevice* RD = RS->get_rendering_device(); auto it = impl->framebuffers.find(vprid); if (it != impl->framebuffers.end()) @@ -71,7 +71,7 @@ RID RdRenderer::GetFramebuffer(RID vprid) return fb; } - RID vptex = RS->texture_get_rd_texture(RS->viewport_get_texture(vprid)); + const RID vptex = RS->texture_get_rd_texture(RS->viewport_get_texture(vprid)); godot::TypedArray arr; arr.push_back(vptex); RID fb = RD->framebuffer_create(arr); @@ -86,11 +86,11 @@ void RdRenderer::Impl::SetupBuffers(ImDrawData* drawData) int globalIdxOffset = 0; int globalVtxOffset = 0; - int idxBufSize = drawData->TotalIdxCount * sizeof(ImDrawIdx); + const int idxBufSize = drawData->TotalIdxCount * sizeof(ImDrawIdx); godot::PackedByteArray idxBuf; idxBuf.resize(idxBufSize); - int vertBufSize = drawData->TotalVtxCount * sizeof(ImDrawVert); + const int vertBufSize = drawData->TotalVtxCount * sizeof(ImDrawVert); godot::PackedByteArray vertBuf; vertBuf.resize(vertBufSize); @@ -112,10 +112,10 @@ void RdRenderer::Impl::SetupBuffers(ImDrawData* drawData) for (int cmdi = 0; cmdi < cmdList->CmdBuffer.Size; ++cmdi) { const ImDrawCmd& drawCmd = cmdList->CmdBuffer[cmdi]; - ImTextureID texid = drawCmd.GetTexID(); + const ImTextureID texid = drawCmd.GetTexID(); if (!texid) continue; - RID texrid = make_rid(texid); + const RID texrid = make_rid(texid); if (!RD->texture_is_valid(texrid)) continue; @@ -212,7 +212,7 @@ bool RdRenderer::Init() TypedArray afs; afs.push_back(af); - int64_t fb_format = RD->framebuffer_format_create(afs); + const int64_t fb_format = RD->framebuffer_format_create(afs); impl->pipeline = RD->render_pipeline_create(impl->shader, fb_format, @@ -280,12 +280,12 @@ void RdRenderer::Render(RID fb, ImDrawData* drawData) impl->SetupBuffers(drawData); // draw - int64_t dl = RD->draw_list_begin(fb, - RenderingDevice::INITIAL_ACTION_CLEAR, - RenderingDevice::FINAL_ACTION_READ, - RenderingDevice::INITIAL_ACTION_CLEAR, - RenderingDevice::FINAL_ACTION_READ, - impl->clearColors); + const int64_t dl = RD->draw_list_begin(fb, + RenderingDevice::INITIAL_ACTION_CLEAR, + RenderingDevice::FINAL_ACTION_READ, + RenderingDevice::INITIAL_ACTION_CLEAR, + RenderingDevice::FINAL_ACTION_READ, + impl->clearColors); RD->draw_list_bind_render_pipeline(dl, impl->pipeline); RD->draw_list_set_push_constant(dl, pcbuf, pcbuf.size()); @@ -298,19 +298,19 @@ void RdRenderer::Render(RID fb, ImDrawData* drawData) for (int cmdi = 0; cmdi < cmdList->CmdBuffer.Size; ++cmdi) { - ImDrawCmd& drawCmd = cmdList->CmdBuffer[cmdi]; + const ImDrawCmd& drawCmd = cmdList->CmdBuffer[cmdi]; if (drawCmd.ElemCount == 0) continue; if (!impl->uniformSets.contains(drawCmd.GetTexID())) continue; - RID idxArray = + const RID idxArray = RD->index_array_create(impl->idxBuffer, drawCmd.IdxOffset + globalIdxOffset, drawCmd.ElemCount); - int64_t voff = (drawCmd.VtxOffset + globalVtxOffset) * sizeof(ImDrawVert); + const int64_t voff = (drawCmd.VtxOffset + globalVtxOffset) * sizeof(ImDrawVert); impl->srcBuffers[0] = impl->srcBuffers[1] = impl->srcBuffers[2] = impl->vtxBuffer; impl->vtxOffsets[0] = impl->vtxOffsets[1] = impl->vtxOffsets[2] = voff; - RID vtxArray = + const RID vtxArray = RD->vertex_array_create(cmdList->VtxBuffer.Size, impl->vtxFormat, impl->srcBuffers, impl->vtxOffsets); RD->draw_list_bind_uniform_set(dl, impl->uniformSets[drawCmd.GetTexID()], 0); @@ -380,7 +380,7 @@ void RdRenderer::Render() if (!(vp->Flags & ImGuiViewportFlags_IsMinimized)) { ReplaceTextureRIDs(vp->DrawData); - RID vprid = make_rid(vp->RendererUserData); + const RID vprid = make_rid(vp->RendererUserData); Render(GetFramebuffer(vprid), vp->DrawData); } } @@ -389,7 +389,7 @@ void RdRenderer::Render() void RdRenderer::ReplaceTextureRIDs(ImDrawData* drawData) { - RenderingServer* RS = RenderingServer::get_singleton(); + const RenderingServer* RS = RenderingServer::get_singleton(); for (int i = 0; i < drawData->CmdListsCount; ++i) { ImDrawList* cmdList = drawData->CmdLists[i]; diff --git a/gdext/src/RdRendererThreadSafe.cpp b/gdext/src/RdRendererThreadSafe.cpp index 6c6eca1..d0568dd 100644 --- a/gdext/src/RdRendererThreadSafe.cpp +++ b/gdext/src/RdRendererThreadSafe.cpp @@ -53,7 +53,8 @@ struct RdRendererThreadSafe::Impl RdRendererThreadSafe::RdRendererThreadSafe() : impl(std::make_unique()) { RenderingServer* RS = RenderingServer::get_singleton(); - RS->connect("frame_pre_draw", Callable(Engine::get_singleton()->get_singleton("ImGuiController"), "on_frame_pre_draw")); + RS->connect("frame_pre_draw", + Callable(Engine::get_singleton()->get_singleton("ImGuiController"), "on_frame_pre_draw")); } RdRendererThreadSafe::~RdRendererThreadSafe() diff --git a/gdext/src/Viewports.cpp b/gdext/src/Viewports.cpp index 5fe1292..90ac048 100644 --- a/gdext/src/Viewports.cpp +++ b/gdext/src/Viewports.cpp @@ -40,7 +40,7 @@ static void Godot_CreateWindow(ImGuiViewport* vp) } } - Rect2i winRect = Rect2i(vp->Pos, vp->Size); + const Rect2i winRect = Rect2i(vp->Pos, vp->Size); ImGuiWindow* igwin = memnew(ImGuiWindow); igwin->init(vp); @@ -60,7 +60,7 @@ static void Godot_CreateWindow(ImGuiViewport* vp) vd->window->set_flag(Window::FLAG_TRANSPARENT, true); // it's our window, so just draw directly to the root viewport - RID vprid = vd->window->get_viewport_rid(); + const RID vprid = vd->window->get_viewport_rid(); vp->RendererUserData = (void*)vprid.get_id(); int32_t windowID = vd->window->get_window_id(); @@ -163,8 +163,8 @@ void Viewports::Impl::InitPlatformInterface() void Viewports::Impl::UpdateMonitors() { auto& pio = ImGui::GetPlatformIO(); - DisplayServer* DS = DisplayServer::get_singleton(); - int screenCount = DS->get_screen_count(); + const DisplayServer* DS = DisplayServer::get_singleton(); + const int screenCount = DS->get_screen_count(); pio.Monitors.resize(0); for (int i = 0; i < screenCount; ++i) @@ -174,7 +174,7 @@ void Viewports::Impl::UpdateMonitors() monitor.MainSize = DS->screen_get_size(i); monitor.DpiScale = DS->screen_get_scale(i); - Rect2i rect = DS->screen_get_usable_rect(i); + const Rect2i rect = DS->screen_get_usable_rect(i); monitor.WorkPos = rect.position; monitor.WorkSize = rect.size; @@ -198,7 +198,6 @@ void Viewports::Impl::UpdateMonitors() Viewports::Viewports() : impl(std::make_unique()) { - auto& io = ImGui::GetIO(); impl->InitPlatformInterface(); impl->UpdateMonitors(); } diff --git a/gdext/src/main.cpp b/gdext/src/main.cpp index 1f37d4e..de4b5c4 100644 --- a/gdext/src/main.cpp +++ b/gdext/src/main.cpp @@ -81,7 +81,8 @@ void initialize_ign_module(ModuleInitializationLevel p_level) if (!ProjectSettings::get_singleton()->has_setting("autoload/ImGuiRoot")) { - UtilityFunctions::push_warning("[imgui-godot] Plugin is not enabled. If you call ImGui methods, your project will crash!"); + UtilityFunctions::push_warning( + "[imgui-godot] Plugin is not enabled. If you call ImGui methods, your project will crash!"); } }