2012-12-13 06:38:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Sacha Refshauge
|
|
|
|
*
|
|
|
|
*/
|
2013-10-29 01:23:42 +00:00
|
|
|
// Qt 4.7+ / 5.0+ implementation of the framework.
|
2014-06-26 07:58:05 +00:00
|
|
|
// Currently supports: Android, Symbian, Blackberry, Maemo/Meego, Linux, Windows, Mac OSX
|
2012-12-13 06:38:33 +00:00
|
|
|
|
2013-10-18 19:21:44 +00:00
|
|
|
#include <QApplication>
|
2012-12-13 06:38:33 +00:00
|
|
|
#include <QUrl>
|
2013-02-19 14:18:13 +00:00
|
|
|
#include <QDir>
|
2012-12-13 06:38:33 +00:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QDesktopServices>
|
2013-10-18 19:21:44 +00:00
|
|
|
#include <QLocale>
|
2013-10-22 04:52:14 +00:00
|
|
|
#include <QThread>
|
2012-12-13 06:38:33 +00:00
|
|
|
|
2014-06-25 05:40:28 +00:00
|
|
|
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
2014-06-03 00:02:24 +00:00
|
|
|
#include <QStandardPaths>
|
2014-07-25 04:41:23 +00:00
|
|
|
#ifdef QT_HAS_SYSTEMINFO
|
2014-07-22 06:03:42 +00:00
|
|
|
#include <QScreenSaver>
|
2014-06-03 00:02:24 +00:00
|
|
|
#endif
|
2014-07-25 04:41:23 +00:00
|
|
|
#endif
|
2014-06-03 00:02:24 +00:00
|
|
|
|
2012-12-13 06:38:33 +00:00
|
|
|
#ifdef __SYMBIAN32__
|
2013-04-17 14:22:38 +00:00
|
|
|
#include <QSystemScreenSaver>
|
2013-10-26 19:32:31 +00:00
|
|
|
#include <QFeedbackHapticsEffect>
|
2013-10-26 14:20:08 +00:00
|
|
|
#include "SymbianMediaKeys.h"
|
2012-12-13 06:38:33 +00:00
|
|
|
#endif
|
2014-12-18 22:57:59 +00:00
|
|
|
#ifdef SDL
|
2013-11-22 00:59:18 +00:00
|
|
|
#include "SDL/SDLJoystick.h"
|
2014-06-25 03:00:42 +00:00
|
|
|
#include "SDL_audio.h"
|
2013-11-22 00:59:18 +00:00
|
|
|
#endif
|
2012-12-13 06:38:33 +00:00
|
|
|
#include "QtMain.h"
|
2014-07-16 13:50:49 +00:00
|
|
|
#include "math/math_util.h"
|
2012-12-13 06:38:33 +00:00
|
|
|
|
2014-09-23 20:30:50 +00:00
|
|
|
#include <string.h>
|
2014-02-12 10:54:53 +00:00
|
|
|
|
2016-02-10 11:37:47 +00:00
|
|
|
InputState input_state;
|
|
|
|
MainUI *emugl = NULL;
|
2013-04-01 12:42:40 +00:00
|
|
|
|
2014-12-18 22:57:59 +00:00
|
|
|
#ifdef SDL
|
2014-06-25 03:00:42 +00:00
|
|
|
extern void mixaudio(void *userdata, Uint8 *stream, int len) {
|
|
|
|
NativeMix((short *)stream, len / 4);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 09:28:19 +00:00
|
|
|
std::string System_GetProperty(SystemProperty prop) {
|
|
|
|
switch (prop) {
|
|
|
|
case SYSPROP_NAME:
|
2013-08-18 07:28:34 +00:00
|
|
|
#ifdef __SYMBIAN32__
|
2013-09-04 09:28:19 +00:00
|
|
|
return "Qt:Symbian";
|
2013-08-18 07:28:34 +00:00
|
|
|
#elif defined(BLACKBERRY)
|
2013-11-26 06:38:00 +00:00
|
|
|
return "Qt:Blackberry";
|
2014-01-05 00:53:47 +00:00
|
|
|
#elif defined(MAEMO)
|
|
|
|
return "Qt:Maemo";
|
2014-06-03 00:02:24 +00:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
return "Qt:Android";
|
2013-10-19 19:03:31 +00:00
|
|
|
#elif defined(Q_OS_LINUX)
|
2013-09-04 09:28:19 +00:00
|
|
|
return "Qt:Linux";
|
2013-08-18 07:28:34 +00:00
|
|
|
#elif defined(_WIN32)
|
2013-09-04 09:28:19 +00:00
|
|
|
return "Qt:Windows";
|
2013-12-08 10:14:49 +00:00
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
return "Qt:Mac";
|
2013-08-18 07:28:34 +00:00
|
|
|
#else
|
2013-09-04 09:28:19 +00:00
|
|
|
return "Qt";
|
2013-08-18 07:28:34 +00:00
|
|
|
#endif
|
2013-10-17 08:41:00 +00:00
|
|
|
case SYSPROP_LANGREGION:
|
|
|
|
return QLocale::system().name().toStdString();
|
2013-09-04 09:28:19 +00:00
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
2013-08-18 07:28:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 13:17:23 +00:00
|
|
|
int System_GetPropertyInt(SystemProperty prop) {
|
|
|
|
switch (prop) {
|
|
|
|
case SYSPROP_AUDIO_SAMPLE_RATE:
|
|
|
|
return 44100;
|
2015-01-13 23:27:21 +00:00
|
|
|
case SYSPROP_DISPLAY_REFRESH_RATE:
|
|
|
|
return 60000;
|
2015-04-03 09:13:38 +00:00
|
|
|
case SYSPROP_DEVICE_TYPE:
|
|
|
|
#ifdef __SYMBIAN32__
|
|
|
|
return DEVICE_TYPE_MOBILE;
|
|
|
|
#elif defined(BLACKBERRY)
|
|
|
|
return DEVICE_TYPE_MOBILE;
|
|
|
|
#elif defined(MAEMO)
|
|
|
|
return DEVICE_TYPE_MOBILE;
|
|
|
|
#elif defined(ANDROID)
|
|
|
|
return DEVICE_TYPE_MOBILE;
|
|
|
|
#elif defined(Q_OS_LINUX)
|
|
|
|
return DEVICE_TYPE_DESKTOP;
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
return DEVICE_TYPE_DESKTOP;
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
return DEVICE_TYPE_DESKTOP;
|
|
|
|
#else
|
|
|
|
return DEVICE_TYPE_DESKTOP;
|
|
|
|
#endif
|
2015-01-11 13:17:23 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2014-07-20 10:04:22 +00:00
|
|
|
|
2013-12-04 17:12:57 +00:00
|
|
|
void System_SendMessage(const char *command, const char *parameter) {
|
2014-02-15 09:42:48 +00:00
|
|
|
if (!strcmp(command, "finish")) {
|
2014-05-15 07:47:33 +00:00
|
|
|
qApp->exit(0);
|
2014-02-15 09:42:48 +00:00
|
|
|
}
|
2013-12-04 17:12:57 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:41:50 +00:00
|
|
|
void System_AskForPermission(SystemPermission permission) {}
|
|
|
|
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
|
|
|
|
|
2014-02-15 09:46:47 +00:00
|
|
|
bool System_InputBoxGetString(const char *title, const char *defaultValue, char *outValue, size_t outLength)
|
2013-12-08 10:14:49 +00:00
|
|
|
{
|
|
|
|
QString text = emugl->InputBoxGetQString(QString(title), QString(defaultValue));
|
|
|
|
if (text.isEmpty())
|
|
|
|
return false;
|
|
|
|
strcpy(outValue, text.toStdString().c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-10 16:49:09 +00:00
|
|
|
void Vibrate(int length_ms) {
|
|
|
|
if (length_ms == -1 || length_ms == -3)
|
|
|
|
length_ms = 50;
|
|
|
|
else if (length_ms == -2)
|
|
|
|
length_ms = 25;
|
2013-10-26 19:32:31 +00:00
|
|
|
// Symbian only for now
|
|
|
|
#if defined(__SYMBIAN32__)
|
|
|
|
QFeedbackHapticsEffect effect;
|
2013-11-04 13:49:30 +00:00
|
|
|
effect.setIntensity(0.8);
|
2013-10-26 19:32:31 +00:00
|
|
|
effect.setDuration(length_ms);
|
|
|
|
effect.start();
|
2013-10-10 16:49:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-12-13 06:38:33 +00:00
|
|
|
void LaunchBrowser(const char *url)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(url));
|
|
|
|
}
|
|
|
|
|
2012-12-13 07:05:12 +00:00
|
|
|
float CalculateDPIScale()
|
|
|
|
{
|
2013-04-06 14:34:46 +00:00
|
|
|
// Sane default rather than check DPI
|
2012-12-13 07:05:12 +00:00
|
|
|
#ifdef __SYMBIAN32__
|
2013-03-19 19:26:53 +00:00
|
|
|
return 1.4f;
|
2013-12-08 10:14:49 +00:00
|
|
|
#elif defined(USING_GLES2)
|
2012-12-16 09:47:51 +00:00
|
|
|
return 1.2f;
|
2013-10-29 01:23:42 +00:00
|
|
|
#else
|
|
|
|
return 1.0f;
|
2012-12-13 07:05:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-15 09:42:48 +00:00
|
|
|
static int mainInternal(QApplication &a)
|
|
|
|
{
|
2014-06-17 13:45:04 +00:00
|
|
|
#ifdef MOBILE_DEVICE
|
2014-02-15 09:42:48 +00:00
|
|
|
emugl = new MainUI();
|
|
|
|
emugl->resize(pixel_xres, pixel_yres);
|
|
|
|
emugl->showFullScreen();
|
|
|
|
#endif
|
2014-07-16 13:50:49 +00:00
|
|
|
EnableFZ();
|
2014-02-15 09:42:48 +00:00
|
|
|
// Disable screensaver
|
2014-07-22 06:03:42 +00:00
|
|
|
#ifdef __SYMBIAN32__
|
|
|
|
QSystemScreenSaver ssObject(emugl);
|
|
|
|
ssObject.setScreenSaverInhibit();
|
2014-02-15 09:42:48 +00:00
|
|
|
QScopedPointer<SymbianMediaKeys> mediakeys(new SymbianMediaKeys());
|
2014-07-25 04:41:23 +00:00
|
|
|
#elif defined(QT_HAS_SYSTEMINFO)
|
2014-07-22 06:03:42 +00:00
|
|
|
QScreenSaver ssObject(emugl);
|
|
|
|
ssObject.setScreenSaverEnabled(false);
|
2014-02-15 09:42:48 +00:00
|
|
|
#endif
|
|
|
|
|
2014-12-18 22:57:59 +00:00
|
|
|
#ifdef SDL
|
2014-06-25 03:00:42 +00:00
|
|
|
SDLJoystick joy(true);
|
|
|
|
joy.startEventLoop();
|
|
|
|
SDL_Init(SDL_INIT_AUDIO);
|
|
|
|
SDL_AudioSpec fmt, ret_fmt;
|
|
|
|
memset(&fmt, 0, sizeof(fmt));
|
|
|
|
fmt.freq = 44100;
|
|
|
|
fmt.format = AUDIO_S16;
|
|
|
|
fmt.channels = 2;
|
|
|
|
fmt.samples = 2048;
|
2016-02-10 14:17:59 +00:00
|
|
|
fmt.callback = &mixaudio;
|
2014-06-25 03:00:42 +00:00
|
|
|
fmt.userdata = (void *)0;
|
|
|
|
|
|
|
|
if (SDL_OpenAudio(&fmt, &ret_fmt) < 0) {
|
|
|
|
ELOG("Failed to open audio: %s", SDL_GetError());
|
|
|
|
} else {
|
2014-06-25 05:40:28 +00:00
|
|
|
if (ret_fmt.samples != fmt.samples) // Notify, but still use it
|
|
|
|
ELOG("Output audio samples: %d (requested: %d)", ret_fmt.samples, fmt.samples);
|
|
|
|
if (ret_fmt.freq != fmt.freq || ret_fmt.format != fmt.format || ret_fmt.channels != fmt.channels) {
|
2014-06-25 03:00:42 +00:00
|
|
|
ELOG("Sound buffer format does not match requested format.");
|
2014-06-25 05:40:28 +00:00
|
|
|
ELOG("Output audio freq: %d (requested: %d)", ret_fmt.freq, fmt.freq);
|
|
|
|
ELOG("Output audio format: %d (requested: %d)", ret_fmt.format, fmt.format);
|
|
|
|
ELOG("Output audio channels: %d (requested: %d)", ret_fmt.channels, fmt.channels);
|
2014-06-25 03:00:42 +00:00
|
|
|
ELOG("Provided output format does not match requirement, turning audio off");
|
|
|
|
SDL_CloseAudio();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_PauseAudio(0);
|
|
|
|
#else
|
2014-02-15 09:42:48 +00:00
|
|
|
QScopedPointer<MainAudio> audio(new MainAudio());
|
2014-08-20 17:46:00 +00:00
|
|
|
audio->run();
|
2014-06-25 03:00:42 +00:00
|
|
|
#endif
|
2014-08-20 17:46:00 +00:00
|
|
|
return a.exec();
|
2014-02-15 09:42:48 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 11:37:47 +00:00
|
|
|
MainUI::MainUI(QWidget *parent):
|
|
|
|
QGLWidget(parent)
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_AcceptTouchEvents);
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
setAttribute(Qt::WA_LockLandscapeOrientation);
|
|
|
|
#endif
|
|
|
|
#if defined(MOBILE_DEVICE) && !defined(MAEMO)
|
|
|
|
acc = new QAccelerometer(this);
|
|
|
|
acc->start();
|
|
|
|
#endif
|
|
|
|
setFocus();
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
|
|
|
startTimer(16);
|
|
|
|
}
|
|
|
|
|
|
|
|
MainUI::~MainUI()
|
|
|
|
{
|
|
|
|
#if defined(MOBILE_DEVICE) && !defined(MAEMO)
|
|
|
|
delete acc;
|
|
|
|
#endif
|
|
|
|
NativeShutdownGraphics();
|
|
|
|
graphicsContext->Shutdown();
|
|
|
|
delete graphicsContext;
|
|
|
|
graphicsContext = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MainUI::InputBoxGetQString(QString title, QString defaultValue)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
QString text = QInputDialog::getText(this, title, title, QLineEdit::Normal, defaultValue, &ok);
|
|
|
|
if (!ok)
|
|
|
|
text = QString();
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2016-02-10 16:25:02 +00:00
|
|
|
void MainUI::resizeGL(int w, int h)
|
2016-02-10 11:37:47 +00:00
|
|
|
{
|
2016-02-10 16:25:02 +00:00
|
|
|
UpdateScreenScale(w, h, false);
|
|
|
|
xscale = w / this->width();
|
|
|
|
yscale = h / this->height();
|
|
|
|
|
2016-02-10 11:37:47 +00:00
|
|
|
PSP_CoreParameter().pixelWidth = pixel_xres;
|
|
|
|
PSP_CoreParameter().pixelHeight = pixel_yres;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainUI::timerEvent(QTimerEvent *)
|
|
|
|
{
|
|
|
|
updateGL();
|
|
|
|
emit newFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainUI::changeEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
QGLWidget::changeEvent(e);
|
|
|
|
if(e->type() == QEvent::WindowStateChange)
|
|
|
|
Core_NotifyWindowHidden(isMinimized());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainUI::event(QEvent *e)
|
|
|
|
{
|
|
|
|
TouchInput input;
|
|
|
|
QList<QTouchEvent::TouchPoint> touchPoints;
|
|
|
|
switch(e->type())
|
|
|
|
{
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
case QEvent::TouchUpdate:
|
|
|
|
case QEvent::TouchEnd:
|
|
|
|
touchPoints = static_cast<QTouchEvent *>(e)->touchPoints();
|
|
|
|
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
|
|
|
|
switch (touchPoint.state()) {
|
|
|
|
case Qt::TouchPointStationary:
|
|
|
|
break;
|
|
|
|
case Qt::TouchPointPressed:
|
|
|
|
case Qt::TouchPointReleased:
|
|
|
|
input_state.pointer_down[touchPoint.id()] = (touchPoint.state() == Qt::TouchPointPressed);
|
2016-02-10 16:25:02 +00:00
|
|
|
input_state.pointer_x[touchPoint.id()] = touchPoint.pos().x() * g_dpi_scale * xscale;
|
|
|
|
input_state.pointer_y[touchPoint.id()] = touchPoint.pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
|
2016-02-10 16:25:02 +00:00
|
|
|
input.x = touchPoint.pos().x() * g_dpi_scale * xscale;
|
|
|
|
input.y = touchPoint.pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
input.flags = (touchPoint.state() == Qt::TouchPointPressed) ? TOUCH_DOWN : TOUCH_UP;
|
|
|
|
input.id = touchPoint.id();
|
|
|
|
NativeTouch(input);
|
|
|
|
break;
|
|
|
|
case Qt::TouchPointMoved:
|
2016-02-10 16:25:02 +00:00
|
|
|
input_state.pointer_x[touchPoint.id()] = touchPoint.pos().x() * g_dpi_scale * xscale;
|
|
|
|
input_state.pointer_y[touchPoint.id()] = touchPoint.pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
|
2016-02-10 16:25:02 +00:00
|
|
|
input.x = touchPoint.pos().x() * g_dpi_scale * xscale;
|
|
|
|
input.y = touchPoint.pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
input.flags = TOUCH_MOVE;
|
|
|
|
input.id = touchPoint.id();
|
|
|
|
NativeTouch(input);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonDblClick:
|
|
|
|
if (!g_Config.bShowTouchControls || GetUIState() != UISTATE_INGAME)
|
|
|
|
emit doubleClick();
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
input_state.pointer_down[0] = (e->type() == QEvent::MouseButtonPress);
|
2016-02-10 16:25:02 +00:00
|
|
|
input_state.pointer_x[0] = ((QMouseEvent*)e)->pos().x() * g_dpi_scale * xscale;
|
|
|
|
input_state.pointer_y[0] = ((QMouseEvent*)e)->pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
|
2016-02-10 16:25:02 +00:00
|
|
|
input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale * xscale;
|
|
|
|
input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
input.flags = (e->type() == QEvent::MouseButtonPress) ? TOUCH_DOWN : TOUCH_UP;
|
|
|
|
input.id = 0;
|
|
|
|
NativeTouch(input);
|
|
|
|
break;
|
|
|
|
case QEvent::MouseMove:
|
2016-02-10 16:25:02 +00:00
|
|
|
input_state.pointer_x[0] = ((QMouseEvent*)e)->pos().x() * g_dpi_scale * xscale;
|
|
|
|
input_state.pointer_y[0] = ((QMouseEvent*)e)->pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
|
2016-02-10 16:25:02 +00:00
|
|
|
input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale * xscale;
|
|
|
|
input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale * yscale;
|
2016-02-10 11:37:47 +00:00
|
|
|
input.flags = TOUCH_MOVE;
|
|
|
|
input.id = 0;
|
|
|
|
NativeTouch(input);
|
|
|
|
break;
|
|
|
|
case QEvent::Wheel:
|
|
|
|
NativeKey(KeyInput(DEVICE_ID_MOUSE, ((QWheelEvent*)e)->delta()<0 ? NKCODE_EXT_MOUSEWHEEL_DOWN : NKCODE_EXT_MOUSEWHEEL_UP, KEY_DOWN));
|
|
|
|
break;
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawQttoNative.find(((QKeyEvent*)e)->key())->second, KEY_DOWN));
|
|
|
|
break;
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawQttoNative.find(((QKeyEvent*)e)->key())->second, KEY_UP));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QWidget::event(e);
|
|
|
|
}
|
|
|
|
e->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainUI::initializeGL()
|
|
|
|
{
|
|
|
|
#ifndef USING_GLES2
|
|
|
|
glewInit();
|
|
|
|
#endif
|
|
|
|
graphicsContext = new QtDummyGraphicsContext();
|
|
|
|
NativeInitGraphics(graphicsContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainUI::paintGL()
|
|
|
|
{
|
|
|
|
updateAccelerometer();
|
|
|
|
UpdateInputState(&input_state);
|
|
|
|
time_update();
|
|
|
|
UpdateRunLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainUI::updateAccelerometer()
|
|
|
|
{
|
|
|
|
#if defined(MOBILE_DEVICE) && !defined(MAEMO)
|
|
|
|
// TODO: Toggle it depending on whether it is enabled
|
|
|
|
QAccelerometerReading *reading = acc->reading();
|
|
|
|
if (reading) {
|
|
|
|
input_state.acc.x = reading->x();
|
|
|
|
input_state.acc.y = reading->y();
|
|
|
|
input_state.acc.z = reading->z();
|
|
|
|
AxisInput axis;
|
|
|
|
axis.deviceId = DEVICE_ID_ACCELEROMETER;
|
|
|
|
axis.flags = 0;
|
|
|
|
|
|
|
|
axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X;
|
|
|
|
axis.value = input_state.acc.x;
|
|
|
|
NativeAxis(axis);
|
|
|
|
|
|
|
|
axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y;
|
|
|
|
axis.value = input_state.acc.y;
|
|
|
|
NativeAxis(axis);
|
|
|
|
|
|
|
|
axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z;
|
|
|
|
axis.value = input_state.acc.z;
|
|
|
|
NativeAxis(axis);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef SDL
|
|
|
|
// Audio
|
|
|
|
#define AUDIO_FREQ 44100
|
|
|
|
#define AUDIO_CHANNELS 2
|
|
|
|
#define AUDIO_SAMPLES 2048
|
|
|
|
#define AUDIO_SAMPLESIZE 16
|
|
|
|
#define AUDIO_BUFFERS 5
|
|
|
|
|
|
|
|
MainAudio::~MainAudio()
|
|
|
|
{
|
|
|
|
if (feed != NULL) {
|
|
|
|
killTimer(timer);
|
|
|
|
feed->close();
|
|
|
|
}
|
|
|
|
if (output) {
|
|
|
|
output->stop();
|
|
|
|
delete output;
|
|
|
|
}
|
|
|
|
if (mixbuf)
|
|
|
|
free(mixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainAudio::run()
|
|
|
|
{
|
|
|
|
QAudioFormat fmt;
|
|
|
|
fmt.setSampleRate(AUDIO_FREQ);
|
|
|
|
fmt.setCodec("audio/pcm");
|
|
|
|
fmt.setChannelCount(AUDIO_CHANNELS);
|
|
|
|
fmt.setSampleSize(AUDIO_SAMPLESIZE);
|
|
|
|
fmt.setByteOrder(QAudioFormat::LittleEndian);
|
|
|
|
fmt.setSampleType(QAudioFormat::SignedInt);
|
|
|
|
mixlen = sizeof(short)*AUDIO_BUFFERS*AUDIO_CHANNELS*AUDIO_SAMPLES;
|
|
|
|
mixbuf = (char*)malloc(mixlen);
|
|
|
|
output = new QAudioOutput(fmt);
|
|
|
|
output->setBufferSize(mixlen);
|
|
|
|
feed = output->start();
|
2016-02-10 16:01:09 +00:00
|
|
|
if (feed != NULL) {
|
|
|
|
// buffering has already done in the internal mixed buffer
|
|
|
|
// use a small interval to copy mixed audio stream from
|
|
|
|
// internal buffer to audio output buffer as soon as possible
|
|
|
|
// use 1 instead of 0 to prevent CPU exhausting
|
2016-02-10 11:39:26 +00:00
|
|
|
timer = startTimer(1);
|
2016-02-10 16:01:09 +00:00
|
|
|
}
|
2016-02-10 11:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainAudio::timerEvent(QTimerEvent *)
|
|
|
|
{
|
|
|
|
memset(mixbuf, 0, mixlen);
|
|
|
|
size_t frames = NativeMix((short *)mixbuf, AUDIO_BUFFERS*AUDIO_SAMPLES);
|
|
|
|
if (frames > 0)
|
|
|
|
feed->write(mixbuf, sizeof(short) * AUDIO_CHANNELS * frames);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-12-18 22:57:59 +00:00
|
|
|
#ifndef SDL
|
2013-11-22 00:59:18 +00:00
|
|
|
Q_DECL_EXPORT
|
|
|
|
#endif
|
|
|
|
int main(int argc, char *argv[])
|
2012-12-13 06:38:33 +00:00
|
|
|
{
|
2014-01-05 00:53:47 +00:00
|
|
|
#if defined(Q_OS_LINUX) && !defined(MAEMO)
|
2013-01-14 09:20:28 +00:00
|
|
|
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
|
|
|
|
#endif
|
2012-12-13 06:38:33 +00:00
|
|
|
QApplication a(argc, argv);
|
|
|
|
QSize res = QApplication::desktop()->screenGeometry().size();
|
|
|
|
if (res.width() < res.height())
|
|
|
|
res.transpose();
|
|
|
|
pixel_xres = res.width();
|
|
|
|
pixel_yres = res.height();
|
2013-08-20 10:30:03 +00:00
|
|
|
g_dpi_scale = CalculateDPIScale();
|
|
|
|
dp_xres = (int)(pixel_xres * g_dpi_scale); dp_yres = (int)(pixel_yres * g_dpi_scale);
|
2012-12-13 07:05:12 +00:00
|
|
|
net::Init();
|
2014-06-25 05:40:28 +00:00
|
|
|
std::string savegame_dir = ".";
|
|
|
|
std::string assets_dir = ".";
|
|
|
|
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
savegame_dir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString();
|
2014-06-26 07:58:05 +00:00
|
|
|
assets_dir = QStandardPaths::writableLocation(QStandardPaths::DataLocation).toStdString();
|
2014-06-25 05:40:28 +00:00
|
|
|
#elif defined(__SYMBIAN32__)
|
|
|
|
savegame_dir = "E:/PPSSPP";
|
|
|
|
assets_dir = "E:/PPSSPP";
|
2012-12-23 07:47:52 +00:00
|
|
|
#elif defined(BLACKBERRY)
|
2014-06-25 05:40:28 +00:00
|
|
|
savegame_dir = "/accounts/1000/shared/misc";
|
|
|
|
assets_dir = "app/native/assets";
|
2014-06-17 17:41:20 +00:00
|
|
|
#elif defined(MAEMO)
|
2014-06-25 05:40:28 +00:00
|
|
|
savegame_dir = "/home/user/MyDocs/PPSSPP";
|
|
|
|
assets_dir = "/opt/PPSSPP";
|
2012-12-13 06:38:33 +00:00
|
|
|
#endif
|
2014-06-25 05:40:28 +00:00
|
|
|
savegame_dir += "/";
|
|
|
|
assets_dir += "/";
|
2014-09-23 20:29:02 +00:00
|
|
|
|
2014-09-24 21:23:25 +00:00
|
|
|
bool fullscreenCLI=false;
|
2014-09-23 20:29:02 +00:00
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(argv[i],"--fullscreen"))
|
|
|
|
fullscreenCLI=true;
|
|
|
|
}
|
2016-01-17 21:11:28 +00:00
|
|
|
NativeInit(argc, (const char **)argv, savegame_dir.c_str(), assets_dir.c_str(), nullptr, fullscreenCLI);
|
2014-09-22 18:08:02 +00:00
|
|
|
|
2014-02-15 09:42:48 +00:00
|
|
|
int ret = mainInternal(a);
|
2012-12-16 09:47:51 +00:00
|
|
|
|
2014-06-25 03:00:42 +00:00
|
|
|
#ifndef MOBILE_DEVICE
|
|
|
|
exit(0);
|
|
|
|
#endif
|
|
|
|
NativeShutdownGraphics();
|
2014-12-18 22:57:59 +00:00
|
|
|
#ifdef SDL
|
2014-06-25 03:00:42 +00:00
|
|
|
SDL_PauseAudio(1);
|
|
|
|
SDL_CloseAudio();
|
2014-06-25 03:26:43 +00:00
|
|
|
#endif
|
2012-12-13 06:38:33 +00:00
|
|
|
NativeShutdown();
|
|
|
|
net::Shutdown();
|
|
|
|
return ret;
|
|
|
|
}
|
2013-10-29 01:23:42 +00:00
|
|
|
|