diff --git a/rts/Game/UI/InfoConsole.cpp b/rts/Game/UI/InfoConsole.cpp index 5a808167ced..0b18fd9d792 100644 --- a/rts/Game/UI/InfoConsole.cpp +++ b/rts/Game/UI/InfoConsole.cpp @@ -170,34 +170,36 @@ int CInfoConsole::GetRawLines(std::deque& lines) { std::lock_guard scoped_lock(infoConsoleMutex); lines = rawData; - const int tmp = newLines; + const int numNewLines = newLines; newLines = 0; - return tmp; + return numNewLines; } -void CInfoConsole::RecordLogMessage(int level, const std::string& section, const std::string& text) +void CInfoConsole::RecordLogMessage(int level, const std::string& section, const std::string& message) { std::lock_guard scoped_lock(infoConsoleMutex); + if (section == prvSection && message == prvMessage) + return; + + newLines += (newLines < maxRawLines); + if (rawData.size() > maxRawLines) rawData.pop_front(); - if (newLines < maxRawLines) - ++newLines; + rawData.emplace_back(prvMessage = message, prvSection = section, level, rawId++); - rawData.emplace_back(text, section, level, rawId++); - - if (!smallFont) + if (smallFont == nullptr) return; // NOTE // do not remove elements from `data` here, ::Draw iterates over it // and can call LOG() which will end up back in ::RecordLogMessage - const float maxWidth = (width * globalRendering->viewSizeX) - (2 * border); - const std::string& wrappedText = smallFont->Wrap(text, fontSize, maxWidth); + const std::string& wrappedText = smallFont->Wrap(message, fontSize, (width * globalRendering->viewSizeX) - (2 * border)); + const std::u8string& unicodeText = toustring(wrappedText); - std::deque lines = std::move(smallFont->SplitIntoLines(toustring(wrappedText))); + std::deque lines = std::move(smallFont->SplitIntoLines(unicodeText)); for (auto& line: lines) { // add the line to the console diff --git a/rts/Game/UI/InfoConsole.h b/rts/Game/UI/InfoConsole.h index 38d8311ee0e..8f93ad77324 100644 --- a/rts/Game/UI/InfoConsole.h +++ b/rts/Game/UI/InfoConsole.h @@ -30,7 +30,7 @@ class CInfoConsole: public CInputReceiver, public CEventClient, public ILogSink void Draw() override; void PushNewLinesToEventHandler(); - void RecordLogMessage(int level, const std::string& section, const std::string& text) override; + void RecordLogMessage(int level, const std::string& section, const std::string& message) override; bool WantsEvent(const std::string& eventName) override { return (eventName == "LastMessagePosition"); @@ -70,6 +70,9 @@ class CInfoConsole: public CInputReceiver, public CEventClient, public ILogSink std::deque rawData; std::deque data; + std::string prvSection; + std::string prvMessage; + spring::recursive_mutex infoConsoleMutex; size_t maxLines = 1; diff --git a/rts/System/Log/LogSinkHandler.cpp b/rts/System/Log/LogSinkHandler.cpp index 4dd40c7d6e7..313086b416d 100644 --- a/rts/System/Log/LogSinkHandler.cpp +++ b/rts/System/Log/LogSinkHandler.cpp @@ -43,13 +43,7 @@ void LogSinkHandler::RecordLogMessage( if (!sinking) return; - if (section == prvSection && message == prvMessage) - return; - - prvSection = section; - prvMessage = message; - - // forward to clients + // forward to clients (currently only InfoConsole) for (ILogSink* sink: sinks) { sink->RecordLogMessage(level, section, message); } diff --git a/rts/System/Log/LogSinkHandler.h b/rts/System/Log/LogSinkHandler.h index 5483c205559..f67cb5f29d8 100644 --- a/rts/System/Log/LogSinkHandler.h +++ b/rts/System/Log/LogSinkHandler.h @@ -4,7 +4,7 @@ #define LOG_SINK_HANDLER_H #include -#include +#include "System/UnorderedSet.hpp" /** @@ -23,8 +23,6 @@ class ILogSink { */ class LogSinkHandler { public: - LogSinkHandler(): sinking(true) {} - static LogSinkHandler& GetInstance() { static LogSinkHandler lsh; return lsh; @@ -52,15 +50,12 @@ class LogSinkHandler { void RecordLogMessage(int level, const std::string& section, const std::string& text); private: - std::set sinks; - - std::string prvSection; - std::string prvMessage; + spring::unsynced_set sinks; /** * Whether log records are passed on to registered sinks, or dismissed. */ - bool sinking; + bool sinking = true; }; #define logSinkHandler (LogSinkHandler::GetInstance()) diff --git a/rts/System/Sound/OpenAL/Sound.cpp b/rts/System/Sound/OpenAL/Sound.cpp index 11a3de39887..e757de1e8c8 100644 --- a/rts/System/Sound/OpenAL/Sound.cpp +++ b/rts/System/Sound/OpenAL/Sound.cpp @@ -532,7 +532,7 @@ void CSound::OpenLoopbackDevice(const std::string& deviceName) return; } - LOG("[Sound::%s] device=%p context=%p channels=%d frames=%d", __func__, curDevice, curContext, obtainedSpec.channels, frameSize); + LOG("[Sound::%s] device=%p context=%p numChannels=%d frameSize=%d", __func__, curDevice, curContext, obtainedSpec.channels, frameSize); #endif }