Qt: Status messages

This commit is contained in:
Jeffrey Pfau 2015-04-26 15:00:15 -07:00
parent 91ee44c458
commit 6ebef8dc16
9 changed files with 117 additions and 40 deletions

View File

@ -12,6 +12,7 @@ Features:
- Analog inputs can be used for shortcuts - Analog inputs can be used for shortcuts
- Menu items for specific solar sensor brightness levels - Menu items for specific solar sensor brightness levels
- Remappable controls for tilt and gyroscope sensors - Remappable controls for tilt and gyroscope sensors
- Status messages for actions taken while a game is running (e.g. save/load state)
Bugfixes: Bugfixes:
- GBA: Fix timers not updating timing when writing to only the reload register - GBA: Fix timers not updating timing when writing to only the reload register
- All: Fix sanitize-deb script not cleaning up after itself - All: Fix sanitize-deb script not cleaning up after itself

View File

@ -109,7 +109,7 @@ ConfigController::ConfigController(QObject* parent)
m_opts.fpsTarget = 60; m_opts.fpsTarget = 60;
m_opts.audioBuffers = 2048; m_opts.audioBuffers = 2048;
m_opts.volume = GBA_AUDIO_VOLUME_MAX; m_opts.volume = GBA_AUDIO_VOLUME_MAX;
m_opts.logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL; m_opts.logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS;
m_opts.rewindEnable = false; m_opts.rewindEnable = false;
m_opts.rewindBufferInterval = 0; m_opts.rewindBufferInterval = 0;
m_opts.rewindBufferCapacity = 0; m_opts.rewindBufferCapacity = 0;

View File

@ -27,6 +27,8 @@ public slots:
virtual void lockAspectRatio(bool lock) = 0; virtual void lockAspectRatio(bool lock) = 0;
virtual void filter(bool filter) = 0; virtual void filter(bool filter) = 0;
virtual void framePosted(const uint32_t*) = 0; virtual void framePosted(const uint32_t*) = 0;
virtual void showMessage(const QString& message) = 0;
}; };
} }

View File

