2023-06-29 04:10:08 -04:00
|
|
|
#include "legoinputmanager.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
|
2023-10-03 13:53:22 -04:00
|
|
|
#include "legocontrolmanager.h"
|
|
|
|
#include "legoomni.h"
|
|
|
|
#include "mxautolocker.h"
|
2023-07-02 03:00:28 -04:00
|
|
|
|
2023-10-03 13:53:22 -04:00
|
|
|
DECOMP_SIZE_ASSERT(LegoInputManager, 0x338);
|
2023-11-19 07:23:30 -05:00
|
|
|
DECOMP_SIZE_ASSERT(LegoEventQueue, 0x18);
|
2023-07-02 03:00:28 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005b790
|
2023-06-29 04:10:08 -04:00
|
|
|
LegoInputManager::LegoInputManager()
|
2023-10-03 13:53:22 -04:00
|
|
|
{
|
2023-11-07 03:30:26 -05:00
|
|
|
m_unk0x5c = NULL;
|
2023-10-24 19:38:27 -04:00
|
|
|
m_world = NULL;
|
|
|
|
m_camera = NULL;
|
2023-11-07 03:30:26 -05:00
|
|
|
m_eventQueue = NULL;
|
2023-10-24 19:38:27 -04:00
|
|
|
m_unk0x80 = 0;
|
|
|
|
m_timer = 0;
|
|
|
|
m_unk0x6c = 0;
|
|
|
|
m_unk0x70 = 0;
|
|
|
|
m_controlManager = NULL;
|
|
|
|
m_unk0x81 = 0;
|
|
|
|
m_unk0x88 = FALSE;
|
|
|
|
m_directInput = NULL;
|
|
|
|
m_directInputDevice = NULL;
|
|
|
|
m_unk0x94 = 0;
|
|
|
|
m_unk0x195 = 0;
|
|
|
|
m_joyid = -1;
|
|
|
|
m_joystickIndex = -1;
|
|
|
|
m_useJoystick = FALSE;
|
|
|
|
m_unk0x335 = FALSE;
|
|
|
|
m_unk0x336 = FALSE;
|
|
|
|
m_unk0x74 = 0x19;
|
|
|
|
m_timeout = 1000;
|
2023-10-03 13:53:22 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// STUB: LEGO1 0x1005b8b0
|
2023-10-03 13:53:22 -04:00
|
|
|
MxResult LegoInputManager::Tickle()
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-11-07 03:30:26 -05:00
|
|
|
ProcessEvents();
|
2023-10-24 19:38:27 -04:00
|
|
|
return SUCCESS;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005b8f0
|
2023-06-29 04:10:08 -04:00
|
|
|
LegoInputManager::~LegoInputManager()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
Destroy();
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005b960
|
2023-11-07 03:30:26 -05:00
|
|
|
MxResult LegoInputManager::Create(HWND p_hwnd)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
if (m_eventQueue == NULL)
|
|
|
|
m_eventQueue = new LegoEventQueue();
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// TEMPLATE: LEGO1 0x1005bb80
|
2023-11-19 07:23:30 -05:00
|
|
|
// MxCollection<LegoEventNotificationParam>::Compare
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// TEMPLATE: LEGO1 0x1005bc30
|
2023-11-19 07:23:30 -05:00
|
|
|
// MxCollection<LegoEventNotificationParam>::Destroy
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// TEMPLATE: LEGO1 0x1005bc80
|
2023-11-19 07:23:30 -05:00
|
|
|
// MxList<LegoEventNotificationParam>::~MxList<LegoEventNotificationParam>
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// SYNTHETIC: LEGO1 0x1005bd50
|
2023-11-19 07:23:30 -05:00
|
|
|
// MxCollection<LegoEventNotificationParam>::`scalar deleting destructor'
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// SYNTHETIC: LEGO1 0x1005bdc0
|
2023-11-19 07:23:30 -05:00
|
|
|
// MxList<LegoEventNotificationParam>::`scalar deleting destructor'
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// SYNTHETIC: LEGO1 0x1005beb0
|
2023-11-19 07:23:30 -05:00
|
|
|
// LegoEventQueue::`scalar deleting destructor'
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// SYNTHETIC: LEGO1 0x1005bf70
|
2023-11-19 07:23:30 -05:00
|
|
|
// MxQueue<LegoEventNotificationParam>::`scalar deleting destructor'
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005bfe0
|
2023-10-03 13:53:22 -04:00
|
|
|
void LegoInputManager::Destroy()
|
2023-06-30 14:34:39 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
ReleaseDX();
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-11-07 03:30:26 -05:00
|
|
|
if (m_unk0x5c)
|
|
|
|
delete m_unk0x5c;
|
|
|
|
m_unk0x5c = NULL;
|
|
|
|
|
2023-10-25 16:51:59 -04:00
|
|
|
if (m_eventQueue)
|
|
|
|
delete m_eventQueue;
|
|
|
|
m_eventQueue = NULL;
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_controlManager)
|
|
|
|
delete m_controlManager;
|
2023-10-03 13:53:22 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c030
|
2023-10-03 13:53:22 -04:00
|
|
|
void LegoInputManager::CreateAndAcquireKeyboard(HWND hwnd)
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
HINSTANCE hinstance = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
|
|
|
|
HRESULT hresult = DirectInputCreate(hinstance, 0x500, &m_directInput, NULL); // 0x500 for DX5
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (hresult == DI_OK) {
|
|
|
|
HRESULT createdeviceresult = m_directInput->CreateDevice(GUID_SysKeyboard, &m_directInputDevice, NULL);
|
|
|
|
if (createdeviceresult == DI_OK) {
|
|
|
|
m_directInputDevice->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
|
|
|
|
m_directInputDevice->SetDataFormat(&c_dfDIKeyboard);
|
|
|
|
m_directInputDevice->Acquire();
|
|
|
|
}
|
|
|
|
}
|
2023-10-03 13:53:22 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c0a0
|
2023-10-03 13:53:22 -04:00
|
|
|
void LegoInputManager::ReleaseDX()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_directInputDevice != NULL) {
|
|
|
|
m_directInputDevice->Unacquire();
|
|
|
|
m_directInputDevice->Release();
|
|
|
|
m_directInputDevice = NULL;
|
|
|
|
}
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_directInput != NULL) {
|
|
|
|
m_directInput->Release();
|
|
|
|
m_directInput = NULL;
|
|
|
|
}
|
2023-10-03 13:53:22 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c240
|
2023-10-03 13:53:22 -04:00
|
|
|
MxResult LegoInputManager::GetJoystickId()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
JOYINFOEX joyinfoex;
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_useJoystick != FALSE) {
|
|
|
|
MxS32 joyid = m_joystickIndex;
|
|
|
|
if (joyid >= 0) {
|
|
|
|
joyinfoex.dwSize = 0x34;
|
|
|
|
joyinfoex.dwFlags = 0xFF;
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR &&
|
|
|
|
joyGetDevCaps(joyid, &m_joyCaps, 0x194) == JOYERR_NOERROR) {
|
|
|
|
m_joyid = joyid;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
for (joyid = JOYSTICKID1; joyid < 16; joyid++) {
|
|
|
|
joyinfoex.dwSize = 0x34;
|
|
|
|
joyinfoex.dwFlags = 0xFF;
|
|
|
|
if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR &&
|
|
|
|
joyGetDevCaps(joyid, &m_joyCaps, 0x194) == JOYERR_NOERROR) {
|
|
|
|
m_joyid = joyid;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-03 13:53:22 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return FAILURE;
|
2023-10-03 13:53:22 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c320
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult LegoInputManager::GetJoystickState(
|
|
|
|
MxU32* joystick_x,
|
|
|
|
MxU32* joystick_y,
|
|
|
|
DWORD* buttons_state,
|
|
|
|
MxU32* pov_position
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (m_useJoystick != FALSE) {
|
|
|
|
if (m_joyid < 0 && GetJoystickId() == -1) {
|
|
|
|
m_useJoystick = FALSE;
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JOYINFOEX joyinfoex;
|
|
|
|
joyinfoex.dwSize = 0x34;
|
|
|
|
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNBUTTONS;
|
|
|
|
MxU32 capabilities = m_joyCaps.wCaps;
|
|
|
|
|
|
|
|
if ((capabilities & JOYCAPS_HASPOV) != 0) {
|
|
|
|
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNPOV | JOY_RETURNBUTTONS;
|
|
|
|
|
|
|
|
if ((capabilities & JOYCAPS_POVCTS) != 0)
|
|
|
|
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNPOV | JOY_RETURNBUTTONS | JOY_RETURNPOVCTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
MMRESULT mmresult = joyGetPosEx(m_joyid, &joyinfoex);
|
|
|
|
|
|
|
|
if (mmresult == MMSYSERR_NOERROR) {
|
|
|
|
*buttons_state = joyinfoex.dwButtons;
|
|
|
|
MxU32 xmin = m_joyCaps.wXmin;
|
|
|
|
MxU32 ymax = m_joyCaps.wYmax;
|
|
|
|
MxU32 ymin = m_joyCaps.wYmin;
|
|
|
|
MxS32 ydiff = ymax - ymin;
|
|
|
|
*joystick_x = ((joyinfoex.dwXpos - xmin) * 100) / (m_joyCaps.wXmax - xmin);
|
|
|
|
*joystick_y = ((joyinfoex.dwYpos - m_joyCaps.wYmin) * 100) / ydiff;
|
|
|
|
if ((m_joyCaps.wCaps & (JOYCAPS_POV4DIR | JOYCAPS_POVCTS)) != 0) {
|
|
|
|
if (joyinfoex.dwPOV == JOY_POVCENTERED) {
|
|
|
|
*pov_position = (MxU32) -1;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
*pov_position = joyinfoex.dwPOV / 100;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*pov_position = (MxU32) -1;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FAILURE;
|
2023-06-30 14:34:39 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// STUB: LEGO1 0x1005c470
|
2023-10-24 19:38:27 -04:00
|
|
|
void LegoInputManager::Register(MxCore*)
|
2023-06-30 14:34:39 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
// TODO
|
2023-06-30 14:34:39 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// STUB: LEGO1 0x1005c5c0
|
2023-10-24 19:38:27 -04:00
|
|
|
void LegoInputManager::UnRegister(MxCore*)
|
2023-06-30 14:34:39 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
// TODO
|
2023-06-30 14:34:39 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c700
|
2023-10-24 19:38:27 -04:00
|
|
|
void LegoInputManager::SetCamera(LegoCameraController* p_camera)
|
2023-10-23 07:16:21 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_camera = p_camera;
|
2023-10-23 07:16:21 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c710
|
2023-10-23 07:16:21 -04:00
|
|
|
void LegoInputManager::ClearCamera()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_camera = NULL;
|
2023-10-23 07:16:21 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c720
|
2023-10-24 19:38:27 -04:00
|
|
|
void LegoInputManager::SetWorld(LegoWorld* p_world)
|
2023-10-23 07:16:21 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_world = p_world;
|
2023-10-23 07:16:21 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c730
|
2023-10-23 07:16:21 -04:00
|
|
|
void LegoInputManager::ClearWorld()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_world = NULL;
|
2023-10-23 07:16:21 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c740
|
2023-11-07 03:30:26 -05:00
|
|
|
void LegoInputManager::QueueEvent(NotificationId p_id, MxU8 p_modifier, MxLong p_x, MxLong p_y, MxU8 p_key)
|
|
|
|
{
|
|
|
|
LegoEventNotificationParam param = LegoEventNotificationParam(p_id, NULL, p_modifier, p_x, p_y, p_key);
|
|
|
|
|
|
|
|
if (((!m_unk0x88) || ((m_unk0x335 && (param.GetType() == c_notificationButtonDown)))) ||
|
|
|
|
((m_unk0x336 && (p_key == ' ')))) {
|
|
|
|
ProcessOneEvent(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005c820
|
2023-11-07 03:30:26 -05:00
|
|
|
void LegoInputManager::ProcessEvents()
|
|
|
|
{
|
|
|
|
MxAutoLocker lock(&m_criticalSection);
|
|
|
|
|
|
|
|
LegoEventNotificationParam event;
|
|
|
|
while (m_eventQueue->Dequeue(event)) {
|
|
|
|
if (ProcessOneEvent(event))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// STUB: LEGO1 0x1005c9c0
|
2023-11-07 03:30:26 -05:00
|
|
|
MxBool LegoInputManager::ProcessOneEvent(LegoEventNotificationParam& p_param)
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
// TODO
|
2023-11-07 03:30:26 -05:00
|
|
|
return FALSE;
|
2023-10-03 13:53:22 -04:00
|
|
|
}
|
2023-06-29 04:10:08 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005cfb0
|
2023-10-03 13:53:22 -04:00
|
|
|
void LegoInputManager::SetTimer()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
LegoOmni* omni = LegoOmni::GetInstance();
|
|
|
|
UINT timer = ::SetTimer(omni->GetWindowHandle(), 1, m_timeout, NULL);
|
|
|
|
m_timer = timer;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1005cfd0
|
2023-10-03 13:53:22 -04:00
|
|
|
void LegoInputManager::KillTimer()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_timer != 0) {
|
|
|
|
LegoOmni* omni = LegoOmni::GetInstance();
|
|
|
|
::KillTimer(omni->GetWindowHandle(), m_timer);
|
|
|
|
}
|
2023-10-25 14:51:59 -04:00
|
|
|
}
|
2023-11-19 07:23:30 -05:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// TEMPLATE: LEGO1 0x1005d010
|
2023-11-19 07:23:30 -05:00
|
|
|
// MxListEntry<LegoEventNotificationParam>::GetValue
|