From 597be2bb04e71157de520e432485f297b5b56f75 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Fri, 11 Jan 2013 23:00:33 +0100 Subject: [PATCH] Update native for Qt Window Add mutex lock. Wait cond didn't work without it. --- base/NativeApp.h | 1 + base/QtMain.cpp | 36 +++++++++++++++++++++++++++++++++++- base/QtMain.h | 12 ++++++++++-- base/mutex.h | 8 +++++--- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/base/NativeApp.h b/base/NativeApp.h index 677568c075..ea46683736 100644 --- a/base/NativeApp.h +++ b/base/NativeApp.h @@ -61,6 +61,7 @@ void NativeRender(); // of num_samples. // This function may be called from a totally separate thread from // the rest of the game, so be careful with synchronization. +void NativeSetMixer(void* mix); void NativeMix(short *audio, int num_samples); // Called when it's time to shutdown. After this has been called, diff --git a/base/QtMain.cpp b/base/QtMain.cpp index 469eb4135f..a3448ccc0f 100644 --- a/base/QtMain.cpp +++ b/base/QtMain.cpp @@ -15,6 +15,16 @@ #endif #include "QtMain.h" +#ifdef LINUX +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "qtapp.h" +#ifdef Q_WS_X11 +#include +#endif +MainWindow* qMW; +#endif + void LaunchBrowser(const char *url) { QDesktopServices::openUrl(QUrl(url)); @@ -52,11 +62,23 @@ float CalculateDPIScale() int main(int argc, char *argv[]) { +#ifdef LINUX +#ifdef Q_WS_X11 + XInitThreads(); +#endif +#endif QApplication a(argc, argv); // Lock orientation to landscape on Symbian #ifdef __SYMBIAN32__ QT_TRAP_THROWING(dynamic_cast(CEikonEnv::Static()->AppUi())->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape)); #endif +#ifdef LINUX + pixel_xres = 480; + pixel_yres = 272; + + float dpi_scale = 1; + dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale); +#else QSize res = QApplication::desktop()->screenGeometry().size(); #ifdef USING_GLES2 if (res.width() < res.height()) @@ -70,21 +92,33 @@ int main(int argc, char *argv[]) #endif float dpi_scale = CalculateDPIScale(); dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale); +#endif + net::Init(); + #ifdef __SYMBIAN32__ NativeInit(argc, (const char **)argv, "E:/PPSSPP/", "E:", "BADCOFFEE"); #elif defined(BLACKBERRY) NativeInit(argc, (const char **)argv, "data/", "/tmp", "BADCOFFEE"); -#else +#elif !defined(LINUX) NativeInit(argc, (const char **)argv, "./", "/tmp", "BADCOFFEE"); +#else + MainWindow mainWindow; + qMW = &mainWindow; + mainWindow.show(); + mainWindow.Create(argc, (const char **)argv, "./", "/tmp", "BADCOFFEE"); #endif +#ifdef LINUX +#else MainUI w(dpi_scale); w.resize(pixel_xres, pixel_yres); #ifdef USING_GLES2 w.showFullScreen(); #else w.show(); +#endif + #endif MainAudio *audio = new MainAudio(); diff --git a/base/QtMain.h b/base/QtMain.h index 4c47054504..c4365ca484 100644 --- a/base/QtMain.h +++ b/base/QtMain.h @@ -5,6 +5,7 @@ #include #include "gfx_es2/glsl_program.h" #include +#include #include #include @@ -88,7 +89,7 @@ protected: break; } } - break; + break; case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: input_state.pointer_down[0] = (e->type() == QEvent::MouseButtonPress); @@ -161,16 +162,23 @@ public: output = new QAudioOutput(fmt); output->setNotifyInterval(1000*AUDIO_SAMPLES / AUDIO_FREQ); output->setBufferSize(mixlen); - this->connect(output, SIGNAL(notify()), this, SLOT(writeData())); feed = output->start(); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(writeData())); + timer->start(1000*AUDIO_SAMPLES / AUDIO_FREQ); + } ~MainAudio() { + feed->close(); delete feed; + output->stop(); delete output; free(mixbuf); } private slots: + void writeData() { memset(mixbuf, 0, mixlen); NativeMix((short *)mixbuf, mixlen / 4); diff --git a/base/mutex.h b/base/mutex.h index 59594ae883..53f8534fe3 100644 --- a/base/mutex.h +++ b/base/mutex.h @@ -115,7 +115,7 @@ public: #ifdef _WIN32 SetEvent(event_); #else - pthread_cond_signal(&event_); + pthread_cond_signal(&event_); #endif } @@ -129,7 +129,9 @@ public: ResetEvent(event_); // necessary? // mtx.lock(); #else - pthread_cond_wait(&event_, &mtx.native_handle()); + pthread_mutex_lock( &mtx.native_handle() ); + pthread_cond_wait(&event_, &mtx.native_handle()); + pthread_mutex_unlock( &mtx.native_handle() ); #endif } @@ -139,4 +141,4 @@ private: #else pthread_cond_t event_; #endif -}; \ No newline at end of file +};