refactored SDL joystick into seperate file
This commit is contained in:
parent
4177cf49db
commit
3b076b41a9
3 changed files with 27 additions and 90 deletions
102
base/PCMain.cpp
102
base/PCMain.cpp
|
@ -31,6 +31,8 @@
|
||||||
#include "base/NKCodeFromSDL.h"
|
#include "base/NKCodeFromSDL.h"
|
||||||
#include "util/const_map.h"
|
#include "util/const_map.h"
|
||||||
#include "math/math_util.h"
|
#include "math/math_util.h"
|
||||||
|
#include "../SDL/SDLJoystick.h"
|
||||||
|
|
||||||
|
|
||||||
GlobalUIState lastUIState = UISTATE_MENU;
|
GlobalUIState lastUIState = UISTATE_MENU;
|
||||||
|
|
||||||
|
@ -171,7 +173,7 @@ void EGL_Close() {
|
||||||
SDL_Joystick *ljoy = NULL;
|
SDL_Joystick *ljoy = NULL;
|
||||||
SDL_Joystick *rjoy = NULL;
|
SDL_Joystick *rjoy = NULL;
|
||||||
#else
|
#else
|
||||||
SDL_Joystick *joy = NULL;
|
SDLJoystick *joystick;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Simple implementations of System functions
|
// Simple implementations of System functions
|
||||||
|
@ -266,7 +268,6 @@ void SimulateGamepad(const uint8 *keys, InputState *input) {
|
||||||
input->pad_lstick_y = 0;
|
input->pad_lstick_y = 0;
|
||||||
input->pad_rstick_x = 0;
|
input->pad_rstick_x = 0;
|
||||||
input->pad_rstick_y = 0;
|
input->pad_rstick_y = 0;
|
||||||
|
|
||||||
// TODO: Use NativeAxis for joy instead.
|
// TODO: Use NativeAxis for joy instead.
|
||||||
#ifdef PANDORA
|
#ifdef PANDORA
|
||||||
if ((ljoy)||(rjoy)) {
|
if ((ljoy)||(rjoy)) {
|
||||||
|
@ -424,8 +425,6 @@ int main(int argc, char *argv[]) {
|
||||||
ELOG("Failed to open audio: %s", SDL_GetError());
|
ELOG("Failed to open audio: %s", SDL_GetError());
|
||||||
|
|
||||||
// Audio must be unpaused _after_ NativeInit()
|
// Audio must be unpaused _after_ NativeInit()
|
||||||
SDL_PauseAudio(0);
|
|
||||||
int numjoys = SDL_NumJoysticks();
|
|
||||||
#ifdef PANDORA
|
#ifdef PANDORA
|
||||||
// Joysticks init, we the nubs if setup as Joystick
|
// Joysticks init, we the nubs if setup as Joystick
|
||||||
if (numjoys > 0) {
|
if (numjoys > 0) {
|
||||||
|
@ -434,40 +433,12 @@ int main(int argc, char *argv[]) {
|
||||||
rjoy = SDL_JoystickOpen(1);
|
rjoy = SDL_JoystickOpen(1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
SDL_JoystickEventState(SDL_ENABLE);
|
joystick = new SDLJoystick();
|
||||||
if (numjoys > 0) {
|
|
||||||
joy = SDL_JoystickOpen(0);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
SDL_PauseAudio(0);
|
||||||
|
|
||||||
EnableFZ();
|
EnableFZ();
|
||||||
|
|
||||||
// This is just a standard mapping that matches the X360 controller on MacOSX. Names will probably be all wrong
|
|
||||||
// on other controllers.
|
|
||||||
std::map<int, int> SDLJoyButtonMap;
|
|
||||||
SDLJoyButtonMap[0] = NKCODE_DPAD_UP;
|
|
||||||
SDLJoyButtonMap[1] = NKCODE_DPAD_DOWN;
|
|
||||||
SDLJoyButtonMap[2] = NKCODE_DPAD_LEFT;
|
|
||||||
SDLJoyButtonMap[3] = NKCODE_DPAD_RIGHT;
|
|
||||||
SDLJoyButtonMap[4] = NKCODE_BUTTON_10;
|
|
||||||
SDLJoyButtonMap[5] = NKCODE_BUTTON_9;
|
|
||||||
SDLJoyButtonMap[6] = NKCODE_BUTTON_5;
|
|
||||||
SDLJoyButtonMap[7] = NKCODE_BUTTON_6;
|
|
||||||
SDLJoyButtonMap[8] = NKCODE_BUTTON_7;
|
|
||||||
SDLJoyButtonMap[9] = NKCODE_BUTTON_8;
|
|
||||||
SDLJoyButtonMap[10] = NKCODE_BUTTON_SELECT;
|
|
||||||
SDLJoyButtonMap[11] = NKCODE_BUTTON_2;
|
|
||||||
SDLJoyButtonMap[12] = NKCODE_BUTTON_3;
|
|
||||||
SDLJoyButtonMap[13] = NKCODE_BUTTON_4;
|
|
||||||
SDLJoyButtonMap[14] = NKCODE_BUTTON_1;
|
|
||||||
|
|
||||||
std::map<int, int> SDLJoyAxisMap;
|
|
||||||
SDLJoyAxisMap[0] = JOYSTICK_AXIS_X;
|
|
||||||
SDLJoyAxisMap[1] = JOYSTICK_AXIS_Y;
|
|
||||||
SDLJoyAxisMap[2] = JOYSTICK_AXIS_Z;
|
|
||||||
SDLJoyAxisMap[3] = JOYSTICK_AXIS_RZ;
|
|
||||||
SDLJoyAxisMap[4] = JOYSTICK_AXIS_LTRIGGER;
|
|
||||||
SDLJoyAxisMap[5] = JOYSTICK_AXIS_RTRIGGER;
|
|
||||||
|
|
||||||
int framecount = 0;
|
int framecount = 0;
|
||||||
float t = 0;
|
float t = 0;
|
||||||
float lastT = 0;
|
float lastT = 0;
|
||||||
|
@ -485,60 +456,6 @@ int main(int argc, char *argv[]) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
quitRequested = 1;
|
quitRequested = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_JOYAXISMOTION:
|
|
||||||
{
|
|
||||||
AxisInput axis;
|
|
||||||
axis.axisId = SDLJoyAxisMap[event.jaxis.axis];
|
|
||||||
// 1.2 to try to approximate the PSP's clamped rectangular range.
|
|
||||||
axis.value = 1.2 * event.jaxis.value / 32767.0f;
|
|
||||||
if (axis.value > 1.0f) axis.value = 1.0f;
|
|
||||||
if (axis.value < -1.0f) axis.value = -1.0f;
|
|
||||||
axis.deviceId = DEVICE_ID_PAD_0;
|
|
||||||
axis.flags = 0;
|
|
||||||
NativeAxis(axis);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_JOYBUTTONDOWN:
|
|
||||||
{
|
|
||||||
KeyInput key;
|
|
||||||
key.flags = KEY_DOWN;
|
|
||||||
key.keyCode = SDLJoyButtonMap[event.jbutton.button];
|
|
||||||
key.deviceId = DEVICE_ID_PAD_0;
|
|
||||||
NativeKey(key);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_JOYBUTTONUP:
|
|
||||||
{
|
|
||||||
KeyInput key;
|
|
||||||
key.flags = KEY_UP;
|
|
||||||
key.keyCode = SDLJoyButtonMap[event.jbutton.button];
|
|
||||||
key.deviceId = DEVICE_ID_PAD_0;
|
|
||||||
NativeKey(key);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_JOYHATMOTION:
|
|
||||||
{
|
|
||||||
AxisInput axisX;
|
|
||||||
AxisInput axisY;
|
|
||||||
axisX.axisId = JOYSTICK_AXIS_HAT_X;
|
|
||||||
axisY.axisId = JOYSTICK_AXIS_HAT_Y;
|
|
||||||
axisX.deviceId = DEVICE_ID_PAD_0;
|
|
||||||
axisY.deviceId = DEVICE_ID_PAD_0;
|
|
||||||
axisX.value = 0.0f;
|
|
||||||
axisY.value = 0.0f;
|
|
||||||
if (event.jhat.value & SDL_HAT_LEFT) axisX.value = -1.0f;
|
|
||||||
if (event.jhat.value & SDL_HAT_RIGHT) axisX.value = 1.0f;
|
|
||||||
if (event.jhat.value & SDL_HAT_DOWN) axisY.value = -1.0f;
|
|
||||||
if (event.jhat.value & SDL_HAT_UP) axisY.value = 1.0f;
|
|
||||||
NativeAxis(axisX);
|
|
||||||
NativeAxis(axisY);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
{
|
{
|
||||||
int k = event.key.keysym.sym;
|
int k = event.key.keysym.sym;
|
||||||
|
@ -662,6 +579,8 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
joystick->processInput(ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,6 +604,11 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
EndInputState(&input_state);
|
EndInputState(&input_state);
|
||||||
|
|
||||||
|
#ifndef PANDORA
|
||||||
|
delete joystick;
|
||||||
|
joystick = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (framecount % 60 == 0) {
|
if (framecount % 60 == 0) {
|
||||||
// glsl_refresh(); // auto-reloads modified GLSL shaders once per second.
|
// glsl_refresh(); // auto-reloads modified GLSL shaders once per second.
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,13 @@
|
||||||
#include <QFeedbackHapticsEffect>
|
#include <QFeedbackHapticsEffect>
|
||||||
#include "SymbianMediaKeys.h"
|
#include "SymbianMediaKeys.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef QT_HAS_SDL
|
||||||
|
#include "SDL/SDLJoystick.h"
|
||||||
|
#endif
|
||||||
#include "QtMain.h"
|
#include "QtMain.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
InputState* input_state;
|
InputState* input_state;
|
||||||
|
|
||||||
std::string System_GetProperty(SystemProperty prop) {
|
std::string System_GetProperty(SystemProperty prop) {
|
||||||
|
@ -77,7 +82,10 @@ float CalculateDPIScale()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECL_EXPORT int main(int argc, char *argv[])
|
#ifndef QT_HAS_SDL
|
||||||
|
Q_DECL_EXPORT
|
||||||
|
#endif
|
||||||
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
|
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
|
||||||
|
@ -134,6 +142,10 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||||
QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||||
thread->start();
|
thread->start();
|
||||||
|
|
||||||
|
#ifdef QT_HAS_SDL
|
||||||
|
SDLJoystick joy(true);
|
||||||
|
joy.startEventLoop();
|
||||||
|
#endif
|
||||||
int ret = a.exec();
|
int ret = a.exec();
|
||||||
delete audio;
|
delete audio;
|
||||||
thread->quit();
|
thread->quit();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// TODO: Move much of this code to vfs.cpp
|
// TODO: Move much of this code to vfs.cpp
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue