Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aronwk-aaron committed Sep 29, 2023
1 parent b24775f commit 6f8aff5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
26 changes: 14 additions & 12 deletions dGame/dComponents/RenderComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,35 @@ void RenderComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitial
outBitStream->Write<uint32_t>(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<uint8_t>(0);
continue;
}

outBitStream->Write<uint8_t>(eff->name.size());
for (const auto& value : eff->name)
outBitStream->Write<uint8_t>(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<uint8_t>(value);

outBitStream->Write(eff->effectID);

outBitStream->Write<uint8_t>(eff->type.size());
for (const auto& value : eff->type)
outBitStream->Write<uint16_t>(value);
for (const auto& value : eff->type) outBitStream->Write<uint16_t>(value);

outBitStream->Write<float_t>(eff->scale);
outBitStream->Write<float_t>(eff->priority);
outBitStream->Write<int64_t>(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;
Expand Down Expand Up @@ -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);

Expand Down
15 changes: 8 additions & 7 deletions dGame/dComponents/RenderComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Entity;
* here.
*/
struct Effect {
Effect() { scale = 1.0f; }
Effect() { priority = 1.0f; }

/**
* The ID of the effect
Expand All @@ -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
Expand Down Expand Up @@ -69,9 +69,10 @@ class RenderComponent : public Component {
* @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
Expand Down Expand Up @@ -109,15 +110,15 @@ class RenderComponent : public Component {
* 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);
Expand Down

0 comments on commit 6f8aff5

Please sign in to comment.