From 44e097e88cc2b741a75ce78ee80b893d510b0d64 Mon Sep 17 00:00:00 2001 From: Xawotihs Date: Tue, 19 Oct 2010 22:09:16 +0000 Subject: [PATCH] reduced framerate to 30 fps, stopped refreshing the UI when the window is hidden or when the screen is off. --- JGE/src/Qtmain.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/JGE/src/Qtmain.cpp b/JGE/src/Qtmain.cpp index 3b4868d59..1a9da00fe 100644 --- a/JGE/src/Qtmain.cpp +++ b/JGE/src/Qtmain.cpp @@ -3,9 +3,18 @@ #include #ifdef Q_WS_MAEMO_5 +// For volume buttons support #include #include #include + +// For screen on/off events support +#include +#include +#include +#include +#include + #endif //Q_WS_MAEMO_5 #include "../include/JGE.h" @@ -24,6 +33,17 @@ class JGEQtRenderer : public QGLWidget public: JGEQtRenderer(QWidget *parent); + virtual ~JGEQtRenderer(){ +#ifdef Q_WS_MAEMO_5 + delete dBusInterface; +#endif //Q_WS_MAEMO_5 + }; + +#ifdef Q_WS_MAEMO_5 +public slots: + void displayStateChanged(const QDBusMessage &message); +#endif //Q_WS_MAEMO_5 + protected: void initializeGL(); @@ -48,6 +68,10 @@ protected: void wheelEvent(QWheelEvent *event); + void showEvent ( QShowEvent * event ); + + void hideEvent ( QHideEvent * event ); + #ifdef Q_WS_MAEMO_5 void grabZoomKeys(bool grab) { @@ -75,10 +99,15 @@ protected: } #endif //Q_WS_MAEMO_5 - protected: QPoint lastPos; + int timerId; + bool timerStarted; +#ifdef Q_WS_MAEMO_5 + QDBusConnection dBusConnection; + QDBusInterface* dBusInterface; +#endif //Q_WS_MAEMO_5 }; uint64_t lastTickCount; @@ -163,8 +192,12 @@ void DestroyGame(void) JGEQtRenderer::JGEQtRenderer(QWidget *parent) : QGLWidget(parent) /* Seems to go faster without double buffering */ + , timerStarted(false) +#ifdef Q_WS_MAEMO_5 + , dBusConnection(QDBusConnection::systemBus()) +#endif //Q_WS_MAEMO_5 { - startTimer( 5 ); +// startTimer( 33 ); // 30 fps should be more than enough setWindowTitle(g_launcher->GetName()); #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5AutoOrientation); @@ -176,8 +209,30 @@ JGEQtRenderer::JGEQtRenderer(QWidget *parent) grabGesture(Qt::PanGesture); grabGesture(Qt::PinchGesture); grabGesture(Qt::SwipeGesture); + +#ifdef Q_WS_MAEMO_5 + dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, dBusConnection); + + // Handle screen state on / off + dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &))); +#endif } +#ifdef Q_WS_MAEMO_5 +void JGEQtRenderer::displayStateChanged(const QDBusMessage &message) +{ + QString state = message.arguments().at(0).toString(); + if (!state.isEmpty()) { + if (state == MCE_DISPLAY_ON_STRING) { + showEvent(0); + } + else if (state == MCE_DISPLAY_OFF_STRING) { + hideEvent(0); + } + } +} +#endif void JGEQtRenderer::initializeGL() { @@ -429,6 +484,24 @@ void JGEQtRenderer::keyPressEvent(QKeyEvent *event) return; } +void JGEQtRenderer::showEvent ( QShowEvent * event ) +{ + if(!timerStarted) + { + timerId = startTimer(33); + timerStarted = true; + } +} + +void JGEQtRenderer::hideEvent ( QHideEvent * event ) +{ + if(timerStarted) + { + killTimer(timerId); + timerStarted = false; + } +} + void JGEQtRenderer::keyReleaseEvent(QKeyEvent *event) { g_engine->ReleaseKey((LocalKeySym)event->key());