Skip to content

Commit

Permalink
fix #5977
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed May 8, 2018
1 parent e5979d1 commit eadbdbc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
24 changes: 13 additions & 11 deletions rts/Game/UI/InfoConsole.cpp
Expand Up @@ -170,34 +170,36 @@ int CInfoConsole::GetRawLines(std::deque<RawLine>& lines)
{
std::lock_guard<spring::recursive_mutex> 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<spring::recursive_mutex> 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<std::string> lines = std::move(smallFont->SplitIntoLines(toustring(wrappedText)));
std::deque<std::string> lines = std::move(smallFont->SplitIntoLines(unicodeText));

for (auto& line: lines) {
// add the line to the console
Expand Down
5 changes: 4 additions & 1 deletion rts/Game/UI/InfoConsole.h
Expand Up @@ -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");
Expand Down Expand Up @@ -70,6 +70,9 @@ class CInfoConsole: public CInputReceiver, public CEventClient, public ILogSink
std::deque<RawLine> rawData;
std::deque<InfoLine> data;

std::string prvSection;
std::string prvMessage;

spring::recursive_mutex infoConsoleMutex;

size_t maxLines = 1;
Expand Down
8 changes: 1 addition & 7 deletions rts/System/Log/LogSinkHandler.cpp
Expand Up @@ -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);
}
Expand Down
11 changes: 3 additions & 8 deletions rts/System/Log/LogSinkHandler.h
Expand Up @@ -4,7 +4,7 @@
#define LOG_SINK_HANDLER_H

#include <string>
#include <set>
#include "System/UnorderedSet.hpp"


/**
Expand All @@ -23,8 +23,6 @@ class ILogSink {
*/
class LogSinkHandler {
public:
LogSinkHandler(): sinking(true) {}

static LogSinkHandler& GetInstance() {
static LogSinkHandler lsh;
return lsh;
Expand Down Expand Up @@ -52,15 +50,12 @@ class LogSinkHandler {
void RecordLogMessage(int level, const std::string& section, const std::string& text);

private:
std::set<ILogSink*> sinks;

std::string prvSection;
std::string prvMessage;
spring::unsynced_set<ILogSink*> sinks;

/**
* Whether log records are passed on to registered sinks, or dismissed.
*/
bool sinking;
bool sinking = true;
};

#define logSinkHandler (LogSinkHandler::GetInstance())
Expand Down
2 changes: 1 addition & 1 deletion rts/System/Sound/OpenAL/Sound.cpp
Expand Up @@ -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
}

Expand Down

0 comments on commit eadbdbc

Please sign in to comment.