mirror of
https://github.com/isledecomp/isle-portable.git
synced 2024-12-20 21:02:28 -05:00
replace directinput joystick APIs with SDL (#41)
Some checks are pending
Build / Current msys2 mingw32 (Debug) (push) Waiting to run
Build / Current msys2 mingw64 (Debug) (push) Waiting to run
Build / Current MSVC (32-bit, Debug) (push) Waiting to run
Build / Current MSVC (64-bit, Debug) (push) Waiting to run
Build / Current MSVC (ARM64, Debug) (push) Waiting to run
Build / Current MSVC (32-bit, Release) (push) Waiting to run
Build / Upload artifacts (push) Blocked by required conditions
Format / C++ (push) Waiting to run
Naming / C++ (push) Waiting to run
Some checks are pending
Build / Current msys2 mingw32 (Debug) (push) Waiting to run
Build / Current msys2 mingw64 (Debug) (push) Waiting to run
Build / Current MSVC (32-bit, Debug) (push) Waiting to run
Build / Current MSVC (64-bit, Debug) (push) Waiting to run
Build / Current MSVC (ARM64, Debug) (push) Waiting to run
Build / Current MSVC (32-bit, Release) (push) Waiting to run
Build / Upload artifacts (push) Blocked by required conditions
Format / C++ (push) Waiting to run
Naming / C++ (push) Waiting to run
This commit is contained in:
parent
d3212a0523
commit
4cd4b55ae7
5 changed files with 72 additions and 68 deletions
|
@ -236,7 +236,7 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv)
|
||||||
{
|
{
|
||||||
*appstate = NULL;
|
*appstate = NULL;
|
||||||
|
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)) {
|
||||||
SDL_ShowSimpleMessageBox(
|
SDL_ShowSimpleMessageBox(
|
||||||
SDL_MESSAGEBOX_ERROR,
|
SDL_MESSAGEBOX_ERROR,
|
||||||
"LEGO® Island Error",
|
"LEGO® Island Error",
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
#include "mxpresenter.h"
|
#include "mxpresenter.h"
|
||||||
#include "mxqueue.h"
|
#include "mxqueue.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_joystick.h>
|
||||||
#include <SDL3/SDL_keyboard.h>
|
#include <SDL3/SDL_keyboard.h>
|
||||||
#include <dinput.h>
|
#include <windows.h>
|
||||||
|
|
||||||
class LegoCameraController;
|
class LegoCameraController;
|
||||||
class LegoControlManager;
|
class LegoControlManager;
|
||||||
|
@ -95,8 +96,8 @@ class LegoInputManager : public MxPresenter {
|
||||||
|
|
||||||
MxResult Create(HWND p_hwnd);
|
MxResult Create(HWND p_hwnd);
|
||||||
void Destroy() override;
|
void Destroy() override;
|
||||||
MxResult GetJoystickId();
|
MxResult GetJoystick();
|
||||||
MxResult GetJoystickState(MxU32* p_joystickX, MxU32* p_joystickY, DWORD* p_buttonsState, MxU32* p_povPosition);
|
MxResult GetJoystickState(MxU32* p_joystickX, MxU32* p_joystickY, MxU32* p_povPosition);
|
||||||
void StartAutoDragTimer();
|
void StartAutoDragTimer();
|
||||||
void StopAutoDragTimer();
|
void StopAutoDragTimer();
|
||||||
void EnableInputProcessing();
|
void EnableInputProcessing();
|
||||||
|
@ -150,10 +151,10 @@ class LegoInputManager : public MxPresenter {
|
||||||
LegoControlManager* m_controlManager; // 0x84
|
LegoControlManager* m_controlManager; // 0x84
|
||||||
MxBool m_unk0x88; // 0x88
|
MxBool m_unk0x88; // 0x88
|
||||||
const bool* m_keyboardState;
|
const bool* m_keyboardState;
|
||||||
MxBool m_unk0x195; // 0x195
|
MxBool m_unk0x195; // 0x195
|
||||||
MxS32 m_joyid; // 0x198
|
SDL_JoystickID* m_joyids;
|
||||||
|
SDL_Joystick* m_joystick;
|
||||||
MxS32 m_joystickIndex; // 0x19c
|
MxS32 m_joystickIndex; // 0x19c
|
||||||
JOYCAPS m_joyCaps; // 0x200
|
|
||||||
MxBool m_useJoystick; // 0x334
|
MxBool m_useJoystick; // 0x334
|
||||||
MxBool m_unk0x335; // 0x335
|
MxBool m_unk0x335; // 0x335
|
||||||
MxBool m_unk0x336; // 0x336
|
MxBool m_unk0x336; // 0x336
|
||||||
|
|
|
@ -499,12 +499,10 @@ MxResult LegoNavController::ProcessJoystickInput(MxBool& p_und)
|
||||||
if (instance->GetInputManager()) {
|
if (instance->GetInputManager()) {
|
||||||
MxS32 joystickX;
|
MxS32 joystickX;
|
||||||
MxS32 joystickY;
|
MxS32 joystickY;
|
||||||
DWORD buttonState;
|
|
||||||
MxS32 povPosition;
|
MxS32 povPosition;
|
||||||
|
|
||||||
if (instance->GetInputManager()
|
if (instance->GetInputManager()
|
||||||
->GetJoystickState((MxU32*) &joystickX, (MxU32*) &joystickY, &buttonState, (MxU32*) &povPosition) !=
|
->GetJoystickState((MxU32*) &joystickX, (MxU32*) &joystickY, (MxU32*) &povPosition) != FAILURE) {
|
||||||
FAILURE) {
|
|
||||||
MxU32 yVal = (joystickY * m_vMax) / 100;
|
MxU32 yVal = (joystickY * m_vMax) / 100;
|
||||||
MxU32 xVal = (joystickX * m_hMax) / 100;
|
MxU32 xVal = (joystickX * m_hMax) / 100;
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,9 @@ LegoInputManager::LegoInputManager()
|
||||||
m_unk0x81 = FALSE;
|
m_unk0x81 = FALSE;
|
||||||
m_unk0x88 = FALSE;
|
m_unk0x88 = FALSE;
|
||||||
m_unk0x195 = 0;
|
m_unk0x195 = 0;
|
||||||
m_joyid = -1;
|
m_joyids = NULL;
|
||||||
m_joystickIndex = -1;
|
m_joystickIndex = -1;
|
||||||
|
m_joystick = NULL;
|
||||||
m_useJoystick = FALSE;
|
m_useJoystick = FALSE;
|
||||||
m_unk0x335 = FALSE;
|
m_unk0x335 = FALSE;
|
||||||
m_unk0x336 = FALSE;
|
m_unk0x336 = FALSE;
|
||||||
|
@ -77,7 +78,7 @@ MxResult LegoInputManager::Create(HWND p_hwnd)
|
||||||
m_eventQueue = new LegoEventQueue;
|
m_eventQueue = new LegoEventQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetJoystickId();
|
GetJoystick();
|
||||||
|
|
||||||
if (!m_keyboardNotifyList || !m_eventQueue) {
|
if (!m_keyboardNotifyList || !m_eventQueue) {
|
||||||
Destroy();
|
Destroy();
|
||||||
|
@ -148,29 +149,27 @@ MxResult LegoInputManager::GetNavigationKeyStates(MxU32& p_keyFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x1005c240
|
// FUNCTION: LEGO1 0x1005c240
|
||||||
MxResult LegoInputManager::GetJoystickId()
|
MxResult LegoInputManager::GetJoystick()
|
||||||
{
|
{
|
||||||
JOYINFOEX joyinfoex;
|
if (m_joystick != NULL && SDL_JoystickConnected(m_joystick) == TRUE) {
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_useJoystick != FALSE) {
|
MxS32 numJoysticks = 0;
|
||||||
|
m_joyids = SDL_GetJoysticks(&numJoysticks);
|
||||||
|
|
||||||
|
if (m_useJoystick != FALSE && numJoysticks != 0) {
|
||||||
MxS32 joyid = m_joystickIndex;
|
MxS32 joyid = m_joystickIndex;
|
||||||
if (joyid >= 0) {
|
if (joyid >= 0) {
|
||||||
joyinfoex.dwSize = 0x34;
|
m_joystick = SDL_OpenJoystick(m_joyids[joyid]);
|
||||||
joyinfoex.dwFlags = 0xFF;
|
if (m_joystick != NULL) {
|
||||||
|
|
||||||
if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR &&
|
|
||||||
joyGetDevCaps(joyid, &m_joyCaps, 0x194) == JOYERR_NOERROR) {
|
|
||||||
m_joyid = joyid;
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (joyid = JOYSTICKID1; joyid < 16; joyid++) {
|
for (joyid = 0; joyid < numJoysticks; joyid++) {
|
||||||
joyinfoex.dwSize = 0x34;
|
m_joystick = SDL_OpenJoystick(m_joyids[joyid]);
|
||||||
joyinfoex.dwFlags = 0xFF;
|
if (m_joystick != NULL) {
|
||||||
if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR &&
|
|
||||||
joyGetDevCaps(joyid, &m_joyCaps, 0x194) == JOYERR_NOERROR) {
|
|
||||||
m_joyid = joyid;
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,55 +179,61 @@ MxResult LegoInputManager::GetJoystickId()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x1005c320
|
// FUNCTION: LEGO1 0x1005c320
|
||||||
MxResult LegoInputManager::GetJoystickState(
|
MxResult LegoInputManager::GetJoystickState(MxU32* p_joystickX, MxU32* p_joystickY, MxU32* p_povPosition)
|
||||||
MxU32* p_joystickX,
|
|
||||||
MxU32* p_joystickY,
|
|
||||||
DWORD* p_buttonsState,
|
|
||||||
MxU32* p_povPosition
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (m_useJoystick != FALSE) {
|
if (m_useJoystick != FALSE) {
|
||||||
if (m_joyid < 0 && GetJoystickId() == -1) {
|
if (GetJoystick() == -1) {
|
||||||
m_useJoystick = FALSE;
|
if (m_joystick != NULL) {
|
||||||
|
// GetJoystick() failed but handle to joystick is still open, close it
|
||||||
|
SDL_CloseJoystick(m_joystick);
|
||||||
|
m_joystick = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
JOYINFOEX joyinfoex;
|
MxS16 xPos = SDL_GetJoystickAxis(m_joystick, 0);
|
||||||
joyinfoex.dwSize = 0x34;
|
MxS16 yPos = SDL_GetJoystickAxis(m_joystick, 1);
|
||||||
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNBUTTONS;
|
MxU8 hatPos = SDL_GetJoystickHat(m_joystick, 0);
|
||||||
MxU32 capabilities = m_joyCaps.wCaps;
|
|
||||||
|
|
||||||
if ((capabilities & JOYCAPS_HASPOV) != 0) {
|
// normalize values acquired from joystick axes
|
||||||
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNPOV | JOY_RETURNBUTTONS;
|
*p_joystickX = ((xPos + 32768) * 100) / 65535;
|
||||||
|
*p_joystickY = ((yPos + 32768) * 100) / 65535;
|
||||||
|
|
||||||
if ((capabilities & JOYCAPS_POVCTS) != 0) {
|
switch (hatPos) {
|
||||||
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNPOV | JOY_RETURNBUTTONS | JOY_RETURNPOVCTS;
|
case SDL_HAT_CENTERED:
|
||||||
}
|
*p_povPosition = (MxU32) -1;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_UP:
|
||||||
|
*p_povPosition = (MxU32) 0;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_RIGHT:
|
||||||
|
*p_povPosition = (MxU32) 9000 / 100;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_DOWN:
|
||||||
|
*p_povPosition = (MxU32) 18000 / 100;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_LEFT:
|
||||||
|
*p_povPosition = (MxU32) 27000 / 100;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_RIGHTUP:
|
||||||
|
*p_povPosition = (MxU32) 4500 / 100;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_RIGHTDOWN:
|
||||||
|
*p_povPosition = (MxU32) 13500 / 100;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_LEFTUP:
|
||||||
|
*p_povPosition = (MxU32) 31500 / 100;
|
||||||
|
break;
|
||||||
|
case SDL_HAT_LEFTDOWN:
|
||||||
|
*p_povPosition = (MxU32) 22500 / 100;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*p_povPosition = (MxU32) -1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MMRESULT mmresult = joyGetPosEx(m_joyid, &joyinfoex);
|
return SUCCESS;
|
||||||
|
|
||||||
if (mmresult == MMSYSERR_NOERROR) {
|
|
||||||
*p_buttonsState = joyinfoex.dwButtons;
|
|
||||||
MxU32 xmin = m_joyCaps.wXmin;
|
|
||||||
MxU32 ymax = m_joyCaps.wYmax;
|
|
||||||
MxU32 ymin = m_joyCaps.wYmin;
|
|
||||||
MxS32 ydiff = ymax - ymin;
|
|
||||||
*p_joystickX = ((joyinfoex.dwXpos - xmin) * 100) / (m_joyCaps.wXmax - xmin);
|
|
||||||
*p_joystickY = ((joyinfoex.dwYpos - m_joyCaps.wYmin) * 100) / ydiff;
|
|
||||||
if ((m_joyCaps.wCaps & (JOYCAPS_POV4DIR | JOYCAPS_POVCTS)) != 0) {
|
|
||||||
if (joyinfoex.dwPOV == JOY_POVCENTERED) {
|
|
||||||
*p_povPosition = (MxU32) -1;
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
*p_povPosition = joyinfoex.dwPOV / 100;
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*p_povPosition = (MxU32) -1;
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
|
|
|
@ -27,7 +27,7 @@ To achieve our goal of platform independence, we need to replace any Windows-onl
|
||||||
| Filesystem | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Afilesystem%5D%22&type=code) |
|
| Filesystem | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Afilesystem%5D%22&type=code) |
|
||||||
| Threads, Mutexes (Synchronization) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Asynchronization%5D%22&type=code) |
|
| Threads, Mutexes (Synchronization) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Asynchronization%5D%22&type=code) |
|
||||||
| Keyboard/Mouse, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
| Keyboard/Mouse, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
||||||
| Joystick/Gamepad, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
| Joystick/Gamepad, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
||||||
| WinMM, DirectSound (Audio) | [SDL3](https://www.libsdl.org/), [miniaudio](https://miniaud.io/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aaudio%5D%22&type=code) |
|
| WinMM, DirectSound (Audio) | [SDL3](https://www.libsdl.org/), [miniaudio](https://miniaud.io/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aaudio%5D%22&type=code) |
|
||||||
| DirectDraw (2D video) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A2d%5D%22&type=code) |
|
| DirectDraw (2D video) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A2d%5D%22&type=code) |
|
||||||
| [Smacker](https://github.com/isledecomp/isle/tree/master/3rdparty/smacker) | [libsmacker](https://github.com/foxtacles/libsmacker) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable%20%22%2F%2F%20%5Blibrary%3Alibsmacker%5D%22&type=code) |
|
| [Smacker](https://github.com/isledecomp/isle/tree/master/3rdparty/smacker) | [libsmacker](https://github.com/foxtacles/libsmacker) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable%20%22%2F%2F%20%5Blibrary%3Alibsmacker%5D%22&type=code) |
|
||||||
|
|
Loading…
Reference in a new issue