From 68a2a04e5d4ab8665a95121d37e2257337ab682e Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 4 Jul 2023 22:52:51 -0700 Subject: [PATCH] LUPExhibitComponent cleanup --- dGame/dComponents/LUPExhibitComponent.cpp | 36 ++++++++--------------- dGame/dComponents/LUPExhibitComponent.h | 8 +++-- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/dGame/dComponents/LUPExhibitComponent.cpp b/dGame/dComponents/LUPExhibitComponent.cpp index 67014bbc..9034d7aa 100644 --- a/dGame/dComponents/LUPExhibitComponent.cpp +++ b/dGame/dComponents/LUPExhibitComponent.cpp @@ -3,42 +3,32 @@ #include "EntityManager.h" LUPExhibitComponent::LUPExhibitComponent(Entity* parent) : Component(parent) { - m_Exhibits = { 11121, 11295, 11423, 11979 }; - m_ExhibitIndex = 0; - - m_Exhibit = m_Exhibits[m_ExhibitIndex]; - - -} - -LUPExhibitComponent::~LUPExhibitComponent() { - + m_UpdateTimer = 0.0f; + m_Exhibit = m_Exhibits.front(); + m_DirtyExhibitInfo = true; } void LUPExhibitComponent::Update(float deltaTime) { m_UpdateTimer += deltaTime; + if (m_UpdateTimer < 20.0f) return; - if (m_UpdateTimer > 20.0f) { - NextExhibit(); - - m_UpdateTimer = 0.0f; - } + NextExhibit(); + m_UpdateTimer = 0.0f; } void LUPExhibitComponent::NextExhibit() { m_ExhibitIndex++; - if (m_ExhibitIndex >= m_Exhibits.size()) { - m_ExhibitIndex = 0; - } - - m_Exhibit = m_Exhibits[m_ExhibitIndex]; - + // After 1361 years, this will skip exhibit 4 one time. I think modulo is ok here. + m_Exhibit = m_Exhibits.at(m_ExhibitIndex % m_Exhibits.size()); EntityManager::Instance()->SerializeEntity(m_ParentEntity); } void LUPExhibitComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags) { - outBitStream->Write1(); // Dirty flag? - outBitStream->Write(m_Exhibit); + outBitStream->Write(bIsInitialUpdate || m_DirtyExhibitInfo); + if (bIsInitialUpdate || m_DirtyExhibitInfo) { + outBitStream->Write(m_Exhibit); + if (!bIsInitialUpdate) m_DirtyExhibitInfo = false; + } } diff --git a/dGame/dComponents/LUPExhibitComponent.h b/dGame/dComponents/LUPExhibitComponent.h index e8db875b..bfa86b48 100644 --- a/dGame/dComponents/LUPExhibitComponent.h +++ b/dGame/dComponents/LUPExhibitComponent.h @@ -8,13 +8,12 @@ * Component that handles the LOT that is shown in the LUP exhibit in the LUP world. Works by setting a timer and * switching the LOTs around that we'd like to display. */ -class LUPExhibitComponent : public Component +class LUPExhibitComponent final : public Component { public: inline static const eReplicaComponentType ComponentType = eReplicaComponentType::EXHIBIT; LUPExhibitComponent(Entity* parent); - ~LUPExhibitComponent(); void Update(float deltaTime) override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags); @@ -36,10 +35,13 @@ private: /** * The list of possible exhibits to show */ - std::vector m_Exhibits; + const std::vector m_Exhibits = { 11121, 11295, 11423, 11979 }; /** * The current index in the exhibit list */ size_t m_ExhibitIndex; + + // Whether or not to notify clients of a change in the visible exhibit + bool m_DirtyExhibitInfo; };