mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-27 18:30:56 +00:00
Dynamically load XInput, lets us to map the home button with a trick
Also avoids failing to start if XInput 1.3 is not installed.
This commit is contained in:
parent
0cbe0dc997
commit
fafa9c9bfd
@ -22,6 +22,7 @@
|
|||||||
#include "ui/ui_context.h"
|
#include "ui/ui_context.h"
|
||||||
#include "UI/EmuScreen.h"
|
#include "UI/EmuScreen.h"
|
||||||
#include "UI/PluginScreen.h"
|
#include "UI/PluginScreen.h"
|
||||||
|
#include "UI/MenuScreens.h"
|
||||||
#include "UI/GameSettingsScreen.h"
|
#include "UI/GameSettingsScreen.h"
|
||||||
#include "UI/GameInfoCache.h"
|
#include "UI/GameInfoCache.h"
|
||||||
#include "UI/MiscScreens.h"
|
#include "UI/MiscScreens.h"
|
||||||
@ -291,6 +292,7 @@ void GlobalSettingsScreen::CreateViews() {
|
|||||||
list->Add(new CheckBox(&enableReports_, gs->T("Enable Error Reporting")));
|
list->Add(new CheckBox(&enableReports_, gs->T("Enable Error Reporting")));
|
||||||
list->Add(new CheckBox(&g_Config.bEnableCheats, gs->T("Enable Cheats")));
|
list->Add(new CheckBox(&g_Config.bEnableCheats, gs->T("Enable Cheats")));
|
||||||
list->Add(new CheckBox(&g_Config.bScreenshotsAsPNG, gs->T("Screenshots as PNG")));
|
list->Add(new CheckBox(&g_Config.bScreenshotsAsPNG, gs->T("Screenshots as PNG")));
|
||||||
|
list->Add(new Choice(gs->T("Control Mapping")))->OnClick.Handle(this, &GlobalSettingsScreen::OnControlMapping);
|
||||||
list->Add(new Choice(gs->T("System Language")))->OnClick.Handle(this, &GlobalSettingsScreen::OnLanguage);
|
list->Add(new Choice(gs->T("System Language")))->OnClick.Handle(this, &GlobalSettingsScreen::OnLanguage);
|
||||||
list->Add(new Choice(gs->T("Developer Tools")))->OnClick.Handle(this, &GlobalSettingsScreen::OnDeveloperTools);
|
list->Add(new Choice(gs->T("Developer Tools")))->OnClick.Handle(this, &GlobalSettingsScreen::OnDeveloperTools);
|
||||||
list->Add(new Choice(g->T("Back")))->OnClick.Handle(this, &GlobalSettingsScreen::OnBack);
|
list->Add(new Choice(g->T("Back")))->OnClick.Handle(this, &GlobalSettingsScreen::OnBack);
|
||||||
@ -311,6 +313,12 @@ UI::EventReturn GlobalSettingsScreen::OnDeveloperTools(UI::EventParams &e) {
|
|||||||
return UI::EVENT_DONE;
|
return UI::EVENT_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UI::EventReturn GlobalSettingsScreen::OnControlMapping(UI::EventParams &e) {
|
||||||
|
screenManager()->push(new ControlsScreen());
|
||||||
|
return UI::EVENT_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
UI::EventReturn GlobalSettingsScreen::OnBack(UI::EventParams &e) {
|
UI::EventReturn GlobalSettingsScreen::OnBack(UI::EventParams &e) {
|
||||||
screenManager()->finishDialog(this, DR_OK);
|
screenManager()->finishDialog(this, DR_OK);
|
||||||
g_Config.sReportHost = enableReports_ ? "report.ppsspp.org" : "";
|
g_Config.sReportHost = enableReports_ ? "report.ppsspp.org" : "";
|
||||||
|
@ -59,6 +59,7 @@ private:
|
|||||||
UI::EventReturn OnFactoryReset(UI::EventParams &e);
|
UI::EventReturn OnFactoryReset(UI::EventParams &e);
|
||||||
UI::EventReturn OnBack(UI::EventParams &e);
|
UI::EventReturn OnBack(UI::EventParams &e);
|
||||||
UI::EventReturn OnDeveloperTools(UI::EventParams &e);
|
UI::EventReturn OnDeveloperTools(UI::EventParams &e);
|
||||||
|
UI::EventReturn OnControlMapping(UI::EventParams &e);
|
||||||
|
|
||||||
// Temporaries to convert bools to other kinds of settings
|
// Temporaries to convert bools to other kinds of settings
|
||||||
bool enableReports_;
|
bool enableReports_;
|
||||||
|
@ -117,7 +117,7 @@
|
|||||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;glu32.lib;comctl32.lib;dsound.lib;xinput.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;glu32.lib;comctl32.lib;dsound.lib;xinput.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<TargetMachine>MachineX86</TargetMachine>
|
<TargetMachine>MachineX86</TargetMachine>
|
||||||
@ -150,7 +150,7 @@
|
|||||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avdevice.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avdevice.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<ProgramDatabaseFile>$(OutDir)$(ProjectName).pdb</ProgramDatabaseFile>
|
<ProgramDatabaseFile>$(OutDir)$(ProjectName).pdb</ProgramDatabaseFile>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@ -184,7 +184,7 @@
|
|||||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;dsound.lib;glu32.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;dsound.lib;glu32.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
@ -225,7 +225,7 @@
|
|||||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avdevice.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avdevice.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "base/NativeApp.h"
|
#include "base/NativeApp.h"
|
||||||
#include "Core/Config.h"
|
#include "Core/Config.h"
|
||||||
#include "input/input_state.h"
|
#include "input/input_state.h"
|
||||||
@ -6,11 +7,71 @@
|
|||||||
#include "XinputDevice.h"
|
#include "XinputDevice.h"
|
||||||
#include "ControlMapping.h"
|
#include "ControlMapping.h"
|
||||||
|
|
||||||
|
// Utilities to dynamically load XInput. Adapted from SDL.
|
||||||
|
|
||||||
|
typedef DWORD (WINAPI *XInputGetState_t) (DWORD dwUserIndex, XINPUT_STATE* pState);
|
||||||
|
typedef DWORD (WINAPI *XInputSetState_t) (DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
|
||||||
|
typedef DWORD (WINAPI *XInputGetCapabilities_t) (DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
|
||||||
|
|
||||||
|
XInputGetState_t PPSSPP_XInputGetState = NULL;
|
||||||
|
XInputSetState_t PPSSPP_XInputSetState = NULL;
|
||||||
|
XInputGetCapabilities_t PPSSPP_XInputGetCapabilities = NULL;
|
||||||
|
static DWORD PPSSPP_XInputVersion = 0;
|
||||||
|
static HMODULE s_pXInputDLL = 0;
|
||||||
|
static int s_XInputDLLRefCount = 0;
|
||||||
|
|
||||||
|
static void UnloadXInputDLL();
|
||||||
|
|
||||||
|
static int LoadXInputDLL() {
|
||||||
|
DWORD version = 0;
|
||||||
|
|
||||||
|
if (s_pXInputDLL) {
|
||||||
|
s_XInputDLLRefCount++;
|
||||||
|
return 0; /* already loaded */
|
||||||
|
}
|
||||||
|
|
||||||
|
version = (1 << 16) | 4;
|
||||||
|
s_pXInputDLL = LoadLibrary( "XInput1_4.dll" ); // 1.4 Ships with Windows 8.
|
||||||
|
if (!s_pXInputDLL) {
|
||||||
|
version = (1 << 16) | 3;
|
||||||
|
s_pXInputDLL = LoadLibrary( "XInput1_3.dll" ); // 1.3 Ships with Vista and Win7, can be installed as a restributable component.
|
||||||
|
}
|
||||||
|
if (!s_pXInputDLL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
PPSSPP_XInputVersion = version;
|
||||||
|
s_XInputDLLRefCount = 1;
|
||||||
|
|
||||||
|
/* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */
|
||||||
|
PPSSPP_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
|
||||||
|
PPSSPP_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
|
||||||
|
PPSSPP_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
|
||||||
|
if ( !PPSSPP_XInputGetState || !PPSSPP_XInputSetState || !PPSSPP_XInputGetCapabilities ) {
|
||||||
|
UnloadXInputDLL();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UnloadXInputDLL() {
|
||||||
|
if ( s_pXInputDLL ) {
|
||||||
|
if (--s_XInputDLLRefCount == 0) {
|
||||||
|
FreeLibrary( s_pXInputDLL );
|
||||||
|
s_pXInputDLL = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef XUSER_MAX_COUNT
|
#ifndef XUSER_MAX_COUNT
|
||||||
#define XUSER_MAX_COUNT 4
|
#define XUSER_MAX_COUNT 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Undocumented. Steam annoyingly grabs this button though....
|
||||||
|
#define XINPUT_GUIDE_BUTTON 0x400
|
||||||
|
|
||||||
|
|
||||||
// Permanent map. Actual mapping happens elsewhere.
|
// Permanent map. Actual mapping happens elsewhere.
|
||||||
static const struct {int from, to;} xinput_ctrl_map[] = {
|
static const struct {int from, to;} xinput_ctrl_map[] = {
|
||||||
{XBOX_CODE_LEFTTRIGGER, KEYCODE_BUTTON_L2},
|
{XBOX_CODE_LEFTTRIGGER, KEYCODE_BUTTON_L2},
|
||||||
@ -29,16 +90,24 @@ static const struct {int from, to;} xinput_ctrl_map[] = {
|
|||||||
{XINPUT_GAMEPAD_DPAD_DOWN, KEYCODE_DPAD_DOWN},
|
{XINPUT_GAMEPAD_DPAD_DOWN, KEYCODE_DPAD_DOWN},
|
||||||
{XINPUT_GAMEPAD_DPAD_LEFT, KEYCODE_DPAD_LEFT},
|
{XINPUT_GAMEPAD_DPAD_LEFT, KEYCODE_DPAD_LEFT},
|
||||||
{XINPUT_GAMEPAD_DPAD_RIGHT, KEYCODE_DPAD_RIGHT},
|
{XINPUT_GAMEPAD_DPAD_RIGHT, KEYCODE_DPAD_RIGHT},
|
||||||
|
{XINPUT_GUIDE_BUTTON, KEYCODE_HOME},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const unsigned int xinput_ctrl_map_size = sizeof(xinput_ctrl_map) / sizeof(xinput_ctrl_map[0]);
|
static const unsigned int xinput_ctrl_map_size = sizeof(xinput_ctrl_map) / sizeof(xinput_ctrl_map[0]);
|
||||||
|
|
||||||
XinputDevice::XinputDevice() {
|
XinputDevice::XinputDevice() {
|
||||||
|
if (LoadXInputDLL() != 0) {
|
||||||
|
ERROR_LOG(HLE, "Failed to load XInput! DLL missing");
|
||||||
|
}
|
||||||
ZeroMemory( &this->prevState, sizeof(this->prevState) );
|
ZeroMemory( &this->prevState, sizeof(this->prevState) );
|
||||||
this->check_delay = 0;
|
this->check_delay = 0;
|
||||||
this->gamepad_idx = -1;
|
this->gamepad_idx = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XinputDevice::~XinputDevice() {
|
||||||
|
UnloadXInputDLL();
|
||||||
|
}
|
||||||
|
|
||||||
struct Stick {
|
struct Stick {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
@ -52,11 +121,11 @@ int XinputDevice::UpdateState(InputState &input_state) {
|
|||||||
|
|
||||||
DWORD dwResult;
|
DWORD dwResult;
|
||||||
if (this->gamepad_idx >= 0)
|
if (this->gamepad_idx >= 0)
|
||||||
dwResult = XInputGetState( this->gamepad_idx, &state );
|
dwResult = PPSSPP_XInputGetState( this->gamepad_idx, &state );
|
||||||
else {
|
else {
|
||||||
// use the first gamepad that responds
|
// use the first gamepad that responds
|
||||||
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
|
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
|
||||||
dwResult = XInputGetState( i, &state );
|
dwResult = PPSSPP_XInputGetState( i, &state );
|
||||||
if (dwResult == ERROR_SUCCESS) {
|
if (dwResult == ERROR_SUCCESS) {
|
||||||
this->gamepad_idx = i;
|
this->gamepad_idx = i;
|
||||||
break;
|
break;
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
#include "Xinput.h"
|
#include "Xinput.h"
|
||||||
|
|
||||||
class XinputDevice :
|
|
||||||
public InputDevice
|
class XinputDevice : public InputDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
XinputDevice();
|
XinputDevice();
|
||||||
|
~XinputDevice();
|
||||||
virtual int UpdateState(InputState &input_state);
|
virtual int UpdateState(InputState &input_state);
|
||||||
virtual bool IsPad() { return true; }
|
virtual bool IsPad() { return true; }
|
||||||
private:
|
private:
|
||||||
@ -15,5 +16,4 @@ private:
|
|||||||
int check_delay;
|
int check_delay;
|
||||||
XINPUT_STATE prevState;
|
XINPUT_STATE prevState;
|
||||||
u32 prevButtons;
|
u32 prevButtons;
|
||||||
};
|
};
|
||||||
|
|
2
native
2
native
@ -1 +1 @@
|
|||||||
Subproject commit ee0f3848272b6eb5446b468a1c55868e3b3c455c
|
Subproject commit b7c8b8ddef4e22324b768129f53a10382684259a
|
Loading…
Reference in New Issue
Block a user