mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-23 05:53:34 +00:00
delta compression fixes (#937)
This commit is contained in:
parent
dc7d0ce142
commit
1789ec7f20
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): Component(parent) {
|
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): Component(parent) {
|
||||||
m_Target = LWOOBJID_EMPTY;
|
m_Target = LWOOBJID_EMPTY;
|
||||||
m_State = AiState::spawn;
|
SetAiState(AiState::spawn);
|
||||||
m_Timer = 1.0f;
|
m_Timer = 1.0f;
|
||||||
m_StartPosition = parent->GetPosition();
|
m_StartPosition = parent->GetPosition();
|
||||||
m_MovementAI = nullptr;
|
m_MovementAI = nullptr;
|
||||||
@ -206,7 +206,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
|
|||||||
switch (m_State) {
|
switch (m_State) {
|
||||||
case AiState::spawn:
|
case AiState::spawn:
|
||||||
Stun(2.0f);
|
Stun(2.0f);
|
||||||
m_State = AiState::idle;
|
SetAiState(AiState::idle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AiState::idle:
|
case AiState::idle:
|
||||||
@ -320,9 +320,9 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
|||||||
m_Timer = 0;
|
m_Timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_State = AiState::aggro;
|
SetAiState(AiState::aggro);
|
||||||
} else {
|
} else {
|
||||||
m_State = AiState::idle;
|
SetAiState(AiState::idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < m_SkillEntries.size(); ++i) {
|
for (auto i = 0; i < m_SkillEntries.size(); ++i) {
|
||||||
@ -348,7 +348,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_Target == LWOOBJID_EMPTY) {
|
if (m_Target == LWOOBJID_EMPTY) {
|
||||||
m_State = AiState::idle;
|
SetAiState(AiState::idle);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
|||||||
m_MovementAI->Stop();
|
m_MovementAI->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_State = AiState::aggro;
|
SetAiState(AiState::aggro);
|
||||||
|
|
||||||
m_Timer = 0;
|
m_Timer = 0;
|
||||||
|
|
||||||
@ -532,11 +532,20 @@ bool BaseCombatAIComponent::IsMech() {
|
|||||||
|
|
||||||
|
|
||||||
void BaseCombatAIComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
void BaseCombatAIComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||||
outBitStream->Write1();
|
outBitStream->Write(m_DirtyStateOrTarget || bIsInitialUpdate);
|
||||||
|
if (m_DirtyStateOrTarget || bIsInitialUpdate) {
|
||||||
outBitStream->Write(uint32_t(m_State));
|
outBitStream->Write(uint32_t(m_State));
|
||||||
outBitStream->Write(m_Target);
|
outBitStream->Write(m_Target);
|
||||||
|
m_DirtyStateOrTarget = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseCombatAIComponent::SetAiState(AiState newState) {
|
||||||
|
if (newState == this->m_State) return;
|
||||||
|
this->m_State = newState;
|
||||||
|
m_DirtyStateOrTarget = true;
|
||||||
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||||
|
}
|
||||||
|
|
||||||
bool BaseCombatAIComponent::IsEnemy(LWOOBJID target) const {
|
bool BaseCombatAIComponent::IsEnemy(LWOOBJID target) const {
|
||||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||||
@ -585,7 +594,10 @@ bool BaseCombatAIComponent::IsEnemy(LWOOBJID target) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseCombatAIComponent::SetTarget(const LWOOBJID target) {
|
void BaseCombatAIComponent::SetTarget(const LWOOBJID target) {
|
||||||
|
if (this->m_Target == target) return;
|
||||||
m_Target = target;
|
m_Target = target;
|
||||||
|
m_DirtyStateOrTarget = true;
|
||||||
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity* BaseCombatAIComponent::GetTargetEntity() const {
|
Entity* BaseCombatAIComponent::GetTargetEntity() const {
|
||||||
@ -700,7 +712,7 @@ void BaseCombatAIComponent::OnAggro() {
|
|||||||
|
|
||||||
m_MovementAI->SetDestination(targetPos);
|
m_MovementAI->SetDestination(targetPos);
|
||||||
|
|
||||||
m_State = AiState::tether;
|
SetAiState(AiState::tether);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Timer += 0.5f;
|
m_Timer += 0.5f;
|
||||||
@ -726,7 +738,7 @@ void BaseCombatAIComponent::OnTether() {
|
|||||||
|
|
||||||
m_MovementAI->SetDestination(m_StartPosition);
|
m_MovementAI->SetDestination(m_StartPosition);
|
||||||
|
|
||||||
m_State = AiState::aggro;
|
SetAiState(AiState::aggro);
|
||||||
} else {
|
} else {
|
||||||
if (IsMech() && Vector3::DistanceSquared(targetPos, currentPos) > m_AttackRadius * m_AttackRadius * 3 * 3) return;
|
if (IsMech() && Vector3::DistanceSquared(targetPos, currentPos) > m_AttackRadius * m_AttackRadius * 3 * 3) return;
|
||||||
|
|
||||||
|
@ -243,6 +243,12 @@ private:
|
|||||||
*/
|
*/
|
||||||
std::vector<LWOOBJID> GetTargetWithinAggroRange() const;
|
std::vector<LWOOBJID> GetTargetWithinAggroRange() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the AiState and prepares the entity for serialization next frame.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void SetAiState(AiState newState);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current state of the AI
|
* The current state of the AI
|
||||||
*/
|
*/
|
||||||
@ -374,6 +380,12 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool m_DirtyThreat = false;
|
bool m_DirtyThreat = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the Component has dirty information and should update next frame
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool m_DirtyStateOrTarget = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the current entity is a mech enemy, needed as mechs tether radius works differently
|
* Whether the current entity is a mech enemy, needed as mechs tether radius works differently
|
||||||
* @return whether this entity is a mech
|
* @return whether this entity is a mech
|
||||||
|
@ -118,6 +118,7 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd
|
|||||||
outBitStream->Write(m_Owner);
|
outBitStream->Write(m_Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bIsInitialUpdate) {
|
||||||
outBitStream->Write(tamed);
|
outBitStream->Write(tamed);
|
||||||
if (tamed) {
|
if (tamed) {
|
||||||
outBitStream->Write(m_ModerationStatus);
|
outBitStream->Write(m_ModerationStatus);
|
||||||
@ -136,6 +137,7 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PetComponent::OnUse(Entity* originator) {
|
void PetComponent::OnUse(Entity* originator) {
|
||||||
if (m_Owner != LWOOBJID_EMPTY) {
|
if (m_Owner != LWOOBJID_EMPTY) {
|
||||||
|
@ -7,8 +7,8 @@ PlayerForcedMovementComponent::PlayerForcedMovementComponent(Entity* parent) : C
|
|||||||
PlayerForcedMovementComponent::~PlayerForcedMovementComponent() {}
|
PlayerForcedMovementComponent::~PlayerForcedMovementComponent() {}
|
||||||
|
|
||||||
void PlayerForcedMovementComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
void PlayerForcedMovementComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||||
outBitStream->Write(m_DirtyInfo);
|
outBitStream->Write(m_DirtyInfo || bIsInitialUpdate);
|
||||||
if (m_DirtyInfo) {
|
if (m_DirtyInfo || bIsInitialUpdate) {
|
||||||
outBitStream->Write(m_PlayerOnRail);
|
outBitStream->Write(m_PlayerOnRail);
|
||||||
outBitStream->Write(m_ShowBillboard);
|
outBitStream->Write(m_ShowBillboard);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user