mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
Use SDL kb state for navigational keys
This commit is contained in:
parent
451907599f
commit
d69cd89d69
@ -7,6 +7,7 @@
|
|||||||
#include "mxpresenter.h"
|
#include "mxpresenter.h"
|
||||||
#include "mxqueue.h"
|
#include "mxqueue.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_keyboard.h>
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
|
||||||
class LegoCameraController;
|
class LegoCameraController;
|
||||||
@ -94,8 +95,6 @@ class LegoInputManager : public MxPresenter {
|
|||||||
|
|
||||||
MxResult Create(HWND p_hwnd);
|
MxResult Create(HWND p_hwnd);
|
||||||
void Destroy() override;
|
void Destroy() override;
|
||||||
void CreateAndAcquireKeyboard(HWND p_hwnd);
|
|
||||||
void ReleaseDX();
|
|
||||||
MxResult GetJoystickId();
|
MxResult GetJoystickId();
|
||||||
MxResult GetJoystickState(MxU32* p_joystickX, MxU32* p_joystickY, DWORD* p_buttonsState, MxU32* p_povPosition);
|
MxResult GetJoystickState(MxU32* p_joystickX, MxU32* p_joystickY, DWORD* p_buttonsState, MxU32* p_povPosition);
|
||||||
void StartAutoDragTimer();
|
void StartAutoDragTimer();
|
||||||
@ -132,31 +131,28 @@ class LegoInputManager : public MxPresenter {
|
|||||||
// LegoInputManager::`scalar deleting destructor'
|
// LegoInputManager::`scalar deleting destructor'
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MxCriticalSection m_criticalSection; // 0x58
|
MxCriticalSection m_criticalSection; // 0x58
|
||||||
LegoNotifyList* m_keyboardNotifyList; // 0x5c
|
LegoNotifyList* m_keyboardNotifyList; // 0x5c
|
||||||
LegoCameraController* m_camera; // 0x60
|
LegoCameraController* m_camera; // 0x60
|
||||||
LegoWorld* m_world; // 0x64
|
LegoWorld* m_world; // 0x64
|
||||||
LegoEventQueue* m_eventQueue; // 0x68
|
LegoEventQueue* m_eventQueue; // 0x68
|
||||||
MxS32 m_x; // 0x6c
|
MxS32 m_x; // 0x6c
|
||||||
MxS32 m_y; // 0x70
|
MxS32 m_y; // 0x70
|
||||||
MxS32 m_unk0x74; // 0x74
|
MxS32 m_unk0x74; // 0x74
|
||||||
UINT m_autoDragTimerID; // 0x78
|
UINT m_autoDragTimerID; // 0x78
|
||||||
UINT m_autoDragTime; // 0x7c
|
UINT m_autoDragTime; // 0x7c
|
||||||
MxBool m_unk0x80; // 0x80
|
MxBool m_unk0x80; // 0x80
|
||||||
MxBool m_unk0x81; // 0x81
|
MxBool m_unk0x81; // 0x81
|
||||||
LegoControlManager* m_controlManager; // 0x84
|
LegoControlManager* m_controlManager; // 0x84
|
||||||
MxBool m_unk0x88; // 0x88
|
MxBool m_unk0x88; // 0x88
|
||||||
IDirectInput* m_directInput; // 0x8c
|
const Uint8* m_keyboardState;
|
||||||
IDirectInputDevice* m_directInputDevice; // 0x90
|
MxBool m_unk0x195; // 0x195
|
||||||
MxBool m_kbStateSuccess; // 0x94
|
MxS32 m_joyid; // 0x198
|
||||||
MxU8 m_keyboardState[256]; // 0x95
|
MxS32 m_joystickIndex; // 0x19c
|
||||||
MxBool m_unk0x195; // 0x195
|
JOYCAPS m_joyCaps; // 0x200
|
||||||
MxS32 m_joyid; // 0x198
|
MxBool m_useJoystick; // 0x334
|
||||||
MxS32 m_joystickIndex; // 0x19c
|
MxBool m_unk0x335; // 0x335
|
||||||
JOYCAPS m_joyCaps; // 0x200
|
MxBool m_unk0x336; // 0x336
|
||||||
MxBool m_useJoystick; // 0x334
|
|
||||||
MxBool m_unk0x335; // 0x335
|
|
||||||
MxBool m_unk0x336; // 0x336
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TEMPLATE: LEGO1 0x10028850
|
// TEMPLATE: LEGO1 0x10028850
|
||||||
|
|||||||
@ -38,9 +38,6 @@ LegoInputManager::LegoInputManager()
|
|||||||
m_controlManager = NULL;
|
m_controlManager = NULL;
|
||||||
m_unk0x81 = FALSE;
|
m_unk0x81 = FALSE;
|
||||||
m_unk0x88 = FALSE;
|
m_unk0x88 = FALSE;
|
||||||
m_directInput = NULL;
|
|
||||||
m_directInputDevice = NULL;
|
|
||||||
m_kbStateSuccess = FALSE;
|
|
||||||
m_unk0x195 = 0;
|
m_unk0x195 = 0;
|
||||||
m_joyid = -1;
|
m_joyid = -1;
|
||||||
m_joystickIndex = -1;
|
m_joystickIndex = -1;
|
||||||
@ -79,10 +76,9 @@ MxResult LegoInputManager::Create(HWND p_hwnd)
|
|||||||
m_eventQueue = new LegoEventQueue;
|
m_eventQueue = new LegoEventQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateAndAcquireKeyboard(p_hwnd);
|
|
||||||
GetJoystickId();
|
GetJoystickId();
|
||||||
|
|
||||||
if (!m_keyboardNotifyList || !m_eventQueue || !m_directInputDevice) {
|
if (!m_keyboardNotifyList || !m_eventQueue) {
|
||||||
Destroy();
|
Destroy();
|
||||||
result = FAILURE;
|
result = FAILURE;
|
||||||
}
|
}
|
||||||
@ -93,8 +89,6 @@ MxResult LegoInputManager::Create(HWND p_hwnd)
|
|||||||
// FUNCTION: LEGO1 0x1005bfe0
|
// FUNCTION: LEGO1 0x1005bfe0
|
||||||
void LegoInputManager::Destroy()
|
void LegoInputManager::Destroy()
|
||||||
{
|
{
|
||||||
ReleaseDX();
|
|
||||||
|
|
||||||
if (m_keyboardNotifyList) {
|
if (m_keyboardNotifyList) {
|
||||||
delete m_keyboardNotifyList;
|
delete m_keyboardNotifyList;
|
||||||
}
|
}
|
||||||
@ -110,55 +104,10 @@ void LegoInputManager::Destroy()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x1005c030
|
|
||||||
void LegoInputManager::CreateAndAcquireKeyboard(HWND p_hwnd)
|
|
||||||
{
|
|
||||||
HINSTANCE hinstance = (HINSTANCE) GetWindowLong(p_hwnd, GWL_HINSTANCE);
|
|
||||||
HRESULT hresult = DirectInputCreate(hinstance, 0x500, &m_directInput, NULL); // 0x500 for DX5
|
|
||||||
|
|
||||||
if (hresult == DI_OK) {
|
|
||||||
HRESULT createdeviceresult = m_directInput->CreateDevice(GUID_SysKeyboard, &m_directInputDevice, NULL);
|
|
||||||
if (createdeviceresult == DI_OK) {
|
|
||||||
m_directInputDevice->SetCooperativeLevel(p_hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
|
|
||||||
m_directInputDevice->SetDataFormat(&c_dfDIKeyboard);
|
|
||||||
m_directInputDevice->Acquire();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x1005c0a0
|
|
||||||
void LegoInputManager::ReleaseDX()
|
|
||||||
{
|
|
||||||
if (m_directInputDevice != NULL) {
|
|
||||||
m_directInputDevice->Unacquire();
|
|
||||||
m_directInputDevice->Release();
|
|
||||||
m_directInputDevice = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_directInput != NULL) {
|
|
||||||
m_directInput->Release();
|
|
||||||
m_directInput = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x1005c0f0
|
// FUNCTION: LEGO1 0x1005c0f0
|
||||||
void LegoInputManager::GetKeyboardState()
|
void LegoInputManager::GetKeyboardState()
|
||||||
{
|
{
|
||||||
m_kbStateSuccess = FALSE;
|
m_keyboardState = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
if (m_directInputDevice) {
|
|
||||||
HRESULT hr = m_directInputDevice->GetDeviceState(sizeOfArray(m_keyboardState), &m_keyboardState);
|
|
||||||
|
|
||||||
if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) {
|
|
||||||
if (m_directInputDevice->Acquire() == S_OK) {
|
|
||||||
hr = m_directInputDevice->GetDeviceState(sizeOfArray(m_keyboardState), &m_keyboardState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hr == S_OK) {
|
|
||||||
m_kbStateSuccess = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x1005c160
|
// FUNCTION: LEGO1 0x1005c160
|
||||||
@ -166,39 +115,29 @@ MxResult LegoInputManager::GetNavigationKeyStates(MxU32& p_keyFlags)
|
|||||||
{
|
{
|
||||||
GetKeyboardState();
|
GetKeyboardState();
|
||||||
|
|
||||||
if (!m_kbStateSuccess) {
|
|
||||||
return FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_unk0x100f67b8) {
|
if (g_unk0x100f67b8) {
|
||||||
if (m_keyboardState[DIK_LEFT] & 0x80 && GetAsyncKeyState(VK_LEFT) == 0) {
|
// [library:input] Figure out if we still need the logic that was here.
|
||||||
m_keyboardState[DIK_LEFT] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_keyboardState[DIK_RIGHT] & 0x80 && GetAsyncKeyState(VK_RIGHT) == 0) {
|
|
||||||
m_keyboardState[DIK_RIGHT] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MxU32 keyFlags = 0;
|
MxU32 keyFlags = 0;
|
||||||
|
|
||||||
if ((m_keyboardState[DIK_NUMPAD8] | m_keyboardState[DIK_UP]) & 0x80) {
|
if (m_keyboardState[SDL_SCANCODE_KP_8] || m_keyboardState[SDL_SCANCODE_UP]) {
|
||||||
keyFlags |= c_up;
|
keyFlags |= c_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_keyboardState[DIK_NUMPAD2] | m_keyboardState[DIK_DOWN]) & 0x80) {
|
if ((m_keyboardState[SDL_SCANCODE_KP_2] || m_keyboardState[SDL_SCANCODE_DOWN])) {
|
||||||
keyFlags |= c_down;
|
keyFlags |= c_down;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_keyboardState[DIK_NUMPAD4] | m_keyboardState[DIK_LEFT]) & 0x80) {
|
if ((m_keyboardState[SDL_SCANCODE_KP_4] || m_keyboardState[SDL_SCANCODE_LEFT])) {
|
||||||
keyFlags |= c_left;
|
keyFlags |= c_left;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_keyboardState[DIK_NUMPAD6] | m_keyboardState[DIK_RIGHT]) & 0x80) {
|
if ((m_keyboardState[SDL_SCANCODE_KP_6] || m_keyboardState[SDL_SCANCODE_RIGHT])) {
|
||||||
keyFlags |= c_right;
|
keyFlags |= c_right;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_keyboardState[DIK_LCONTROL] | m_keyboardState[DIK_RCONTROL]) & 0x80) {
|
if (m_keyboardState[SDL_SCANCODE_LCTRL] || m_keyboardState[SDL_SCANCODE_RCTRL]) {
|
||||||
keyFlags |= c_bit5;
|
keyFlags |= c_bit5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user