mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-01-23 14:24:52 +00:00
Add a class for keyboard input
Removes the windows-specific hack from sceCtrl to read keyboard input and instead add a hack to PPSSPPWindows. The input mapping is still hardcoded and is the same as it was in sceCtrl. Add an std::list to WindowsHost that, curretly, contains a hardcoded list of preferred `InputDevice`s. Devices are tried in-order until one of them reports success. Xinput is preferred over Keyboard. Keyboard always returns success. Pointers are stored in the std::list for polymorphism. Change XinputDevice to report failure as soon as a device can't be queried, instead of only a frame later.
This commit is contained in:
parent
2210b19244
commit
7e7e9a0452
@ -66,48 +66,6 @@ void SampleControls() {
|
||||
_ctrl_data &data = ctrl;
|
||||
data.frame=1;//frame;
|
||||
frame++;
|
||||
#ifdef _WIN32
|
||||
// TODO: Move this outta here!
|
||||
data.buttons = 0;
|
||||
int analogX = 128;
|
||||
int analogY = 128;
|
||||
if (GetAsyncKeyState(VK_SPACE))
|
||||
data.buttons|=CTRL_START;
|
||||
if (GetAsyncKeyState('V'))
|
||||
data.buttons|=CTRL_SELECT;
|
||||
if (GetAsyncKeyState('A'))
|
||||
data.buttons|=CTRL_SQUARE;
|
||||
if (GetAsyncKeyState('S'))
|
||||
data.buttons|=CTRL_TRIANGLE;
|
||||
if (GetAsyncKeyState('X'))
|
||||
data.buttons|=CTRL_CIRCLE;
|
||||
if (GetAsyncKeyState('Z'))
|
||||
data.buttons|=CTRL_CROSS;
|
||||
if (GetAsyncKeyState('Q'))
|
||||
data.buttons|=CTRL_LTRIGGER;
|
||||
if (GetAsyncKeyState('W'))
|
||||
data.buttons|=CTRL_RTRIGGER;
|
||||
if (GetAsyncKeyState(VK_UP)) {
|
||||
data.buttons|=CTRL_UP;
|
||||
analogY -= 100;
|
||||
}
|
||||
if (GetAsyncKeyState(VK_DOWN)) {
|
||||
data.buttons|=CTRL_DOWN;
|
||||
analogY += 100;
|
||||
}
|
||||
if (GetAsyncKeyState(VK_LEFT)) {
|
||||
data.buttons|=CTRL_LEFT;
|
||||
analogX -= 100;
|
||||
}
|
||||
if (GetAsyncKeyState(VK_RIGHT))
|
||||
{
|
||||
data.buttons|=CTRL_RIGHT;
|
||||
analogX += 100;
|
||||
}
|
||||
|
||||
data.analog[0] = analogX;
|
||||
data.analog[1] = analogY;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
13
Windows/InputDevice.cpp
Normal file
13
Windows/InputDevice.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "InputDevice.h"
|
||||
#include "XinputDevice.h"
|
||||
#include "KeyboardDevice.h"
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#define PUSH_BACK(Cls) do { list.push_back(std::shared_ptr<InputDevice>(new Cls())); } while (0)
|
||||
std::list<std::shared_ptr<InputDevice>> getInputDevices() {
|
||||
std::list<std::shared_ptr<InputDevice>> list;
|
||||
PUSH_BACK(XinputDevice);
|
||||
PUSH_BACK(KeyboardDevice);
|
||||
return list;
|
||||
}
|
@ -8,3 +8,6 @@ public:
|
||||
virtual int UpdateState() = 0;
|
||||
};
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
std::list<std::shared_ptr<InputDevice>> getInputDevices();
|
||||
|
46
Windows/KeyboardDevice.cpp
Normal file
46
Windows/KeyboardDevice.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "KeyboardDevice.h"
|
||||
#include "../Common/CommonTypes.h"
|
||||
#include "../Core/HLE/sceCtrl.h"
|
||||
#include "WinUser.h"
|
||||
|
||||
static const unsigned short key_ctrl_map[] = {
|
||||
VK_SPACE, CTRL_START,
|
||||
'V', CTRL_SELECT,
|
||||
'A', CTRL_SQUARE,
|
||||
'S', CTRL_TRIANGLE,
|
||||
'X', CTRL_CIRCLE,
|
||||
'Z', CTRL_CROSS,
|
||||
'Q', CTRL_LTRIGGER,
|
||||
'W', CTRL_RTRIGGER,
|
||||
VK_UP, CTRL_UP,
|
||||
VK_DOWN, CTRL_DOWN,
|
||||
VK_LEFT, CTRL_LEFT,
|
||||
VK_RIGHT, CTRL_RIGHT,
|
||||
};
|
||||
int KeyboardDevice::UpdateState() {
|
||||
float analogX = 0;
|
||||
float analogY = 0;
|
||||
for (int i = 0; i < sizeof(key_ctrl_map)/sizeof(key_ctrl_map[0]); i += 2) {
|
||||
if (!GetAsyncKeyState(key_ctrl_map[i]))
|
||||
__CtrlButtonUp(key_ctrl_map[i+1]);
|
||||
else {
|
||||
__CtrlButtonDown(key_ctrl_map[i+1]);
|
||||
switch (key_ctrl_map[i]) {
|
||||
case VK_UP:
|
||||
analogY -= .8f;
|
||||
break;
|
||||
case VK_DOWN:
|
||||
analogY += .8f;
|
||||
break;
|
||||
case VK_LEFT:
|
||||
analogX -= .8f;
|
||||
break;
|
||||
case VK_RIGHT:
|
||||
analogX += .8f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
__CtrlSetAnalog(analogX, analogY);
|
||||
return 0;
|
||||
}
|
7
Windows/KeyboardDevice.h
Normal file
7
Windows/KeyboardDevice.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "InputDevice.h"
|
||||
|
||||
class KeyboardDevice : public InputDevice {
|
||||
public:
|
||||
virtual int UpdateState();
|
||||
};
|
@ -364,6 +364,8 @@
|
||||
<ClCompile Include="Debugger\Debugger_MemoryDlg.cpp" />
|
||||
<ClCompile Include="Debugger\Debugger_VFPUDlg.cpp" />
|
||||
<ClCompile Include="EmuThread.cpp" />
|
||||
<ClCompile Include="InputDevice.cpp" />
|
||||
<ClCompile Include="KeyboardDevice.cpp" />
|
||||
<ClCompile Include="W32Util\DialogManager.cpp" />
|
||||
<ClCompile Include="W32Util\Misc.cpp">
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'">$(IntDir)%(Filename)2.obj</ObjectFileName>
|
||||
@ -405,6 +407,7 @@
|
||||
<ClInclude Include="Debugger\Debugger_VFPUDlg.h" />
|
||||
<ClInclude Include="EmuThread.h" />
|
||||
<ClInclude Include="InputDevice.h" />
|
||||
<ClInclude Include="KeyboardDevice.h" />
|
||||
<ClInclude Include="W32Util\DialogManager.h" />
|
||||
<ClInclude Include="W32Util\Misc.h" />
|
||||
<ClInclude Include="W32Util\PropertySheet.h" />
|
||||
|
@ -98,6 +98,12 @@
|
||||
<ClCompile Include="XinputDevice.cpp">
|
||||
<Filter>Windows\Input</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="KeyboardDevice.cpp">
|
||||
<Filter>Windows\Input</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="InputDevice.cpp">
|
||||
<Filter>Windows\Input</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Debugger\CtrlDisAsmView.h">
|
||||
@ -173,6 +179,9 @@
|
||||
<ClInclude Include="XinputDevice.h">
|
||||
<Filter>Windows\Input</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="KeyboardDevice.h">
|
||||
<Filter>Windows\Input</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="icon1.ico">
|
||||
|
@ -85,7 +85,9 @@ void WindowsHost::SetDebugMode(bool mode)
|
||||
|
||||
void WindowsHost::BeginFrame()
|
||||
{
|
||||
xinput.UpdateState();
|
||||
for (auto iter = this->input.begin(); iter != this->input.end(); iter++)
|
||||
if ((*iter)->UpdateState() == 0)
|
||||
break; // *iter is std::shared_ptr, **iter is InputDevice
|
||||
GL_BeginFrame();
|
||||
}
|
||||
void WindowsHost::EndFrame()
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "../Core/Host.h"
|
||||
#include "XinputDevice.h"
|
||||
#include "InputDevice.h"
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
class WindowsHost : public Host
|
||||
{
|
||||
@ -7,6 +9,7 @@ public:
|
||||
WindowsHost(HWND _displayWindow)
|
||||
{
|
||||
displayWindow = _displayWindow;
|
||||
input = getInputDevices();
|
||||
}
|
||||
void UpdateMemView();
|
||||
void UpdateDisassembly();
|
||||
@ -31,5 +34,5 @@ public:
|
||||
|
||||
private:
|
||||
HWND displayWindow;
|
||||
XinputDevice xinput;
|
||||
std::list<std::shared_ptr<InputDevice>> input;
|
||||
};
|
@ -40,12 +40,13 @@ int XinputDevice::UpdateState() {
|
||||
__CtrlSetAnalog(left.x, left.y);
|
||||
this->prevState = state;
|
||||
this->check_delay = 0;
|
||||
return 0;
|
||||
} else {
|
||||
// wait check_delay frames before polling the controller again
|
||||
this->gamepad_idx = -1;
|
||||
this->check_delay = 100;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We only filter the left stick since PSP has no analog triggers or right stick
|
||||
|
Loading…
x
Reference in New Issue
Block a user