mirror of https://github.com/mgba-emu/mgba.git
Qt: Discard log levels without cross-thread communication if we can
This commit is contained in:
parent
467fbcf54d
commit
65d74a2e34
|
@ -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<GameController*>(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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue