2023-12-04 15:20:41 +00:00
|
|
|
#include "HavokVehiclePhysicsComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
|
2023-12-04 15:20:41 +00:00
|
|
|
HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent) : PhysicsComponent(parent) {
|
2024-01-29 07:53:12 +00:00
|
|
|
m_Velocity = NiPoint3Constant::ZERO;
|
|
|
|
m_AngularVelocity = NiPoint3Constant::ZERO;
|
2021-12-05 17:54:36 +00:00
|
|
|
m_IsOnGround = true;
|
|
|
|
m_IsOnRail = false;
|
|
|
|
m_DirtyPosition = true;
|
2023-04-18 06:40:20 +00:00
|
|
|
m_EndBehavior = GeneralUtils::GenerateRandomNumber<uint32_t>(0, 7);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 15:20:41 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetVelocity(const NiPoint3& vel) {
|
2023-06-20 14:19:21 +00:00
|
|
|
if (vel == m_Velocity) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
|
|
|
m_Velocity = vel;
|
|
|
|
}
|
|
|
|
|
2023-12-04 15:20:41 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) {
|
2023-06-20 14:19:21 +00:00
|
|
|
if (vel == m_AngularVelocity) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
|
|
|
m_AngularVelocity = vel;
|
|
|
|
}
|
|
|
|
|
2023-12-04 15:20:41 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetIsOnGround(bool val) {
|
2023-06-20 14:19:21 +00:00
|
|
|
if (val == m_IsOnGround) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
|
|
|
m_IsOnGround = val;
|
|
|
|
}
|
|
|
|
|
2023-12-04 15:20:41 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetIsOnRail(bool val) {
|
2023-06-20 14:19:21 +00:00
|
|
|
if (val == m_IsOnRail) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
|
|
|
m_IsOnRail = val;
|
|
|
|
}
|
|
|
|
|
2023-12-04 15:20:41 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) {
|
2024-02-28 05:40:26 +00:00
|
|
|
if (remoteInputInfo == m_RemoteInputInfo) return;
|
2023-06-20 14:19:21 +00:00
|
|
|
this->m_RemoteInputInfo = remoteInputInfo;
|
2024-02-28 05:40:26 +00:00
|
|
|
m_DirtyPosition = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
|
|
|
outBitStream.Write(bIsInitialUpdate || m_DirtyPosition);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (bIsInitialUpdate || m_DirtyPosition) {
|
2023-06-20 14:19:21 +00:00
|
|
|
m_DirtyPosition = false;
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_Position.x);
|
|
|
|
outBitStream.Write(m_Position.y);
|
|
|
|
outBitStream.Write(m_Position.z);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_Rotation.x);
|
|
|
|
outBitStream.Write(m_Rotation.y);
|
|
|
|
outBitStream.Write(m_Rotation.z);
|
|
|
|
outBitStream.Write(m_Rotation.w);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_IsOnGround);
|
|
|
|
outBitStream.Write(m_IsOnRail);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-28 05:40:26 +00:00
|
|
|
bool isNotZero = m_Velocity != NiPoint3Constant::ZERO;
|
|
|
|
outBitStream.Write(isNotZero);
|
|
|
|
if (isNotZero) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_Velocity.x);
|
|
|
|
outBitStream.Write(m_Velocity.y);
|
|
|
|
outBitStream.Write(m_Velocity.z);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 05:40:26 +00:00
|
|
|
isNotZero = m_AngularVelocity != NiPoint3Constant::ZERO;
|
|
|
|
outBitStream.Write(isNotZero);
|
|
|
|
if (isNotZero) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_AngularVelocity.x);
|
|
|
|
outBitStream.Write(m_AngularVelocity.y);
|
|
|
|
outBitStream.Write(m_AngularVelocity.z);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write0(); // local_space_info. TODO: Implement this
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-28 05:40:26 +00:00
|
|
|
// This structure only has this bool flag set to false if a ptr to the peVehicle is null, which we don't have
|
|
|
|
// therefore, this will always be 1, even if all the values in the structure are 0.
|
|
|
|
outBitStream.Write1(); // has remote_input_info
|
|
|
|
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputX);
|
|
|
|
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputY);
|
|
|
|
outBitStream.Write(m_RemoteInputInfo.m_IsPowersliding);
|
|
|
|
outBitStream.Write(m_RemoteInputInfo.m_IsModified);
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(125.0f); // remote_input_ping TODO: Figure out how this should be calculated as it seems to be constant through the whole race.
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (!bIsInitialUpdate) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write0();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bIsInitialUpdate) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write<uint8_t>(m_EndBehavior);
|
|
|
|
outBitStream.Write1(); // is input locked?
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write0();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|