diff --git a/LEGO1/legonavcontroller.cpp b/LEGO1/legonavcontroller.cpp index aaea52e6..754d0421 100644 --- a/LEGO1/legonavcontroller.cpp +++ b/LEGO1/legonavcontroller.cpp @@ -1,5 +1,8 @@ #include "legonavcontroller.h" +#include "legoomni.h" +#include "legoutil.h" + int g_mouseDeadzone = 40; float g_zeroThreshold = 0.001f; float g_movementMaxSpeed = 40.0f; @@ -10,13 +13,13 @@ float g_movementMinAccel = 4.0f; float g_turnMinAccel = 15.0f; float g_movementDecel = 50.0f; float g_turnDecel = 50.0f; -float g_rotationSensitivity = 0.4f; +float g_turnSensitivity = 0.4f; MxBool g_turnUseVelocity = 0; 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, - float *p_rotationSensitivity, MxBool *p_turnUseVelocity) + float *p_turnSensitivity, MxBool *p_turnUseVelocity) { *p_mouseDeadzone = g_mouseDeadzone; *p_movementMaxSpeed = g_movementMaxSpeed; @@ -27,14 +30,14 @@ void LegoNavController::GetDefaults(int *p_mouseDeadzone, float *p_movementMaxSp *p_turnDecel = g_turnDecel; *p_movementMinAccel = g_movementMinAccel; *p_turnMinAccel = g_turnMinAccel; - *p_rotationSensitivity = g_rotationSensitivity; + *p_turnSensitivity = g_turnSensitivity; *p_turnUseVelocity = g_turnUseVelocity; } void LegoNavController::SetDefaults(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, - float p_rotationSensitivity, MxBool p_turnUseVelocity) + float p_turnSensitivity, MxBool p_turnUseVelocity) { g_mouseDeadzone = p_mouseDeadzone; g_movementMaxSpeed = p_movementMaxSpeed; @@ -45,10 +48,55 @@ void LegoNavController::SetDefaults(int p_mouseDeadzone, float p_movementMaxSpee g_turnDecel = p_turnDecel; g_movementMinAccel = p_movementMinAccel; g_turnMinAccel = p_turnMinAccel; - g_rotationSensitivity = p_rotationSensitivity; + g_turnSensitivity = p_turnSensitivity; g_turnUseVelocity = p_turnUseVelocity; } +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; + this->m_trackDefault = 0; + this->m_unk5D = 0; + this->m_unk6C = 0; + this->m_unk64 = 0; + this->m_unk68 = 0; + this->m_unk60 = 0; + + // TODO: Timer(), InputManager() + // MxTimer* timer = Timer(); + // if (timer[0xc] == 0) { + // assign to this->m_Timer + // } + // else { + // assign to this->m_Timer + // } + + // LegoInputManager* inputManager = InputManager(); + // inputManager->Register(this); +} + +// TODO: VideoManager() +// void LegoNavController::SetControlMax(int p_hMax, int p_vMax) +// { +// LegoVideoManager* videoManager = VideoManager(); + +// this->m_hMax = p_hMax; +// this->m_vMax = p_vMax; + +// if ((videoManager->m_unk44 & 0x01) != 0) +// { +// this->m_hMax = 640; +// this->m_vMax = 480; +// } +// } + void LegoNavController::ResetToDefault() { this->m_mouseDeadzone = g_mouseDeadzone; @@ -62,5 +110,58 @@ void LegoNavController::ResetToDefault() this->m_turnMaxSpeed = g_turnMaxSpeed; this->m_movementMaxSpeed = g_movementMaxSpeed; this->m_turnUseVelocity = g_turnUseVelocity; - this->m_rotationSensitivity = g_rotationSensitivity; + this->m_turnSensitivity = g_turnSensitivity; +} + +void LegoNavController::SetTargets(int p_hPos, int p_vPos, MxBool p_accel) +{ + if (this->m_trackDefault != 0) + { + ResetToDefault(); + } + + if (p_accel != 0) + { + 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_turnMinAccel); + } + else + { + this->m_targetTurnSpeed = 0.0f; + this->m_targetMovementSpeed = 0.0f; + this->m_movementAccel = this->m_movementDecel; + this->m_turnAccel = this->m_turnDecel; + } +} + +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; +} + +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; } \ No newline at end of file diff --git a/LEGO1/legonavcontroller.h b/LEGO1/legonavcontroller.h index 84be9b62..7e7320c5 100644 --- a/LEGO1/legonavcontroller.h +++ b/LEGO1/legonavcontroller.h @@ -3,6 +3,7 @@ #include "mxcore.h" #include "mxbool.h" +#include "mxtimer.h" class LegoNavController : public MxCore { @@ -15,25 +16,44 @@ class LegoNavController : public MxCore float p_movementMaxAccel, float p_turnMaxAccel, float p_movementDecel, float p_turnDecel, float p_movementMinAccel, float p_turnMinAccel, float p_rotationSensitivity, MxBool p_turnUseVelocity); + + LegoNavController(); + + // void SetControlMax(int p_hMax, int p_vMax); void ResetToDefault(); + void SetTargets(int p_hPos, int p_vPos, MxBool p_accel); + float CalculateNewTargetSpeed(int p_pos, int p_center, float p_maxSpeed); + float CalculateNewAccel(int p_pos, int p_center, float p_maxAccel, int p_minAccel); private: - int unk_08; // known to be set to window width: 640 (default) - int unk_0C; // known to be set to window height: 480 (default) + int m_hMax; + int m_vMax; int m_mouseDeadzone; float m_zeroThreshold; - int unk_18[4]; + float unk_18; + float unk_1C; + float m_targetMovementSpeed; + float m_targetTurnSpeed; float m_movementMaxSpeed; float m_turnMaxSpeed; - int unk_30[2]; + float m_movementAccel; + float m_turnAccel; float m_movementMaxAccel; float m_turnMaxAccel; float m_movementMinAccel; float m_turnMinAccel; float m_movementDecel; float m_turnDecel; - float m_rotationSensitivity; + float m_turnSensitivity; MxBool m_turnUseVelocity; + MxTimer *m_Timer; + MxBool m_trackDefault; + MxBool m_unk5D; + char m_unk5E[2]; + int m_unk60; + int m_unk64; + int m_unk68; + MxBool m_unk6C; }; #endif // LEGONAVCONTROLLER_H diff --git a/LEGO1/legoutil.h b/LEGO1/legoutil.h new file mode 100644 index 00000000..440b01d0 --- /dev/null +++ b/LEGO1/legoutil.h @@ -0,0 +1,10 @@ +#ifndef LEGOUTIL_H +#define LEGOUTIL_H + +template +inline T Abs(T p_t) +{ + return p_t < 0 ? -p_t : p_t; +} + +#endif // LEGOUTIL_H \ No newline at end of file diff --git a/isle.mak b/isle.mak index 22a99c81..11c4165a 100644 --- a/isle.mak +++ b/isle.mak @@ -507,9 +507,41 @@ DEP_CPP_MXCRI=\ SOURCE=.\LEGO1\legonavcontroller.cpp DEP_CPP_LEGON=\ + ".\LEGO1\legoanimationmanager.h"\ + ".\LEGO1\legobuildingmanager.h"\ + ".\LEGO1\legoentity.h"\ + ".\LEGO1\legogamestate.h"\ + ".\LEGO1\legoinputmanager.h"\ + ".\LEGO1\legomodelpresenter.h"\ ".\LEGO1\legonavcontroller.h"\ + ".\LEGO1\legoomni.h"\ + ".\LEGO1\legopartpresenter.h"\ + ".\LEGO1\legoroi.h"\ + ".\LEGO1\legoutil.h"\ + ".\LEGO1\legovideomanager.h"\ + ".\LEGO1\legoworldpresenter.h"\ + ".\LEGO1\mxatomid.h"\ + ".\LEGO1\mxbackgroundaudiomanager.h"\ ".\LEGO1\mxbool.h"\ ".\LEGO1\mxcore.h"\ + ".\LEGO1\mxdsaction.h"\ + ".\LEGO1\mxdsfile.h"\ + ".\LEGO1\mxdsobject.h"\ + ".\LEGO1\mxomnicreateflags.h"\ + ".\LEGO1\mxomnicreateparam.h"\ + ".\LEGO1\mxomnicreateparambase.h"\ + ".\LEGO1\mxpalette.h"\ + ".\LEGO1\mxrect32.h"\ + ".\LEGO1\mxresult.h"\ + ".\LEGO1\mxstreamcontroller.h"\ + ".\LEGO1\mxstreamer.h"\ + ".\LEGO1\mxstring.h"\ + ".\LEGO1\mxticklemanager.h"\ + ".\LEGO1\mxtimer.h"\ + ".\LEGO1\mxtransitionmanager.h"\ + ".\LEGO1\mxvariabletable.h"\ + ".\LEGO1\mxvideoparam.h"\ + ".\LEGO1\mxvideoparamflags.h"\ "$(INTDIR)\legonavcontroller.obj" : $(SOURCE) $(DEP_CPP_LEGON) "$(INTDIR)" diff --git a/isle.mdp b/isle.mdp index e90eca4d..f0946445 100644 Binary files a/isle.mdp and b/isle.mdp differ