mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-27 07:57:21 +00:00
455f9470a5
* Move EntityManager to Game namespace * move initialization to later Need to wait for dZoneManager to be initialized. * Fix bugs - Cannot delete from a RandomAccessIterator while in a range based for loop. Touchup zone manager initialize replace magic numbers with better named constants replace magic zonecontrol id with a more readable hex alternative condense stack variables move initializers closer to their use initialize entity manager with zone control change initialize timings If zone is not zero we expect to initialize the entity manager during zone manager initialization Add constexpr for zone control LOT * Add proper error handling * revert vanity changes * Update WorldServer.cpp * Update dZoneManager.cpp
144 lines
4.0 KiB
C++
144 lines
4.0 KiB
C++
#include "VehiclePhysicsComponent.h"
|
|
#include "EntityManager.h"
|
|
|
|
VehiclePhysicsComponent::VehiclePhysicsComponent(Entity* parent) : Component(parent) {
|
|
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;
|
|
m_EndBehavior = GeneralUtils::GenerateRandomNumber<uint32_t>(0, 7);
|
|
}
|
|
|
|
VehiclePhysicsComponent::~VehiclePhysicsComponent() {
|
|
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetPosition(const NiPoint3& pos) {
|
|
if (pos == m_Position) return;
|
|
m_DirtyPosition = true;
|
|
m_Position = pos;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetRotation(const NiQuaternion& rot) {
|
|
if (rot == m_Rotation) return;
|
|
m_DirtyPosition = true;
|
|
m_Rotation = rot;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetVelocity(const NiPoint3& vel) {
|
|
if (vel == m_Velocity) return;
|
|
m_DirtyPosition = true;
|
|
m_Velocity = vel;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) {
|
|
if (vel == m_AngularVelocity) return;
|
|
m_DirtyPosition = true;
|
|
m_AngularVelocity = vel;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetIsOnGround(bool val) {
|
|
if (val == m_IsOnGround) return;
|
|
m_DirtyPosition = true;
|
|
m_IsOnGround = val;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetIsOnRail(bool val) {
|
|
if (val == m_IsOnRail) return;
|
|
m_DirtyPosition = true;
|
|
m_IsOnRail = val;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) {
|
|
if (m_RemoteInputInfo == remoteInputInfo) return;
|
|
this->m_RemoteInputInfo = remoteInputInfo;
|
|
m_DirtyRemoteInput = true;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetDirtyPosition(bool val) {
|
|
m_DirtyPosition = val;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetDirtyVelocity(bool val) {
|
|
m_DirtyVelocity = val;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) {
|
|
m_DirtyAngularVelocity = val;
|
|
}
|
|
|
|
void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyPosition);
|
|
|
|
if (bIsInitialUpdate || m_DirtyPosition) {
|
|
m_DirtyPosition = false;
|
|
outBitStream->Write(m_Position.x);
|
|
outBitStream->Write(m_Position.y);
|
|
outBitStream->Write(m_Position.z);
|
|
|
|
outBitStream->Write(m_Rotation.x);
|
|
outBitStream->Write(m_Rotation.y);
|
|
outBitStream->Write(m_Rotation.z);
|
|
outBitStream->Write(m_Rotation.w);
|
|
|
|
outBitStream->Write(m_IsOnGround);
|
|
outBitStream->Write(m_IsOnRail);
|
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyVelocity);
|
|
|
|
if (bIsInitialUpdate || m_DirtyVelocity) {
|
|
outBitStream->Write(m_Velocity.x);
|
|
outBitStream->Write(m_Velocity.y);
|
|
outBitStream->Write(m_Velocity.z);
|
|
m_DirtyVelocity = false;
|
|
}
|
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyAngularVelocity);
|
|
|
|
if (bIsInitialUpdate || m_DirtyAngularVelocity) {
|
|
outBitStream->Write(m_AngularVelocity.x);
|
|
outBitStream->Write(m_AngularVelocity.y);
|
|
outBitStream->Write(m_AngularVelocity.z);
|
|
m_DirtyAngularVelocity = false;
|
|
}
|
|
|
|
outBitStream->Write0(); // local_space_info. TODO: Implement this
|
|
|
|
outBitStream->Write(m_DirtyRemoteInput || bIsInitialUpdate); // remote_input_info
|
|
if (m_DirtyRemoteInput || bIsInitialUpdate) {
|
|
outBitStream->Write(m_RemoteInputInfo.m_RemoteInputX);
|
|
outBitStream->Write(m_RemoteInputInfo.m_RemoteInputY);
|
|
outBitStream->Write(m_RemoteInputInfo.m_IsPowersliding);
|
|
outBitStream->Write(m_RemoteInputInfo.m_IsModified);
|
|
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.
|
|
|
|
if (!bIsInitialUpdate) {
|
|
outBitStream->Write0();
|
|
}
|
|
}
|
|
|
|
if (bIsInitialUpdate) {
|
|
outBitStream->Write<uint8_t>(m_EndBehavior);
|
|
outBitStream->Write1(); // is input locked?
|
|
}
|
|
|
|
outBitStream->Write0();
|
|
}
|
|
|
|
void VehiclePhysicsComponent::Update(float deltaTime) {
|
|
if (m_SoftUpdate > 5) {
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
m_SoftUpdate = 0;
|
|
} else {
|
|
m_SoftUpdate += deltaTime;
|
|
}
|
|
}
|