diff --git a/Core/Core.cpp b/Core/Core.cpp index 33f1526f12..655e9dea43 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -104,14 +104,18 @@ void Core_RunLoop() UpdateScreenScale(); { { - lock_guard guard(input_state.lock); #ifdef _WIN32 + lock_guard guard(input_state.lock); + input_state.pad_buttons = 0; + input_state.pad_lstick_x = 0; + input_state.pad_lstick_y = 0; // Temporary hack. if (GetAsyncKeyState(VK_ESCAPE)) { input_state.pad_buttons |= PAD_BUTTON_MENU; } else { input_state.pad_buttons &= ~PAD_BUTTON_MENU; } + host->PollControllers(input_state); #endif } NativeUpdate(input_state); diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 72147481f7..df367a9021 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -444,9 +444,6 @@ void hleEnterVblank(u64 userdata, int cyclesLate) { void hleAfterFlip(u64 userdata, int cyclesLate) { - // This checks input on PC. Fine to do even if not calling BeginFrame. - host->BeginFrame(); - gpu->BeginFrame(); // doesn't really matter if begin or end of frame. } diff --git a/Core/Host.h b/Core/Host.h index ee0143a71c..4d346b5921 100644 --- a/Core/Host.h +++ b/Core/Host.h @@ -21,6 +21,8 @@ #include #include "../Globals.h" +struct InputState; + class PMixer { public: @@ -48,6 +50,7 @@ public: virtual void InitSound(PMixer *mixer) = 0; virtual void UpdateSound() {} virtual void ShutdownSound() = 0; + virtual void PollControllers(InputState &input_state) {} //this is sent from EMU thread! Make sure that Host handles it properly! virtual void BootDone() {} diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 05ff8ab7cb..a7fab39c4e 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -112,7 +112,6 @@ public: virtual void SetDebugMode(bool mode) { } virtual bool InitGL(std::string *error_message) { return true; } - virtual void BeginFrame() {} virtual void ShutdownGL() {} virtual void InitSound(PMixer *mixer); diff --git a/Windows/InputDevice.h b/Windows/InputDevice.h index 8d651152c6..ebbc8a5a7a 100644 --- a/Windows/InputDevice.h +++ b/Windows/InputDevice.h @@ -1,14 +1,17 @@ +#pragma once + +#include +#include + #include "../Common/CommonTypes.h" #include "../Core/HLE/sceCtrl.h" -#pragma once +struct InputState; + class InputDevice { public: - virtual int UpdateState() = 0; + virtual int UpdateState(InputState &input_state) = 0; }; -#include -#include -#include std::list> getInputDevices(); diff --git a/Windows/KeyboardDevice.cpp b/Windows/KeyboardDevice.cpp index d0deb442b9..cd7349ff0a 100644 --- a/Windows/KeyboardDevice.cpp +++ b/Windows/KeyboardDevice.cpp @@ -1,3 +1,4 @@ +#include "input/input_state.h" #include "KeyboardDevice.h" #include "../Common/CommonTypes.h" #include "../Core/HLE/sceCtrl.h" @@ -18,6 +19,21 @@ static const unsigned short key_ctrl_map[] = { VK_RIGHT, CTRL_RIGHT, }; +static const unsigned short key_pad_map[] = { + VK_SPACE, PAD_BUTTON_START, + 'V', PAD_BUTTON_SELECT, + 'A', PAD_BUTTON_X, + 'S', PAD_BUTTON_Y, + 'X', PAD_BUTTON_B, + 'Z', PAD_BUTTON_A, + 'Q', PAD_BUTTON_LBUMPER, + 'W', PAD_BUTTON_RBUMPER, + VK_UP, PAD_BUTTON_UP, + VK_DOWN, PAD_BUTTON_DOWN, + VK_LEFT, PAD_BUTTON_LEFT, + VK_RIGHT, PAD_BUTTON_RIGHT, +}; + static const unsigned short analog_ctrl_map[] = { 'I', CTRL_UP, 'K', CTRL_DOWN, @@ -25,7 +41,7 @@ static const unsigned short analog_ctrl_map[] = { 'L', CTRL_RIGHT, }; -int KeyboardDevice::UpdateState() { +int KeyboardDevice::UpdateState(InputState &input_state) { bool alternate = GetAsyncKeyState(VK_SHIFT) != 0; static u32 alternator = 0; bool doAlternate = alternate && (alternator++ % 10) < 5; @@ -33,9 +49,11 @@ int KeyboardDevice::UpdateState() { for (int i = 0; i < sizeof(key_ctrl_map)/sizeof(key_ctrl_map[0]); i += 2) { if (!GetAsyncKeyState(key_ctrl_map[i]) || doAlternate) __CtrlButtonUp(key_ctrl_map[i+1]); - else { + else __CtrlButtonDown(key_ctrl_map[i+1]); - } + + //if (GetAsyncKeyState(key_pad_map[i]) && !doAlternate) + // input_state.pad_buttons |= key_pad_map[i+1]; } float analogX = 0; @@ -61,6 +79,8 @@ int KeyboardDevice::UpdateState() { } } - __CtrlSetAnalog(analogX, analogY); + // __CtrlSetAnalog(analogX, analogY); + input_state.pad_lstick_x = analogX; + input_state.pad_lstick_y = analogY; return 0; } \ No newline at end of file diff --git a/Windows/KeyboardDevice.h b/Windows/KeyboardDevice.h index 79d238348c..b97ef13688 100644 --- a/Windows/KeyboardDevice.h +++ b/Windows/KeyboardDevice.h @@ -3,5 +3,5 @@ class KeyboardDevice : public InputDevice { public: - virtual int UpdateState(); + virtual int UpdateState(InputState &input_state); }; diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index b0d8ecb981..87ff538cc0 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -129,10 +129,10 @@ void WindowsHost::SetDebugMode(bool mode) } -void WindowsHost::BeginFrame() +void WindowsHost::PollControllers(InputState &input_state) { for (auto iter = this->input.begin(); iter != this->input.end(); iter++) - if ((*iter)->UpdateState() == 0) + if ((*iter)->UpdateState(input_state) == 0) break; // *iter is std::shared_ptr, **iter is InputDevice } diff --git a/Windows/WindowsHost.h b/Windows/WindowsHost.h index 9aa2f9237c..268abcba59 100644 --- a/Windows/WindowsHost.h +++ b/Windows/WindowsHost.h @@ -37,7 +37,7 @@ public: void AddSymbol(std::string name, u32 addr, u32 size, int type); bool InitGL(std::string *error_message); - void BeginFrame(); + void PollControllers(InputState &input_state); void ShutdownGL(); void InitSound(PMixer *mixer); diff --git a/Windows/XinputDevice.cpp b/Windows/XinputDevice.cpp index 86fc0dab64..5ff28fdf4a 100644 --- a/Windows/XinputDevice.cpp +++ b/Windows/XinputDevice.cpp @@ -1,7 +1,6 @@ -#include "stdafx.h" -#include "XinputDevice.h" #include -#include + +#include "XinputDevice.h" #ifndef XUSER_MAX_COUNT #define XUSER_MAX_COUNT 4 @@ -19,7 +18,7 @@ struct Stick { }; static Stick NormalizedDeadzoneFilter(XINPUT_STATE &state); -int XinputDevice::UpdateState() { +int XinputDevice::UpdateState(InputState &input_state) { if (this->check_delay-- > 0) return -1; XINPUT_STATE state; ZeroMemory( &state, sizeof(XINPUT_STATE) ); diff --git a/Windows/XinputDevice.h b/Windows/XinputDevice.h index 71a31becfe..c70f8d853b 100644 --- a/Windows/XinputDevice.h +++ b/Windows/XinputDevice.h @@ -7,7 +7,7 @@ class XinputDevice : { public: XinputDevice(); - virtual int UpdateState(); + virtual int UpdateState(InputState &input_state); private: void ApplyDiff(XINPUT_STATE &state); int gamepad_idx; diff --git a/headless/StubHost.h b/headless/StubHost.h index 727bec7e56..5a17b07c56 100644 --- a/headless/StubHost.h +++ b/headless/StubHost.h @@ -34,7 +34,6 @@ public: virtual void SetDebugMode(bool mode) { } virtual bool InitGL(std::string *error_message) {return true;} - virtual void BeginFrame() {} virtual void ShutdownGL() {} virtual void InitSound(PMixer *mixer) {} diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index a6629982f2..b3b13a37a9 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -213,11 +213,6 @@ bool WindowsHeadlessHost::ResizeGL() return true; } -void WindowsHeadlessHost::BeginFrame() -{ - -} - void WindowsHeadlessHost::SwapBuffers() { ::SwapBuffers(hDC); diff --git a/headless/WindowsHeadlessHost.h b/headless/WindowsHeadlessHost.h index d624f4d3cc..faf5c7b54a 100644 --- a/headless/WindowsHeadlessHost.h +++ b/headless/WindowsHeadlessHost.h @@ -29,7 +29,6 @@ class WindowsHeadlessHost : public HeadlessHost { public: virtual void InitGL(); - virtual void BeginFrame(); virtual void ShutdownGL(); virtual bool isGLWorking() { return glOkay; } diff --git a/native b/native index 34c4700adb..435392b137 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 34c4700adb67b405fe7b1f6804cca41d49eb165e +Subproject commit 435392b137e7c80ff40db8b2af2feac6019f970e