2013-04-06 14:34:46 +00:00
|
|
|
// SDL/EGL implementation of the framework.
|
|
|
|
// This is quite messy due to platform-specific implementations and #ifdef's.
|
|
|
|
// It is suggested to use the Qt implementation instead.
|
2012-04-10 09:59:57 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <ShellAPI.h>
|
2014-02-05 13:46:21 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_timer.h"
|
|
|
|
#include "SDL_audio.h"
|
|
|
|
#include "SDL_video.h"
|
2012-11-27 15:53:22 +00:00
|
|
|
#else
|
2013-12-13 10:03:40 +00:00
|
|
|
#include <unistd.h>
|
2013-11-05 02:58:30 +00:00
|
|
|
#include <pwd.h>
|
2012-11-25 21:25:54 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_timer.h"
|
|
|
|
#include "SDL_audio.h"
|
|
|
|
#include "SDL_video.h"
|
2012-11-27 15:53:22 +00:00
|
|
|
#endif
|
2013-12-13 11:49:38 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-04-10 09:59:57 +00:00
|
|
|
#include "base/display.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/timeutil.h"
|
2013-01-11 18:02:56 +00:00
|
|
|
#include "gfx_es2/gl_state.h"
|
2012-04-10 09:59:57 +00:00
|
|
|
#include "input/input_state.h"
|
2013-06-30 02:15:55 +00:00
|
|
|
#include "input/keycodes.h"
|
2012-06-03 17:01:08 +00:00
|
|
|
#include "net/resolve.h"
|
2013-11-05 02:58:30 +00:00
|
|
|
#include "base/NKCodeFromSDL.h"
|
2013-06-30 02:15:55 +00:00
|
|
|
#include "util/const_map.h"
|
2013-11-04 13:49:30 +00:00
|
|
|
#include "math/math_util.h"
|
2014-02-05 13:46:21 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
2013-12-13 10:03:40 +00:00
|
|
|
#include "SDL/SDLJoystick.h"
|
2014-02-05 13:46:21 +00:00
|
|
|
#endif
|
2013-12-13 10:03:40 +00:00
|
|
|
|
|
|
|
#ifdef PPSSPP
|
2013-11-26 15:30:10 +00:00
|
|
|
// Bad: PPSSPP includes from native
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Config.h"
|
2013-11-22 00:59:18 +00:00
|
|
|
|
2013-11-05 02:58:30 +00:00
|
|
|
GlobalUIState lastUIState = UISTATE_MENU;
|
2013-12-13 10:03:40 +00:00
|
|
|
#endif
|
2013-11-05 02:58:30 +00:00
|
|
|
|
2014-01-03 14:15:35 +00:00
|
|
|
static SDL_Surface* g_Screen = NULL;
|
2014-02-07 10:33:31 +00:00
|
|
|
static bool g_ToggleFullScreenNextFrame = false;
|
|
|
|
static int g_QuitRequested = 0;
|
2014-01-03 14:15:35 +00:00
|
|
|
|
2013-05-06 13:56:41 +00:00
|
|
|
#if defined(MAEMO) || defined(PANDORA)
|
2013-03-22 15:14:18 +00:00
|
|
|
#define EGL
|
2013-01-12 15:38:37 +00:00
|
|
|
#include "EGL/egl.h"
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include "SDL_syswm.h"
|
2013-05-06 13:56:41 +00:00
|
|
|
#include "math.h"
|
|
|
|
|
2014-01-03 14:15:35 +00:00
|
|
|
static EGLDisplay g_eglDisplay = NULL;
|
|
|
|
static EGLContext g_eglContext = NULL;
|
|
|
|
static EGLSurface g_eglSurface = NULL;
|
|
|
|
static Display* g_Display = NULL;
|
|
|
|
static NativeWindowType g_Window = (NativeWindowType)NULL;
|
2013-01-12 15:38:37 +00:00
|
|
|
|
2013-01-14 11:32:39 +00:00
|
|
|
int8_t CheckEGLErrors(const std::string& file, uint16_t line) {
|
2013-01-12 15:38:37 +00:00
|
|
|
EGLenum error;
|
2013-01-14 11:32:39 +00:00
|
|
|
std::string errortext;
|
2013-01-12 15:38:37 +00:00
|
|
|
|
|
|
|
error = eglGetError();
|
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case EGL_SUCCESS: case 0: return 0;
|
|
|
|
case EGL_NOT_INITIALIZED: errortext = "EGL_NOT_INITIALIZED"; break;
|
|
|
|
case EGL_BAD_ACCESS: errortext = "EGL_BAD_ACCESS"; break;
|
|
|
|
case EGL_BAD_ALLOC: errortext = "EGL_BAD_ALLOC"; break;
|
|
|
|
case EGL_BAD_ATTRIBUTE: errortext = "EGL_BAD_ATTRIBUTE"; break;
|
|
|
|
case EGL_BAD_CONTEXT: errortext = "EGL_BAD_CONTEXT"; break;
|
|
|
|
case EGL_BAD_CONFIG: errortext = "EGL_BAD_CONFIG"; break;
|
|
|
|
case EGL_BAD_CURRENT_SURFACE: errortext = "EGL_BAD_CURRENT_SURFACE"; break;
|
|
|
|
case EGL_BAD_DISPLAY: errortext = "EGL_BAD_DISPLAY"; break;
|
|
|
|
case EGL_BAD_SURFACE: errortext = "EGL_BAD_SURFACE"; break;
|
|
|
|
case EGL_BAD_MATCH: errortext = "EGL_BAD_MATCH"; break;
|
|
|
|
case EGL_BAD_PARAMETER: errortext = "EGL_BAD_PARAMETER"; break;
|
|
|
|
case EGL_BAD_NATIVE_PIXMAP: errortext = "EGL_BAD_NATIVE_PIXMAP"; break;
|
|
|
|
case EGL_BAD_NATIVE_WINDOW: errortext = "EGL_BAD_NATIVE_WINDOW"; break;
|
|
|
|
default: errortext = "unknown"; break;
|
|
|
|
}
|
|
|
|
printf( "ERROR: EGL Error detected in file %s at line %d: %s (0x%X)\n", file.c_str(), line, errortext.c_str(), error );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#define EGL_ERROR(str, check) { \
|
|
|
|
if (check) CheckEGLErrors( __FILE__, __LINE__ ); \
|
|
|
|
printf("EGL ERROR: " str "\n"); \
|
|
|
|
return 1; \
|
|
|
|
}
|
|
|
|
|
2013-01-14 11:32:39 +00:00
|
|
|
int8_t EGL_Open() {
|
2013-05-06 13:56:41 +00:00
|
|
|
#ifdef PANDORA
|
|
|
|
g_Display = EGL_DEFAULT_DISPLAY;
|
|
|
|
#else
|
2013-01-12 15:38:37 +00:00
|
|
|
if ((g_Display = XOpenDisplay(NULL)) == NULL)
|
|
|
|
EGL_ERROR("Unable to get display!", false);
|
2013-05-06 13:56:41 +00:00
|
|
|
#endif
|
2013-01-12 15:38:37 +00:00
|
|
|
if ((g_eglDisplay = eglGetDisplay((NativeDisplayType)g_Display)) == EGL_NO_DISPLAY)
|
|
|
|
EGL_ERROR("Unable to create EGL display.", true);
|
|
|
|
if (eglInitialize(g_eglDisplay, NULL, NULL) != EGL_TRUE)
|
|
|
|
EGL_ERROR("Unable to initialize EGL display.", true);
|
2013-01-14 11:32:39 +00:00
|
|
|
return 0;
|
2013-01-12 15:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int8_t EGL_Init() {
|
2014-02-07 13:18:45 +00:00
|
|
|
EGLConfig g_eglConfig;
|
2013-01-12 15:38:37 +00:00
|
|
|
EGLint g_numConfigs = 0;
|
|
|
|
EGLint attrib_list[]= {
|
2013-03-22 15:14:18 +00:00
|
|
|
#ifdef PANDORA
|
2013-01-12 15:38:37 +00:00
|
|
|
EGL_RED_SIZE, 5,
|
|
|
|
EGL_GREEN_SIZE, 6,
|
|
|
|
EGL_BLUE_SIZE, 5,
|
2013-03-22 15:14:18 +00:00
|
|
|
#endif
|
2013-01-12 15:38:37 +00:00
|
|
|
EGL_DEPTH_SIZE, 16,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_SAMPLE_BUFFERS, 0,
|
|
|
|
EGL_SAMPLES, 0,
|
2013-03-22 15:14:18 +00:00
|
|
|
#ifdef MAEMO
|
|
|
|
EGL_BUFFER_SIZE, 16,
|
|
|
|
#endif
|
2013-01-12 15:38:37 +00:00
|
|
|
EGL_NONE};
|
|
|
|
|
|
|
|
const EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
|
|
|
|
2013-03-22 15:14:18 +00:00
|
|
|
EGLBoolean result = eglChooseConfig(g_eglDisplay, attrib_list, &g_eglConfig, 1, &g_numConfigs);
|
2013-01-14 11:32:39 +00:00
|
|
|
if (result != EGL_TRUE || g_numConfigs == 0) EGL_ERROR("Unable to query for available configs.", true);
|
2013-01-12 15:38:37 +00:00
|
|
|
|
2013-03-22 15:14:18 +00:00
|
|
|
g_eglContext = eglCreateContext(g_eglDisplay, g_eglConfig, NULL, attributes );
|
2013-01-12 15:38:37 +00:00
|
|
|
if (g_eglContext == EGL_NO_CONTEXT) EGL_ERROR("Unable to create GLES context!", true);
|
|
|
|
|
|
|
|
// Get the SDL window handle
|
|
|
|
SDL_SysWMinfo sysInfo; //Will hold our Window information
|
|
|
|
SDL_VERSION(&sysInfo.version); //Set SDL version
|
2014-02-07 13:18:45 +00:00
|
|
|
if(SDL_GetWMInfo(&sysInfo) <= 0) {
|
2013-01-12 15:38:37 +00:00
|
|
|
printf("EGL ERROR: Unable to get SDL window handle: %s\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
2012-04-10 09:59:57 +00:00
|
|
|
|
2013-05-06 13:56:41 +00:00
|
|
|
#ifdef PANDORA
|
|
|
|
g_Window = (NativeWindowType)NULL;
|
|
|
|
#else
|
2013-01-12 15:38:37 +00:00
|
|
|
g_Window = (NativeWindowType)sysInfo.info.x11.window;
|
2013-05-06 13:56:41 +00:00
|
|
|
#endif
|
2013-01-12 15:38:37 +00:00
|
|
|
g_eglSurface = eglCreateWindowSurface(g_eglDisplay, g_eglConfig, g_Window, 0);
|
2014-01-21 14:57:15 +00:00
|
|
|
if (g_eglSurface == EGL_NO_SURFACE)
|
|
|
|
EGL_ERROR("Unable to create EGL surface!", true);
|
2013-01-12 15:38:37 +00:00
|
|
|
|
|
|
|
if (eglMakeCurrent(g_eglDisplay, g_eglSurface, g_eglSurface, g_eglContext) != EGL_TRUE)
|
|
|
|
EGL_ERROR("Unable to make GLES context current.", true);
|
2013-05-06 13:56:41 +00:00
|
|
|
|
2013-01-12 15:38:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EGL_Close() {
|
2014-02-07 13:18:45 +00:00
|
|
|
if (g_eglDisplay != NULL) {
|
2013-01-12 15:38:37 +00:00
|
|
|
eglMakeCurrent(g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT);
|
|
|
|
if (g_eglContext != NULL) {
|
|
|
|
eglDestroyContext(g_eglDisplay, g_eglContext);
|
|
|
|
}
|
|
|
|
if (g_eglSurface != NULL) {
|
|
|
|
eglDestroySurface(g_eglDisplay, g_eglSurface);
|
|
|
|
}
|
|
|
|
eglTerminate(g_eglDisplay);
|
|
|
|
g_eglDisplay = NULL;
|
|
|
|
}
|
|
|
|
if (g_Display != NULL) {
|
|
|
|
XCloseDisplay(g_Display);
|
|
|
|
g_Display = NULL;
|
|
|
|
}
|
|
|
|
g_eglSurface = NULL;
|
|
|
|
g_eglContext = NULL;
|
|
|
|
}
|
2013-07-14 11:51:30 +00:00
|
|
|
#else
|
2013-08-23 08:15:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PANDORA
|
|
|
|
SDL_Joystick *ljoy = NULL;
|
|
|
|
SDL_Joystick *rjoy = NULL;
|
|
|
|
#else
|
2014-02-05 13:46:21 +00:00
|
|
|
#ifndef _WIN32
|
2013-11-24 05:13:24 +00:00
|
|
|
SDLJoystick *joystick = NULL;
|
2013-01-12 15:38:37 +00:00
|
|
|
#endif
|
2014-02-05 13:46:21 +00:00
|
|
|
#endif
|
2013-01-12 15:38:37 +00:00
|
|
|
|
|
|
|
// Simple implementations of System functions
|
2012-07-16 13:00:52 +00:00
|
|
|
|
|
|
|
|
2012-04-10 09:59:57 +00:00
|
|
|
void SystemToast(const char *text) {
|
2012-07-05 21:30:35 +00:00
|
|
|
#ifdef _WIN32
|
2012-07-06 20:32:32 +00:00
|
|
|
MessageBox(0, text, "Toast!", MB_ICONINFORMATION);
|
2012-07-05 21:30:35 +00:00
|
|
|
#else
|
2012-07-06 20:32:32 +00:00
|
|
|
puts(text);
|
2012-07-05 21:30:35 +00:00
|
|
|
#endif
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 21:30:13 +00:00
|
|
|
void ShowKeyboard() {
|
|
|
|
// Irrelevant on PC
|
|
|
|
}
|
|
|
|
|
2012-04-10 09:59:57 +00:00
|
|
|
void Vibrate(int length_ms) {
|
|
|
|
// Ignore on PC
|
|
|
|
}
|
|
|
|
|
2013-12-04 16:38:37 +00:00
|
|
|
void System_SendMessage(const char *command, const char *parameter) {
|
2014-01-03 14:15:35 +00:00
|
|
|
if (!strcmp(command, "toggle_fullscreen")) {
|
|
|
|
g_ToggleFullScreenNextFrame = true;
|
2014-02-07 10:33:31 +00:00
|
|
|
} else if (!strcmp(command, "finish")) {
|
|
|
|
// Do a clean exit
|
|
|
|
g_QuitRequested = true;
|
2014-01-03 14:15:35 +00:00
|
|
|
}
|
2013-12-04 16:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchBrowser(const char *url) {
|
2012-04-10 09:59:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
|
2013-10-30 21:48:12 +00:00
|
|
|
#elif __linux__
|
|
|
|
std::string command = std::string("xdg-open ") + url;
|
2014-01-30 16:33:48 +00:00
|
|
|
int err = system(command.c_str());
|
|
|
|
if (err) {
|
2014-01-30 16:23:04 +00:00
|
|
|
ILOG("Would have gone to %s but xdg-utils seems not to be installed", url)
|
|
|
|
}
|
2013-10-31 16:46:59 +00:00
|
|
|
#elif __APPLE__
|
2013-11-01 17:09:36 +00:00
|
|
|
std::string command = std::string("open ") + url;
|
|
|
|
system(command.c_str());
|
2012-04-10 09:59:57 +00:00
|
|
|
#else
|
2012-10-31 13:01:32 +00:00
|
|
|
ILOG("Would have gone to %s but LaunchBrowser is not implemented on this platform", url);
|
2012-04-10 09:59:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-04 16:38:37 +00:00
|
|
|
void LaunchMarket(const char *url) {
|
2012-04-10 09:59:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
|
2013-10-30 21:48:12 +00:00
|
|
|
#elif __linux__
|
|
|
|
std::string command = std::string("xdg-open ") + url;
|
2014-01-30 16:33:48 +00:00
|
|
|
int err = system(command.c_str());
|
|
|
|
if (err) {
|
2014-01-30 16:23:04 +00:00
|
|
|
ILOG("Would have gone to %s but xdg-utils seems not to be installed", url)
|
|
|
|
}
|
2013-11-01 17:09:36 +00:00
|
|
|
#elif __APPLE__
|
|
|
|
std::string command = std::string("open ") + url;
|
|
|
|
system(command.c_str());
|
2012-04-10 09:59:57 +00:00
|
|
|
#else
|
2012-10-31 13:01:32 +00:00
|
|
|
ILOG("Would have gone to %s but LaunchMarket is not implemented on this platform", url);
|
2012-04-10 09:59:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-04 16:38:37 +00:00
|
|
|
void LaunchEmail(const char *email_address) {
|
2012-04-10 09:59:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
ShellExecute(NULL, "open", (std::string("mailto:") + email_address).c_str(), NULL, NULL, SW_SHOWNORMAL);
|
2013-10-30 21:48:12 +00:00
|
|
|
#elif __linux__
|
2013-11-01 17:09:36 +00:00
|
|
|
std::string command = std::string("xdg-email ") + email_address;
|
2014-01-30 16:33:48 +00:00
|
|
|
int err = system(command.c_str());
|
|
|
|
if (err) {
|
2014-01-30 16:23:04 +00:00
|
|
|
ILOG("Would have gone to %s but xdg-utils seems not to be installed", email_address)
|
|
|
|
}
|
2013-11-01 17:09:36 +00:00
|
|
|
#elif __APPLE__
|
|
|
|
std::string command = std::string("open mailto:") + email_address;
|
2013-10-30 21:48:12 +00:00
|
|
|
system(command.c_str());
|
2012-04-10 09:59:57 +00:00
|
|
|
#else
|
2012-10-31 13:01:32 +00:00
|
|
|
ILOG("Would have opened your email client for %s but LaunchEmail is not implemented on this platform", email_address);
|
2012-04-10 09:59:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-04 09:28:19 +00:00
|
|
|
std::string System_GetProperty(SystemProperty prop) {
|
|
|
|
switch (prop) {
|
|
|
|
case SYSPROP_NAME:
|
2013-11-26 06:38:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
return "SDL:Windows";
|
|
|
|
#elif __linux__
|
|
|
|
return "SDL:Linux";
|
|
|
|
#elif __APPLE__
|
|
|
|
return "SDL:OSX";
|
|
|
|
#else
|
2013-09-04 09:28:19 +00:00
|
|
|
return "SDL:";
|
2013-11-26 06:38:00 +00:00
|
|
|
#endif
|
2013-09-04 09:28:19 +00:00
|
|
|
case SYSPROP_LANGREGION:
|
|
|
|
return "en_US";
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
2013-08-17 22:14:25 +00:00
|
|
|
}
|
|
|
|
|
2013-03-30 05:20:21 +00:00
|
|
|
InputState input_state;
|
|
|
|
|
2013-12-13 11:17:46 +00:00
|
|
|
static const int legacyKeyMap[] {
|
|
|
|
NKCODE_X, //A
|
|
|
|
NKCODE_S, //B
|
|
|
|
NKCODE_Z, //X
|
|
|
|
NKCODE_A, //Y
|
|
|
|
NKCODE_W, //LBUMPER
|
|
|
|
NKCODE_Q, //RBUMPER
|
|
|
|
NKCODE_1, //START
|
|
|
|
NKCODE_2, //SELECT
|
|
|
|
NKCODE_DPAD_UP, //UP
|
|
|
|
NKCODE_DPAD_DOWN, //DOWN
|
|
|
|
NKCODE_DPAD_LEFT, //LEFT
|
|
|
|
NKCODE_DPAD_RIGHT, //RIGHT
|
|
|
|
0, //MENU (SwipeDown)
|
|
|
|
NKCODE_ESCAPE, //BACK
|
|
|
|
NKCODE_I, //JOY UP
|
|
|
|
NKCODE_K, //JOY DOWN
|
|
|
|
NKCODE_J, //JOY LEFT
|
|
|
|
NKCODE_L, //JOY RIGHT
|
|
|
|
};
|
|
|
|
|
2012-04-10 09:59:57 +00:00
|
|
|
void SimulateGamepad(const uint8 *keys, InputState *input) {
|
2013-12-13 11:17:46 +00:00
|
|
|
// Legacy key mapping.
|
2012-07-06 20:32:32 +00:00
|
|
|
input->pad_buttons = 0;
|
|
|
|
input->pad_lstick_x = 0;
|
|
|
|
input->pad_lstick_y = 0;
|
|
|
|
input->pad_rstick_x = 0;
|
|
|
|
input->pad_rstick_y = 0;
|
2013-12-13 11:17:46 +00:00
|
|
|
|
2013-01-12 15:38:37 +00:00
|
|
|
#ifdef PANDORA
|
2014-01-03 14:15:35 +00:00
|
|
|
if (ljoy || rjoy) {
|
2013-01-14 11:32:39 +00:00
|
|
|
SDL_JoystickUpdate();
|
|
|
|
if (ljoy) {
|
2013-07-14 11:51:30 +00:00
|
|
|
input->pad_lstick_x = max(min(SDL_JoystickGetAxis(ljoy, 0) / 32000.0f, 1.0f), -1.0f);
|
|
|
|
input->pad_lstick_y = max(min(-SDL_JoystickGetAxis(ljoy, 1) / 32000.0f, 1.0f), -1.0f);
|
2013-01-14 11:32:39 +00:00
|
|
|
}
|
|
|
|
if (rjoy) {
|
2013-07-14 11:51:30 +00:00
|
|
|
input->pad_rstick_x = max(min(SDL_JoystickGetAxis(rjoy, 0) / 32000.0f, 1.0f), -1.0f);
|
|
|
|
input->pad_rstick_y = max(min(SDL_JoystickGetAxis(rjoy, 1) / 32000.0f, 1.0f), -1.0f);
|
2013-01-14 11:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-12 15:38:37 +00:00
|
|
|
#endif
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern void mixaudio(void *userdata, Uint8 *stream, int len) {
|
2012-10-31 13:01:32 +00:00
|
|
|
NativeMix((short *)stream, len / 4);
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 13:05:51 +00:00
|
|
|
// returns -1 on failure
|
2014-01-21 14:57:15 +00:00
|
|
|
static int parseInt(const char *str) {
|
2013-12-16 13:05:51 +00:00
|
|
|
int val;
|
|
|
|
int retval = sscanf(str, "%d", &val);
|
2014-01-21 14:57:15 +00:00
|
|
|
printf("%i = scanf %s\n", retval, str);
|
2013-12-16 13:05:51 +00:00
|
|
|
if (retval != 1) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-21 14:57:15 +00:00
|
|
|
static float parseFloat(const char *str) {
|
|
|
|
float val;
|
|
|
|
int retval = sscanf(str, "%f", &val);
|
|
|
|
printf("%i = sscanf %s\n", retval, str);
|
|
|
|
if (retval != 1) {
|
|
|
|
return -1.0f;
|
|
|
|
} else {
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-03 14:15:35 +00:00
|
|
|
void ToggleFullScreenIfFlagSet() {
|
|
|
|
if (g_ToggleFullScreenNextFrame) {
|
|
|
|
g_ToggleFullScreenNextFrame = false;
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
int flags = g_Screen->flags; // Save the current flags in case toggling fails
|
|
|
|
g_Screen = SDL_SetVideoMode(0, 0, 0, g_Screen->flags ^ SDL_FULLSCREEN); // Toggles FullScreen Mode
|
|
|
|
if (g_Screen == NULL) {
|
|
|
|
g_Screen = SDL_SetVideoMode(0, 0, 0, flags); // If toggle FullScreen failed, then switch back
|
|
|
|
}
|
|
|
|
if (g_Screen == NULL) {
|
|
|
|
exit(1); // If you can't switch back for some reason, then epic fail
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-10 09:59:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#undef main
|
|
|
|
#endif
|
|
|
|
int main(int argc, char *argv[]) {
|
2014-02-07 10:33:31 +00:00
|
|
|
// Avoid warning about conversion from const char * to char *
|
|
|
|
char envTemp[256];
|
|
|
|
strcpy(envTemp, "SDL_VIDEO_CENTERED=1");
|
|
|
|
putenv(envTemp);
|
2014-02-05 18:44:43 +00:00
|
|
|
|
2012-04-10 09:59:57 +00:00
|
|
|
std::string app_name;
|
|
|
|
std::string app_name_nice;
|
2012-10-31 11:12:24 +00:00
|
|
|
bool landscape;
|
|
|
|
NativeGetAppInfo(&app_name, &app_name_nice, &landscape);
|
2013-07-14 11:51:30 +00:00
|
|
|
|
2012-07-06 20:32:32 +00:00
|
|
|
net::Init();
|
2012-09-01 13:16:23 +00:00
|
|
|
#ifdef __APPLE__
|
2012-10-31 11:12:24 +00:00
|
|
|
// Make sure to request a somewhat modern GL context at least - the
|
2012-09-01 13:16:23 +00:00
|
|
|
// latest supported by MacOSX (really, really sad...)
|
2013-10-30 03:05:17 +00:00
|
|
|
// Requires SDL 2.0
|
2013-10-30 11:22:22 +00:00
|
|
|
// We really should upgrade to SDL 2.0 soon.
|
2012-09-01 13:16:23 +00:00
|
|
|
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
|
|
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
|
|
|
#endif
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2013-05-06 13:56:41 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) {
|
2012-04-10 09:59:57 +00:00
|
|
|
fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
2013-03-22 15:14:18 +00:00
|
|
|
#ifdef EGL
|
2013-01-14 11:32:39 +00:00
|
|
|
if (EGL_Open())
|
|
|
|
return 1;
|
2013-01-12 15:38:37 +00:00
|
|
|
#endif
|
2012-04-10 09:59:57 +00:00
|
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
|
|
|
|
|
2013-10-30 03:05:17 +00:00
|
|
|
int mode;
|
2014-01-23 13:31:56 +00:00
|
|
|
float set_dpi = 1.0f;
|
|
|
|
float set_scale = 1.0f;
|
2013-01-12 15:38:37 +00:00
|
|
|
#ifdef USING_GLES2
|
2013-10-30 03:05:17 +00:00
|
|
|
mode = SDL_SWSURFACE | SDL_FULLSCREEN;
|
2014-01-01 23:29:34 +00:00
|
|
|
int set_xres = -1;
|
|
|
|
int set_yres = -1;
|
2013-01-12 15:38:37 +00:00
|
|
|
#else
|
2013-10-30 03:05:17 +00:00
|
|
|
mode = SDL_OPENGL;
|
2013-12-16 13:05:51 +00:00
|
|
|
int set_xres = -1;
|
|
|
|
int set_yres = -1;
|
2014-01-21 14:57:15 +00:00
|
|
|
|
2013-12-16 13:05:51 +00:00
|
|
|
for (int i = 1; i < argc; i++) {
|
2013-10-30 03:05:17 +00:00
|
|
|
if (!strcmp(argv[i],"--fullscreen"))
|
|
|
|
mode |= SDL_FULLSCREEN;
|
2013-12-16 13:05:51 +00:00
|
|
|
if (set_xres == -2) {
|
|
|
|
set_xres = parseInt(argv[i]);
|
|
|
|
} else if (set_yres == -2) {
|
|
|
|
set_yres = parseInt(argv[i]);
|
|
|
|
}
|
2014-01-21 14:57:15 +00:00
|
|
|
if (set_dpi == -2)
|
|
|
|
set_dpi = parseFloat(argv[i]);
|
2014-01-23 13:31:56 +00:00
|
|
|
if (set_scale == -2)
|
|
|
|
set_scale = parseFloat(argv[i]);
|
2014-01-21 14:57:15 +00:00
|
|
|
|
2013-12-16 13:05:51 +00:00
|
|
|
if (!strcmp(argv[i],"--xres"))
|
|
|
|
set_xres = -2;
|
|
|
|
if (!strcmp(argv[i],"--yres"))
|
|
|
|
set_yres = -2;
|
2014-01-21 14:57:15 +00:00
|
|
|
if (!strcmp(argv[i],"--dpi"))
|
|
|
|
set_dpi = -2;
|
2014-01-23 13:31:56 +00:00
|
|
|
if (!strcmp(argv[i],"--scale"))
|
|
|
|
set_scale = -2;
|
2013-12-16 13:05:51 +00:00
|
|
|
}
|
2013-01-12 15:38:37 +00:00
|
|
|
#endif
|
2013-11-04 13:49:30 +00:00
|
|
|
if (mode & SDL_FULLSCREEN) {
|
|
|
|
const SDL_VideoInfo* info = SDL_GetVideoInfo();
|
|
|
|
pixel_xres = info->current_w;
|
|
|
|
pixel_yres = info->current_h;
|
2013-12-13 10:03:40 +00:00
|
|
|
#ifdef PPSSPP
|
2013-11-05 02:58:30 +00:00
|
|
|
g_Config.bFullScreen = true;
|
2013-12-13 10:03:40 +00:00
|
|
|
#endif
|
2013-11-04 13:49:30 +00:00
|
|
|
} else {
|
2013-10-30 11:22:22 +00:00
|
|
|
// set a sensible default resolution (2x)
|
2014-01-23 13:31:56 +00:00
|
|
|
pixel_xres = 480 * 2 * set_scale;
|
|
|
|
pixel_yres = 272 * 2 * set_scale;
|
2013-12-13 10:03:40 +00:00
|
|
|
#ifdef PPSSPP
|
2013-11-05 02:58:30 +00:00
|
|
|
g_Config.bFullScreen = false;
|
2013-12-13 10:03:40 +00:00
|
|
|
#endif
|
2013-10-30 11:22:22 +00:00
|
|
|
}
|
2013-12-13 11:49:38 +00:00
|
|
|
|
2014-01-23 13:31:56 +00:00
|
|
|
set_dpi = 1.0f / set_dpi;
|
|
|
|
|
2013-12-13 11:49:38 +00:00
|
|
|
if (!landscape) {
|
|
|
|
std::swap(pixel_xres, pixel_yres);
|
|
|
|
}
|
|
|
|
|
2013-12-16 13:05:51 +00:00
|
|
|
if (set_xres > 0) {
|
|
|
|
pixel_xres = set_xres;
|
|
|
|
}
|
|
|
|
if (set_yres > 0) {
|
|
|
|
pixel_yres = set_yres;
|
|
|
|
}
|
2014-01-21 14:57:15 +00:00
|
|
|
float dpi_scale = 1.0f;
|
|
|
|
if (set_dpi > 0) {
|
|
|
|
dpi_scale = set_dpi;
|
|
|
|
}
|
2013-12-16 13:05:51 +00:00
|
|
|
|
2014-01-21 14:57:15 +00:00
|
|
|
dp_xres = (float)pixel_xres * dpi_scale;
|
|
|
|
dp_yres = (float)pixel_yres * dpi_scale;
|
2013-10-30 11:22:22 +00:00
|
|
|
|
2014-01-03 14:15:35 +00:00
|
|
|
g_Screen = SDL_SetVideoMode(pixel_xres, pixel_yres, 0, mode);
|
|
|
|
if (g_Screen == NULL) {
|
2012-04-10 09:59:57 +00:00
|
|
|
fprintf(stderr, "SDL SetVideoMode failed: Unable to create OpenGL screen: %s\n", SDL_GetError());
|
|
|
|
SDL_Quit();
|
2013-12-16 13:05:51 +00:00
|
|
|
return 2;
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
2014-01-03 14:15:35 +00:00
|
|
|
|
2013-03-22 15:14:18 +00:00
|
|
|
#ifdef EGL
|
2013-01-12 15:38:37 +00:00
|
|
|
EGL_Init();
|
|
|
|
#endif
|
2012-11-07 17:29:35 +00:00
|
|
|
|
2013-12-13 10:03:40 +00:00
|
|
|
#ifdef PPSSPP
|
2013-11-26 06:38:00 +00:00
|
|
|
SDL_WM_SetCaption((app_name_nice + " " + PPSSPP_GIT_VERSION).c_str(), NULL);
|
2013-12-13 10:03:40 +00:00
|
|
|
#endif
|
|
|
|
|
2013-03-25 18:45:39 +00:00
|
|
|
#ifdef MAEMO
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
#endif
|
|
|
|
|
2012-04-10 09:59:57 +00:00
|
|
|
|
2013-01-12 15:38:37 +00:00
|
|
|
#ifndef USING_GLES2
|
2012-04-10 09:59:57 +00:00
|
|
|
if (GLEW_OK != glewInit()) {
|
|
|
|
printf("Failed to initialize glew!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GLEW_VERSION_2_0) {
|
|
|
|
printf("OpenGL 2.0 or higher.\n");
|
|
|
|
} else {
|
|
|
|
printf("Sorry, this program requires OpenGL 2.0.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-12 15:38:37 +00:00
|
|
|
#endif
|
2012-04-10 09:59:57 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
// VFSRegister("temp/", new DirectoryAssetReader("E:\\Temp\\"));
|
|
|
|
TCHAR path[MAX_PATH];
|
|
|
|
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path);
|
|
|
|
PathAppend(path, (app_name + "\\").c_str());
|
|
|
|
#else
|
2012-07-15 15:04:27 +00:00
|
|
|
// Mac / Linux
|
2012-10-31 11:12:24 +00:00
|
|
|
char path[512];
|
2012-09-17 17:26:28 +00:00
|
|
|
const char *the_path = getenv("HOME");
|
|
|
|
if (!the_path) {
|
2012-04-10 09:59:57 +00:00
|
|
|
struct passwd* pwd = getpwuid(getuid());
|
|
|
|
if (pwd)
|
2012-09-17 17:26:28 +00:00
|
|
|
the_path = pwd->pw_dir;
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
2012-10-31 11:12:24 +00:00
|
|
|
strcpy(path, the_path);
|
|
|
|
if (path[strlen(path)-1] != '/')
|
|
|
|
strcat(path, "/");
|
2012-04-10 09:59:57 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-28 08:01:01 +00:00
|
|
|
#ifdef _WIN32
|
2012-10-31 11:12:24 +00:00
|
|
|
NativeInit(argc, (const char **)argv, path, "D:\\", "BADCOFFEE");
|
2012-09-28 08:01:01 +00:00
|
|
|
#else
|
2012-08-31 11:11:40 +00:00
|
|
|
NativeInit(argc, (const char **)argv, path, "/tmp", "BADCOFFEE");
|
2012-09-28 08:01:01 +00:00
|
|
|
#endif
|
2012-07-15 15:04:27 +00:00
|
|
|
|
2012-11-21 14:30:43 +00:00
|
|
|
pixel_in_dps = (float)pixel_xres / dp_xres;
|
2013-07-15 12:53:06 +00:00
|
|
|
g_dpi_scale = dp_xres / (float)pixel_xres;
|
2012-11-21 14:30:43 +00:00
|
|
|
|
2012-10-31 11:12:24 +00:00
|
|
|
printf("Pixels: %i x %i\n", pixel_xres, pixel_yres);
|
|
|
|
printf("Virtual pixels: %i x %i\n", dp_xres, dp_yres);
|
2013-11-04 13:49:30 +00:00
|
|
|
NativeInitGraphics();
|
2012-07-15 15:04:27 +00:00
|
|
|
|
2012-07-06 20:32:32 +00:00
|
|
|
SDL_AudioSpec fmt;
|
|
|
|
fmt.freq = 44100;
|
|
|
|
fmt.format = AUDIO_S16;
|
|
|
|
fmt.channels = 2;
|
2013-10-22 03:29:34 +00:00
|
|
|
fmt.samples = 2048;
|
2012-07-06 20:32:32 +00:00
|
|
|
fmt.callback = &mixaudio;
|
|
|
|
fmt.userdata = (void *)0;
|
|
|
|
|
2013-12-16 13:05:51 +00:00
|
|
|
if (SDL_OpenAudio(&fmt, NULL) < 0) {
|
2012-07-06 20:32:32 +00:00
|
|
|
ELOG("Failed to open audio: %s", SDL_GetError());
|
2013-12-16 13:05:51 +00:00
|
|
|
}
|
2012-07-06 20:32:32 +00:00
|
|
|
|
|
|
|
// Audio must be unpaused _after_ NativeInit()
|
2013-11-24 05:13:24 +00:00
|
|
|
SDL_PauseAudio(0);
|
2013-01-14 11:32:39 +00:00
|
|
|
#ifdef PANDORA
|
2013-11-24 05:13:24 +00:00
|
|
|
int numjoys = SDL_NumJoysticks();
|
2013-01-14 11:32:39 +00:00
|
|
|
// Joysticks init, we the nubs if setup as Joystick
|
2013-07-14 11:51:30 +00:00
|
|
|
if (numjoys > 0) {
|
|
|
|
ljoy = SDL_JoystickOpen(0);
|
|
|
|
if (numjoys > 1)
|
|
|
|
rjoy = SDL_JoystickOpen(1);
|
2013-05-06 13:56:41 +00:00
|
|
|
}
|
2013-07-14 11:51:30 +00:00
|
|
|
#else
|
2014-02-05 13:46:21 +00:00
|
|
|
#ifndef _WIN32
|
2013-11-22 00:59:18 +00:00
|
|
|
joystick = new SDLJoystick();
|
2014-02-05 13:46:21 +00:00
|
|
|
#endif
|
2013-01-14 11:32:39 +00:00
|
|
|
#endif
|
2013-11-22 00:59:18 +00:00
|
|
|
EnableFZ();
|
2013-07-14 11:51:30 +00:00
|
|
|
|
2012-07-06 20:32:32 +00:00
|
|
|
int framecount = 0;
|
2013-07-14 11:51:30 +00:00
|
|
|
float t = 0;
|
|
|
|
float lastT = 0;
|
2013-12-16 13:05:51 +00:00
|
|
|
uint32_t pad_buttons = 0; // legacy pad buttons
|
2012-04-10 09:59:57 +00:00
|
|
|
while (true) {
|
2012-07-06 20:32:32 +00:00
|
|
|
input_state.accelerometer_valid = false;
|
|
|
|
input_state.mouse_valid = true;
|
2012-10-31 11:12:24 +00:00
|
|
|
|
|
|
|
SDL_Event event;
|
2012-04-10 09:59:57 +00:00
|
|
|
while (SDL_PollEvent(&event)) {
|
2013-12-16 13:05:51 +00:00
|
|
|
float mx = event.motion.x * g_dpi_scale;
|
|
|
|
float my = event.motion.y * g_dpi_scale;
|
2012-07-15 15:04:27 +00:00
|
|
|
|
2013-07-14 11:51:30 +00:00
|
|
|
switch (event.type) {
|
|
|
|
case SDL_QUIT:
|
2014-02-07 10:33:31 +00:00
|
|
|
g_QuitRequested = 1;
|
2013-07-14 11:51:30 +00:00
|
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
{
|
|
|
|
int k = event.key.keysym.sym;
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_DOWN;
|
|
|
|
key.keyCode = KeyMapRawSDLtoNative.find(k)->second;
|
|
|
|
key.deviceId = DEVICE_ID_KEYBOARD;
|
|
|
|
NativeKey(key);
|
2013-12-13 11:17:46 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(legacyKeyMap); i++) {
|
|
|
|
if (legacyKeyMap[i] == key.keyCode)
|
|
|
|
pad_buttons |= 1 << i;
|
|
|
|
}
|
2013-07-14 11:51:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_KEYUP:
|
|
|
|
{
|
|
|
|
int k = event.key.keysym.sym;
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_UP;
|
|
|
|
key.keyCode = KeyMapRawSDLtoNative.find(k)->second;
|
|
|
|
key.deviceId = DEVICE_ID_KEYBOARD;
|
|
|
|
NativeKey(key);
|
2013-12-13 11:17:46 +00:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(legacyKeyMap); i++) {
|
|
|
|
if (legacyKeyMap[i] == key.keyCode)
|
|
|
|
pad_buttons &= ~(1 << i);
|
|
|
|
}
|
2013-07-14 11:51:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2013-07-08 09:03:14 +00:00
|
|
|
switch (event.button.button) {
|
|
|
|
case SDL_BUTTON_LEFT:
|
|
|
|
{
|
|
|
|
input_state.pointer_x[0] = mx;
|
|
|
|
input_state.pointer_y[0] = my;
|
|
|
|
input_state.pointer_down[0] = true;
|
2013-08-27 17:43:40 +00:00
|
|
|
input_state.mouse_valid = true;
|
2013-07-08 09:03:14 +00:00
|
|
|
TouchInput input;
|
|
|
|
input.x = mx;
|
|
|
|
input.y = my;
|
|
|
|
input.flags = TOUCH_DOWN;
|
|
|
|
input.id = 0;
|
|
|
|
NativeTouch(input);
|
2013-08-04 17:30:34 +00:00
|
|
|
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_DOWN);
|
2013-07-09 14:33:05 +00:00
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_RIGHT:
|
|
|
|
{
|
2013-08-04 17:30:34 +00:00
|
|
|
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_DOWN);
|
2013-07-09 14:33:05 +00:00
|
|
|
NativeKey(key);
|
2013-07-08 09:03:14 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_WHEELUP:
|
|
|
|
{
|
|
|
|
KeyInput key;
|
2013-07-08 10:34:39 +00:00
|
|
|
key.deviceId = DEVICE_ID_MOUSE;
|
2013-08-04 17:30:34 +00:00
|
|
|
key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
|
2013-07-08 09:03:14 +00:00
|
|
|
key.flags = KEY_DOWN;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_WHEELDOWN:
|
|
|
|
{
|
|
|
|
KeyInput key;
|
2013-07-08 10:34:39 +00:00
|
|
|
key.deviceId = DEVICE_ID_MOUSE;
|
2013-08-04 17:30:34 +00:00
|
|
|
key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
|
2013-07-08 09:03:14 +00:00
|
|
|
key.flags = KEY_DOWN;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
break;
|
2013-05-25 13:12:46 +00:00
|
|
|
}
|
2013-07-14 11:51:30 +00:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEMOTION:
|
2013-06-15 13:12:18 +00:00
|
|
|
if (input_state.pointer_down[0]) {
|
|
|
|
input_state.pointer_x[0] = mx;
|
|
|
|
input_state.pointer_y[0] = my;
|
2013-08-27 17:43:40 +00:00
|
|
|
input_state.mouse_valid = true;
|
2013-05-02 22:21:39 +00:00
|
|
|
TouchInput input;
|
|
|
|
input.x = mx;
|
|
|
|
input.y = my;
|
2013-06-15 13:12:18 +00:00
|
|
|
input.flags = TOUCH_MOVE;
|
2013-05-02 22:21:39 +00:00
|
|
|
input.id = 0;
|
|
|
|
NativeTouch(input);
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
2013-07-14 11:51:30 +00:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2013-07-08 09:03:14 +00:00
|
|
|
switch (event.button.button) {
|
|
|
|
case SDL_BUTTON_LEFT:
|
|
|
|
{
|
|
|
|
input_state.pointer_x[0] = mx;
|
|
|
|
input_state.pointer_y[0] = my;
|
|
|
|
input_state.pointer_down[0] = false;
|
2013-08-27 17:43:40 +00:00
|
|
|
input_state.mouse_valid = true;
|
2013-07-08 09:03:14 +00:00
|
|
|
//input_state.mouse_buttons_up = 1;
|
|
|
|
TouchInput input;
|
|
|
|
input.x = mx;
|
|
|
|
input.y = my;
|
|
|
|
input.flags = TOUCH_UP;
|
|
|
|
input.id = 0;
|
|
|
|
NativeTouch(input);
|
2013-08-04 17:30:34 +00:00
|
|
|
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_UP);
|
2013-07-09 14:33:05 +00:00
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_RIGHT:
|
|
|
|
{
|
2013-08-04 17:30:34 +00:00
|
|
|
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_UP);
|
2013-07-09 14:33:05 +00:00
|
|
|
NativeKey(key);
|
2013-07-08 09:03:14 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_WHEELUP:
|
|
|
|
{
|
|
|
|
KeyInput key;
|
|
|
|
key.deviceId = DEVICE_ID_DEFAULT;
|
2013-08-04 17:30:34 +00:00
|
|
|
key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
|
2013-07-08 09:03:14 +00:00
|
|
|
key.flags = KEY_UP;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_WHEELDOWN:
|
|
|
|
{
|
|
|
|
KeyInput key;
|
|
|
|
key.deviceId = DEVICE_ID_DEFAULT;
|
2013-08-04 17:30:34 +00:00
|
|
|
key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
|
2013-07-08 09:03:14 +00:00
|
|
|
key.flags = KEY_UP;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
break;
|
2012-07-06 20:32:32 +00:00
|
|
|
}
|
2013-07-14 11:51:30 +00:00
|
|
|
break;
|
2013-11-22 00:59:18 +00:00
|
|
|
default:
|
2014-02-05 13:46:21 +00:00
|
|
|
#ifndef _WIN32
|
2013-11-22 12:19:32 +00:00
|
|
|
joystick->ProcessInput(event);
|
2014-02-05 13:46:21 +00:00
|
|
|
#endif
|
2013-11-22 12:19:32 +00:00
|
|
|
break;
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 10:33:31 +00:00
|
|
|
if (g_QuitRequested)
|
2012-07-06 20:32:32 +00:00
|
|
|
break;
|
2012-05-06 21:21:26 +00:00
|
|
|
|
2012-07-15 15:04:27 +00:00
|
|
|
const uint8 *keys = (const uint8 *)SDL_GetKeyState(NULL);
|
2012-04-10 09:59:57 +00:00
|
|
|
SimulateGamepad(keys, &input_state);
|
2013-12-13 11:17:46 +00:00
|
|
|
input_state.pad_buttons = pad_buttons;
|
|
|
|
UpdateInputState(&input_state, true);
|
2012-07-06 20:32:32 +00:00
|
|
|
NativeUpdate(input_state);
|
|
|
|
NativeRender();
|
2013-12-13 10:03:40 +00:00
|
|
|
#if defined(PPSSPP) && !defined(MAEMO)
|
2013-11-05 02:58:30 +00:00
|
|
|
if (lastUIState != globalUIState) {
|
|
|
|
lastUIState = globalUIState;
|
|
|
|
if (lastUIState == UISTATE_INGAME && g_Config.bFullScreen && !g_Config.bShowTouchControls)
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
if (lastUIState != UISTATE_INGAME && g_Config.bFullScreen)
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-26 16:42:17 +00:00
|
|
|
|
2012-10-31 11:12:24 +00:00
|
|
|
EndInputState(&input_state);
|
2012-10-26 16:42:17 +00:00
|
|
|
|
2012-07-06 20:32:32 +00:00
|
|
|
if (framecount % 60 == 0) {
|
2012-10-31 11:12:24 +00:00
|
|
|
// glsl_refresh(); // auto-reloads modified GLSL shaders once per second.
|
2012-07-06 20:32:32 +00:00
|
|
|
}
|
2012-10-31 11:12:24 +00:00
|
|
|
|
2013-03-22 15:14:18 +00:00
|
|
|
#ifdef EGL
|
2013-01-12 15:38:37 +00:00
|
|
|
eglSwapBuffers(g_eglDisplay, g_eglSurface);
|
|
|
|
#else
|
2013-01-26 01:24:50 +00:00
|
|
|
if (!keys[SDLK_TAB] || t - lastT >= 1.0/60.0)
|
|
|
|
{
|
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
lastT = t;
|
|
|
|
}
|
2013-01-12 15:38:37 +00:00
|
|
|
#endif
|
2014-01-03 14:15:35 +00:00
|
|
|
|
|
|
|
ToggleFullScreenIfFlagSet();
|
2012-07-06 20:32:32 +00:00
|
|
|
time_update();
|
2012-04-10 09:59:57 +00:00
|
|
|
t = time_now();
|
2012-07-06 20:32:32 +00:00
|
|
|
framecount++;
|
2012-04-10 09:59:57 +00:00
|
|
|
}
|
2013-11-24 05:13:24 +00:00
|
|
|
#ifndef PANDORA
|
2014-02-05 13:46:21 +00:00
|
|
|
#ifndef _WIN32
|
2013-11-24 05:13:24 +00:00
|
|
|
delete joystick;
|
|
|
|
joystick = NULL;
|
2014-02-05 13:46:21 +00:00
|
|
|
#endif
|
2013-11-24 05:13:24 +00:00
|
|
|
#endif
|
2012-07-06 20:32:32 +00:00
|
|
|
// Faster exit, thanks to the OS. Remove this if you want to debug shutdown
|
2012-10-31 11:12:24 +00:00
|
|
|
// The speed difference is only really noticable on Linux. On Windows you do notice it though
|
2012-11-27 15:38:24 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
exit(0);
|
|
|
|
#endif
|
2012-07-06 20:32:32 +00:00
|
|
|
NativeShutdownGraphics();
|
|
|
|
SDL_PauseAudio(1);
|
|
|
|
SDL_CloseAudio();
|
2012-11-21 14:30:43 +00:00
|
|
|
NativeShutdown();
|
2013-03-22 15:14:18 +00:00
|
|
|
#ifdef EGL
|
2013-01-12 15:38:37 +00:00
|
|
|
EGL_Close();
|
|
|
|
#endif
|
2012-04-10 09:59:57 +00:00
|
|
|
SDL_Quit();
|
2012-10-31 11:12:24 +00:00
|
|
|
net::Shutdown();
|
|
|
|
exit(0);
|
2012-04-10 09:59:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|