From 65d74a2e3465cda20832621c217f56744fd6d6d9 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 27 Nov 2014 01:23:25 -0800 Subject: [PATCH] Qt: Discard log levels without cross-thread communication if we can --- src/platform/qt/GameController.cpp | 22 ++++++++++++++++++++++ src/platform/qt/GameController.h | 5 +++++ src/platform/qt/LogView.cpp | 14 +++++++++++++- src/platform/qt/LogView.h | 9 +++++++-- src/platform/qt/Window.cpp | 5 +++++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 2233e5922..7f3eaaf2e 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -20,6 +20,7 @@ GameController::GameController(QObject* parent) , m_drawContext(new uint32_t[256 * 256]) , m_threadContext() , m_activeKeys(0) + , m_logLevels(0) , m_gameOpen(false) , m_audioThread(new QThread(this)) , m_audioProcessor(AudioProcessor::create()) @@ -67,6 +68,9 @@ GameController::GameController(QObject* parent) m_threadContext.logHandler = [] (GBAThread* context, enum GBALogLevel level, const char* format, va_list args) { GameController* controller = static_cast(context->userData); + if (!(controller->m_logLevels & level)) { + return; + } controller->postLog(level, QString().vsprintf(format, args)); }; @@ -340,6 +344,24 @@ void GameController::updateKeys() { m_threadContext.activeKeys = activeKeys; } +void GameController::setLogLevel(int levels) { + threadInterrupt(); + m_logLevels = levels; + threadContinue(); +} + +void GameController::enableLogLevel(int levels) { + threadInterrupt(); + m_logLevels |= levels; + threadContinue(); +} + +void GameController::disableLogLevel(int levels) { + threadInterrupt(); + m_logLevels &= ~levels; + threadContinue(); +} + #ifdef BUILD_SDL void GameController::testSDLEvents() { if (!m_inputController) { diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index 5a097950b..2015ef3a0 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -85,6 +85,10 @@ public slots: void setAVStream(GBAAVStream*); void clearAVStream(); + void setLogLevel(int); + void enableLogLevel(int); + void disableLogLevel(int); + #ifdef BUILD_SDL private slots: void testSDLEvents(); @@ -101,6 +105,7 @@ private: GBAThread m_threadContext; GBAVideoSoftwareRenderer* m_renderer; int m_activeKeys; + int m_logLevels; bool m_gameOpen; bool m_dirmode; diff --git a/src/platform/qt/LogView.cpp b/src/platform/qt/LogView.cpp index 4763132bd..01808e442 100644 --- a/src/platform/qt/LogView.cpp +++ b/src/platform/qt/LogView.cpp @@ -19,7 +19,7 @@ LogView::LogView(QWidget* parent) connect(m_ui.levelSWI, SIGNAL(toggled(bool)), this, SLOT(setLevelSWI(bool))); connect(m_ui.clear, SIGNAL(clicked()), this, SLOT(clear())); connect(m_ui.maxLines, SIGNAL(valueChanged(int)), this, SLOT(setMaxLines(int))); - m_logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL; + m_logLevel = 0; m_lines = 0; m_ui.maxLines->setValue(DEFAULT_LINE_LIMIT); } @@ -51,6 +51,8 @@ void LogView::setLevels(int levels) { m_ui.levelFatal->setCheckState(levels & GBA_LOG_FATAL ? Qt::Checked : Qt::Unchecked); m_ui.levelGameError->setCheckState(levels & GBA_LOG_GAME_ERROR ? Qt::Checked : Qt::Unchecked); m_ui.levelSWI->setCheckState(levels & GBA_LOG_SWI ? Qt::Checked : Qt::Unchecked); + + emit levelsSet(levels); } void LogView::setLevelDebug(bool set) { @@ -146,6 +148,16 @@ QString LogView::toString(int level) { return QString(); } +void LogView::setLevel(int level) { + m_logLevel |= level; + emit levelsEnabled(level); +} + +void LogView::clearLevel(int level) { + m_logLevel &= ~level; + emit levelsDisabled(level); +} + void LogView::clearLine() { QTextCursor cursor(m_ui.view->document()); cursor.setPosition(0); diff --git a/src/platform/qt/LogView.h b/src/platform/qt/LogView.h index b372e7344..5c5ed70a9 100644 --- a/src/platform/qt/LogView.h +++ b/src/platform/qt/LogView.h @@ -17,6 +17,11 @@ Q_OBJECT public: LogView(QWidget* parent = nullptr); +signals: + void levelsSet(int levels); + void levelsEnabled(int levels); + void levelsDisabled(int levels); + public slots: void postLog(int level, const QString& log); void setLevels(int levels); @@ -42,8 +47,8 @@ private: int m_lineLimit; static QString toString(int level); - void setLevel(int level) { m_logLevel |= level; } - void clearLevel(int level) { m_logLevel &= ~level; } + void setLevel(int level); + void clearLevel(int level); void clearLine(); }; diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index c9e4bdc7f..fb00702c0 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -67,6 +67,9 @@ Window::Window(ConfigController* config, QWidget* parent) #endif connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), m_display, SLOT(unpauseDrawing())); connect(m_controller, SIGNAL(postLog(int, const QString&)), m_logView, SLOT(postLog(int, const QString&))); + connect(m_logView, SIGNAL(levelsSet(int)), m_controller, SLOT(setLogLevel(int))); + connect(m_logView, SIGNAL(levelsEnabled(int)), m_controller, SLOT(enableLogLevel(int))); + connect(m_logView, SIGNAL(levelsDisabled(int)), m_controller, SLOT(disableLogLevel(int))); connect(this, SIGNAL(startDrawing(const uint32_t*, GBAThread*)), m_display, SLOT(startDrawing(const uint32_t*, GBAThread*)), Qt::QueuedConnection); connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing())); connect(this, SIGNAL(shutdown()), m_controller, SLOT(closeGame())); @@ -74,6 +77,8 @@ Window::Window(ConfigController* config, QWidget* parent) connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int))); connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); + m_logView->setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL); + setupMenu(menuBar()); }