delta compression fixes (#937)

This commit is contained in:
David Markowitz 2023-01-03 09:22:04 -08:00 committed by GitHub
parent dc7d0ce142
commit 1789ec7f20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 35 deletions

View File

@ -23,9 +23,9 @@
#include "RebuildComponent.h" #include "RebuildComponent.h"
#include "DestroyableComponent.h" #include "DestroyableComponent.h"
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);
outBitStream->Write(uint32_t(m_State)); if (m_DirtyStateOrTarget || bIsInitialUpdate) {
outBitStream->Write(m_Target); outBitStream->Write(uint32_t(m_State));
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;

View File

@ -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

View File

@ -59,7 +59,7 @@ std::map<LOT, uint32_t> PetComponent::petFlags = {
{ 13067, 838 }, // Skeleton dragon { 13067, 838 }, // Skeleton dragon
}; };
PetComponent::PetComponent(Entity* parent, uint32_t componentId) : Component(parent) { PetComponent::PetComponent(Entity* parent, uint32_t componentId): Component(parent) {
m_ComponentId = componentId; m_ComponentId = componentId;
m_Interaction = LWOOBJID_EMPTY; m_Interaction = LWOOBJID_EMPTY;
@ -118,21 +118,23 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd
outBitStream->Write(m_Owner); outBitStream->Write(m_Owner);
} }
outBitStream->Write(tamed); if (bIsInitialUpdate) {
if (tamed) { outBitStream->Write(tamed);
outBitStream->Write(m_ModerationStatus); if (tamed) {
outBitStream->Write(m_ModerationStatus);
const auto nameData = GeneralUtils::UTF8ToUTF16(m_Name); const auto nameData = GeneralUtils::UTF8ToUTF16(m_Name);
const auto ownerNameData = GeneralUtils::UTF8ToUTF16(m_OwnerName); const auto ownerNameData = GeneralUtils::UTF8ToUTF16(m_OwnerName);
outBitStream->Write(static_cast<uint8_t>(nameData.size())); outBitStream->Write(static_cast<uint8_t>(nameData.size()));
for (const auto c : nameData) { for (const auto c : nameData) {
outBitStream->Write(c); outBitStream->Write(c);
} }
outBitStream->Write(static_cast<uint8_t>(ownerNameData.size())); outBitStream->Write(static_cast<uint8_t>(ownerNameData.size()));
for (const auto c : ownerNameData) { for (const auto c : ownerNameData) {
outBitStream->Write(c); outBitStream->Write(c);
}
} }
} }
} }
@ -916,16 +918,16 @@ void PetComponent::AddDrainImaginationTimer(Item* item, bool fromTaming) {
return; return;
} }
// If we are out of imagination despawn the pet. // If we are out of imagination despawn the pet.
if (playerDestroyableComponent->GetImagination() == 0) { if (playerDestroyableComponent->GetImagination() == 0) {
this->Deactivate(); this->Deactivate();
auto playerEntity = playerDestroyableComponent->GetParent(); auto playerEntity = playerDestroyableComponent->GetParent();
if (!playerEntity) return; if (!playerEntity) return;
GameMessages::SendUseItemRequirementsResponse(playerEntity->GetObjectID(), playerEntity->GetSystemAddress(), UseItemResponse::NoImaginationForPet); GameMessages::SendUseItemRequirementsResponse(playerEntity->GetObjectID(), playerEntity->GetSystemAddress(), UseItemResponse::NoImaginationForPet);
} }
this->AddDrainImaginationTimer(item); this->AddDrainImaginationTimer(item);
}); });
} }

View File

@ -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);
} }