HavokVehicleComponent improvements

serialization, moving stuff to header, removal of update as we serialize dirty position so often this check is pointless.
This commit is contained in:
David Markowitz 2023-06-26 23:28:23 -07:00
parent f55bec026d
commit c2fe7f6205
2 changed files with 7 additions and 35 deletions

View File

@ -14,10 +14,6 @@ HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent) : Com
m_EndBehavior = GeneralUtils::GenerateRandomNumber<uint32_t>(0, 7); m_EndBehavior = GeneralUtils::GenerateRandomNumber<uint32_t>(0, 7);
} }
HavokVehiclePhysicsComponent::~HavokVehiclePhysicsComponent() {
}
void HavokVehiclePhysicsComponent::SetPosition(const NiPoint3& pos) { void HavokVehiclePhysicsComponent::SetPosition(const NiPoint3& pos) {
if (pos == m_Position) return; if (pos == m_Position) return;
m_DirtyPosition = true; m_DirtyPosition = true;
@ -60,23 +56,11 @@ void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& rem
m_DirtyRemoteInput = true; m_DirtyRemoteInput = true;
} }
void HavokVehiclePhysicsComponent::SetDirtyPosition(bool val) {
m_DirtyPosition = val;
}
void HavokVehiclePhysicsComponent::SetDirtyVelocity(bool val) {
m_DirtyVelocity = val;
}
void HavokVehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) {
m_DirtyAngularVelocity = val;
}
void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(bIsInitialUpdate || m_DirtyPosition); outBitStream->Write(bIsInitialUpdate || m_DirtyPosition);
if (bIsInitialUpdate || m_DirtyPosition) { if (bIsInitialUpdate || m_DirtyPosition) {
m_DirtyPosition = false; if (!bIsInitialUpdate) m_DirtyPosition = false;
outBitStream->Write(m_Position.x); outBitStream->Write(m_Position.x);
outBitStream->Write(m_Position.y); outBitStream->Write(m_Position.y);
outBitStream->Write(m_Position.z); outBitStream->Write(m_Position.z);
@ -95,7 +79,7 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo
outBitStream->Write(m_Velocity.x); outBitStream->Write(m_Velocity.x);
outBitStream->Write(m_Velocity.y); outBitStream->Write(m_Velocity.y);
outBitStream->Write(m_Velocity.z); outBitStream->Write(m_Velocity.z);
m_DirtyVelocity = false; if (!bIsInitialUpdate) m_DirtyVelocity = false;
} }
outBitStream->Write(bIsInitialUpdate || m_DirtyAngularVelocity); outBitStream->Write(bIsInitialUpdate || m_DirtyAngularVelocity);
@ -104,7 +88,7 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo
outBitStream->Write(m_AngularVelocity.x); outBitStream->Write(m_AngularVelocity.x);
outBitStream->Write(m_AngularVelocity.y); outBitStream->Write(m_AngularVelocity.y);
outBitStream->Write(m_AngularVelocity.z); outBitStream->Write(m_AngularVelocity.z);
m_DirtyAngularVelocity = false; if (!bIsInitialUpdate) m_DirtyAngularVelocity = false;
} }
outBitStream->Write0(); // local_space_info. TODO: Implement this outBitStream->Write0(); // local_space_info. TODO: Implement this
@ -115,7 +99,7 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo
outBitStream->Write(m_RemoteInputInfo.m_RemoteInputY); outBitStream->Write(m_RemoteInputInfo.m_RemoteInputY);
outBitStream->Write(m_RemoteInputInfo.m_IsPowersliding); outBitStream->Write(m_RemoteInputInfo.m_IsPowersliding);
outBitStream->Write(m_RemoteInputInfo.m_IsModified); outBitStream->Write(m_RemoteInputInfo.m_IsModified);
m_DirtyRemoteInput = false; if (!bIsInitialUpdate) m_DirtyRemoteInput = false;
} }
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. 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.
@ -132,12 +116,3 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo
outBitStream->Write0(); outBitStream->Write0();
} }
void HavokVehiclePhysicsComponent::Update(float deltaTime) {
if (m_SoftUpdate > 5) {
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
m_SoftUpdate = 0;
} else {
m_SoftUpdate += deltaTime;
}
}

View File

@ -31,12 +31,9 @@ public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::HAVOK_VEHICLE_PHYSICS; inline static const eReplicaComponentType ComponentType = eReplicaComponentType::HAVOK_VEHICLE_PHYSICS;
HavokVehiclePhysicsComponent(Entity* parentEntity); HavokVehiclePhysicsComponent(Entity* parentEntity);
~HavokVehiclePhysicsComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void Update(float deltaTime) override;
/** /**
* Sets the position * Sets the position
* @param pos the new position * @param pos the new position
@ -109,9 +106,9 @@ public:
*/ */
const bool GetIsOnRail() const { return m_IsOnRail; } const bool GetIsOnRail() const { return m_IsOnRail; }
void SetDirtyPosition(bool val); void SetDirtyPosition(bool val) { m_DirtyPosition = val; }
void SetDirtyVelocity(bool val); void SetDirtyVelocity(bool val) { m_DirtyVelocity = val; }
void SetDirtyAngularVelocity(bool val); void SetDirtyAngularVelocity(bool val) { m_DirtyAngularVelocity = val; }
void SetRemoteInputInfo(const RemoteInputInfo&); void SetRemoteInputInfo(const RemoteInputInfo&);
private: private: