port: EterLib/Input over host key events (DirectInput polling adapted)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5d64311a4d
commit
32c5a09d6e
@@ -1,81 +1,86 @@
|
||||
// Platform skeleton for EterLib/Input.h (40250 EterLib/Input.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 EterLib/Input.cpp without DirectInput. 40250 polls the DirectInput keyboard once per frame
|
||||
// (CPythonApplication::Process -> UpdateKeyboard), diffs the 256-byte device state against ms_bPressedKey
|
||||
// and calls KeyDown/KeyUp, which record the key and call the virtual OnKeyDown/OnKeyUp.
|
||||
//
|
||||
// PORT: the host delivers key events instead (PythonBoot::UIKey). It calls KeyDown/KeyUp at event time and
|
||||
// then runs the OnKeyDown/OnKeyUp body itself, since the platform has no constructed CPythonApplication to
|
||||
// dispatch the virtual through. ms_diks mirrors the pressed state, as the device state 40250 read.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/Input.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
LPDIRECTINPUT8 CInputDevice::ms_lpDI = NULL;
|
||||
LPDIRECTINPUTDEVICE8 CInputKeyboard::ms_lpKeyboard = NULL;
|
||||
bool CInputKeyboard::ms_bPressedKey[256];
|
||||
char CInputKeyboard::ms_diks[256];
|
||||
|
||||
CInputDevice::CInputDevice()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
// PORT: 40250 releases the shared DirectInput object; there is none.
|
||||
CInputDevice::~CInputDevice()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CInputDevice::CreateDevice(HWND) -> HRESULT
|
||||
// PORT: 40250 creates (or AddRefs) the shared DirectInput8 object; the host keyboard needs none.
|
||||
HRESULT CInputDevice::CreateDevice(HWND /*hWnd*/)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<HRESULT>();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
decltype(CInputDevice::ms_lpDI) CInputDevice::ms_lpDI{};
|
||||
|
||||
CInputKeyboard::CInputKeyboard()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
ResetKeyboard();
|
||||
}
|
||||
|
||||
// PORT: 40250 unacquires and releases the keyboard device; there is none.
|
||||
CInputKeyboard::~CInputKeyboard()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CInputKeyboard::InitializeKeyboard(HWND) -> bool
|
||||
void CInputKeyboard::ResetKeyboard()
|
||||
{
|
||||
ResetKeyboard();
|
||||
memset(ms_diks, 0, sizeof(ms_diks));
|
||||
memset(ms_bPressedKey, 0, sizeof(ms_bPressedKey));
|
||||
}
|
||||
|
||||
// PORT: 40250 creates the system keyboard device (c_dfDIKeyboard, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)
|
||||
// and acquires it; it fails only if DirectInput does.
|
||||
bool CInputKeyboard::InitializeKeyboard(HWND hWnd)
|
||||
{
|
||||
if (FAILED(CreateDevice(hWnd)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CInputKeyboard::UpdateKeyboard() -> void
|
||||
// PORT: no device state to poll; the host's key events have already called KeyDown/KeyUp.
|
||||
void CInputKeyboard::UpdateKeyboard()
|
||||
{
|
||||
}
|
||||
|
||||
auto CInputKeyboard::ResetKeyboard() -> void
|
||||
// PORT: 40250 sets ms_bPressedKey and calls OnKeyDown; the caller (PythonBoot::UIKey) runs OnKeyDown's body.
|
||||
void CInputKeyboard::KeyDown(int iIndex)
|
||||
{
|
||||
memset(ms_bPressedKey, 0, sizeof(ms_bPressedKey));
|
||||
memset(ms_diks, 0, sizeof(ms_diks));
|
||||
if (iIndex < 0 || iIndex >= 256)
|
||||
return;
|
||||
|
||||
ms_bPressedKey[iIndex] = true;
|
||||
ms_diks[iIndex] = (char) 0x80;
|
||||
}
|
||||
|
||||
auto CInputKeyboard::IsPressed(int iIndex) -> bool
|
||||
// PORT: as KeyDown, for OnKeyUp.
|
||||
void CInputKeyboard::KeyUp(int iIndex)
|
||||
{
|
||||
if (iIndex >= 0 && iIndex < 256)
|
||||
return (ms_diks[iIndex] & 0x80) != 0;
|
||||
return false;
|
||||
if (iIndex < 0 || iIndex >= 256)
|
||||
return;
|
||||
|
||||
ms_bPressedKey[iIndex] = false;
|
||||
ms_diks[iIndex] = 0;
|
||||
}
|
||||
|
||||
auto CInputKeyboard::KeyDown(int iIndex) -> void
|
||||
bool CInputKeyboard::IsPressed(int iIndex)
|
||||
{
|
||||
if (iIndex >= 0 && iIndex < 256)
|
||||
{
|
||||
ms_bPressedKey[iIndex] = true;
|
||||
ms_diks[iIndex] = (char)0x80;
|
||||
}
|
||||
return ms_bPressedKey[iIndex];
|
||||
}
|
||||
|
||||
auto CInputKeyboard::KeyUp(int iIndex) -> void
|
||||
{
|
||||
if (iIndex >= 0 && iIndex < 256)
|
||||
{
|
||||
ms_bPressedKey[iIndex] = false;
|
||||
ms_diks[iIndex] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
decltype(CInputKeyboard::ms_lpKeyboard) CInputKeyboard::ms_lpKeyboard{};
|
||||
|
||||
decltype(CInputKeyboard::ms_bPressedKey) CInputKeyboard::ms_bPressedKey{};
|
||||
|
||||
decltype(CInputKeyboard::ms_diks) CInputKeyboard::ms_diks{};
|
||||
|
||||
@@ -205,6 +205,9 @@ if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
|
||||
add_executable(port_ms_window_test ${PROJECT_SOURCE_DIR}/tests/port/port_ms_window_test.cpp)
|
||||
target_link_libraries(port_ms_window_test PRIVATE port_platform)
|
||||
add_test(NAME port.ms_window COMMAND $<TARGET_FILE:port_ms_window_test>)
|
||||
add_executable(port_input_test ${PROJECT_SOURCE_DIR}/tests/port/port_input_test.cpp)
|
||||
target_link_libraries(port_input_test PRIVATE port_platform)
|
||||
add_test(NAME port.input COMMAND $<TARGET_FILE:port_input_test>)
|
||||
|
||||
# MilesLib: the 40250 sound managers over the Miles emulation (platform/MilesLib/MilesAil.cpp).
|
||||
add_executable(port_miles_test ${PROJECT_SOURCE_DIR}/tests/port/port_miles_test.cpp)
|
||||
|
||||
Reference in New Issue
Block a user