2022-05-19 01:51:26 -07:00
|
|
|
#include "dinput.h"
|
|
|
|
|
2022-09-23 05:43:44 -07:00
|
|
|
namespace fallout {
|
|
|
|
|
2022-08-07 04:52:44 -07:00
|
|
|
static int gMouseWheelDeltaX = 0;
|
|
|
|
static int gMouseWheelDeltaY = 0;
|
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
// 0x4E0400
|
|
|
|
bool directInputInit()
|
|
|
|
{
|
2022-05-23 01:44:49 -07:00
|
|
|
if (SDL_InitSubSystem(SDL_INIT_EVENTS) != 0) {
|
2022-05-19 01:51:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mouseDeviceInit()) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!keyboardDeviceInit()) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
2022-05-23 01:44:49 -07:00
|
|
|
directInputFree();
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E0478
|
|
|
|
void directInputFree()
|
|
|
|
{
|
2022-05-23 01:44:49 -07:00
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
2022-05-19 01:51:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E04E8
|
|
|
|
bool mouseDeviceAcquire()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E0514
|
|
|
|
bool mouseDeviceUnacquire()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E053C
|
|
|
|
bool mouseDeviceGetData(MouseData* mouseState)
|
|
|
|
{
|
2023-05-23 13:32:11 -07:00
|
|
|
// CE: This function is sometimes called outside loops calling `get_input`
|
|
|
|
// and subsequently `GNW95_process_message`, so mouse events might not be
|
|
|
|
// handled by SDL yet.
|
|
|
|
//
|
|
|
|
// TODO: Move mouse events processing into `GNW95_process_message` and
|
|
|
|
// update mouse position manually.
|
|
|
|
SDL_PumpEvents();
|
|
|
|
|
2023-05-09 08:36:20 -07:00
|
|
|
Uint32 buttons = SDL_GetRelativeMouseState(&(mouseState->x), &(mouseState->y));
|
|
|
|
mouseState->buttons[0] = (buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
|
|
|
|
mouseState->buttons[1] = (buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
|
|
|
|
mouseState->wheelX = gMouseWheelDeltaX;
|
|
|
|
mouseState->wheelY = gMouseWheelDeltaY;
|
|
|
|
|
|
|
|
gMouseWheelDeltaX = 0;
|
|
|
|
gMouseWheelDeltaY = 0;
|
2022-08-07 04:52:44 -07:00
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E05A8
|
|
|
|
bool keyboardDeviceAcquire()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E05D4
|
|
|
|
bool keyboardDeviceUnacquire()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E05FC
|
|
|
|
bool keyboardDeviceReset()
|
|
|
|
{
|
2022-05-23 01:44:49 -07:00
|
|
|
SDL_FlushEvents(SDL_KEYDOWN, SDL_TEXTINPUT);
|
2022-05-19 01:51:26 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E0650
|
|
|
|
bool keyboardDeviceGetData(KeyboardData* keyboardData)
|
|
|
|
{
|
2022-05-23 01:44:49 -07:00
|
|
|
return true;
|
2022-05-19 01:51:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E070C
|
|
|
|
bool mouseDeviceInit()
|
|
|
|
{
|
2022-05-23 01:44:49 -07:00
|
|
|
return SDL_SetRelativeMouseMode(SDL_TRUE) == 0;
|
2022-05-19 01:51:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E078C
|
|
|
|
void mouseDeviceFree()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E07B8
|
|
|
|
bool keyboardDeviceInit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E0874
|
|
|
|
void keyboardDeviceFree()
|
|
|
|
{
|
|
|
|
}
|
2022-07-29 10:04:37 -07:00
|
|
|
|
2022-08-19 03:36:14 -07:00
|
|
|
void handleMouseEvent(SDL_Event* event)
|
|
|
|
{
|
|
|
|
// Mouse movement and buttons are accumulated in SDL itself and will be
|
|
|
|
// processed later in `mouseDeviceGetData` via `SDL_GetRelativeMouseState`.
|
|
|
|
|
|
|
|
if (event->type == SDL_MOUSEWHEEL) {
|
|
|
|
gMouseWheelDeltaX += event->wheel.x;
|
|
|
|
gMouseWheelDeltaY += event->wheel.y;
|
|
|
|
}
|
2022-08-07 04:52:44 -07:00
|
|
|
}
|
2022-09-23 05:43:44 -07:00
|
|
|
|
|
|
|
} // namespace fallout
|