2023-06-13 14:17:20 -04:00
|
|
|
#include "legonavcontroller.h"
|
|
|
|
|
2023-06-19 04:34:58 -04:00
|
|
|
#include "legoomni.h"
|
|
|
|
#include "legoutil.h"
|
|
|
|
|
|
|
|
// 0x100f4c28
|
2023-06-13 14:17:20 -04:00
|
|
|
int g_mouseDeadzone = 40;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c2c
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_zeroThreshold = 0.001f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c30
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_movementMaxSpeed = 40.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c34
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_turnMaxSpeed = 20.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c38
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_movementMaxAccel = 15.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c3c
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_turnMaxAccel = 30.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c40
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_movementMinAccel = 4.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c44
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_turnMinAccel = 15.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c48
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_movementDecel = 50.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c4c
|
2023-06-13 14:17:20 -04:00
|
|
|
float g_turnDecel = 50.0f;
|
2023-06-19 04:34:58 -04:00
|
|
|
// 0x100f4c50
|
|
|
|
float g_turnSensitivity = 0.4f;
|
|
|
|
// 0x100f4c54
|
2023-06-27 22:04:07 -04:00
|
|
|
MxBool g_turnUseVelocity = FALSE;
|
2023-06-13 14:17:20 -04:00
|
|
|
|
2023-06-19 04:34:58 -04:00
|
|
|
// OFFSET: LEGO1 0x10054d40
|
2023-06-13 14:17:20 -04:00
|
|
|
void LegoNavController::GetDefaults(int *p_mouseDeadzone, float *p_movementMaxSpeed, float *p_turnMaxSpeed,
|
|
|
|
float *p_movementMaxAccel, float *p_turnMaxAccel, float *p_movementDecel,
|
|
|
|
float *p_turnDecel, float *p_movementMinAccel, float *p_turnMinAccel,
|
2023-06-19 04:34:58 -04:00
|
|
|
float *p_turnSensitivity, MxBool *p_turnUseVelocity)
|
2023-06-13 14:17:20 -04:00
|
|
|
{
|
|
|
|
*p_mouseDeadzone = g_mouseDeadzone;
|
|
|
|
*p_movementMaxSpeed = g_movementMaxSpeed;
|
|
|
|
*p_turnMaxSpeed = g_turnMaxSpeed;
|
|
|
|
*p_movementMaxAccel = g_movementMaxAccel;
|
|
|
|
*p_turnMaxAccel = g_turnMaxAccel;
|
|
|
|
*p_movementDecel = g_movementDecel;
|
|
|
|
*p_turnDecel = g_turnDecel;
|
|
|
|
*p_movementMinAccel = g_movementMinAccel;
|
|
|
|
*p_turnMinAccel = g_turnMinAccel;
|
2023-06-19 04:34:58 -04:00
|
|
|
*p_turnSensitivity = g_turnSensitivity;
|
2023-06-13 14:17:20 -04:00
|
|
|
*p_turnUseVelocity = g_turnUseVelocity;
|
|
|
|
}
|
|
|
|
|
2023-06-19 04:34:58 -04:00
|
|
|
// OFFSET: LEGO1 0x10054dd0
|
2023-06-13 14:17:20 -04:00
|
|
|
void LegoNavController::SetDefaults(int p_mouseDeadzone, float p_movementMaxSpeed, float p_turnMaxSpeed,
|
2023-06-13 14:45:02 -04:00
|
|
|
float p_movementMaxAccel, float p_turnMaxAccel, float p_movementDecel,
|
|
|
|
float p_turnDecel, float p_movementMinAccel, float p_turnMinAccel,
|
2023-06-19 04:34:58 -04:00
|
|
|
float p_turnSensitivity, MxBool p_turnUseVelocity)
|
2023-06-13 14:17:20 -04:00
|
|
|
{
|
|
|
|
g_mouseDeadzone = p_mouseDeadzone;
|
|
|
|
g_movementMaxSpeed = p_movementMaxSpeed;
|
|
|
|
g_turnMaxSpeed = p_turnMaxSpeed;
|
|
|
|
g_movementMaxAccel = p_movementMaxAccel;
|
|
|
|
g_turnMaxAccel = p_turnMaxAccel;
|
|
|
|
g_movementDecel = p_movementDecel;
|
|
|
|
g_turnDecel = p_turnDecel;
|
|
|
|
g_movementMinAccel = p_movementMinAccel;
|
|
|
|
g_turnMinAccel = p_turnMinAccel;
|
2023-06-19 04:34:58 -04:00
|
|
|
g_turnSensitivity = p_turnSensitivity;
|
2023-06-13 14:17:20 -04:00
|
|
|
g_turnUseVelocity = p_turnUseVelocity;
|
|
|
|
}
|
|
|
|
|
2023-06-19 04:34:58 -04:00
|
|
|
// OFFSET: LEGO1 0x10054ac0
|
|
|
|
LegoNavController::LegoNavController()
|
|
|
|
{
|
|
|
|
ResetToDefault();
|
|
|
|
|
|
|
|
this->unk_18 = 0.0f;
|
|
|
|
this->unk_1C = 0.0f;
|
|
|
|
this->m_targetMovementSpeed = 0.0f;
|
|
|
|
this->m_targetTurnSpeed = 0.0f;
|
|
|
|
this->m_movementAccel = 0.0f;
|
|
|
|
this->m_turnAccel = 0.0f;
|
2023-06-27 22:04:07 -04:00
|
|
|
this->m_trackDefault = FALSE;
|
|
|
|
this->m_unk5D = FALSE;
|
|
|
|
this->m_unk6C = FALSE;
|
2023-06-19 04:34:58 -04:00
|
|
|
this->m_unk64 = 0;
|
|
|
|
this->m_unk68 = 0;
|
|
|
|
this->m_unk60 = 0;
|
|
|
|
|
|
|
|
MxTimer *timer = Timer();
|
|
|
|
this->m_time = timer->GetTime();
|
|
|
|
|
|
|
|
// TODO: InputManager()
|
|
|
|
// LegoInputManager* inputManager = InputManager();
|
|
|
|
// inputManager->Register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: InputManager()
|
|
|
|
// OFFSET: LEGO1 0x10054c30
|
|
|
|
// LegoNavController::~LegoNavController()
|
|
|
|
// {
|
|
|
|
// LegoInputManager* inputManager = InputManager();
|
|
|
|
// inputManager->UnRegister(this);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x10054ca0
|
2023-06-24 13:09:46 -04:00
|
|
|
void LegoNavController::SetControlMax(int p_hMax, int p_vMax)
|
|
|
|
{
|
|
|
|
this->m_hMax = p_hMax;
|
|
|
|
this->m_vMax = p_vMax;
|
2023-06-19 04:34:58 -04:00
|
|
|
|
2023-06-24 13:09:46 -04:00
|
|
|
if (VideoManager()->GetVideoParam().flags().GetFullScreen())
|
|
|
|
{
|
|
|
|
this->m_hMax = 640;
|
|
|
|
this->m_vMax = 480;
|
|
|
|
}
|
|
|
|
}
|
2023-06-19 04:34:58 -04:00
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x10054cd0
|
2023-06-13 14:17:20 -04:00
|
|
|
void LegoNavController::ResetToDefault()
|
|
|
|
{
|
|
|
|
this->m_mouseDeadzone = g_mouseDeadzone;
|
|
|
|
this->m_zeroThreshold = g_zeroThreshold;
|
|
|
|
this->m_turnMaxAccel = g_turnMaxAccel;
|
|
|
|
this->m_movementMaxAccel = g_movementMaxAccel;
|
|
|
|
this->m_turnMinAccel = g_turnMinAccel;
|
|
|
|
this->m_movementMinAccel = g_movementMinAccel;
|
|
|
|
this->m_turnDecel = g_turnDecel;
|
|
|
|
this->m_movementDecel = g_movementDecel;
|
|
|
|
this->m_turnMaxSpeed = g_turnMaxSpeed;
|
|
|
|
this->m_movementMaxSpeed = g_movementMaxSpeed;
|
|
|
|
this->m_turnUseVelocity = g_turnUseVelocity;
|
2023-06-19 04:34:58 -04:00
|
|
|
this->m_turnSensitivity = g_turnSensitivity;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x10054e40
|
|
|
|
void LegoNavController::SetTargets(int p_hPos, int p_vPos, MxBool p_accel)
|
|
|
|
{
|
2023-06-27 22:04:07 -04:00
|
|
|
if (this->m_trackDefault != FALSE)
|
2023-06-19 04:34:58 -04:00
|
|
|
{
|
|
|
|
ResetToDefault();
|
|
|
|
}
|
|
|
|
|
2023-06-27 22:04:07 -04:00
|
|
|
if (p_accel != FALSE)
|
2023-06-19 04:34:58 -04:00
|
|
|
{
|
|
|
|
this->m_targetTurnSpeed = CalculateNewTargetSpeed(p_hPos, this->m_hMax / 2, this->m_turnMaxSpeed);
|
|
|
|
this->m_targetMovementSpeed = CalculateNewTargetSpeed(this->m_vMax - p_vPos, this->m_vMax / 2, this->m_movementMaxSpeed);
|
|
|
|
this->m_turnAccel = CalculateNewAccel(p_hPos, this->m_hMax / 2, this->m_turnMaxAccel, (int)this->m_turnMinAccel);
|
|
|
|
this->m_movementAccel = CalculateNewAccel(this->m_vMax - p_vPos, this->m_vMax / 2, this->m_movementMaxAccel, (int)this->m_movementMinAccel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->m_targetTurnSpeed = 0.0f;
|
|
|
|
this->m_targetMovementSpeed = 0.0f;
|
|
|
|
this->m_movementAccel = this->m_movementDecel;
|
|
|
|
this->m_turnAccel = this->m_turnDecel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x10054f10
|
|
|
|
float LegoNavController::CalculateNewTargetSpeed(int p_pos, int p_center, float p_maxSpeed)
|
|
|
|
{
|
|
|
|
float result;
|
|
|
|
int diff = p_pos - p_center;
|
|
|
|
|
|
|
|
if (diff > this->m_mouseDeadzone)
|
|
|
|
result = (diff - m_mouseDeadzone) * p_maxSpeed / (p_center - m_mouseDeadzone);
|
|
|
|
else if (diff < -m_mouseDeadzone)
|
|
|
|
result = (diff + m_mouseDeadzone) * p_maxSpeed / (p_center - m_mouseDeadzone);
|
|
|
|
else
|
|
|
|
result = 0.0f;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x10054f90
|
|
|
|
float LegoNavController::CalculateNewAccel(int p_pos, int p_center, float p_maxAccel, int p_minAccel)
|
|
|
|
{
|
|
|
|
float result;
|
|
|
|
int diff = p_pos - p_center;
|
|
|
|
|
|
|
|
result = Abs(diff) * p_maxAccel / p_center;
|
|
|
|
|
|
|
|
if (result < p_minAccel)
|
|
|
|
{
|
|
|
|
result = (float)p_minAccel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2023-06-27 22:04:07 -04:00
|
|
|
}
|