2023-06-08 15:29:17 +00:00
|
|
|
#include "HavokVehiclePhysicsComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent) : Component(parent) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Position = NiPoint3::ZERO;
|
|
|
|
m_Rotation = NiQuaternion::IDENTITY;
|
|
|
|
m_Velocity = NiPoint3::ZERO;
|
|
|
|
m_AngularVelocity = NiPoint3::ZERO;
|
|
|
|
m_IsOnGround = true;
|
|
|
|
m_IsOnRail = false;
|
|
|
|
m_DirtyPosition = true;
|
|
|
|
m_DirtyVelocity = true;
|
|
|
|
m_DirtyAngularVelocity = 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-06-08 15:29:17 +00:00
|
|
|
HavokVehiclePhysicsComponent::~HavokVehiclePhysicsComponent() {
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetPosition(const NiPoint3& pos) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Position = pos;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetRotation(const NiQuaternion& rot) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Rotation = rot;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetVelocity(const NiPoint3& vel) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Velocity = vel;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
2022-07-28 13:39:57 +00:00
|
|
|
m_AngularVelocity = vel;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetIsOnGround(bool val) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
2022-07-28 13:39:57 +00:00
|
|
|
m_IsOnGround = val;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetIsOnRail(bool val) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_DirtyPosition = true;
|
2022-07-28 13:39:57 +00:00
|
|
|
m_IsOnRail = val;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetDirtyPosition(bool val) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_DirtyPosition = val;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetDirtyVelocity(bool val) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_DirtyVelocity = val;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_DirtyAngularVelocity = val;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyPosition);
|
|
|
|
|
|
|
|
if (bIsInitialUpdate || m_DirtyPosition) {
|
|
|
|
outBitStream->Write(m_Position);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write(m_Rotation);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write(m_IsOnGround);
|
|
|
|
outBitStream->Write(m_IsOnRail);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyVelocity);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (bIsInitialUpdate || m_DirtyVelocity) {
|
|
|
|
outBitStream->Write(m_Velocity);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyAngularVelocity);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (bIsInitialUpdate || m_DirtyAngularVelocity) {
|
|
|
|
outBitStream->Write(m_AngularVelocity);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write0();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
outBitStream->Write0();
|
|
|
|
|
|
|
|
outBitStream->Write(0.0f);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!bIsInitialUpdate) {
|
|
|
|
outBitStream->Write0();
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (bIsInitialUpdate) {
|
2023-04-18 06:40:20 +00:00
|
|
|
outBitStream->Write<uint8_t>(m_EndBehavior);
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write1();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
outBitStream->Write0();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:29:17 +00:00
|
|
|
void HavokVehiclePhysicsComponent::Update(float deltaTime) {
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_SoftUpdate > 5) {
|
2023-06-07 01:59:53 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(m_OwningEntity);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
m_SoftUpdate = 0;
|
|
|
|
} else {
|
|
|
|
m_SoftUpdate += deltaTime;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|