@ -51,7 +51,6 @@ void DisplayGL::startDrawing(GBAThread* thread) {
m_context = thread; m_context = thread;
m_painter->resize(size()); m_painter->resize(size());
m_gl->move(0, 0); m_gl->move(0, 0);
m_gl->resize(size());
m_drawThread = new QThread(this); m_drawThread = new QThread(this);
m_gl->context()->doneCurrent(); m_gl->context()->doneCurrent();
m_gl->context()->moveToThread(m_drawThread); m_gl->context()->moveToThread(m_drawThread);
@ -61,6 +60,7 @@ void DisplayGL::startDrawing(GBAThread* thread) {
lockAspectRatio(m_lockAspectRatio); lockAspectRatio(m_lockAspectRatio);
filter(m_filter); filter(m_filter);
resizePainter();
} }
void DisplayGL::stopDrawing() { void DisplayGL::stopDrawing() {
@ -133,20 +133,39 @@ void DisplayGL::framePosted(const uint32_t* buffer) {
} }
} }
void DisplayGL::resizeEvent(QResizeEvent* event) { void DisplayGL::showMessage(const QString& message) {
if (m_drawThread) {
QMetaObject::invokeMethod(m_painter, "showMessage", Q_ARG(const QString&, message));
}
}
void DisplayGL::resizeEvent(QResizeEvent*) {
resizePainter();
}
void DisplayGL::resizePainter() {
m_gl->resize(size()); m_gl->resize(size());
if (m_drawThread) { if (m_drawThread) {
QMetaObject::invokeMethod(m_painter, "resize", Qt::BlockingQueuedConnection, Q_ARG(QSize, event->size())); QMetaObject::invokeMethod(m_painter, "resize", Qt::BlockingQueuedConnection, Q_ARG(QSize, size()));
} }
} }
PainterGL::PainterGL(QGLWidget* parent) PainterGL::PainterGL(QGLWidget* parent)
: m_gl(parent) : m_gl(parent)
, m_drawTimer(nullptr) , m_drawTimer(nullptr)
, m_messageTimer(this)
, m_lockAspectRatio(false) , m_lockAspectRatio(false)
, m_filter(false) , m_filter(false)
, m_context(nullptr) , m_context(nullptr)
{ {
m_messageFont.setFamily("Source Code Pro");
m_messageFont.setStyleHint(QFont::Monospace);
m_messageFont.setPixelSize(6);
connect(&m_messageTimer, SIGNAL(timeout()), this, SLOT(clearMessage()));
m_messageTimer.setSingleShot(true);
m_messageTimer.setInterval(5000);
clearMessage();
} }
void PainterGL::setContext(GBAThread* context) { void PainterGL::setContext(GBAThread* context) {
@ -155,6 +174,7 @@ void PainterGL::setContext(GBAThread* context) {
void PainterGL::setBacking(const uint32_t* backing) { void PainterGL::setBacking(const uint32_t* backing) {
m_gl->makeCurrent(); m_gl->makeCurrent();
glBindTexture(GL_TEXTURE_2D, m_tex);
#ifdef COLOR_16_BIT #ifdef COLOR_16_BIT
#ifdef COLOR_5_6_5 #ifdef COLOR_5_6_5
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, backing); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, backing);
@ -169,9 +189,30 @@ void PainterGL::setBacking(const uint32_t* backing) {
void PainterGL::resize(const QSize& size) { void PainterGL::resize(const QSize& size) {
m_size = size; m_size = size;
int w = m_size.width() * m_gl->devicePixelRatio();
int h = m_size.height() *m_gl->devicePixelRatio();
int drawW = w;
int drawH = h;
if (m_lockAspectRatio) {
if (w * 2 > h * 3) {
drawW = h * 3 / 2;
} else if (w * 2 < h * 3) {
drawH = w * 2 / 3;
}
}
m_viewport = QRect((w - drawW) / 2, (h - drawH) / 2, drawW, drawH);
m_painter.begin(m_gl->context()->device());
m_world = QTransform(
qreal(drawW) / VIDEO_HORIZONTAL_PIXELS, 0,
0, qreal(drawH) / VIDEO_VERTICAL_PIXELS,
m_viewport.x() / 2,
m_viewport.y() / 2);
m_painter.setWorldTransform(m_world);
m_painter.setFont(m_messageFont);
m_message.prepare(m_world, m_messageFont);
m_painter.end();
if (m_drawTimer) { if (m_drawTimer) {
forceDraw(); forceDraw();
forceDraw();
} }
} }
@ -179,7 +220,6 @@ void PainterGL::lockAspectRatio(bool lock) {
m_lockAspectRatio = lock; m_lockAspectRatio = lock;
if (m_drawTimer) { if (m_drawTimer) {
forceDraw(); forceDraw();
forceDraw();
} }
} }
@ -213,9 +253,6 @@ void PainterGL::start() {
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_INT, 0, _glVertices); glVertexPointer(2, GL_INT, 0, _glVertices);
glTexCoordPointer(2, GL_INT, 0, _glTexCoords); glTexCoordPointer(2, GL_INT, 0, _glTexCoords);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 240, 160, 0, 0, 1);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glClearColor(0, 0, 0, 0); glClearColor(0, 0, 0, 0);
@ -230,21 +267,21 @@ void PainterGL::start() {
} }
void PainterGL::draw() { void PainterGL::draw() {
m_gl->makeCurrent();
GBASyncWaitFrameStart(&m_context->sync, m_context->frameskip); GBASyncWaitFrameStart(&m_context->sync, m_context->frameskip);
m_painter.begin(m_gl->context()->device());
m_painter.setWorldTransform(m_world);
performDraw(); performDraw();
m_painter.end();
GBASyncWaitFrameEnd(&m_context->sync); GBASyncWaitFrameEnd(&m_context->sync);
m_gl->swapBuffers(); m_gl->swapBuffers();
m_gl->doneCurrent();
} }
void PainterGL::forceDraw() { void PainterGL::forceDraw() {
m_gl->makeCurrent(); m_painter.begin(m_gl->context()->device());
glViewport(0, 0, m_size.width() * m_gl->devicePixelRatio(), m_size.height() * m_gl->devicePixelRatio()); m_painter.setWorldTransform(m_world);
glClear(GL_COLOR_BUFFER_BIT);
performDraw(); performDraw();
m_painter.end();
m_gl->swapBuffers(); m_gl->swapBuffers();
m_gl->doneCurrent();
} }
void PainterGL::stop() { void PainterGL::stop() {
@ -253,6 +290,7 @@ void PainterGL::stop() {
m_drawTimer = nullptr; m_drawTimer = nullptr;
m_gl->makeCurrent(); m_gl->makeCurrent();
glDeleteTextures(1, &m_tex); glDeleteTextures(1, &m_tex);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
m_gl->swapBuffers(); m_gl->swapBuffers();
m_gl->doneCurrent(); m_gl->doneCurrent();
@ -272,26 +310,42 @@ void PainterGL::unpause() {
} }
void PainterGL::performDraw() { void PainterGL::performDraw() {
int w = m_size.width() * m_gl->devicePixelRatio(); m_painter.beginNativePainting();
int h = m_size.height() *m_gl->devicePixelRatio(); glMatrixMode(GL_PROJECTION);
#ifndef Q_OS_MAC glLoadIdentity();
// TODO: This seems to cause framerates to drag down to 120 FPS on OS X, glOrtho(0, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, 0, 0, 1);
// even if the emulator can go faster. Look into why. glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, m_size.width() * m_gl->devicePixelRatio(), m_size.height() * m_gl->devicePixelRatio()); glViewport(0, 0, m_size.width() * m_gl->devicePixelRatio(), m_size.height() * m_gl->devicePixelRatio());
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
#endif glViewport(m_viewport.x(), m_viewport.y(), m_viewport.width(), m_viewport.height());
int drawW = w;
int drawH = h;
if (m_lockAspectRatio) {
if (w * 2 > h * 3) {
drawW = h * 3 / 2;
} else if (w * 2 < h * 3) {
drawH = w * 2 / 3;
}
}
glViewport((w - drawW) / 2, (h - drawH) / 2, drawW, drawH);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
if (m_context->sync.videoFrameWait) { if (m_context->sync.videoFrameWait) {
glFlush(); glFlush();
} }
m_painter.endNativePainting();
m_painter.setRenderHint(QPainter::Antialiasing);
m_painter.setFont(m_messageFont);
m_painter.setPen(Qt::black);
m_painter.translate(1, 72);
for (int i = 0; i < 16; ++i) {
m_painter.save();
m_painter.translate(cos(i * M_PI / 8.0) * 0.4, sin(i * M_PI / 8.0) * 0.4);
m_painter.drawStaticText(0, 0, m_message);
m_painter.restore();
}
m_painter.setPen(Qt::white);
m_painter.drawStaticText(0, 0, m_message);
}
void PainterGL::showMessage(const QString& message) {
m_message.setText(message);
m_message.prepare(m_world, m_messageFont);
m_messageTimer.stop();
m_messageTimer.start();
}
void PainterGL::clearMessage() {
m_message.setText(QString());
} }

View File

@ -9,6 +9,7 @@
#include "Display.h" #include "Display.h"
#include <QGLWidget> #include <QGLWidget>
#include <QStaticText>
#include <QThread> #include <QThread>
#include <QTimer> #include <QTimer>
@ -18,7 +19,7 @@ namespace QGBA {
class EmptyGLWidget : public QGLWidget { class EmptyGLWidget : public QGLWidget {
public: public:
EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) {} EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
protected: protected:
void paintEvent(QPaintEvent*) override {} void paintEvent(QPaintEvent*) override {}
@ -43,14 +44,15 @@ public slots:
void filter(bool filter) override; void filter(bool filter) override;
void framePosted(const uint32_t*) override; void framePosted(const uint32_t*) override;
void showMessage(const QString& message) override;
protected: protected:
virtual void paintEvent(QPaintEvent*) override { virtual void paintEvent(QPaintEvent*) override {}
QPainter paint(this);
paint.fillRect(QRect(QPoint(), size()), Qt::black);
};
virtual void resizeEvent(QResizeEvent*) override; virtual void resizeEvent(QResizeEvent*) override;
private: private:
void resizePainter();
QGLWidget* m_gl; QGLWidget* m_gl;
PainterGL* m_painter; PainterGL* m_painter;
QThread* m_drawThread; QThread* m_drawThread;
@ -79,17 +81,26 @@ public slots:
void lockAspectRatio(bool lock); void lockAspectRatio(bool lock);
void filter(bool filter); void filter(bool filter);
void showMessage(const QString& message);
void clearMessage();
private: private:
void performDraw(); void performDraw();
QPainter m_painter;
QStaticText m_message;
QGLWidget* m_gl; QGLWidget* m_gl;
QThread* m_thread; QThread* m_thread;
QTimer* m_drawTimer; QTimer* m_drawTimer;
QTimer m_messageTimer;
GBAThread* m_context; GBAThread* m_context;
GLuint m_tex; GLuint m_tex;
QSize m_size; QSize m_size;
bool m_lockAspectRatio; bool m_lockAspectRatio;
bool m_filter; bool m_filter;
QRect m_viewport;
QTransform m_world;
QFont m_messageFont;
}; };
} }

View File

@ -31,6 +31,8 @@ public slots:
void filter(bool filter) override; void filter(bool filter) override;
void framePosted(const uint32_t*) override; void framePosted(const uint32_t*) override;
void showMessage(const QString& message) override {};
protected: protected:
virtual void paintEvent(QPaintEvent*) override; virtual void paintEvent(QPaintEvent*) override;

View File

@ -94,8 +94,6 @@ GameController::GameController(QObject* parent)
m_threadContext.startCallback = [] (GBAThread* context) { m_threadContext.startCallback = [] (GBAThread* context) {
GameController* controller = static_cast<GameController*>(context->userData); GameController* controller = static_cast<GameController*>(context->userData);
controller->m_audioProcessor->setInput(context); controller->m_audioProcessor->setInput(context);
// Override the GBA object's log level to prevent stdout spew
context->gba->logLevel = GBA_LOG_FATAL;
context->gba->luminanceSource = &controller->m_lux; context->gba->luminanceSource = &controller->m_lux;
context->gba->rtcSource = &controller->m_rtc; context->gba->rtcSource = &controller->m_rtc;
#ifdef BUILD_SDL #ifdef BUILD_SDL
@ -128,6 +126,9 @@ GameController::GameController(QObject* parent)
m_threadContext.logHandler = [] (GBAThread* context, enum GBALogLevel level, const char* format, va_list args) { m_threadContext.logHandler = [] (GBAThread* context, enum GBALogLevel level, const char* format, va_list args) {
static const char* stubMessage = "Stub software interrupt"; static const char* stubMessage = "Stub software interrupt";
if (!context) {
return;
}
GameController* controller = static_cast<GameController*>(context->userData); GameController* controller = static_cast<GameController*>(context->userData);
if (level == GBA_LOG_STUB && strncmp(stubMessage, format, strlen(stubMessage)) == 0) { if (level == GBA_LOG_STUB && strncmp(stubMessage, format, strlen(stubMessage)) == 0) {
va_list argc; va_list argc;
@ -140,7 +141,11 @@ GameController::GameController(QObject* parent)
} else if (!(controller->m_logLevels & level)) { } else if (!(controller->m_logLevels & level)) {
return; return;
} }
controller->postLog(level, QString().vsprintf(format, args)); QString message(QString().vsprintf(format, args));
if (level == GBA_LOG_STATUS) {
controller->statusPosted(message);
}
controller->postLog(level, message);
}; };
m_audioThread->start(QThread::TimeCriticalPriority); m_audioThread->start(QThread::TimeCriticalPriority);

View File

@ -90,6 +90,7 @@ signals:
void luminanceValueChanged(int); void luminanceValueChanged(int);
void statusPosted(const QString& message);
void postLog(int level, const QString& log); void postLog(int level, const QString& log);
public slots: public slots:

View File

@ -108,6 +108,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
connect(m_controller, SIGNAL(gameCrashed(const QString&)), this, SLOT(gameCrashed(const QString&))); connect(m_controller, SIGNAL(gameCrashed(const QString&)), this, SLOT(gameCrashed(const QString&)));
connect(m_controller, SIGNAL(gameFailed()), this, SLOT(gameFailed())); connect(m_controller, SIGNAL(gameFailed()), this, SLOT(gameFailed()));
connect(m_controller, SIGNAL(unimplementedBiosCall(int)), this, SLOT(unimplementedBiosCall(int))); connect(m_controller, SIGNAL(unimplementedBiosCall(int)), this, SLOT(unimplementedBiosCall(int)));
connect(m_controller, SIGNAL(statusPosted(const QString&)), m_display, SLOT(showMessage(const QString&)));
connect(m_logView, SIGNAL(levelsSet(int)), m_controller, SLOT(setLogLevel(int))); 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(levelsEnabled(int)), m_controller, SLOT(enableLogLevel(int)));
connect(m_logView, SIGNAL(levelsDisabled(int)), m_controller, SLOT(disableLogLevel(int))); connect(m_logView, SIGNAL(levelsDisabled(int)), m_controller, SLOT(disableLogLevel(int)));
@ -119,7 +120,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float)));
connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS())); connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS()));
m_logView->setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL); m_logView->setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS);
m_fpsTimer.setInterval(FPS_TIMER_INTERVAL); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL);
m_shortcutController->setConfigController(m_config); m_shortcutController->setConfigController(m_config);