diff --git a/dGame/dComponents/RenderComponent.cpp b/dGame/dComponents/RenderComponent.cpp index 44663a17..6f32dd79 100644 --- a/dGame/dComponents/RenderComponent.cpp +++ b/dGame/dComponents/RenderComponent.cpp @@ -60,33 +60,35 @@ void RenderComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitial outBitStream->Write(m_Effects.size()); for (Effect* eff : m_Effects) { - // Check that the effect is non-null - assert(eff); + // we still need to write 0 as the size for name if it is a nullptr + if (!eff) { + outBitStream->Write(0); + continue; + } outBitStream->Write(eff->name.size()); - for (const auto& value : eff->name) - outBitStream->Write(value); + // if there is no name, then we don't write anything else + if (eff->name.empty()) continue; + + for (const auto& value : eff->name) outBitStream->Write(value); outBitStream->Write(eff->effectID); outBitStream->Write(eff->type.size()); - for (const auto& value : eff->type) - outBitStream->Write(value); + for (const auto& value : eff->type) outBitStream->Write(value); - outBitStream->Write(eff->scale); + outBitStream->Write(eff->priority); outBitStream->Write(eff->secondary); } } -Effect* RenderComponent::AddEffect(const int32_t effectId, const std::string& name, const std::u16string& type) { +Effect* RenderComponent::AddEffect(const int32_t effectId, const std::string& name, const std::u16string& type, const float priority) { auto* eff = new Effect(); eff->effectID = effectId; - eff->name = name; - eff->type = type; - + eff->priority = priority; m_Effects.push_back(eff); return eff; @@ -143,7 +145,7 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e GameMessages::SendPlayFXEffect(m_Parent, effectId, effectType, name, secondary, priority, scale, serialize); - auto* effect = AddEffect(effectId, name, effectType); + auto* effect = AddEffect(effectId, name, effectType, priority); const auto& pair = m_DurationCache.find(effectId); diff --git a/dGame/dComponents/RenderComponent.h b/dGame/dComponents/RenderComponent.h index 24cfd16d..54c0da25 100644 --- a/dGame/dComponents/RenderComponent.h +++ b/dGame/dComponents/RenderComponent.h @@ -17,7 +17,7 @@ class Entity; * here. */ struct Effect { - Effect() { scale = 1.0f; } + Effect() { priority = 1.0f; } /** * The ID of the effect @@ -35,9 +35,9 @@ struct Effect { std::u16string type = u""; /** - * How scaled (enlarged) the effect is + * The importantness of the effect */ - float scale = 1.0f; + float priority = 1.0f; /** * Some related entity that casted the effect @@ -69,9 +69,10 @@ public: * @param effectId the ID of the effect * @param name the name of the effect * @param type the type of the effect + * @param priority the priority of the effect * @return if successful, the effect that was created */ - Effect* AddEffect(int32_t effectId, const std::string& name, const std::u16string& type); + Effect* AddEffect(int32_t effectId, const std::string& name, const std::u16string& type, const float priority); /** * Removes an effect for this entity @@ -109,15 +110,15 @@ public: * if it has the animation assigned to its group. If it does, the animation is echo'd * down to all clients to be played and the duration of the played animation is returned. * If the animation did not exist or the function was called in an invalid state, 0 is returned. - * + * * The logic here matches the exact client logic. - * + * * @param self The entity that wants to play an animation * @param animation The animation_type (animationID in the client) to be played. * @param sendAnimation Whether or not to echo the animation down to all clients. * @param priority The priority of the animation. Only used if sendAnimation is true. * @param scale The scale of the animation. Only used if sendAnimation is true. - * + * * @return The duration of the animation that was played. */ static float DoAnimation(Entity* self, const std::string& animation, bool sendAnimation, float priority = 0.0f, float scale = 1.0f);