implement a few legonavcontroller functions (#718)

* implement a few legonavcontroller functions

* Match LegoNavController::ProcessJoystickInput

* Style

* Match LegoNavController::ProcessKeyboardInput

* Style

* Fix

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
Misha
2024-03-24 10:30:12 -04:00
committed by GitHub
parent 3f03940fcb
commit b66e28ac5e
6 changed files with 207 additions and 17 deletions

View File

@@ -122,6 +122,12 @@ void LegoCameraController::SetWorldTransform(const Vector3& p_at, const Vector3&
m_matrix2 = m_matrix1;
}
// STUB: LEGO1 0x10012320
void LegoCameraController::FUN_10012320(MxFloat)
{
// TODO
}
// FUNCTION: LEGO1 0x100123e0
void LegoCameraController::FUN_100123e0(const Matrix4& p_transform, MxU32 p_und)
{

View File

@@ -307,8 +307,8 @@ MxBool LegoNavController::CalculateNewPosDir(
float deltaTime = (currentTime - m_lastTime) / 1000.0;
m_lastTime = currentTime;
if (FUN_100558b0() == -1) {
FUN_10055750(und);
if (ProcessKeyboardInput() == FAILURE) {
ProcessJoystickInput(und);
}
if (m_useRotationalVel) {
@@ -471,18 +471,121 @@ MxResult LegoNavController::UpdateCameraLocation(MxU32 p_location)
return result;
}
// STUB: LEGO1 0x10055750
int LegoNavController::FUN_10055750(MxBool& p_und)
// FUNCTION: LEGO1 0x10055750
MxResult LegoNavController::ProcessJoystickInput(MxBool& p_und)
{
// TODO
return -1;
LegoOmni* instance = LegoOmni::GetInstance();
if (instance->GetInputManager()) {
MxS32 joystickX;
MxS32 joystickY;
DWORD buttonState;
MxS32 povPosition;
if (instance->GetInputManager()
->GetJoystickState((MxU32*) &joystickX, (MxU32*) &joystickY, &buttonState, (MxU32*) &povPosition) !=
FAILURE) {
MxU32 yVal = (joystickY * m_vMax) / 100;
MxU32 xVal = (joystickX * m_hMax) / 100;
if (joystickX <= 45 || joystickX >= 55 || joystickY <= 45 || joystickY >= 55) {
m_targetLinearVel = CalculateNewTargetVel(m_vMax - yVal, m_vMax / 2, m_maxLinearVel);
m_linearAccel = CalculateNewAccel(m_vMax - yVal, m_vMax / 2, m_maxLinearAccel, (int) m_minLinearAccel);
m_targetRotationalVel = CalculateNewTargetVel(xVal, m_hMax / 2, m_maxRotationalVel);
m_rotationalAccel =
CalculateNewAccel(xVal, m_hMax / 2, m_maxRotationalAccel, (int) m_minRotationalAccel);
}
else {
m_targetRotationalVel = 0.0;
m_targetLinearVel = 0.0;
m_linearAccel = m_maxLinearDeccel;
m_rotationalAccel = m_maxRotationalDeccel;
}
if (povPosition >= 0) {
LegoWorld* world = CurrentWorld();
if (world && world->GetCamera()) {
world->GetCamera()->FUN_10012320(DTOR(povPosition));
p_und = TRUE;
}
}
return SUCCESS;
}
}
return FAILURE;
}
// STUB: LEGO1 0x100558b0
int LegoNavController::FUN_100558b0()
// FUNCTION: LEGO1 0x100558b0
MxResult LegoNavController::ProcessKeyboardInput()
{
// TODO
return -1;
MxBool bool1 = FALSE;
MxBool bool2 = FALSE;
LegoInputManager* inputManager = LegoOmni::GetInstance()->GetInputManager();
MxU32 keyFlags;
if (inputManager == NULL || inputManager->FUN_1005c160(keyFlags) == FAILURE) {
return FAILURE;
}
if (keyFlags == 0) {
if (m_unk0x6c) {
m_targetRotationalVel = 0.0;
m_targetLinearVel = 0.0;
m_rotationalAccel = m_maxRotationalDeccel;
m_linearAccel = m_maxLinearDeccel;
m_unk0x6c = FALSE;
}
return FAILURE;
}
m_unk0x6c = TRUE;
MxS32 hMax;
if ((keyFlags & LegoInputManager::c_leftOrRight) == LegoInputManager::c_left) {
hMax = 0;
}
else if ((keyFlags & LegoInputManager::c_leftOrRight) == LegoInputManager::c_right) {
hMax = m_hMax;
}
else {
m_targetRotationalVel = 0.0;
m_rotationalAccel = m_maxRotationalDeccel;
bool1 = TRUE;
}
MxS32 vMax;
if ((keyFlags & LegoInputManager::c_upOrDown) == LegoInputManager::c_up) {
vMax = 0;
}
else if ((keyFlags & LegoInputManager::c_upOrDown) == LegoInputManager::c_down) {
vMax = m_vMax;
}
else {
m_targetLinearVel = 0.0;
m_linearAccel = m_maxLinearDeccel;
bool2 = TRUE;
}
MxFloat val = keyFlags & 0x10 ? 1.0f : 4.0f;
MxFloat val2 = keyFlags & 0x10 ? 1.0f : 2.0f;
if (!bool1) {
m_targetRotationalVel = CalculateNewTargetVel(hMax, m_hMax / 2, m_maxRotationalVel);
m_rotationalAccel =
CalculateNewAccel(hMax, m_hMax / 2, m_maxRotationalAccel / val, (int) (m_minRotationalAccel / val2));
}
if (!bool2) {
m_targetLinearVel = CalculateNewTargetVel(m_vMax - vMax, m_vMax / 2, m_maxLinearVel);
m_linearAccel =
CalculateNewAccel(m_vMax - vMax, m_vMax / 2, m_maxLinearAccel / val, (int) (m_minLinearAccel / val2));
}
return SUCCESS;
}
// STUB: LEGO1 0x10055a60

View File

@@ -18,6 +18,9 @@ MxS32 g_unk0x100f31b0 = -1;
// GLOBAL: LEGO1 0x100f31b4
const char* g_unk0x100f31b4 = NULL;
// GLOBAL: LEGO1 0x100f67b8
MxBool g_unk0x100f67b8 = TRUE;
// FUNCTION: LEGO1 0x1005b790
LegoInputManager::LegoInputManager()
{
@@ -34,7 +37,7 @@ LegoInputManager::LegoInputManager()
m_unk0x88 = FALSE;
m_directInput = NULL;
m_directInputDevice = NULL;
m_unk0x94 = 0;
m_unk0x94 = FALSE;
m_unk0x195 = 0;
m_joyid = -1;
m_joystickIndex = -1;
@@ -135,6 +138,72 @@ void LegoInputManager::ReleaseDX()
}
}
// FUNCTION: LEGO1 0x1005c0f0
void LegoInputManager::FUN_1005c0f0()
{
m_unk0x94 = FALSE;
if (m_directInputDevice) {
HRESULT hr = m_directInputDevice->GetDeviceState(_countof(m_unk0x95), &m_unk0x95);
if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) {
if (m_directInputDevice->Acquire() == S_OK) {
hr = m_directInputDevice->GetDeviceState(_countof(m_unk0x95), &m_unk0x95);
}
}
if (hr == S_OK) {
m_unk0x94 = TRUE;
}
}
}
// FUNCTION: LEGO1 0x1005c160
MxResult LegoInputManager::FUN_1005c160(MxU32& p_keyFlags)
{
FUN_1005c0f0();
if (!m_unk0x94) {
return FAILURE;
}
if (g_unk0x100f67b8) {
if (m_unk0x95[DIK_LEFT] & 0x80 && GetAsyncKeyState(VK_LEFT) == 0) {
m_unk0x95[DIK_LEFT] = 0;
}
if (m_unk0x95[DIK_RIGHT] & 0x80 && GetAsyncKeyState(VK_RIGHT) == 0) {
m_unk0x95[DIK_RIGHT] = 0;
}
}
MxU32 keyFlags = 0;
if ((m_unk0x95[DIK_NUMPAD8] | m_unk0x95[DIK_UP]) & 0x80) {
keyFlags |= c_up;
}
if ((m_unk0x95[DIK_NUMPAD2] | m_unk0x95[DIK_DOWN]) & 0x80) {
keyFlags |= c_down;
}
if ((m_unk0x95[DIK_NUMPAD4] | m_unk0x95[DIK_LEFT]) & 0x80) {
keyFlags |= c_left;
}
if ((m_unk0x95[DIK_NUMPAD6] | m_unk0x95[DIK_RIGHT]) & 0x80) {
keyFlags |= c_right;
}
if ((m_unk0x95[DIK_LCONTROL] | m_unk0x95[DIK_RCONTROL]) & 0x80) {
keyFlags |= c_bit5;
}
p_keyFlags = keyFlags;
return SUCCESS;
}
// FUNCTION: LEGO1 0x1005c240
MxResult LegoInputManager::GetJoystickId()
{