all repos — mgba @ 65d74a2e3465cda20832621c217f56744fd6d6d9

mGBA Game Boy Advance Emulator

Qt: Discard log levels without cross-thread communication if we can
Jeffrey Pfau jeffrey@endrift.com
Thu, 27 Nov 2014 01:23:25 -0800
commit

65d74a2e3465cda20832621c217f56744fd6d6d9

parent

467fbcf54d0942b2732aec8c6643f2616bb0174b

M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -20,6 +20,7 @@ : 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 @@ };

m_threadContext.logHandler = [] (GBAThread* context, enum GBALogLevel level, const char* format, va_list args) { GameController* controller = static_cast<GameController*>(context->userData); + if (!(controller->m_logLevels & level)) { + return; + } controller->postLog(level, QString().vsprintf(format, args)); };

@@ -338,6 +342,24 @@ #ifdef BUILD_SDL

activeKeys |= m_activeButtons; #endif 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
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -85,6 +85,10 @@ void setTurbo(bool, bool forced = true);

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 @@ uint32_t* m_drawContext;

GBAThread m_threadContext; GBAVideoSoftwareRenderer* m_renderer; int m_activeKeys; + int m_logLevels; bool m_gameOpen; bool m_dirmode;
M src/platform/qt/LogView.cppsrc/platform/qt/LogView.cpp

@@ -19,7 +19,7 @@ connect(m_ui.levelGameError, SIGNAL(toggled(bool)), this, SLOT(setLevelGameError(bool)));

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 @@ m_ui.levelError->setCheckState(levels & GBA_LOG_ERROR ? Qt::Checked : Qt::Unchecked);

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) {

@@ -144,6 +146,16 @@ case GBA_LOG_SWI:

return tr("SWI"); } 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() {
M src/platform/qt/LogView.hsrc/platform/qt/LogView.h

@@ -17,6 +17,11 @@

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 @@ int m_lines;

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(); };
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -67,12 +67,17 @@ });

#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())); connect(this, SIGNAL(shutdown()), m_logView, SLOT(hide())); 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()); }