From 99b057438fdc2188999ab7e7b7d6254d9967eaa5 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:43:43 +0100 Subject: [PATCH] More fixes for console * Fix 'ClearAutoComplete' getting called recursively for some single operations. * Fix unnecessary mutex lock. --- r5dev/gameui/IConsole.cpp | 56 +++++++++++++++------------------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index d661c323..ee8ad5b1 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -282,6 +282,20 @@ void CConsole::DrawSurface(void) ImGui::Separator(); + std::function fnHandleInput = [&](void) + { + if (m_szInputBuf[0]) + { + ProcessCommand(m_szInputBuf); + ClearAutoComplete(); + + m_bModifyInput = true; + } + + BuildSummary(); + m_bReclaimFocus = true; + }; + /////////////////////////////////////////////////////////////////////// ImGui::PushItemWidth(flFooterWidthReserve - 80); if (ImGui::InputText("##input", m_szInputBuf, IM_ARRAYSIZE(m_szInputBuf), m_nInputFlags, &TextEditCallbackStub, reinterpret_cast(this))) @@ -289,25 +303,14 @@ void CConsole::DrawSurface(void) if (m_nSuggestPos > -1) { BuildInputFromSelected(m_vSuggest[m_nSuggestPos], m_svInputConVar); - m_bModifyInput = true; - - ClearAutoComplete(); - m_bReclaimFocus = true; - BuildSummary(m_svInputConVar); + + m_bModifyInput = true; + m_bReclaimFocus = true; } else { - if (m_szInputBuf[0]) - { - ProcessCommand(m_szInputBuf); - m_bModifyInput = true; - } - - ClearAutoComplete(); - m_bReclaimFocus = true; - - BuildSummary(); + fnHandleInput(); } } @@ -326,15 +329,7 @@ void CConsole::DrawSurface(void) ImGui::SameLine(); if (ImGui::Button("Submit")) { - if (m_szInputBuf[0]) - { - ProcessCommand(m_szInputBuf); - m_bModifyInput = true; - } - ClearAutoComplete(); - m_bReclaimFocus = true; - - BuildSummary(); + fnHandleInput(); } ImGui::End(); } @@ -441,19 +436,14 @@ void CConsole::SuggestPanel(void) if (ImGui::Selectable(suggest.m_svName.c_str(), bIsIndexActive)) { ImGui::Separator(); - string svConVar; - BuildInputFromSelected(suggest, svConVar); + BuildInputFromSelected(suggest, svConVar); memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1); - ClearAutoComplete(); m_bCanAutoComplete = true; m_bReclaimFocus = true; - // Mutex lock is obtained here are we modify m_vHistory - // which is used in the main and render thread. - std::lock_guard l(m_Mutex); BuildSummary(svConVar); } ImGui::PopID(); @@ -696,8 +686,7 @@ void CConsole::BuildSummary(string svConVar) return; } } - // Display amount of history items if ConVar cannot be found or input is empty. - ClampHistorySize(); + snprintf(m_szSummary, sizeof(m_szSummary), "%zu history items", m_vHistory.size()); } @@ -982,8 +971,6 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData) iData->InsertChars(0, m_svInputConVar.c_str()); m_svInputConVar.clear(); - ClearAutoComplete(); - m_bCanAutoComplete = true; m_bReclaimFocus = true; } @@ -1027,7 +1014,6 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData) } else // Reset state and enable history scrolling when buffer is empty. { - ResetAutoComplete(); m_bCanAutoComplete = false; }