diff --git a/r5dev/gameui/IBrowser.h b/r5dev/gameui/IBrowser.h index 7e5c2f7e..b9a3752b 100644 --- a/r5dev/gameui/IBrowser.h +++ b/r5dev/gameui/IBrowser.h @@ -16,6 +16,8 @@ public: virtual void Think(void); virtual void RunFrame(void); + virtual void RunTask(void){}; + virtual void DrawSurface(void); void BrowserPanel(void); diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index e759a593..84cdb9d3 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -139,25 +139,32 @@ void CConsole::RunFrame(void) } //----------------------------------------------------------------------------- -// Purpose: runs tasks for the console while not being drawn +// Purpose: runs tasks for the console while not being drawn +// (!!! RunTask and RunFrame must be called from the same thread !!!) +//----------------------------------------------------------------------------- +void CConsole::RunTask() +{ + if (m_Logger.GetTotalLines() > con_max_size_logvector->GetInt()) + { + while (m_Logger.GetTotalLines() > con_max_size_logvector->GetInt()) + { + m_Logger.RemoveLine(0); + m_nScrollBack++; + m_nSelectBack++; + } + m_Logger.MoveSelection(m_nSelectBack, false); + m_Logger.MoveCursor(m_nSelectBack, false); + m_nSelectBack = 0; + } +} + +//----------------------------------------------------------------------------- +// Purpose: think //----------------------------------------------------------------------------- void CConsole::Think(void) { for (;;) // Loop running at 100-tps. { - if (m_Logger.GetTotalLines() > con_max_size_logvector->GetInt()) - { - while (m_Logger.GetTotalLines() > con_max_size_logvector->GetInt()) - { - m_Logger.RemoveLine(0); - m_nScrollBack++; - m_nSelectBack++; - } - m_Logger.MoveSelection(m_nSelectBack, false); - m_Logger.MoveCursor(m_nSelectBack, false); - m_nSelectBack = 0; - } - while (m_vHistory.size() > 512) { m_vHistory.erase(m_vHistory.begin()); diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index 3319dcf0..719e5e52 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -16,6 +16,8 @@ public: virtual void Think(void); virtual void RunFrame(void); + virtual void RunTask(void); + virtual void DrawSurface(void); void OptionsPanel(void); diff --git a/r5dev/public/isurfacesystem.h b/r5dev/public/isurfacesystem.h index ab531206..83fd18ab 100644 --- a/r5dev/public/isurfacesystem.h +++ b/r5dev/public/isurfacesystem.h @@ -8,6 +8,7 @@ public: virtual bool Init() = 0; virtual void Think() = 0; virtual void RunFrame() = 0; + virtual void RunTask() = 0; virtual void DrawSurface() = 0; virtual void SetStyleVar() = 0; }; diff --git a/r5dev/thirdparty/imgui/include/imgui_logger.h b/r5dev/thirdparty/imgui/include/imgui_logger.h index d60158d2..83101710 100644 --- a/r5dev/thirdparty/imgui/include/imgui_logger.h +++ b/r5dev/thirdparty/imgui/include/imgui_logger.h @@ -165,8 +165,8 @@ public: bool HasSelection() const; void MoveSelection(int aLines, bool aForward = true); - void RemoveLine(int aStart, int aEnd, bool aInternal = false); - void RemoveLine(int aIndex, bool aInternal = false); + void RemoveLine(int aStart, int aEnd); + void RemoveLine(int aIndex); private: struct LoggerState_t @@ -229,7 +229,6 @@ private: Lines m_Lines; LoggerState_t m_State; - std::mutex m_Mutex; std::string m_svLineBuffer; public: ImGuiTextFilter m_itFilter; diff --git a/r5dev/thirdparty/imgui/src/imgui_logger.cpp b/r5dev/thirdparty/imgui/src/imgui_logger.cpp index 373e2444..99238006 100644 --- a/r5dev/thirdparty/imgui/src/imgui_logger.cpp +++ b/r5dev/thirdparty/imgui/src/imgui_logger.cpp @@ -494,33 +494,21 @@ bool CTextLogger::IsOnWordBoundary(const Coordinates & aAt) const return isspace(line[cindex].m_Char) != isspace(line[cindex - 1].m_Char); } -void CTextLogger::RemoveLine(int aStart, int aEnd, bool aInternal) +void CTextLogger::RemoveLine(int aStart, int aEnd) { - if (!aInternal) - m_Mutex.lock(); - assert(aEnd >= aStart); assert(m_Lines.size() > (size_t)(aEnd - aStart)); m_Lines.erase(m_Lines.begin() + aStart, m_Lines.begin() + aEnd); assert(!m_Lines.empty()); - - if (!aInternal) - m_Mutex.unlock(); } -void CTextLogger::RemoveLine(int aIndex, bool aInternal) +void CTextLogger::RemoveLine(int aIndex) { - if (!aInternal) - m_Mutex.lock(); - assert(m_Lines.size() > 1); m_Lines.erase(m_Lines.begin() + aIndex); assert(!m_Lines.empty()); - - if (!aInternal) - m_Mutex.unlock(); } CTextLogger::Line& CTextLogger::InsertLine(int aIndex) @@ -689,8 +677,6 @@ void CTextLogger::HandleMouseInputs(bool bHoveredScrollbar, bool bActiveScrollba void CTextLogger::Render() { - m_Mutex.lock(); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f)); ImGuiWindow* pWindow = ImGui::GetCurrentWindow(); @@ -880,7 +866,6 @@ void CTextLogger::Render() ImGui::PopAllowKeyboardFocus(); ImGui::PopStyleVar(); - m_Mutex.unlock(); } void CTextLogger::Copy(bool aCopyAll) @@ -1047,8 +1032,6 @@ void CTextLogger::SetTabSize(int aValue) void CTextLogger::InsertText(const ConLog_t & aValue) { - m_Mutex.lock(); - if (!aValue.m_svConLog.empty()) { Coordinates pos = GetActualLastLineCoordinates(); @@ -1058,8 +1041,6 @@ void CTextLogger::InsertText(const ConLog_t & aValue) totalLines += InsertTextAt(pos, aValue.m_svConLog.c_str(), aValue.m_imColor); } - - m_Mutex.unlock(); } void CTextLogger::MoveUp(int aAmount, bool aSelect) diff --git a/r5dev/windows/id3dx.cpp b/r5dev/windows/id3dx.cpp index e832f4c8..47b7755e 100644 --- a/r5dev/windows/id3dx.cpp +++ b/r5dev/windows/id3dx.cpp @@ -273,6 +273,9 @@ void DrawImGui() ImGui::NewFrame(); + g_pBrowser->RunTask(); + g_pConsole->RunTask(); + if (g_pBrowser->m_bActivate) { g_pInputSystem->EnableInput(false); // Disable input to game when browser is drawn.