From fca56230f6536054538e334f9f94e245a388443e Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 10 Feb 2024 18:48:07 -0600 Subject: [PATCH 01/22] Rewrite AMF and behavior logic to use smart pointers, references, and string_views over raw pointers and std::string& --- dCommon/AMFDeserialize.cpp | 32 +-- dCommon/AMFDeserialize.h | 23 ++- dCommon/Amf3.h | 183 +++++++++--------- dCommon/GeneralUtils.h | 23 +++ dGame/dComponents/ModelComponent.h | 6 +- dGame/dGameMessages/GameMessages.cpp | 7 +- dGame/dPropertyBehaviors/BlockDefinition.cpp | 8 +- dGame/dPropertyBehaviors/BlockDefinition.h | 15 +- .../ControlBehaviorMessages/Action.cpp | 38 ++-- .../ControlBehaviorMessages/Action.h | 21 +- .../ControlBehaviorMessages/ActionContext.cpp | 25 +-- .../ControlBehaviorMessages/ActionContext.h | 19 +- .../AddActionMessage.cpp | 13 +- .../AddActionMessage.h | 20 +- .../ControlBehaviorMessages/AddMessage.cpp | 10 +- .../ControlBehaviorMessages/AddMessage.h | 7 +- .../AddStripMessage.cpp | 23 +-- .../ControlBehaviorMessages/AddStripMessage.h | 21 +- .../BehaviorMessageBase.cpp | 22 +-- .../BehaviorMessageBase.h | 15 +- .../MergeStripsMessage.cpp | 12 +- .../MergeStripsMessage.h | 29 ++- .../MigrateActionsMessage.cpp | 14 +- .../MigrateActionsMessage.h | 34 ++-- .../MoveToInventoryMessage.cpp | 8 +- .../MoveToInventoryMessage.h | 8 +- .../RearrangeStripMessage.cpp | 12 +- .../RearrangeStripMessage.h | 18 +- .../RemoveActionsMessage.cpp | 9 +- .../RemoveActionsMessage.h | 14 +- .../RemoveStripMessage.cpp | 7 +- .../RemoveStripMessage.h | 9 +- .../ControlBehaviorMessages/RenameMessage.cpp | 8 +- .../ControlBehaviorMessages/RenameMessage.h | 8 +- .../SplitStripMessage.cpp | 14 +- .../SplitStripMessage.h | 35 ++-- .../StripUiPosition.cpp | 29 ++- .../ControlBehaviorMessages/StripUiPosition.h | 13 +- .../UpdateActionMessage.cpp | 15 +- .../UpdateActionMessage.h | 20 +- .../UpdateStripUiMessage.cpp | 9 +- .../UpdateStripUiMessage.h | 15 +- dGame/dPropertyBehaviors/ControlBehaviors.cpp | 32 +-- dGame/dPropertyBehaviors/ControlBehaviors.h | 19 +- dGame/dPropertyBehaviors/PropertyBehavior.cpp | 13 +- dGame/dPropertyBehaviors/PropertyBehavior.h | 8 +- dGame/dPropertyBehaviors/State.cpp | 30 +-- dGame/dPropertyBehaviors/State.h | 3 +- dGame/dPropertyBehaviors/Strip.cpp | 25 ++- dGame/dPropertyBehaviors/Strip.h | 5 +- tests/dCommonTests/AMFDeserializeTests.cpp | 89 +++++---- .../dGameMessagesTests/GameMessageTests.cpp | 62 +++--- 52 files changed, 626 insertions(+), 531 deletions(-) diff --git a/dCommon/AMFDeserialize.cpp b/dCommon/AMFDeserialize.cpp index 648d1ed11..4675b31b8 100644 --- a/dCommon/AMFDeserialize.cpp +++ b/dCommon/AMFDeserialize.cpp @@ -9,31 +9,31 @@ * AMF3 Deserializer written by EmosewaMC */ -AMFBaseValue* AMFDeserialize::Read(RakNet::BitStream* inStream) { +std::unique_ptr AMFDeserialize::Read(RakNet::BitStream* inStream) { if (!inStream) return nullptr; - AMFBaseValue* returnValue = nullptr; + std::unique_ptr returnValue = nullptr; // Read in the value type from the bitStream eAmf marker; inStream->Read(marker); // Based on the typing, create the value associated with that and return the base value class switch (marker) { case eAmf::Undefined: { - returnValue = new AMFBaseValue(); + returnValue = std::make_unique(); break; } case eAmf::Null: { - returnValue = new AMFNullValue(); + returnValue = std::make_unique(); break; } case eAmf::False: { - returnValue = new AMFBoolValue(false); + returnValue = std::make_unique(false); break; } case eAmf::True: { - returnValue = new AMFBoolValue(true); + returnValue = std::make_unique(true); break; } @@ -119,20 +119,20 @@ const std::string AMFDeserialize::ReadString(RakNet::BitStream* inStream) { } } -AMFBaseValue* AMFDeserialize::ReadAmfDouble(RakNet::BitStream* inStream) { +std::unique_ptr AMFDeserialize::ReadAmfDouble(RakNet::BitStream* inStream) { double value; inStream->Read(value); - return new AMFDoubleValue(value); + return std::make_unique(value); } -AMFBaseValue* AMFDeserialize::ReadAmfArray(RakNet::BitStream* inStream) { - auto arrayValue = new AMFArrayValue(); +std::unique_ptr AMFDeserialize::ReadAmfArray(RakNet::BitStream* inStream) { + auto arrayValue = std::make_unique(); // Read size of dense array - auto sizeOfDenseArray = (ReadU29(inStream) >> 1); + const auto sizeOfDenseArray = (ReadU29(inStream) >> 1); // Then read associative portion while (true) { - auto key = ReadString(inStream); + const auto key = ReadString(inStream); // No more associative values when we encounter an empty string key if (key.size() == 0) break; arrayValue->Insert(key, Read(inStream)); @@ -144,10 +144,10 @@ AMFBaseValue* AMFDeserialize::ReadAmfArray(RakNet::BitStream* inStream) { return arrayValue; } -AMFBaseValue* AMFDeserialize::ReadAmfString(RakNet::BitStream* inStream) { - return new AMFStringValue(ReadString(inStream)); +std::unique_ptr AMFDeserialize::ReadAmfString(RakNet::BitStream* inStream) { + return std::make_unique(ReadString(inStream)); } -AMFBaseValue* AMFDeserialize::ReadAmfInteger(RakNet::BitStream* inStream) { - return new AMFIntValue(ReadU29(inStream)); +std::unique_ptr AMFDeserialize::ReadAmfInteger(RakNet::BitStream* inStream) { + return std::make_unique(ReadU29(inStream)); // NOTE: NARROWING CONVERSION FROM UINT TO INT. IS THIS INTENDED? } diff --git a/dCommon/AMFDeserialize.h b/dCommon/AMFDeserialize.h index 5e2729eb4..798c7eb16 100644 --- a/dCommon/AMFDeserialize.h +++ b/dCommon/AMFDeserialize.h @@ -2,11 +2,22 @@ #include "BitStream.h" +#include #include #include +// Forward declarations +template +class AMFValue; + +class AMFArrayValue; class AMFBaseValue; +using AMFDoubleValue = class AMFValue; +using AMFStringValue = class AMFValue; +using AMFIntValue = class AMFValue; + +// Class definition class AMFDeserialize { public: /** @@ -15,7 +26,7 @@ class AMFDeserialize { * @param inStream inStream to read value from. * @return Returns an AMFValue with all the information from the bitStream in it. */ - AMFBaseValue* Read(RakNet::BitStream* inStream); + std::unique_ptr Read(RakNet::BitStream* inStream); private: /** * @brief Private method to read a U29 integer from a bitstream @@ -23,7 +34,7 @@ class AMFDeserialize { * @param inStream bitstream to read data from * @return The number as an unsigned 29 bit integer */ - uint32_t ReadU29(RakNet::BitStream* inStream); + static uint32_t ReadU29(RakNet::BitStream* inStream); /** * @brief Reads a string from a bitstream @@ -39,7 +50,7 @@ class AMFDeserialize { * @param inStream bitStream to read data from * @return Double value represented as an AMFValue */ - AMFBaseValue* ReadAmfDouble(RakNet::BitStream* inStream); + static std::unique_ptr ReadAmfDouble(RakNet::BitStream* inStream); /** * @brief Read an AMFArray from a bitStream @@ -47,7 +58,7 @@ class AMFDeserialize { * @param inStream bitStream to read data from * @return Array value represented as an AMFValue */ - AMFBaseValue* ReadAmfArray(RakNet::BitStream* inStream); + std::unique_ptr ReadAmfArray(RakNet::BitStream* inStream); /** * @brief Read an AMFString from a bitStream @@ -55,7 +66,7 @@ class AMFDeserialize { * @param inStream bitStream to read data from * @return String value represented as an AMFValue */ - AMFBaseValue* ReadAmfString(RakNet::BitStream* inStream); + std::unique_ptr ReadAmfString(RakNet::BitStream* inStream); /** * @brief Read an AMFInteger from a bitStream @@ -63,7 +74,7 @@ class AMFDeserialize { * @param inStream bitStream to read data from * @return Integer value represented as an AMFValue */ - AMFBaseValue* ReadAmfInteger(RakNet::BitStream* inStream); + static std::unique_ptr ReadAmfInteger(RakNet::BitStream* inStream); /** * List of strings read so far saved to be read by reference. diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index dbafba1fe..6348dffa7 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -41,12 +41,14 @@ template class AMFValue : public AMFBaseValue { public: AMFValue() = default; - AMFValue(const ValueType value) { m_Data = value; } + AMFValue(const ValueType value) : m_Data{ value } {} + virtual ~AMFValue() override = default; [[nodiscard]] constexpr eAmf GetValueType() const noexcept override; [[nodiscard]] const ValueType& GetValue() const { return m_Data; } + void SetValue(const ValueType value) { m_Data = value; } protected: @@ -54,7 +56,7 @@ class AMFValue : public AMFBaseValue { }; // Explicit template class instantiations -template class AMFValue; +template class AMFValue; template class AMFValue; template class AMFValue; template class AMFValue; @@ -103,36 +105,33 @@ using AMFDoubleValue = AMFValue; * and are not to be deleted by a caller. */ class AMFArrayValue : public AMFBaseValue { - using AMFAssociative = std::unordered_map; - using AMFDense = std::vector; + using AMFAssociative = + std::unordered_map, GeneralUtils::transparent_string_hash, std::equal_to<>>; + + using AMFDense = std::vector>; public: [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Array; } - ~AMFArrayValue() override { - for (auto valueToDelete : GetDense()) { - if (valueToDelete) { - delete valueToDelete; - valueToDelete = nullptr; - } - } - for (auto valueToDelete : GetAssociative()) { - if (valueToDelete.second) { - delete valueToDelete.second; - valueToDelete.second = nullptr; - } - } - } + /** + * Returns the Associative portion of the object (const) + */ + [[nodiscard]] inline const AMFAssociative& GetAssociative() const noexcept { return m_Associative; } + + /** + * Returns the Associative portion of the object (non-const) + */ + [[nodiscard]] inline AMFAssociative& GetAssociative() noexcept { return m_Associative; } /** - * Returns the Associative portion of the object + * Returns the dense portion of the object (const) */ - [[nodiscard]] inline AMFAssociative& GetAssociative() noexcept { return this->associative; } + [[nodiscard]] inline const AMFDense& GetDense() const noexcept { return m_Dense; } /** - * Returns the dense portion of the object + * Returns the dense portion of the object (non-const) */ - [[nodiscard]] inline AMFDense& GetDense() noexcept { return this->dense; } + [[nodiscard]] inline AMFDense& GetDense() noexcept { return m_Dense; } /** * Inserts an AMFValue into the associative portion with the given key. @@ -149,30 +148,38 @@ class AMFArrayValue : public AMFBaseValue { * or nullptr if a key existed and was not the same type */ template - [[maybe_unused]] std::pair*, bool> Insert(const std::string& key, const ValueType value) { - auto element = associative.find(key); + [[maybe_unused]] std::pair*, bool> Insert(const std::string_view key, const ValueType value) { + const auto element = m_Associative.find(key); AMFValue* val = nullptr; bool found = true; - if (element == associative.end()) { - val = new AMFValue(value); - associative.insert(std::make_pair(key, val)); + if (element == m_Associative.end()) { + auto newVal = std::make_unique>(value); + val = newVal.get(); + m_Associative.emplace( + std::piecewise_construct, + std::forward_as_tuple(key), + std::forward_as_tuple(std::move(newVal))); } else { - val = dynamic_cast*>(element->second); + val = dynamic_cast*>(element->second.get()); found = false; } return std::make_pair(val, found); } - // Associates an array with a string key - [[maybe_unused]] std::pair Insert(const std::string& key) { - auto element = associative.find(key); + // Associates an array with a string keys + [[maybe_unused]] std::pair Insert(const std::string_view key) { + const auto element = m_Associative.find(key); AMFArrayValue* val = nullptr; bool found = true; - if (element == associative.end()) { - val = new AMFArrayValue(); - associative.insert(std::make_pair(key, val)); + if (element == m_Associative.end()) { + auto newVal = std::make_unique(); + val = newVal.get(); + m_Associative.emplace( + std::piecewise_construct, + std::forward_as_tuple(key), + std::forward_as_tuple(std::move(newVal))); } else { - val = dynamic_cast(element->second); + val = dynamic_cast(element->second.get()); found = false; } return std::make_pair(val, found); @@ -180,15 +187,13 @@ class AMFArrayValue : public AMFBaseValue { // Associates an array with an integer key [[maybe_unused]] std::pair Insert(const size_t index) { - AMFArrayValue* val = nullptr; bool inserted = false; - if (index >= dense.size()) { - dense.resize(index + 1); - val = new AMFArrayValue(); - dense.at(index) = val; + if (index >= m_Dense.size()) { + m_Dense.resize(index + 1); + m_Dense.at(index) = std::make_unique(); inserted = true; } - return std::make_pair(dynamic_cast(dense.at(index)), inserted); + return std::make_pair(dynamic_cast(m_Dense.at(index).get()), inserted); } /** @@ -203,15 +208,13 @@ class AMFArrayValue : public AMFBaseValue { */ template [[maybe_unused]] std::pair*, bool> Insert(const size_t index, const ValueType value) { - AMFValue* val = nullptr; bool inserted = false; - if (index >= this->dense.size()) { - this->dense.resize(index + 1); - val = new AMFValue(value); - this->dense.at(index) = val; + if (index >= m_Dense.size()) { + m_Dense.resize(index + 1); + m_Dense.at(index) = std::make_unique>(value); inserted = true; } - return std::make_pair(dynamic_cast*>(this->dense.at(index)), inserted); + return std::make_pair(dynamic_cast*>(m_Dense.at(index).get()), inserted); } /** @@ -223,13 +226,15 @@ class AMFArrayValue : public AMFBaseValue { * @param key The key to associate with the value * @param value The value to insert */ - void Insert(const std::string& key, AMFBaseValue* const value) { - auto element = associative.find(key); - if (element != associative.end() && element->second) { - delete element->second; - element->second = value; + void Insert(const std::string_view key, std::unique_ptr value) { + auto element = m_Associative.find(key); + if (element != m_Associative.end() && element->second) { + element->second.swap(value); // Swapped value should be deleted as this goes out of scope } else { - associative.insert(std::make_pair(key, value)); + m_Associative.emplace( + std::piecewise_construct, + std::forward_as_tuple(key), + std::forward_as_tuple(std::move(value))); } } @@ -242,14 +247,14 @@ class AMFArrayValue : public AMFBaseValue { * @param key The key to associate with the value * @param value The value to insert */ - void Insert(const size_t index, AMFBaseValue* const value) { - if (index < dense.size()) { - AMFDense::iterator itr = dense.begin() + index; - if (*itr) delete dense.at(index); + void Insert(const size_t index, std::unique_ptr value) { + if (index < m_Dense.size()) { + AMFDense::iterator itr = m_Dense.begin() + index; + if (*itr) m_Dense.at(index).reset(); } else { - dense.resize(index + 1); + m_Dense.resize(index + 1); } - dense.at(index) = value; + m_Dense.at(index) = std::move(value); } /** @@ -264,7 +269,7 @@ class AMFArrayValue : public AMFBaseValue { */ template [[maybe_unused]] inline AMFValue* Push(const ValueType value) { - return Insert(this->dense.size(), value).first; + return Insert(m_Dense.size(), value).first; } /** @@ -275,10 +280,10 @@ class AMFArrayValue : public AMFBaseValue { * @param key The key to remove from the associative portion */ void Remove(const std::string& key, const bool deleteValue = true) { - AMFAssociative::iterator it = this->associative.find(key); - if (it != this->associative.end()) { - if (deleteValue) delete it->second; - this->associative.erase(it); + AMFAssociative::iterator it = m_Associative.find(key); + if (it != m_Associative.end()) { + if (deleteValue) it->second.reset(); + m_Associative.erase(it); } } @@ -286,30 +291,30 @@ class AMFArrayValue : public AMFBaseValue { * Pops the last element in the dense portion, deleting it in the process. */ void Remove(const size_t index) { - if (!this->dense.empty() && index < this->dense.size()) { - auto itr = this->dense.begin() + index; - if (*itr) delete (*itr); - this->dense.erase(itr); + if (!m_Dense.empty() && index < m_Dense.size()) { + auto itr = m_Dense.begin() + index; + if (*itr) itr->reset(); + m_Dense.erase(itr); } } void Pop() { - if (!this->dense.empty()) Remove(this->dense.size() - 1); + if (!m_Dense.empty()) Remove(m_Dense.size() - 1); } - [[nodiscard]] AMFArrayValue* GetArray(const std::string& key) { - AMFAssociative::const_iterator it = this->associative.find(key); - if (it != this->associative.end()) { - return dynamic_cast(it->second); + [[nodiscard]] AMFArrayValue* GetArray(const std::string_view key) const { + AMFAssociative::const_iterator it = m_Associative.find(key); + if (it != m_Associative.end()) { + return dynamic_cast(it->second.get()); } return nullptr; } - [[nodiscard]] AMFArrayValue* GetArray(const size_t index) { - return index >= this->dense.size() ? nullptr : dynamic_cast(this->dense.at(index)); + [[nodiscard]] AMFArrayValue* GetArray(const size_t index) const { + return index >= m_Dense.size() ? nullptr : dynamic_cast(m_Dense.at(index).get()); } - [[maybe_unused]] inline AMFArrayValue* InsertArray(const std::string& key) { + [[maybe_unused]] inline AMFArrayValue* InsertArray(const std::string_view key) { return static_cast(Insert(key).first); } @@ -318,7 +323,7 @@ class AMFArrayValue : public AMFBaseValue { } [[maybe_unused]] inline AMFArrayValue* PushArray() { - return static_cast(Insert(this->dense.size()).first); + return static_cast(Insert(m_Dense.size()).first); } /** @@ -331,17 +336,17 @@ class AMFArrayValue : public AMFBaseValue { * @return The AMFValue */ template - [[nodiscard]] AMFValue* Get(const std::string& key) const { - AMFAssociative::const_iterator it = this->associative.find(key); - return it != this->associative.end() ? - dynamic_cast*>(it->second) : + [[nodiscard]] AMFValue* Get(const std::string_view key) const { + AMFAssociative::const_iterator it = m_Associative.find(key); + return it != m_Associative.end() ? + dynamic_cast*>(it->second.get()) : nullptr; } // Get from the array but dont cast it - [[nodiscard]] AMFBaseValue* Get(const std::string& key) const { - AMFAssociative::const_iterator it = this->associative.find(key); - return it != this->associative.end() ? it->second : nullptr; + [[nodiscard]] AMFBaseValue* Get(const std::string_view key) const { + AMFAssociative::const_iterator it = m_Associative.find(key); + return it != m_Associative.end() ? it->second.get() : nullptr; } /** @@ -355,27 +360,27 @@ class AMFArrayValue : public AMFBaseValue { */ template [[nodiscard]] AMFValue* Get(const size_t index) const { - return index < this->dense.size() ? - dynamic_cast*>(this->dense.at(index)) : + return index < m_Dense.size() ? + dynamic_cast*>(m_Dense.at(index).get()) : nullptr; } // Get from the dense but dont cast it [[nodiscard]] AMFBaseValue* Get(const size_t index) const { - return index < this->dense.size() ? this->dense.at(index) : nullptr; + return index < m_Dense.size() ? m_Dense.at(index).get() : nullptr; } private: /** * The associative portion. These values are key'd with strings to an AMFValue. */ - AMFAssociative associative; + AMFAssociative m_Associative; /** * The dense portion. These AMFValue's are stored one after * another with the most recent addition being at the back. */ - AMFDense dense; + AMFDense m_Dense; }; #endif //!__AMF3__H__ diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 15659912b..7138be250 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -126,6 +126,29 @@ namespace GeneralUtils { std::vector GetSqlFileNamesFromFolder(const std::string& folder); + /** + * Transparent string hasher - used to allow string_view key lookups for maps storing std::string keys + * https://www.reddit.com/r/cpp_questions/comments/12xw3sn/find_stdstring_view_in_unordered_map_with/jhki225/ + * https://godbolt.org/z/789xv8Eeq + */ + template + struct overload : Bases... { + using is_transparent = void; + using Bases::operator() ... ; + }; + + struct char_pointer_hash { + auto operator()(const char* const ptr) const noexcept { + return std::hash{}(ptr); + } + }; + + using transparent_string_hash = overload< + std::hash, + std::hash, + char_pointer_hash + >; + // Concept constraining to enum types template concept Enum = std::is_enum_v; diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 0d720d04e..c98b02740 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -61,10 +61,10 @@ class ModelComponent final : public Component { * @param args the arguments of the message to be deserialized */ template - void HandleControlBehaviorsMsg(AMFArrayValue* args) { + void HandleControlBehaviorsMsg(const AMFArrayValue& args) { static_assert(std::is_base_of_v, "Msg must be a BehaviorMessageBase"); - Msg msg(args); - for (auto& behavior : m_Behaviors) { + Msg msg{ args }; + for (auto&& behavior : m_Behaviors) { if (behavior.GetBehaviorId() == msg.GetBehaviorId()) { behavior.HandleMsg(msg); return; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 8b4d1f05c..a4708a0a2 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2488,14 +2488,15 @@ void GameMessages::SendUnSmash(Entity* entity, LWOOBJID builderID, float duratio void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { AMFDeserialize reader; - std::unique_ptr amfArguments(reader.Read(inStream)); + std::unique_ptr amfArguments{ static_cast(reader.Read(inStream).release()) }; if (amfArguments->GetValueType() != eAmf::Array) return; uint32_t commandLength{}; inStream->Read(commandLength); std::string command; - for (uint32_t i = 0; i < commandLength; i++) { + command.reserve(commandLength); + for (uint32_t i = 0; i < commandLength; ++i) { unsigned char character; inStream->Read(character); command.push_back(character); @@ -2504,7 +2505,7 @@ void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* e auto owner = PropertyManagementComponent::Instance()->GetOwner(); if (!owner) return; - ControlBehaviors::Instance().ProcessCommand(entity, sysAddr, static_cast(amfArguments.get()), command, owner); + ControlBehaviors::Instance().ProcessCommand(entity, *amfArguments.get(), command, owner); } void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { diff --git a/dGame/dPropertyBehaviors/BlockDefinition.cpp b/dGame/dPropertyBehaviors/BlockDefinition.cpp index 2950ac822..5b38f986b 100644 --- a/dGame/dPropertyBehaviors/BlockDefinition.cpp +++ b/dGame/dPropertyBehaviors/BlockDefinition.cpp @@ -2,8 +2,8 @@ BlockDefinition BlockDefinition::blockDefinitionDefault{}; -BlockDefinition::BlockDefinition(std::string defaultValue, float minimumValue, float maximumValue) { - this->defaultValue = defaultValue; - this->minimumValue = minimumValue; - this->maximumValue = maximumValue; +BlockDefinition::BlockDefinition(const std::string_view defaultValue, const float minimumValue, const float maximumValue) + : defaultValue{ defaultValue } + , minimumValue{ minimumValue } + , maximumValue{ maximumValue } { } diff --git a/dGame/dPropertyBehaviors/BlockDefinition.h b/dGame/dPropertyBehaviors/BlockDefinition.h index 3a5a6bf11..dbea95cd5 100644 --- a/dGame/dPropertyBehaviors/BlockDefinition.h +++ b/dGame/dPropertyBehaviors/BlockDefinition.h @@ -7,15 +7,16 @@ class AMFArrayValue; class BlockDefinition { public: - BlockDefinition(std::string defaultValue = "", float minimumValue = 0.0f, float maximumValue = 0.0f); + BlockDefinition(const std::string_view defaultValue = "", const float minimumValue = 0.0f, const float maximumValue = 0.0f); static BlockDefinition blockDefinitionDefault; - std::string& GetDefaultValue() { return defaultValue; }; - float GetMinimumValue() { return minimumValue; }; - float GetMaximumValue() { return maximumValue; }; - void SetDefaultValue(std::string value) { defaultValue = value; }; - void SetMinimumValue(float value) { minimumValue = value; }; - void SetMaximumValue(float value) { maximumValue = value; }; + [[nodiscard]] std::string_view GetDefaultValue() const { return defaultValue; }; + [[nodiscard]] float GetMinimumValue() const noexcept { return minimumValue; }; + [[nodiscard]] float GetMaximumValue() const noexcept { return maximumValue; }; + void SetDefaultValue(const std::string_view value) { defaultValue = std::string{ value }; }; + void SetMinimumValue(const float value) noexcept { minimumValue = value; }; + void SetMaximumValue(const float value) noexcept { maximumValue = value; }; + private: std::string defaultValue; float minimumValue; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp index 73f1391d5..63ec39e30 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp @@ -1,46 +1,34 @@ #include "Action.h" #include "Amf3.h" -Action::Action() { - type = ""; - valueParameterName = ""; - valueParameterString = ""; - valueParameterDouble = 0.0; -} - -Action::Action(AMFArrayValue* arguments) { - type = ""; - valueParameterName = ""; - valueParameterString = ""; - valueParameterDouble = 0.0; - for (auto& [paramName, paramValue] : arguments->GetAssociative()) { +Action::Action(const AMFArrayValue& arguments) { + for (const auto& [paramName, paramValue] : arguments.GetAssociative()) { if (paramName == "Type") { if (paramValue->GetValueType() != eAmf::String) continue; - type = static_cast(paramValue)->GetValue(); + m_Type = static_cast(paramValue.get())->GetValue(); } else { - valueParameterName = paramName; + m_ValueParameterName = paramName; // Message is the only known string parameter - if (valueParameterName == "Message") { + if (m_ValueParameterName == "Message") { if (paramValue->GetValueType() != eAmf::String) continue; - valueParameterString = static_cast(paramValue)->GetValue(); + m_ValueParameterString = static_cast(paramValue.get())->GetValue(); } else { if (paramValue->GetValueType() != eAmf::Double) continue; - valueParameterDouble = static_cast(paramValue)->GetValue(); + m_ValueParameterDouble = static_cast(paramValue.get())->GetValue(); } } } } void Action::SendBehaviorBlocksToClient(AMFArrayValue& args) const { - auto* actionArgs = args.PushArray(); - actionArgs->Insert("Type", type); + auto* const actionArgs = args.PushArray(); + actionArgs->Insert("Type", m_Type); - auto valueParameterName = GetValueParameterName(); - if (valueParameterName.empty()) return; + if (m_ValueParameterName.empty()) return; - if (valueParameterName == "Message") { - actionArgs->Insert(valueParameterName, valueParameterString); + if (m_ValueParameterName == "Message") { + actionArgs->Insert(m_ValueParameterName, m_ValueParameterString); } else { - actionArgs->Insert(valueParameterName, valueParameterDouble); + actionArgs->Insert(m_ValueParameterName, m_ValueParameterDouble); } } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h index df6658896..36715e324 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h @@ -11,19 +11,20 @@ class AMFArrayValue; */ class Action { public: - Action(); - Action(AMFArrayValue* arguments); - const std::string& GetType() const { return type; }; - const std::string& GetValueParameterName() const { return valueParameterName; }; - const std::string& GetValueParameterString() const { return valueParameterString; }; - const double GetValueParameterDouble() const { return valueParameterDouble; }; + Action() = default; + Action(const AMFArrayValue& arguments); + [[nodiscard]] std::string_view GetType() const { return m_Type; }; + [[nodiscard]] std::string_view GetValueParameterName() const { return m_ValueParameterName; }; + [[nodiscard]] std::string_view GetValueParameterString() const { return m_ValueParameterString; }; + [[nodiscard]] double GetValueParameterDouble() const noexcept { return m_ValueParameterDouble; }; void SendBehaviorBlocksToClient(AMFArrayValue& args) const; + private: - std::string type; - std::string valueParameterName; - std::string valueParameterString; - double valueParameterDouble; + double m_ValueParameterDouble{ 0.0 }; + std::string m_Type{ "" }; + std::string m_ValueParameterName{ "" }; + std::string m_ValueParameterString{ "" }; }; #endif //!__ACTION__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp index c2ba2eebd..9c88acc3c 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp @@ -4,28 +4,21 @@ #include "Amf3.h" -ActionContext::ActionContext() { - stripId = 0; - stateId = BehaviorState::HOME_STATE; +ActionContext::ActionContext(const AMFArrayValue& arguments, const std::string_view customStateKey, const std::string_view customStripKey) + : m_StripId{ GetStripIdFromArgument(arguments, customStripKey) } + , m_StateId{ GetBehaviorStateFromArgument(arguments, customStateKey) } { } -ActionContext::ActionContext(AMFArrayValue* arguments, std::string customStateKey, std::string customStripKey) { - stripId = 0; - stateId = BehaviorState::HOME_STATE; - stripId = GetStripIdFromArgument(arguments, customStripKey); - stateId = GetBehaviorStateFromArgument(arguments, customStateKey); -} - -BehaviorState ActionContext::GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key) { - auto* stateIDValue = arguments->Get(key); - if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\""); +BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue& arguments, const std::string_view key) const { + const auto* const stateIDValue = arguments.Get(key); + if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + std::string{ key } + "\""); return static_cast(stateIDValue->GetValue()); } -StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) { - auto* stripIdValue = arguments->Get(key); - if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\""); +StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue& arguments, const std::string_view key) const { + const auto* const stripIdValue = arguments.Get(key); + if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + std::string{ key } + "\""); return static_cast(stripIdValue->GetValue()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h index 91e91e728..d6b84aba7 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h @@ -4,6 +4,8 @@ #include "BehaviorStates.h" #include "dCommonVars.h" +#include + class AMFArrayValue; /** @@ -12,15 +14,16 @@ class AMFArrayValue; */ class ActionContext { public: - ActionContext(); - ActionContext(AMFArrayValue* arguments, std::string customStateKey = "stateID", std::string customStripKey = "stripID"); - const StripId GetStripId() const { return stripId; }; - const BehaviorState GetStateId() const { return stateId; }; + ActionContext() noexcept = default; + ActionContext(const AMFArrayValue& arguments, const std::string_view customStateKey = "stateID", const std::string_view customStripKey = "stripID"); + [[nodiscard]] StripId GetStripId() const noexcept { return m_StripId; }; + [[nodiscard]] BehaviorState GetStateId() const noexcept { return m_StateId; }; + private: - BehaviorState GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key); - StripId GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key); - StripId stripId; - BehaviorState stateId; + [[nodiscard]] BehaviorState GetBehaviorStateFromArgument(const AMFArrayValue& arguments, const std::string_view key) const; + [[nodiscard]] StripId GetStripIdFromArgument(const AMFArrayValue& arguments, const std::string_view key) const; + StripId m_StripId{ 0 }; + BehaviorState m_StateId{ BehaviorState::HOME_STATE }; }; #endif //!__ACTIONCONTEXT__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp index 36d9a3dc0..0b0b9eaf4 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp @@ -1,13 +1,14 @@ #include "AddActionMessage.h" -AddActionMessage::AddActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - actionContext = ActionContext(arguments); - actionIndex = GetActionIndexFromArgument(arguments); +AddActionMessage::AddActionMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_ActionIndex{ GetActionIndexFromArgument(arguments) } + , m_ActionContext{ arguments } { - auto* actionValue = arguments->GetArray("action"); + const auto* const actionValue = arguments.GetArray("action"); if (!actionValue) return; - action = Action(actionValue); + m_Action = Action{ *actionValue }; - LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i", actionIndex, actionContext.GetStripId(), actionContext.GetStateId(), action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId); + LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f m_BehaviorId %i", m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_Action.GetType().data(), m_Action.GetValueParameterName().data(), m_Action.GetValueParameterString().data(), m_Action.GetValueParameterDouble(), m_BehaviorId); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h index ac3a96122..e2b07f6bb 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h @@ -13,14 +13,20 @@ class AMFArrayValue; */ class AddActionMessage : public BehaviorMessageBase { public: - AddActionMessage(AMFArrayValue* arguments); - int32_t GetActionIndex() const { return actionIndex; }; - Action GetAction() const { return action; }; - ActionContext GetActionContext() const { return actionContext; }; + AddActionMessage(const AMFArrayValue& arguments); + + [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }; + + [[nodiscard]] const Action& GetAction() const noexcept { return m_Action; }; + [[nodiscard]] Action& GetAction() noexcept { return m_Action; }; + + [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }; + [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; }; + private: - int32_t actionIndex = -1; - ActionContext actionContext; - Action action; + int32_t m_ActionIndex{ -1 }; + ActionContext m_ActionContext; + Action m_Action; }; #endif //!__ADDACTIONMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp index cf96ab134..45e3d9741 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp @@ -1,11 +1,9 @@ #include "AddMessage.h" -AddMessage::AddMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - behaviorIndex = 0; - auto* behaviorIndexValue = arguments->Get("BehaviorIndex"); - +AddMessage::AddMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } { + const auto* const behaviorIndexValue = arguments.Get("BehaviorIndex"); if (!behaviorIndexValue) return; - behaviorIndex = static_cast(behaviorIndexValue->GetValue()); - LOG_DEBUG("behaviorId %i index %i", behaviorId, behaviorIndex); + m_BehaviorIndex = static_cast(behaviorIndexValue->GetValue()); + LOG_DEBUG("behaviorId %i index %i", m_BehaviorId, m_BehaviorIndex); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h index 766276655..8bf0b70cf 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h @@ -9,10 +9,11 @@ */ class AddMessage : public BehaviorMessageBase { public: - AddMessage(AMFArrayValue* arguments); - const uint32_t GetBehaviorIndex() const { return behaviorIndex; }; + AddMessage(const AMFArrayValue& arguments); + [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; }; + private: - uint32_t behaviorIndex; + uint32_t m_BehaviorIndex{ 0 }; }; #endif //!__ADDMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp index ac6e8db7a..ff5009ccf 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp @@ -2,27 +2,24 @@ #include "Action.h" -AddStripMessage::AddStripMessage(AMFArrayValue* const arguments) : BehaviorMessageBase{ arguments } { - actionContext = ActionContext(arguments); - position = StripUiPosition(arguments); +AddStripMessage::AddStripMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_Position{ arguments } + , m_ActionContext{ arguments } { - auto* strip = arguments->GetArray("strip"); + const auto* const strip = arguments.GetArray("strip"); if (!strip) return; - auto* actions = strip->GetArray("actions"); + const auto* const actions = strip->GetArray("actions"); if (!actions) return; for (uint32_t actionNumber = 0; actionNumber < actions->GetDense().size(); actionNumber++) { - auto* actionValue = actions->GetArray(actionNumber); + const auto* const actionValue = actions->GetArray(actionNumber); if (!actionValue) continue; - actionsToAdd.push_back(Action(actionValue)); + m_ActionsToAdd.push_back(Action{ *actionValue }); - LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId, actionsToAdd.back().GetType().c_str(), actionsToAdd.back().GetValueParameterName().c_str(), actionsToAdd.back().GetValueParameterString().c_str(), actionsToAdd.back().GetValueParameterDouble()); + LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().data(), m_ActionsToAdd.back().GetValueParameterName().data(), m_ActionsToAdd.back().GetValueParameterString().data(), m_ActionsToAdd.back().GetValueParameterDouble()); } - LOG_DEBUG("number of actions %i", actionsToAdd.size()); -} - -std::vector AddStripMessage::GetActionsToAdd() const { - return actionsToAdd; + LOG_DEBUG("number of actions %i", m_ActionsToAdd.size()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h index 2e2bf9a0d..ddc24642d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h @@ -18,14 +18,21 @@ class AMFArrayValue; */ class AddStripMessage : public BehaviorMessageBase { public: - AddStripMessage(AMFArrayValue* const arguments); - StripUiPosition GetPosition() const { return position; }; - ActionContext GetActionContext() const { return actionContext; }; - std::vector GetActionsToAdd() const; + AddStripMessage(const AMFArrayValue& arguments); + + [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; } + [[nodiscard]] StripUiPosition& GetPosition() noexcept { return m_Position; } + + [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } + [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } + + [[nodiscard]] const std::vector& GetActionsToAdd() const noexcept { return m_ActionsToAdd; } + [[nodiscard]] std::vector& GetActionsToAdd() noexcept { return m_ActionsToAdd; } + private: - StripUiPosition position; - ActionContext actionContext; - std::vector actionsToAdd; + StripUiPosition m_Position; + ActionContext m_ActionContext; + std::vector m_ActionsToAdd; }; #endif //!__ADDSTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp index a49a8aebb..fdacbdad8 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -4,26 +4,22 @@ #include "BehaviorStates.h" #include "dCommonVars.h" -BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) { - this->behaviorId = GetBehaviorIdFromArgument(arguments); -} - -int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* const arguments) { - const char* const key = "BehaviorID"; - const auto* const behaviorIDValue = arguments->Get(key); +int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) { + static constexpr std::string_view key = "BehaviorID"; + const auto* const behaviorIDValue = arguments.Get(key); if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { - this->behaviorId = - GeneralUtils::TryParse(behaviorIDValue->GetValue()).value_or(this->behaviorId); - } else if (arguments->Get(key) && arguments->Get(key)->GetValueType() != eAmf::Undefined) { + m_BehaviorId = + GeneralUtils::TryParse(behaviorIDValue->GetValue()).value_or(m_BehaviorId); + } else if (arguments.Get(key) && arguments.Get(key)->GetValueType() != eAmf::Undefined) { throw std::invalid_argument("Unable to find behavior ID"); } - return this->behaviorId; + return m_BehaviorId; } -int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName) const { - const auto* const actionIndexAmf = arguments->Get(keyName); +int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string_view keyName) const { + const auto* const actionIndexAmf = arguments.Get(keyName); if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex"); return static_cast(actionIndexAmf->GetValue()); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h index f55fde8ec..cc8c293dd 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -15,14 +15,15 @@ enum class BehaviorState : uint32_t; */ class BehaviorMessageBase { public: - static constexpr int32_t DefaultBehaviorId = -1; - [[nodiscard]] int32_t GetBehaviorId() const { return behaviorId; }; - [[nodiscard]] bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; - BehaviorMessageBase(AMFArrayValue* const arguments); + static constexpr int32_t DefaultBehaviorId{ -1 }; + BehaviorMessageBase(const AMFArrayValue& arguments) : m_BehaviorId{ GetBehaviorIdFromArgument(arguments) } {} + [[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; } + [[nodiscard]] bool IsDefaultBehaviorId() const noexcept { return m_BehaviorId == DefaultBehaviorId; } + protected: - [[nodiscard]] int32_t GetBehaviorIdFromArgument(AMFArrayValue* const arguments); - [[nodiscard]] int32_t GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName = "actionIndex") const; - int32_t behaviorId = DefaultBehaviorId; + [[nodiscard]] int32_t GetBehaviorIdFromArgument(const AMFArrayValue& arguments); + [[nodiscard]] int32_t GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string_view keyName = "actionIndex") const; + int32_t m_BehaviorId{ DefaultBehaviorId }; }; #endif //!__BEHAVIORMESSAGEBASE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp index 18327ecf6..1efc5aee7 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp @@ -1,11 +1,11 @@ #include "MergeStripsMessage.h" -MergeStripsMessage::MergeStripsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); +MergeStripsMessage::MergeStripsMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } + , m_SourceActionContext{ arguments, "srcStateID", "srcStripID" } + , m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" } { - destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); - dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex"); - - LOG_DEBUG("srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), dstActionIndex, behaviorId); + LOG_DEBUG("srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_DstActionIndex, m_BehaviorId); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h index 7fa4d3a89..6b2987bc9 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h @@ -13,17 +13,26 @@ class AMFArrayValue; */ class MergeStripsMessage : public BehaviorMessageBase { public: - MergeStripsMessage(AMFArrayValue* arguments); - int32_t GetDstActionIndex() const { return dstActionIndex; }; - ActionContext GetSourceActionContext() const { return sourceActionContext; }; - ActionContext GetDestinationActionContext() const { return destinationActionContext; }; - const std::vector& GetMigratedActions() const { return migratedActions; }; - void SetMigratedActions(std::vector::const_iterator start, std::vector::const_iterator end) { migratedActions.assign(start, end); }; + MergeStripsMessage(const AMFArrayValue& arguments); + + [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } + + [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; } + [[nodiscard]] ActionContext& GetSourceActionContext() noexcept { return m_SourceActionContext; } + + [[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; } + [[nodiscard]] ActionContext& GetDestinationActionContext() noexcept { return m_DestinationActionContext; } + + [[nodiscard]] const std::vector& GetMigratedActions() const noexcept { return m_MigratedActions; } + [[nodiscard]] std::vector& GetMigratedActions() noexcept { return m_MigratedActions; } + + void SetMigratedActions(std::vector::const_iterator start, std::vector::const_iterator end) { m_MigratedActions.assign(start, end); }; + private: - std::vector migratedActions; - ActionContext sourceActionContext; - ActionContext destinationActionContext; - int32_t dstActionIndex; + int32_t m_DstActionIndex; + std::vector m_MigratedActions; + ActionContext m_SourceActionContext; + ActionContext m_DestinationActionContext; }; #endif //!__MERGESTRIPSMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp index 4d45429b7..9791bc2ae 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp @@ -1,11 +1,11 @@ #include "MigrateActionsMessage.h" -MigrateActionsMessage::MigrateActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); - srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); +MigrateActionsMessage::MigrateActionsMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } + , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } + , m_SourceActionContext{ arguments, "srcStateID", "srcStripID" } + , m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" } { - destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); - dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex"); - - LOG_DEBUG("srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", srcActionIndex, dstActionIndex, sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), behaviorId); + LOG_DEBUG("srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", m_SrcActionIndex, m_DstActionIndex, m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_BehaviorId); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h index 2f1ac2439..b0d845fa6 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h @@ -13,19 +13,29 @@ class AMFArrayValue; */ class MigrateActionsMessage : public BehaviorMessageBase { public: - MigrateActionsMessage(AMFArrayValue* arguments); - int32_t GetSrcActionIndex() const { return srcActionIndex; }; - int32_t GetDstActionIndex() const { return dstActionIndex; }; - ActionContext GetSourceActionContext() const { return sourceActionContext; }; - ActionContext GetDestinationActionContext() const { return destinationActionContext; }; - const std::vector& GetMigratedActions() const { return migratedActions; }; - void SetMigratedActions(std::vector::const_iterator start, std::vector::const_iterator end) { migratedActions.assign(start, end); }; + MigrateActionsMessage(const AMFArrayValue& arguments); + + [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } + + [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } + + [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; } + [[nodiscard]] ActionContext& GetSourceActionContext() noexcept { return m_SourceActionContext; } + + [[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; } + [[nodiscard]] ActionContext& GetDestinationActionContext() noexcept { return m_DestinationActionContext; } + + [[nodiscard]] const std::vector& GetMigratedActions() const noexcept { return m_MigratedActions; } + [[nodiscard]] std::vector& GetMigratedActions() noexcept { return m_MigratedActions; } + + void SetMigratedActions(std::vector::const_iterator start, std::vector::const_iterator end) { m_MigratedActions.assign(start, end); } + private: - std::vector migratedActions; - ActionContext sourceActionContext; - ActionContext destinationActionContext; - int32_t srcActionIndex; - int32_t dstActionIndex; + int32_t m_SrcActionIndex; + int32_t m_DstActionIndex; + std::vector m_MigratedActions; + ActionContext m_SourceActionContext; + ActionContext m_DestinationActionContext; }; #endif //!__MIGRATEACTIONSMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp index 5195e6766..cab5c4a3e 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp @@ -1,9 +1,9 @@ #include "MoveToInventoryMessage.h" -MoveToInventoryMessage::MoveToInventoryMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - auto* behaviorIndexValue = arguments->Get("BehaviorIndex"); +MoveToInventoryMessage::MoveToInventoryMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } { + const auto* const behaviorIndexValue = arguments.Get("BehaviorIndex"); if (!behaviorIndexValue) return; - behaviorIndex = static_cast(behaviorIndexValue->GetValue()); - LOG_DEBUG("behaviorId %i behaviorIndex %i", behaviorId, behaviorIndex); + m_BehaviorIndex = static_cast(behaviorIndexValue->GetValue()); + LOG_DEBUG("behaviorId %i behaviorIndex %i", m_BehaviorId, m_BehaviorIndex); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h index dc1057666..e1f88713d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h @@ -7,15 +7,15 @@ class AMFArrayValue; /** * @brief Sent when a player moves a Behavior A at position B to their inventory. - * */ #pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.") class MoveToInventoryMessage : public BehaviorMessageBase { public: - MoveToInventoryMessage(AMFArrayValue* arguments); - const uint32_t GetBehaviorIndex() const { return behaviorIndex; }; + MoveToInventoryMessage(const AMFArrayValue& arguments); + [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; }; + private: - uint32_t behaviorIndex; + uint32_t m_BehaviorIndex; }; #endif //!__MOVETOINVENTORYMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp index d612ae2a1..99fe6f6a4 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp @@ -1,10 +1,10 @@ #include "RearrangeStripMessage.h" -RearrangeStripMessage::RearrangeStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - actionContext = ActionContext(arguments); - srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); +RearrangeStripMessage::RearrangeStripMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } + , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } + , m_ActionContext{ arguments } { - dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex"); - - LOG_DEBUG("srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", srcActionIndex, dstActionIndex, actionContext.GetStripId(), behaviorId, actionContext.GetStateId()); + LOG_DEBUG("srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", m_SrcActionIndex, m_DstActionIndex, m_ActionContext.GetStripId(), m_BehaviorId, m_ActionContext.GetStateId()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h index db12c046c..0d76f851b 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h @@ -10,14 +10,18 @@ */ class RearrangeStripMessage : public BehaviorMessageBase { public: - RearrangeStripMessage(AMFArrayValue* arguments); - int32_t GetSrcActionIndex() const { return srcActionIndex; }; - int32_t GetDstActionIndex() const { return dstActionIndex; }; - ActionContext GetActionContext() const { return actionContext; }; + RearrangeStripMessage(const AMFArrayValue& arguments); + + [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } + [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } + + [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } + [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } + private: - ActionContext actionContext; - int32_t srcActionIndex; - int32_t dstActionIndex; + int32_t m_SrcActionIndex; + int32_t m_DstActionIndex; + ActionContext m_ActionContext; }; #endif //!__REARRANGESTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp index c6164c6f7..154070123 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp @@ -1,8 +1,9 @@ #include "RemoveActionsMessage.h" -RemoveActionsMessage::RemoveActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - actionContext = ActionContext(arguments); - actionIndex = GetActionIndexFromArgument(arguments); +RemoveActionsMessage::RemoveActionsMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_ActionIndex{ GetActionIndexFromArgument(arguments) } + , m_ActionContext{ arguments } { - LOG_DEBUG("behaviorId %i actionIndex %i stripId %i stateId %i", behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId()); + LOG_DEBUG("behaviorId %i actionIndex %i stripId %i stateId %i", m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h index 860df0af4..cf801c2e3 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h @@ -12,12 +12,16 @@ class AMFArrayValue; */ class RemoveActionsMessage : public BehaviorMessageBase { public: - RemoveActionsMessage(AMFArrayValue* arguments); - int32_t GetActionIndex() const { return actionIndex; }; - ActionContext GetActionContext() const { return actionContext; }; + RemoveActionsMessage(const AMFArrayValue& arguments); + + [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } + + [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } + [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } + private: - ActionContext actionContext; - int32_t actionIndex; + int32_t m_ActionIndex; + ActionContext m_ActionContext; }; #endif //!__REMOVEACTIONSMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp index b70beecee..f02753778 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp @@ -1,7 +1,8 @@ #include "RemoveStripMessage.h" -RemoveStripMessage::RemoveStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - actionContext = ActionContext(arguments); +RemoveStripMessage::RemoveStripMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_ActionContext{ arguments } { - LOG_DEBUG("stripId %i stateId %i behaviorId %i", actionContext.GetStripId(), actionContext.GetStateId(), behaviorId); + LOG_DEBUG("stripId %i stateId %i behaviorId %i", m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h index 6a32ab0c5..6c6948402 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h @@ -10,10 +10,13 @@ */ class RemoveStripMessage : public BehaviorMessageBase { public: - RemoveStripMessage(AMFArrayValue* arguments); - ActionContext GetActionContext() const { return actionContext; }; + RemoveStripMessage(const AMFArrayValue& arguments); + + const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } + ActionContext& GetActionContext() noexcept { return m_ActionContext; } + private: - ActionContext actionContext; + ActionContext m_ActionContext; }; #endif //!__REMOVESTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp index 17365be22..82d88bf83 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp @@ -1,9 +1,9 @@ #include "RenameMessage.h" -RenameMessage::RenameMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - auto* nameAmf = arguments->Get("Name"); +RenameMessage::RenameMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } { + const auto* const nameAmf = arguments.Get("Name"); if (!nameAmf) return; - name = nameAmf->GetValue(); - LOG_DEBUG("behaviorId %i n %s", behaviorId, name.c_str()); + m_Name = nameAmf->GetValue(); + LOG_DEBUG("behaviorId %i n %s", m_BehaviorId, m_Name.c_str()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h index 3f4119d2b..68cc83d74 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h @@ -7,14 +7,14 @@ class AMFArrayValue; /** * @brief Sent when a player renames this behavior - * */ class RenameMessage : public BehaviorMessageBase { public: - RenameMessage(AMFArrayValue* arguments); - const std::string& GetName() const { return name; }; + RenameMessage(const AMFArrayValue& arguments); + [[nodiscard]] std::string_view GetName() const { return m_Name; }; + private: - std::string name; + std::string m_Name; }; #endif //!__RENAMEMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp index 45dad737a..6003c9823 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp @@ -1,11 +1,11 @@ #include "SplitStripMessage.h" -SplitStripMessage::SplitStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); - srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); +SplitStripMessage::SplitStripMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } + , m_SourceActionContext{ arguments, "srcStateID", "srcStripID" } + , m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" } + , m_DestinationPosition{ arguments, "dstStripUI" } { - destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); - destinationPosition = StripUiPosition(arguments, "dstStripUI"); - - LOG_DEBUG("behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", behaviorId, destinationPosition.GetX(), destinationPosition.GetY(), sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), srcActionIndex); + LOG_DEBUG("behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", m_BehaviorId, m_DestinationPosition.GetX(), m_DestinationPosition.GetY(), m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_SrcActionIndex); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h index e41d50ebb..76b7c290d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h @@ -14,20 +14,31 @@ class AMFArrayValue; */ class SplitStripMessage : public BehaviorMessageBase { public: - SplitStripMessage(AMFArrayValue* arguments); - ActionContext GetSourceActionContext() const { return sourceActionContext; }; - ActionContext GetDestinationActionContext() const { return destinationActionContext; }; - int32_t GetSrcActionIndex() const { return srcActionIndex; }; - StripUiPosition GetPosition() const { return destinationPosition; }; - const std::vector& GetTransferredActions() const { return transferredActions; }; - void SetTransferredActions(std::vector::const_iterator begin, std::vector::const_iterator end) { transferredActions.assign(begin, end); }; + SplitStripMessage(const AMFArrayValue& arguments); + + [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } + + [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; } + [[nodiscard]] ActionContext& GetSourceActionContext() noexcept { return m_SourceActionContext; } + + [[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; } + [[nodiscard]] ActionContext& GetDestinationActionContext() noexcept { return m_DestinationActionContext; } + + [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_DestinationPosition; } + [[nodiscard]] StripUiPosition& GetPosition() noexcept { return m_DestinationPosition; } + + [[nodiscard]] const std::vector& GetTransferredActions() const noexcept { return m_TransferredActions; } + [[nodiscard]] std::vector& GetTransferredActions() noexcept { return m_TransferredActions; } + + void SetTransferredActions(std::vector::const_iterator begin, std::vector::const_iterator end) { m_TransferredActions.assign(begin, end); }; + private: - ActionContext sourceActionContext; - ActionContext destinationActionContext; - int32_t srcActionIndex; - StripUiPosition destinationPosition; + int32_t m_SrcActionIndex; + ActionContext m_SourceActionContext; + ActionContext m_DestinationActionContext; + StripUiPosition m_DestinationPosition; - std::vector transferredActions; + std::vector m_TransferredActions; }; #endif //!__SPLITSTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp index 8b2d1d365..249aafcb7 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp @@ -2,27 +2,22 @@ #include "Amf3.h" -StripUiPosition::StripUiPosition() { - xPosition = 0.0; - yPosition = 0.0; -} - -StripUiPosition::StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName) { - xPosition = 0.0; - yPosition = 0.0; - auto* uiArray = arguments->GetArray(uiKeyName); +StripUiPosition::StripUiPosition(const AMFArrayValue& arguments, const std::string_view uiKeyName) { + const auto* const uiArray = arguments.GetArray(uiKeyName); if (!uiArray) return; - auto* xPositionValue = uiArray->Get("x"); - auto* yPositionValue = uiArray->Get("y"); - if (!xPositionValue || !yPositionValue) return; + const auto* const xPositionValue = uiArray->Get("x"); + if (!xPositionValue) return; + + const auto* const yPositionValue = uiArray->Get("y"); + if (!yPositionValue) return; - yPosition = yPositionValue->GetValue(); - xPosition = xPositionValue->GetValue(); + m_YPosition = yPositionValue->GetValue(); + m_XPosition = xPositionValue->GetValue(); } void StripUiPosition::SendBehaviorBlocksToClient(AMFArrayValue& args) const { - auto* uiArgs = args.InsertArray("ui"); - uiArgs->Insert("x", xPosition); - uiArgs->Insert("y", yPosition); + auto* const uiArgs = args.InsertArray("ui"); + uiArgs->Insert("x", m_XPosition); + uiArgs->Insert("y", m_YPosition); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h index 92578cdc2..932d6d23e 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h @@ -9,14 +9,15 @@ class AMFArrayValue; */ class StripUiPosition { public: - StripUiPosition(); - StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName = "ui"); + StripUiPosition() noexcept = default; + StripUiPosition(const AMFArrayValue& arguments, const std::string_view uiKeyName = "ui"); void SendBehaviorBlocksToClient(AMFArrayValue& args) const; - double GetX() const { return xPosition; }; - double GetY() const { return yPosition; }; + [[nodiscard]] double GetX() const noexcept { return m_XPosition; } + [[nodiscard]] double GetY() const noexcept { return m_YPosition; } + private: - double xPosition; - double yPosition; + double m_XPosition{ 0.0 }; + double m_YPosition{ 0.0 }; }; #endif //!__STRIPUIPOSITION__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp index 924a9e62a..04111a7db 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp @@ -2,14 +2,15 @@ #include "Action.h" -UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - actionContext = ActionContext(arguments); +UpdateActionMessage::UpdateActionMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_ActionIndex{ GetActionIndexFromArgument(arguments) } + , m_ActionContext{ arguments } { - auto* actionValue = arguments->GetArray("action"); + const auto* const actionValue = arguments.GetArray("action"); if (!actionValue) return; + + m_Action = Action{ *actionValue }; - action = Action(actionValue); - actionIndex = GetActionIndexFromArgument(arguments); - - LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId()); + LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", m_Action.GetType().data(), m_Action.GetValueParameterName().data(), m_Action.GetValueParameterString().data(), m_Action.GetValueParameterDouble(), m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h index aa34940b6..05aa4f9d9 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h @@ -13,14 +13,20 @@ class AMFArrayValue; */ class UpdateActionMessage : public BehaviorMessageBase { public: - UpdateActionMessage(AMFArrayValue* arguments); - int32_t GetActionIndex() const { return actionIndex; }; - ActionContext GetActionContext() const { return actionContext; }; - Action GetAction() const { return action; }; + UpdateActionMessage(const AMFArrayValue& arguments); + + [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } + + [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } + [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } + + [[nodiscard]] const Action& GetAction() const noexcept { return m_Action; } + [[nodiscard]] Action& GetAction() noexcept { return m_Action; } + private: - int32_t actionIndex; - ActionContext actionContext; - Action action; + int32_t m_ActionIndex; + ActionContext m_ActionContext; + Action m_Action; }; #endif //!__UPDATEACTIONMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp index 05dc7cf77..badb8c7af 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp @@ -1,8 +1,9 @@ #include "UpdateStripUiMessage.h" -UpdateStripUiMessage::UpdateStripUiMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { - position = StripUiPosition(arguments); - actionContext = ActionContext(arguments); +UpdateStripUiMessage::UpdateStripUiMessage(const AMFArrayValue& arguments) + : BehaviorMessageBase{ arguments } + , m_Position{ arguments } + , m_ActionContext{ arguments } { - LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId); + LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h index 0e9afe815..42cbe0e25 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h @@ -13,12 +13,17 @@ class AMFArrayValue; */ class UpdateStripUiMessage : public BehaviorMessageBase { public: - UpdateStripUiMessage(AMFArrayValue* arguments); - StripUiPosition GetPosition() const { return position; }; - ActionContext GetActionContext() const { return actionContext; }; + UpdateStripUiMessage(const AMFArrayValue& arguments); + + [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; }; + [[nodiscard]] StripUiPosition& GetPosition() noexcept { return m_Position; }; + + [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }; + [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; }; + private: - StripUiPosition position; - ActionContext actionContext; + StripUiPosition m_Position; + ActionContext m_ActionContext; }; #endif //!__UPDATESTRIPUIMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index 5fee358de..4e13980b4 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -63,7 +63,7 @@ void ControlBehaviors::SendBehaviorListToClient(const ControlBehaviorContext& co // TODO This is also supposed to serialize the state of the behaviors in progress but those aren't implemented yet void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& context) { if (!context) return; - BehaviorMessageBase behaviorMsg(context.arguments); + BehaviorMessageBase behaviorMsg{ context.arguments }; context.modelComponent->VerifyBehaviors(); AMFArrayValue behavior; @@ -71,42 +71,42 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& contex GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorBlocks", behavior); } -void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) { - UpdateActionMessage updateActionMessage(arguments); +void ControlBehaviors::UpdateAction(const AMFArrayValue& arguments) { + UpdateActionMessage updateActionMessage{ arguments }; auto blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType()); if (!blockDefinition) { - LOG("Received undefined block type %s. Ignoring.", updateActionMessage.GetAction().GetType().c_str()); + LOG("Received undefined block type %s. Ignoring.", updateActionMessage.GetAction().GetType().data()); return; } if (updateActionMessage.GetAction().GetValueParameterString().size() > 0) { if (updateActionMessage.GetAction().GetValueParameterString().size() < blockDefinition->GetMinimumValue() || updateActionMessage.GetAction().GetValueParameterString().size() > blockDefinition->GetMaximumValue()) { - LOG("Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str()); + LOG("Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().data()); return; } } else { if (updateActionMessage.GetAction().GetValueParameterDouble() < blockDefinition->GetMinimumValue() || updateActionMessage.GetAction().GetValueParameterDouble() > blockDefinition->GetMaximumValue()) { - LOG("Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str()); + LOG("Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().data()); return; } } } -void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& sysAddr, AMFArrayValue* arguments, std::string command, Entity* modelOwner) { - if (!isInitialized || !modelEntity || !modelOwner || !arguments) return; - auto* modelComponent = modelEntity->GetComponent(); +void ControlBehaviors::ProcessCommand(Entity* modelEntity, const AMFArrayValue& arguments, std::string_view command, Entity* modelOwner) { + if (!isInitialized || !modelEntity || !modelOwner) return; + auto* const modelComponent = modelEntity->GetComponent(); if (!modelComponent) return; - ControlBehaviorContext context(arguments, modelComponent, modelOwner); + ControlBehaviorContext context{ arguments, modelComponent, modelOwner }; if (command == "sendBehaviorListToClient") { SendBehaviorListToClient(context); } else if (command == "modelTypeChanged") { - auto* modelType = arguments->Get("ModelType"); + auto* const modelType = arguments.Get("ModelType"); if (!modelType) return; modelEntity->SetVar(u"modelType", modelType->GetValue()); @@ -131,7 +131,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& } else if (command == "rearrangeStrip") { context.modelComponent->HandleControlBehaviorsMsg(arguments); } else if (command == "add") { - AddMessage msg(context.arguments); + AddMessage msg{ context.arguments }; context.modelComponent->AddBehavior(msg); SendBehaviorListToClient(context); } else if (command == "removeActions") { @@ -144,7 +144,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& } else if (command == "sendBehaviorBlocksToClient") { SendBehaviorBlocksToClient(context); } else if (command == "moveToInventory") { - MoveToInventoryMessage msg(arguments); + MoveToInventoryMessage msg{ arguments }; context.modelComponent->MoveToInventory(msg); auto* characterComponent = modelOwner->GetComponent(); if (!characterComponent) return; @@ -157,7 +157,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& } else if (command == "updateAction") { context.modelComponent->HandleControlBehaviorsMsg(arguments); } else { - LOG("Unknown behavior command (%s)", command.c_str()); + LOG("Unknown behavior command (%s)", command.data()); } } @@ -279,11 +279,11 @@ ControlBehaviors::ControlBehaviors() { isInitialized = true; LOG_DEBUG("Created all base block classes"); for (auto& [name, block] : blockTypes) { - LOG_DEBUG("block name is %s default %s min %f max %f", name.c_str(), block.GetDefaultValue().c_str(), block.GetMinimumValue(), block.GetMaximumValue()); + LOG_DEBUG("block name is %s default %s min %f max %f", name.data(), block.GetDefaultValue().data(), block.GetMinimumValue(), block.GetMaximumValue()); } } -std::optional ControlBehaviors::GetBlockInfo(const BlockName& blockName) { +std::optional ControlBehaviors::GetBlockInfo(const std::string_view blockName) { auto blockDefinition = blockTypes.find(blockName); return blockDefinition != blockTypes.end() ? std::optional(blockDefinition->second) : std::nullopt; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.h b/dGame/dPropertyBehaviors/ControlBehaviors.h index ab7394083..ec5e78fe8 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.h +++ b/dGame/dPropertyBehaviors/ControlBehaviors.h @@ -19,15 +19,17 @@ class SystemAddress; typedef std::string BlockName; //! A block name struct ControlBehaviorContext { - ControlBehaviorContext(AMFArrayValue* args, ModelComponent* modelComponent, Entity* modelOwner) : arguments(args), modelComponent(modelComponent), modelOwner(modelOwner) {}; + ControlBehaviorContext(const AMFArrayValue& args, ModelComponent* modelComponent, Entity* modelOwner) noexcept + : arguments{ args }, modelComponent{ modelComponent }, modelOwner{ modelOwner } { + }; operator bool() const { - return arguments != nullptr && modelComponent != nullptr && modelOwner != nullptr; + return modelComponent != nullptr && modelOwner != nullptr; } - AMFArrayValue* arguments; - Entity* modelOwner; + std::reference_wrapper arguments; ModelComponent* modelComponent; + Entity* modelOwner; }; class ControlBehaviors: public Singleton { @@ -37,12 +39,11 @@ class ControlBehaviors: public Singleton { * @brief Main driver for processing Property Behavior commands * * @param modelEntity The model that sent this command - * @param sysAddr The SystemAddress to respond to * @param arguments The arguments formatted as an AMFArrayValue * @param command The command to perform * @param modelOwner The owner of the model which sent this command */ - void ProcessCommand(Entity* modelEntity, const SystemAddress& sysAddr, AMFArrayValue* arguments, std::string command, Entity* modelOwner); + void ProcessCommand(Entity* modelEntity, const AMFArrayValue& arguments, std::string_view command, Entity* modelOwner); /** * @brief Gets a blocks parameter values by the name @@ -52,13 +53,13 @@ class ControlBehaviors: public Singleton { * * @return A pair of the block parameter name to its typing */ - std::optional GetBlockInfo(const BlockName& blockName); + [[nodiscard]] std::optional GetBlockInfo(const std::string_view blockName); private: void RequestUpdatedID(ControlBehaviorContext& context); void SendBehaviorListToClient(const ControlBehaviorContext& context); void SendBehaviorBlocksToClient(ControlBehaviorContext& context); - void UpdateAction(AMFArrayValue* arguments); - std::map blockTypes{}; + void UpdateAction(const AMFArrayValue& arguments); + std::map> blockTypes{}; // If false, property behaviors will not be able to be edited. bool isInitialized = false; diff --git a/dGame/dPropertyBehaviors/PropertyBehavior.cpp b/dGame/dPropertyBehaviors/PropertyBehavior.cpp index f6f6e4f1f..423751c42 100644 --- a/dGame/dPropertyBehaviors/PropertyBehavior.cpp +++ b/dGame/dPropertyBehaviors/PropertyBehavior.cpp @@ -83,10 +83,6 @@ void PropertyBehavior::HandleMsg(AddMessage& msg) { isLoot = m_BehaviorId != 7965; }; -void PropertyBehavior::SetBehaviorId(int32_t behaviorId) { - m_BehaviorId = behaviorId; -} - void PropertyBehavior::SendBehaviorListToClient(AMFArrayValue& args) const { args.Insert("id", std::to_string(m_BehaviorId)); args.Insert("name", m_Name); @@ -111,19 +107,18 @@ void PropertyBehavior::VerifyLastEditedState() { } void PropertyBehavior::SendBehaviorBlocksToClient(AMFArrayValue& args) const { - auto* stateArray = args.InsertArray("states"); + auto* const stateArray = args.InsertArray("states"); - auto lastState = BehaviorState::HOME_STATE; - for (auto& [stateId, state] : m_States) { + for (const auto& [stateId, state] : m_States) { if (state.IsEmpty()) continue; LOG_DEBUG("Serializing state %i", stateId); - auto* stateArgs = stateArray->PushArray(); + auto* const stateArgs = stateArray->PushArray(); stateArgs->Insert("id", static_cast(stateId)); state.SendBehaviorBlocksToClient(*stateArgs); } - auto* executionState = args.InsertArray("executionState"); + auto* const executionState = args.InsertArray("executionState"); executionState->Insert("stateID", static_cast(m_LastEditedState)); executionState->InsertArray("strips"); diff --git a/dGame/dPropertyBehaviors/PropertyBehavior.h b/dGame/dPropertyBehaviors/PropertyBehavior.h index dc53bbed6..c9cb4b987 100644 --- a/dGame/dPropertyBehaviors/PropertyBehavior.h +++ b/dGame/dPropertyBehaviors/PropertyBehavior.h @@ -13,7 +13,8 @@ class AMFArrayValue; class PropertyBehavior { public: PropertyBehavior(); - template + + template void HandleMsg(Msg& msg); // If the last edited state has no strips, this method will set the last edited state to the first state that has strips. @@ -21,8 +22,9 @@ class PropertyBehavior { void SendBehaviorListToClient(AMFArrayValue& args) const; void SendBehaviorBlocksToClient(AMFArrayValue& args) const; - int32_t GetBehaviorId() const { return m_BehaviorId; } - void SetBehaviorId(int32_t id); + [[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; } + void SetBehaviorId(int32_t id) noexcept { m_BehaviorId = id; } + private: // The states this behavior has. diff --git a/dGame/dPropertyBehaviors/State.cpp b/dGame/dPropertyBehaviors/State.cpp index 59a9aa8bf..0c8a11d95 100644 --- a/dGame/dPropertyBehaviors/State.cpp +++ b/dGame/dPropertyBehaviors/State.cpp @@ -3,7 +3,7 @@ #include "Amf3.h" #include "ControlBehaviorMsgs.h" -template<> +template <> void State::HandleMsg(AddStripMessage& msg) { if (m_Strips.size() <= msg.GetActionContext().GetStripId()) { m_Strips.resize(msg.GetActionContext().GetStripId() + 1); @@ -11,7 +11,7 @@ void State::HandleMsg(AddStripMessage& msg) { m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); }; -template<> +template <> void State::HandleMsg(AddActionMessage& msg) { if (m_Strips.size() <= msg.GetActionContext().GetStripId()) { return; @@ -20,7 +20,7 @@ void State::HandleMsg(AddActionMessage& msg) { m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); }; -template<> +template <> void State::HandleMsg(UpdateStripUiMessage& msg) { if (m_Strips.size() <= msg.GetActionContext().GetStripId()) { return; @@ -29,7 +29,7 @@ void State::HandleMsg(UpdateStripUiMessage& msg) { m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); }; -template<> +template <> void State::HandleMsg(RemoveActionsMessage& msg) { if (m_Strips.size() <= msg.GetActionContext().GetStripId()) { return; @@ -38,7 +38,7 @@ void State::HandleMsg(RemoveActionsMessage& msg) { m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); }; -template<> +template <> void State::HandleMsg(RearrangeStripMessage& msg) { if (m_Strips.size() <= msg.GetActionContext().GetStripId()) { return; @@ -47,7 +47,7 @@ void State::HandleMsg(RearrangeStripMessage& msg) { m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); }; -template<> +template <> void State::HandleMsg(UpdateActionMessage& msg) { if (m_Strips.size() <= msg.GetActionContext().GetStripId()) { return; @@ -56,7 +56,7 @@ void State::HandleMsg(UpdateActionMessage& msg) { m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); }; -template<> +template <> void State::HandleMsg(RemoveStripMessage& msg) { if (m_Strips.size() <= msg.GetActionContext().GetStripId()) { return; @@ -65,7 +65,7 @@ void State::HandleMsg(RemoveStripMessage& msg) { m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); }; -template<> +template <> void State::HandleMsg(SplitStripMessage& msg) { if (msg.GetTransferredActions().empty()) { if (m_Strips.size() <= msg.GetSourceActionContext().GetStripId()) { @@ -82,7 +82,7 @@ void State::HandleMsg(SplitStripMessage& msg) { } }; -template<> +template <> void State::HandleMsg(MergeStripsMessage& msg) { if (msg.GetMigratedActions().empty()) { if (m_Strips.size() <= msg.GetSourceActionContext().GetStripId()) { @@ -99,7 +99,7 @@ void State::HandleMsg(MergeStripsMessage& msg) { } }; -template<> +template <> void State::HandleMsg(MigrateActionsMessage& msg) { if (msg.GetMigratedActions().empty()) { if (m_Strips.size() <= msg.GetSourceActionContext().GetStripId()) { @@ -117,19 +117,19 @@ void State::HandleMsg(MigrateActionsMessage& msg) { }; bool State::IsEmpty() const { - for (auto& strip : m_Strips) { + for (const auto& strip : m_Strips) { if (!strip.IsEmpty()) return false; } return true; } void State::SendBehaviorBlocksToClient(AMFArrayValue& args) const { - auto* strips = args.InsertArray("strips"); - for (int32_t stripId = 0; stripId < m_Strips.size(); stripId++) { - auto& strip = m_Strips.at(stripId); + auto* const strips = args.InsertArray("strips"); + for (size_t stripId = 0; stripId < m_Strips.size(); ++stripId) { + const auto& strip = m_Strips.at(stripId); if (strip.IsEmpty()) continue; - auto* stripArgs = strips->PushArray(); + auto* const stripArgs = strips->PushArray(); stripArgs->Insert("id", static_cast(stripId)); strip.SendBehaviorBlocksToClient(*stripArgs); diff --git a/dGame/dPropertyBehaviors/State.h b/dGame/dPropertyBehaviors/State.h index a6a6d23be..f04257635 100644 --- a/dGame/dPropertyBehaviors/State.h +++ b/dGame/dPropertyBehaviors/State.h @@ -7,11 +7,12 @@ class AMFArrayValue; class State { public: - template + template void HandleMsg(Msg& msg); void SendBehaviorBlocksToClient(AMFArrayValue& args) const; bool IsEmpty() const; + private: std::vector m_Strips; }; diff --git a/dGame/dPropertyBehaviors/Strip.cpp b/dGame/dPropertyBehaviors/Strip.cpp index 7d27cacd4..0f459e469 100644 --- a/dGame/dPropertyBehaviors/Strip.cpp +++ b/dGame/dPropertyBehaviors/Strip.cpp @@ -3,48 +3,47 @@ #include "Amf3.h" #include "ControlBehaviorMsgs.h" -template<> +template <> void Strip::HandleMsg(AddStripMessage& msg) { m_Actions = msg.GetActionsToAdd(); m_Position = msg.GetPosition(); }; -template<> +template <> void Strip::HandleMsg(AddActionMessage& msg) { if (msg.GetActionIndex() == -1) return; - m_Actions.insert(m_Actions.begin() + msg.GetActionIndex(), msg.GetAction()); }; -template<> +template <> void Strip::HandleMsg(UpdateStripUiMessage& msg) { m_Position = msg.GetPosition(); }; -template<> +template <> void Strip::HandleMsg(RemoveStripMessage& msg) { m_Actions.clear(); }; -template<> +template <> void Strip::HandleMsg(RemoveActionsMessage& msg) { if (msg.GetActionIndex() >= m_Actions.size()) return; m_Actions.erase(m_Actions.begin() + msg.GetActionIndex(), m_Actions.end()); }; -template<> +template <> void Strip::HandleMsg(UpdateActionMessage& msg) { if (msg.GetActionIndex() >= m_Actions.size()) return; m_Actions.at(msg.GetActionIndex()) = msg.GetAction(); }; -template<> +template <> void Strip::HandleMsg(RearrangeStripMessage& msg) { if (msg.GetDstActionIndex() >= m_Actions.size() || msg.GetSrcActionIndex() >= m_Actions.size() || msg.GetSrcActionIndex() <= msg.GetDstActionIndex()) return; std::rotate(m_Actions.begin() + msg.GetDstActionIndex(), m_Actions.begin() + msg.GetSrcActionIndex(), m_Actions.end()); }; -template<> +template <> void Strip::HandleMsg(SplitStripMessage& msg) { if (msg.GetTransferredActions().empty() && !m_Actions.empty()) { auto startToMove = m_Actions.begin() + msg.GetSrcActionIndex(); @@ -56,7 +55,7 @@ void Strip::HandleMsg(SplitStripMessage& msg) { } }; -template<> +template <> void Strip::HandleMsg(MergeStripsMessage& msg) { if (msg.GetMigratedActions().empty() && !m_Actions.empty()) { msg.SetMigratedActions(m_Actions.begin(), m_Actions.end()); @@ -66,7 +65,7 @@ void Strip::HandleMsg(MergeStripsMessage& msg) { } }; -template<> +template <> void Strip::HandleMsg(MigrateActionsMessage& msg) { if (msg.GetMigratedActions().empty() && !m_Actions.empty()) { auto startToMove = m_Actions.begin() + msg.GetSrcActionIndex(); @@ -80,8 +79,8 @@ void Strip::HandleMsg(MigrateActionsMessage& msg) { void Strip::SendBehaviorBlocksToClient(AMFArrayValue& args) const { m_Position.SendBehaviorBlocksToClient(args); - auto* actions = args.InsertArray("actions"); - for (auto& action : m_Actions) { + auto* const actions = args.InsertArray("actions"); + for (const auto& action : m_Actions) { action.SendBehaviorBlocksToClient(*actions); } }; diff --git a/dGame/dPropertyBehaviors/Strip.h b/dGame/dPropertyBehaviors/Strip.h index f3e10964e..107fee112 100644 --- a/dGame/dPropertyBehaviors/Strip.h +++ b/dGame/dPropertyBehaviors/Strip.h @@ -10,11 +10,12 @@ class AMFArrayValue; class Strip { public: - template + template void HandleMsg(Msg& msg); void SendBehaviorBlocksToClient(AMFArrayValue& args) const; - bool IsEmpty() const { return m_Actions.empty(); } + bool IsEmpty() const noexcept { return m_Actions.empty(); } + private: std::vector m_Actions; StripUiPosition m_Position; diff --git a/tests/dCommonTests/AMFDeserializeTests.cpp b/tests/dCommonTests/AMFDeserializeTests.cpp index 58c465841..cc3ea551d 100644 --- a/tests/dCommonTests/AMFDeserializeTests.cpp +++ b/tests/dCommonTests/AMFDeserializeTests.cpp @@ -11,10 +11,9 @@ /** * Helper method that all tests use to get their respective AMF. */ -AMFBaseValue* ReadFromBitStream(RakNet::BitStream* bitStream) { +std::unique_ptr ReadFromBitStream(RakNet::BitStream* bitStream) { AMFDeserialize deserializer; - AMFBaseValue* returnValue(deserializer.Read(bitStream)); - return returnValue; + return std::unique_ptr{ static_cast(deserializer.Read(bitStream).release()) }; } /** @@ -23,7 +22,7 @@ AMFBaseValue* ReadFromBitStream(RakNet::BitStream* bitStream) { TEST(dCommonTests, AMFDeserializeAMFUndefinedTest) { CBITSTREAM; bitStream.Write(0x00); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Undefined); } @@ -34,7 +33,7 @@ TEST(dCommonTests, AMFDeserializeAMFUndefinedTest) { TEST(dCommonTests, AMFDeserializeAMFNullTest) { CBITSTREAM; bitStream.Write(0x01); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Null); } @@ -44,7 +43,7 @@ TEST(dCommonTests, AMFDeserializeAMFNullTest) { TEST(dCommonTests, AMFDeserializeAMFFalseTest) { CBITSTREAM; bitStream.Write(0x02); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::False); } @@ -54,7 +53,7 @@ TEST(dCommonTests, AMFDeserializeAMFFalseTest) { TEST(dCommonTests, AMFDeserializeAMFTrueTest) { CBITSTREAM; bitStream.Write(0x03); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::True); } @@ -67,7 +66,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) { bitStream.Write(0x04); // 127 == 01111111 bitStream.Write(127); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Integer); // Check that the max value of a byte can be read correctly ASSERT_EQ(static_cast(res.get())->GetValue(), 127); @@ -76,7 +75,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) { { bitStream.Write(0x04); bitStream.Write(UINT32_MAX); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Integer); // Check that we can read the maximum value correctly ASSERT_EQ(static_cast(res.get())->GetValue(), 536870911); @@ -90,7 +89,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) { bitStream.Write(255); // 127 == 01111111 bitStream.Write(127); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Integer); // Check that short max can be read correctly ASSERT_EQ(static_cast(res.get())->GetValue(), UINT16_MAX); @@ -102,7 +101,7 @@ TEST(dCommonTests, AMFDeserializeAMFIntegerTest) { bitStream.Write(255); // 127 == 01111111 bitStream.Write(127); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Integer); // Check that 2 byte max can be read correctly ASSERT_EQ(static_cast(res.get())->GetValue(), 16383); @@ -116,7 +115,7 @@ TEST(dCommonTests, AMFDeserializeAMFDoubleTest) { CBITSTREAM; bitStream.Write(0x05); bitStream.Write(25346.4f); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Double); ASSERT_EQ(static_cast(res.get())->GetValue(), 25346.4f); } @@ -130,7 +129,7 @@ TEST(dCommonTests, AMFDeserializeAMFStringTest) { bitStream.Write(0x0F); std::string toWrite = "stateID"; for (auto e : toWrite) bitStream.Write(e); - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::String); ASSERT_EQ(static_cast(res.get())->GetValue(), "stateID"); } @@ -145,7 +144,7 @@ TEST(dCommonTests, AMFDeserializeAMFArrayTest) { bitStream.Write(0x01); bitStream.Write(0x01); { - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Array); ASSERT_EQ(static_cast(res.get())->GetAssociative().size(), 0); ASSERT_EQ(static_cast(res.get())->GetDense().size(), 0); @@ -164,7 +163,7 @@ TEST(dCommonTests, AMFDeserializeAMFArrayTest) { bitStream.Write(0x0B); for (auto e : "10447") if (e != '\0') bitStream.Write(e); { - std::unique_ptr res(ReadFromBitStream(&bitStream)); + std::unique_ptr res{ ReadFromBitStream(&bitStream) }; ASSERT_EQ(res->GetValueType(), eAmf::Array); ASSERT_EQ(static_cast(res.get())->GetAssociative().size(), 1); ASSERT_EQ(static_cast(res.get())->GetDense().size(), 1); @@ -238,107 +237,107 @@ TEST(dCommonTests, AMFDeserializeLivePacketTest) { testFileStream.close(); - std::unique_ptr resultFromFn(ReadFromBitStream(&testBitStream)); - auto result = static_cast(resultFromFn.get()); + std::unique_ptr resultFromFn{ ReadFromBitStream(&testBitStream) }; + auto* result = static_cast(resultFromFn.get()); // Test the outermost array ASSERT_EQ(result->Get("BehaviorID")->GetValue(), "10447"); ASSERT_EQ(result->Get("objectID")->GetValue(), "288300744895913279"); // Test the execution state array - auto executionState = result->GetArray("executionState"); + auto* executionState = result->GetArray("executionState"); ASSERT_NE(executionState, nullptr); - auto strips = executionState->GetArray("strips")->GetDense(); + auto& strips = executionState->GetArray("strips")->GetDense(); ASSERT_EQ(strips.size(), 1); - auto stripsPosition0 = dynamic_cast(strips[0]); + auto* stripsPosition0 = dynamic_cast(strips[0].get()); - auto actionIndex = stripsPosition0->Get("actionIndex"); + auto* actionIndex = stripsPosition0->Get("actionIndex"); ASSERT_EQ(actionIndex->GetValue(), 0.0f); - auto stripIdExecution = stripsPosition0->Get("id"); + auto* stripIdExecution = stripsPosition0->Get("id"); ASSERT_EQ(stripIdExecution->GetValue(), 0.0f); - auto stateIdExecution = executionState->Get("stateID"); + auto* stateIdExecution = executionState->Get("stateID"); ASSERT_EQ(stateIdExecution->GetValue(), 0.0f); - auto states = result->GetArray("states")->GetDense(); + auto& states = result->GetArray("states")->GetDense(); ASSERT_EQ(states.size(), 1); - auto firstState = dynamic_cast(states[0]); + auto* firstState = dynamic_cast(states[0].get()); - auto stateID = firstState->Get("id"); + auto* stateID = firstState->Get("id"); ASSERT_EQ(stateID->GetValue(), 0.0f); - auto stripsInState = firstState->GetArray("strips")->GetDense(); + auto& stripsInState = firstState->GetArray("strips")->GetDense(); ASSERT_EQ(stripsInState.size(), 1); - auto firstStrip = dynamic_cast(stripsInState[0]); + auto* firstStrip = dynamic_cast(stripsInState[0].get()); - auto actionsInFirstStrip = firstStrip->GetArray("actions")->GetDense(); + auto& actionsInFirstStrip = firstStrip->GetArray("actions")->GetDense(); ASSERT_EQ(actionsInFirstStrip.size(), 3); - auto actionID = firstStrip->Get("id"); + auto* actionID = firstStrip->Get("id"); ASSERT_EQ(actionID->GetValue(), 0.0f); - auto uiArray = firstStrip->GetArray("ui"); + auto* uiArray = firstStrip->GetArray("ui"); - auto xPos = uiArray->Get("x"); - auto yPos = uiArray->Get("y"); + auto* xPos = uiArray->Get("x"); + auto* yPos = uiArray->Get("y"); ASSERT_EQ(xPos->GetValue(), 103.0f); ASSERT_EQ(yPos->GetValue(), 82.0f); - auto stripId = firstStrip->Get("id"); + auto* stripId = firstStrip->Get("id"); ASSERT_EQ(stripId->GetValue(), 0.0f); - auto firstAction = dynamic_cast(actionsInFirstStrip[0]); + auto* firstAction = dynamic_cast(actionsInFirstStrip[0].get()); - auto firstType = firstAction->Get("Type"); + auto* firstType = firstAction->Get("Type"); ASSERT_EQ(firstType->GetValue(), "OnInteract"); - auto firstCallback = firstAction->Get("__callbackID__"); + auto* firstCallback = firstAction->Get("__callbackID__"); ASSERT_EQ(firstCallback->GetValue(), ""); - auto secondAction = dynamic_cast(actionsInFirstStrip[1]); + auto* secondAction = dynamic_cast(actionsInFirstStrip[1].get()); - auto secondType = secondAction->Get("Type"); + auto* secondType = secondAction->Get("Type"); ASSERT_EQ(secondType->GetValue(), "FlyUp"); - auto secondCallback = secondAction->Get("__callbackID__"); + auto* secondCallback = secondAction->Get("__callbackID__"); ASSERT_EQ(secondCallback->GetValue(), ""); - auto secondDistance = secondAction->Get("Distance"); + auto* secondDistance = secondAction->Get("Distance"); ASSERT_EQ(secondDistance->GetValue(), 25.0f); - auto thirdAction = dynamic_cast(actionsInFirstStrip[2]); + auto* thirdAction = dynamic_cast(actionsInFirstStrip[2].get()); - auto thirdType = thirdAction->Get("Type"); + auto* thirdType = thirdAction->Get("Type"); ASSERT_EQ(thirdType->GetValue(), "FlyDown"); - auto thirdCallback = thirdAction->Get("__callbackID__"); + auto* thirdCallback = thirdAction->Get("__callbackID__"); ASSERT_EQ(thirdCallback->GetValue(), ""); - auto thirdDistance = thirdAction->Get("Distance"); + auto* thirdDistance = thirdAction->Get("Distance"); ASSERT_EQ(thirdDistance->GetValue(), 25.0f); } diff --git a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp index 047f56d65..d4bdf420e 100644 --- a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp @@ -38,11 +38,11 @@ class GameMessageTests: public GameDependenciesTest { } return readFile; } - AMFArrayValue* ReadArrayFromBitStream(RakNet::BitStream* inStream) { + std::unique_ptr ReadArrayFromBitStream(RakNet::BitStream* inStream) { AMFDeserialize des; - AMFBaseValue* readArray = des.Read(inStream); + AMFBaseValue* readArray = des.Read(inStream).release(); EXPECT_EQ(readArray->GetValueType(), eAmf::Array); - return static_cast(readArray); + return std::unique_ptr{ static_cast(readArray) }; } }; @@ -88,12 +88,13 @@ TEST_F(GameMessageTests, SendBlueprintLoadItemResponse) { TEST_F(GameMessageTests, ControlBehaviorAddStrip) { auto data = ReadFromFile("addStrip"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - AddStripMessage addStrip(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + AddStripMessage addStrip(*msg.get()); ASSERT_FLOAT_EQ(addStrip.GetPosition().GetX(), 50.65); ASSERT_FLOAT_EQ(addStrip.GetPosition().GetY(), 178.05); ASSERT_EQ(addStrip.GetActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(addStrip.GetActionContext().GetStateId()), 0); - ASSERT_EQ(addStrip.GetBehaviorId(), -1); + ASSERT_EQ(addStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetType(), "DropImagination"); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterName(), "Amount"); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterString(), ""); @@ -103,29 +104,32 @@ TEST_F(GameMessageTests, ControlBehaviorAddStrip) { TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) { auto data = ReadFromFile("removeStrip"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - RemoveStripMessage removeStrip(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + RemoveStripMessage removeStrip(*msg.get()); ASSERT_EQ(static_cast(removeStrip.GetActionContext().GetStripId()), 1); ASSERT_EQ(static_cast(removeStrip.GetActionContext().GetStateId()), 0); - ASSERT_EQ(removeStrip.GetBehaviorId(), -1); + ASSERT_EQ(removeStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } TEST_F(GameMessageTests, ControlBehaviorMergeStrips) { auto data = ReadFromFile("mergeStrips"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - MergeStripsMessage mergeStrips(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + MergeStripsMessage mergeStrips(*msg.get()); ASSERT_EQ(mergeStrips.GetSourceActionContext().GetStripId(), 2); ASSERT_EQ(mergeStrips.GetDestinationActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(mergeStrips.GetSourceActionContext().GetStateId()), 0); ASSERT_EQ(static_cast(mergeStrips.GetDestinationActionContext().GetStateId()), 0); ASSERT_EQ(mergeStrips.GetDstActionIndex(), 0); - ASSERT_EQ(mergeStrips.GetBehaviorId(), -1); + ASSERT_EQ(mergeStrips.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } TEST_F(GameMessageTests, ControlBehaviorSplitStrip) { auto data = ReadFromFile("splitStrip"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - SplitStripMessage splitStrip(ReadArrayFromBitStream(&inStream)); - ASSERT_EQ(splitStrip.GetBehaviorId(), -1); + auto msg = ReadArrayFromBitStream(&inStream); + SplitStripMessage splitStrip(*msg.get()); + ASSERT_EQ(splitStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetX(), 275.65); ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetY(), 28.7); @@ -139,18 +143,20 @@ TEST_F(GameMessageTests, ControlBehaviorSplitStrip) { TEST_F(GameMessageTests, ControlBehaviorUpdateStripUI) { auto data = ReadFromFile("updateStripUI"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - UpdateStripUiMessage updateStripUi(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + UpdateStripUiMessage updateStripUi(*msg.get()); ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetX(), 116.65); ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetY(), 35.35); ASSERT_EQ(updateStripUi.GetActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(updateStripUi.GetActionContext().GetStateId()), 0); - ASSERT_EQ(updateStripUi.GetBehaviorId(), -1); + ASSERT_EQ(updateStripUi.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } TEST_F(GameMessageTests, ControlBehaviorAddAction) { auto data = ReadFromFile("addAction"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - AddActionMessage addAction(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + AddActionMessage addAction{ *msg.get() }; ASSERT_EQ(addAction.GetActionIndex(), 3); ASSERT_EQ(addAction.GetActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(addAction.GetActionContext().GetStateId()), 0); @@ -158,37 +164,40 @@ TEST_F(GameMessageTests, ControlBehaviorAddAction) { ASSERT_EQ(addAction.GetAction().GetValueParameterName(), ""); ASSERT_EQ(addAction.GetAction().GetValueParameterString(), ""); ASSERT_EQ(addAction.GetAction().GetValueParameterDouble(), 0.0); - ASSERT_EQ(addAction.GetBehaviorId(), -1); + ASSERT_EQ(addAction.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } TEST_F(GameMessageTests, ControlBehaviorMigrateActions) { auto data = ReadFromFile("migrateActions"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - MigrateActionsMessage migrateActions(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + MigrateActionsMessage migrateActions(*msg.get()); ASSERT_EQ(migrateActions.GetSrcActionIndex(), 1); ASSERT_EQ(migrateActions.GetDstActionIndex(), 2); ASSERT_EQ(migrateActions.GetSourceActionContext().GetStripId(), 1); ASSERT_EQ(migrateActions.GetDestinationActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(migrateActions.GetSourceActionContext().GetStateId()), 0); ASSERT_EQ(static_cast(migrateActions.GetDestinationActionContext().GetStateId()), 0); - ASSERT_EQ(migrateActions.GetBehaviorId(), -1); + ASSERT_EQ(migrateActions.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) { auto data = ReadFromFile("rearrangeStrip"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - RearrangeStripMessage rearrangeStrip(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + RearrangeStripMessage rearrangeStrip(*msg.get()); ASSERT_EQ(rearrangeStrip.GetSrcActionIndex(), 2); ASSERT_EQ(rearrangeStrip.GetDstActionIndex(), 1); ASSERT_EQ(rearrangeStrip.GetActionContext().GetStripId(), 0); - ASSERT_EQ(rearrangeStrip.GetBehaviorId(), -1); + ASSERT_EQ(rearrangeStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); ASSERT_EQ(static_cast(rearrangeStrip.GetActionContext().GetStateId()), 0); } TEST_F(GameMessageTests, ControlBehaviorAdd) { auto data = ReadFromFile("add"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - AddMessage add(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + AddMessage add(*msg.get()); ASSERT_EQ(add.GetBehaviorId(), 10446); ASSERT_EQ(add.GetBehaviorIndex(), 0); } @@ -196,7 +205,8 @@ TEST_F(GameMessageTests, ControlBehaviorAdd) { TEST_F(GameMessageTests, ControlBehaviorRemoveActions) { auto data = ReadFromFile("removeActions"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - RemoveActionsMessage removeActions(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + RemoveActionsMessage removeActions(*msg.get()); ASSERT_EQ(removeActions.GetBehaviorId(), -1); ASSERT_EQ(removeActions.GetActionIndex(), 1); ASSERT_EQ(removeActions.GetActionContext().GetStripId(), 0); @@ -206,20 +216,22 @@ TEST_F(GameMessageTests, ControlBehaviorRemoveActions) { TEST_F(GameMessageTests, ControlBehaviorRename) { auto data = ReadFromFile("rename"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - RenameMessage rename(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + RenameMessage rename(*msg.get()); ASSERT_EQ(rename.GetName(), "test"); - ASSERT_EQ(rename.GetBehaviorId(), -1); + ASSERT_EQ(rename.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } TEST_F(GameMessageTests, ControlBehaviorUpdateAction) { auto data = ReadFromFile("updateAction"); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); - UpdateActionMessage updateAction(ReadArrayFromBitStream(&inStream)); + auto msg = ReadArrayFromBitStream(&inStream); + UpdateActionMessage updateAction(*msg.get()); ASSERT_EQ(updateAction.GetAction().GetType(), "FlyDown"); ASSERT_EQ(updateAction.GetAction().GetValueParameterName(), "Distance"); ASSERT_EQ(updateAction.GetAction().GetValueParameterString(), ""); ASSERT_EQ(updateAction.GetAction().GetValueParameterDouble(), 50.0); - ASSERT_EQ(updateAction.GetBehaviorId(), -1); + ASSERT_EQ(updateAction.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); ASSERT_EQ(updateAction.GetActionIndex(), 1); ASSERT_EQ(updateAction.GetActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(updateAction.GetActionContext().GetStateId()), 0); From acd601f5271186cec74770716319111eb8723b49 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 01:49:05 -0600 Subject: [PATCH 02/22] fix m_BehaviorID initialization --- .../ControlBehaviorMessages/BehaviorMessageBase.cpp | 4 ++++ .../ControlBehaviorMessages/BehaviorMessageBase.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp index fdacbdad8..32d1dc2b5 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -4,6 +4,10 @@ #include "BehaviorStates.h" #include "dCommonVars.h" +BehaviorMessageBase::BehaviorMessageBase(const AMFArrayValue& arguments) { + m_BehaviorId = GetBehaviorIdFromArgument(arguments); +} + int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) { static constexpr std::string_view key = "BehaviorID"; const auto* const behaviorIDValue = arguments.Get(key); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h index cc8c293dd..ec21a6791 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -16,7 +16,7 @@ enum class BehaviorState : uint32_t; class BehaviorMessageBase { public: static constexpr int32_t DefaultBehaviorId{ -1 }; - BehaviorMessageBase(const AMFArrayValue& arguments) : m_BehaviorId{ GetBehaviorIdFromArgument(arguments) } {} + BehaviorMessageBase(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; } [[nodiscard]] bool IsDefaultBehaviorId() const noexcept { return m_BehaviorId == DefaultBehaviorId; } From c75cef290a3c74de6082b40885f6e5c51105d991 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 01:58:00 -0600 Subject: [PATCH 03/22] Fix BlockDefinition member naming --- dGame/dPropertyBehaviors/BlockDefinition.cpp | 6 +++--- dGame/dPropertyBehaviors/BlockDefinition.h | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dGame/dPropertyBehaviors/BlockDefinition.cpp b/dGame/dPropertyBehaviors/BlockDefinition.cpp index 5b38f986b..173784232 100644 --- a/dGame/dPropertyBehaviors/BlockDefinition.cpp +++ b/dGame/dPropertyBehaviors/BlockDefinition.cpp @@ -3,7 +3,7 @@ BlockDefinition BlockDefinition::blockDefinitionDefault{}; BlockDefinition::BlockDefinition(const std::string_view defaultValue, const float minimumValue, const float maximumValue) - : defaultValue{ defaultValue } - , minimumValue{ minimumValue } - , maximumValue{ maximumValue } { + : m_DefaultValue{ defaultValue } + , m_MinimumValue{ minimumValue } + , m_MaximumValue{ maximumValue } { } diff --git a/dGame/dPropertyBehaviors/BlockDefinition.h b/dGame/dPropertyBehaviors/BlockDefinition.h index dbea95cd5..31041d651 100644 --- a/dGame/dPropertyBehaviors/BlockDefinition.h +++ b/dGame/dPropertyBehaviors/BlockDefinition.h @@ -10,17 +10,17 @@ class BlockDefinition { BlockDefinition(const std::string_view defaultValue = "", const float minimumValue = 0.0f, const float maximumValue = 0.0f); static BlockDefinition blockDefinitionDefault; - [[nodiscard]] std::string_view GetDefaultValue() const { return defaultValue; }; - [[nodiscard]] float GetMinimumValue() const noexcept { return minimumValue; }; - [[nodiscard]] float GetMaximumValue() const noexcept { return maximumValue; }; - void SetDefaultValue(const std::string_view value) { defaultValue = std::string{ value }; }; - void SetMinimumValue(const float value) noexcept { minimumValue = value; }; - void SetMaximumValue(const float value) noexcept { maximumValue = value; }; + [[nodiscard]] std::string_view GetDefaultValue() const { return m_DefaultValue; }; + [[nodiscard]] float GetMinimumValue() const noexcept { return m_MinimumValue; }; + [[nodiscard]] float GetMaximumValue() const noexcept { return m_MaximumValue; }; + void SetDefaultValue(const std::string_view value) { m_DefaultValue = std::string{ value }; }; + void SetMinimumValue(const float value) noexcept { m_MinimumValue = value; }; + void SetMaximumValue(const float value) noexcept { m_MaximumValue = value; }; private: - std::string defaultValue; - float minimumValue; - float maximumValue; + std::string m_DefaultValue; + float m_MinimumValue; + float m_MaximumValue; }; #endif //!__BLOCKDEFINITION__H__ From 07b51350e1cb759f4555342ab7e12bcd3545f972 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 01:58:32 -0600 Subject: [PATCH 04/22] remove redundant reset()s --- dCommon/Amf3.h | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 6348dffa7..57a6889c9 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -155,10 +155,7 @@ class AMFArrayValue : public AMFBaseValue { if (element == m_Associative.end()) { auto newVal = std::make_unique>(value); val = newVal.get(); - m_Associative.emplace( - std::piecewise_construct, - std::forward_as_tuple(key), - std::forward_as_tuple(std::move(newVal))); + m_Associative.emplace(key, std::move(newVal)); } else { val = dynamic_cast*>(element->second.get()); found = false; @@ -174,10 +171,7 @@ class AMFArrayValue : public AMFBaseValue { if (element == m_Associative.end()) { auto newVal = std::make_unique(); val = newVal.get(); - m_Associative.emplace( - std::piecewise_construct, - std::forward_as_tuple(key), - std::forward_as_tuple(std::move(newVal))); + m_Associative.emplace(key, std::move(newVal)); } else { val = dynamic_cast(element->second.get()); found = false; @@ -229,12 +223,9 @@ class AMFArrayValue : public AMFBaseValue { void Insert(const std::string_view key, std::unique_ptr value) { auto element = m_Associative.find(key); if (element != m_Associative.end() && element->second) { - element->second.swap(value); // Swapped value should be deleted as this goes out of scope + element->second = std::move(value); } else { - m_Associative.emplace( - std::piecewise_construct, - std::forward_as_tuple(key), - std::forward_as_tuple(std::move(value))); + m_Associative.emplace(key, std::move(value)); } } @@ -248,10 +239,7 @@ class AMFArrayValue : public AMFBaseValue { * @param value The value to insert */ void Insert(const size_t index, std::unique_ptr value) { - if (index < m_Dense.size()) { - AMFDense::iterator itr = m_Dense.begin() + index; - if (*itr) m_Dense.at(index).reset(); - } else { + if (index >= m_Dense.size()) { m_Dense.resize(index + 1); } m_Dense.at(index) = std::move(value); @@ -282,8 +270,7 @@ class AMFArrayValue : public AMFBaseValue { void Remove(const std::string& key, const bool deleteValue = true) { AMFAssociative::iterator it = m_Associative.find(key); if (it != m_Associative.end()) { - if (deleteValue) it->second.reset(); - m_Associative.erase(it); + if (deleteValue) m_Associative.erase(it); } } @@ -292,9 +279,8 @@ class AMFArrayValue : public AMFBaseValue { */ void Remove(const size_t index) { if (!m_Dense.empty() && index < m_Dense.size()) { - auto itr = m_Dense.begin() + index; - if (*itr) itr->reset(); - m_Dense.erase(itr); + const auto itr = m_Dense.begin() + index; + if (*itr) m_Dense.erase(itr); } } From 7e036a356cd7c6e4ef989aefa517ad508881f22d Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 02:09:54 -0600 Subject: [PATCH 05/22] Replace UB forward template declarations with header include --- dCommon/AMFDeserialize.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/dCommon/AMFDeserialize.h b/dCommon/AMFDeserialize.h index 798c7eb16..821bb2ec2 100644 --- a/dCommon/AMFDeserialize.h +++ b/dCommon/AMFDeserialize.h @@ -1,22 +1,12 @@ #pragma once +#include "Amf3.h" #include "BitStream.h" #include #include #include -// Forward declarations -template -class AMFValue; - -class AMFArrayValue; -class AMFBaseValue; - -using AMFDoubleValue = class AMFValue; -using AMFStringValue = class AMFValue; -using AMFIntValue = class AMFValue; - // Class definition class AMFDeserialize { public: From b8498c34c21246d2fbd7f2654061f2802cce2241 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 02:42:54 -0600 Subject: [PATCH 06/22] remove unneeded comment --- dCommon/AMFDeserialize.h | 1 - 1 file changed, 1 deletion(-) diff --git a/dCommon/AMFDeserialize.h b/dCommon/AMFDeserialize.h index 821bb2ec2..5971a9616 100644 --- a/dCommon/AMFDeserialize.h +++ b/dCommon/AMFDeserialize.h @@ -7,7 +7,6 @@ #include #include -// Class definition class AMFDeserialize { public: /** From 1bb82b864008c8805ec8a738762b8807a9987e92 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 03:20:26 -0600 Subject: [PATCH 07/22] remove non-const ref getters --- dCommon/Amf3.h | 2 +- .../ControlBehaviorMessages/AddActionMessage.h | 2 -- .../ControlBehaviorMessages/AddStripMessage.h | 3 --- .../ControlBehaviorMessages/MergeStripsMessage.h | 3 --- .../ControlBehaviorMessages/MigrateActionsMessage.h | 3 --- .../ControlBehaviorMessages/RearrangeStripMessage.h | 1 - .../ControlBehaviorMessages/RemoveActionsMessage.h | 1 - .../ControlBehaviorMessages/RemoveStripMessage.h | 1 - .../ControlBehaviorMessages/SplitStripMessage.h | 4 ---- .../ControlBehaviorMessages/UpdateActionMessage.h | 2 -- .../ControlBehaviorMessages/UpdateStripUiMessage.h | 2 -- 11 files changed, 1 insertion(+), 23 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 57a6889c9..518723181 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -280,7 +280,7 @@ class AMFArrayValue : public AMFBaseValue { void Remove(const size_t index) { if (!m_Dense.empty() && index < m_Dense.size()) { const auto itr = m_Dense.begin() + index; - if (*itr) m_Dense.erase(itr); + m_Dense.erase(itr); } } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h index e2b07f6bb..7f94820d3 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h @@ -18,10 +18,8 @@ class AddActionMessage : public BehaviorMessageBase { [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }; [[nodiscard]] const Action& GetAction() const noexcept { return m_Action; }; - [[nodiscard]] Action& GetAction() noexcept { return m_Action; }; [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }; - [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; }; private: int32_t m_ActionIndex{ -1 }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h index ddc24642d..a53610347 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h @@ -21,13 +21,10 @@ class AddStripMessage : public BehaviorMessageBase { AddStripMessage(const AMFArrayValue& arguments); [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; } - [[nodiscard]] StripUiPosition& GetPosition() noexcept { return m_Position; } [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } - [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } [[nodiscard]] const std::vector& GetActionsToAdd() const noexcept { return m_ActionsToAdd; } - [[nodiscard]] std::vector& GetActionsToAdd() noexcept { return m_ActionsToAdd; } private: StripUiPosition m_Position; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h index 6b2987bc9..d778d6328 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h @@ -18,13 +18,10 @@ class MergeStripsMessage : public BehaviorMessageBase { [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; } - [[nodiscard]] ActionContext& GetSourceActionContext() noexcept { return m_SourceActionContext; } [[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; } - [[nodiscard]] ActionContext& GetDestinationActionContext() noexcept { return m_DestinationActionContext; } [[nodiscard]] const std::vector& GetMigratedActions() const noexcept { return m_MigratedActions; } - [[nodiscard]] std::vector& GetMigratedActions() noexcept { return m_MigratedActions; } void SetMigratedActions(std::vector::const_iterator start, std::vector::const_iterator end) { m_MigratedActions.assign(start, end); }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h index b0d845fa6..9813fbf42 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h @@ -20,13 +20,10 @@ class MigrateActionsMessage : public BehaviorMessageBase { [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; } - [[nodiscard]] ActionContext& GetSourceActionContext() noexcept { return m_SourceActionContext; } [[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; } - [[nodiscard]] ActionContext& GetDestinationActionContext() noexcept { return m_DestinationActionContext; } [[nodiscard]] const std::vector& GetMigratedActions() const noexcept { return m_MigratedActions; } - [[nodiscard]] std::vector& GetMigratedActions() noexcept { return m_MigratedActions; } void SetMigratedActions(std::vector::const_iterator start, std::vector::const_iterator end) { m_MigratedActions.assign(start, end); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h index 0d76f851b..629757bf2 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h @@ -16,7 +16,6 @@ class RearrangeStripMessage : public BehaviorMessageBase { [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } - [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } private: int32_t m_SrcActionIndex; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h index cf801c2e3..2caa6366f 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h @@ -17,7 +17,6 @@ class RemoveActionsMessage : public BehaviorMessageBase { [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } - [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } private: int32_t m_ActionIndex; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h index 6c6948402..37501ea6d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h @@ -13,7 +13,6 @@ class RemoveStripMessage : public BehaviorMessageBase { RemoveStripMessage(const AMFArrayValue& arguments); const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } - ActionContext& GetActionContext() noexcept { return m_ActionContext; } private: ActionContext m_ActionContext; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h index 76b7c290d..33d6ec6a7 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h @@ -19,16 +19,12 @@ class SplitStripMessage : public BehaviorMessageBase { [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; } - [[nodiscard]] ActionContext& GetSourceActionContext() noexcept { return m_SourceActionContext; } [[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; } - [[nodiscard]] ActionContext& GetDestinationActionContext() noexcept { return m_DestinationActionContext; } [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_DestinationPosition; } - [[nodiscard]] StripUiPosition& GetPosition() noexcept { return m_DestinationPosition; } [[nodiscard]] const std::vector& GetTransferredActions() const noexcept { return m_TransferredActions; } - [[nodiscard]] std::vector& GetTransferredActions() noexcept { return m_TransferredActions; } void SetTransferredActions(std::vector::const_iterator begin, std::vector::const_iterator end) { m_TransferredActions.assign(begin, end); }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h index 05aa4f9d9..c53a4d47e 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h @@ -18,10 +18,8 @@ class UpdateActionMessage : public BehaviorMessageBase { [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } - [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; } [[nodiscard]] const Action& GetAction() const noexcept { return m_Action; } - [[nodiscard]] Action& GetAction() noexcept { return m_Action; } private: int32_t m_ActionIndex; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h index 42cbe0e25..e684fd4a6 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h @@ -16,10 +16,8 @@ class UpdateStripUiMessage : public BehaviorMessageBase { UpdateStripUiMessage(const AMFArrayValue& arguments); [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; }; - [[nodiscard]] StripUiPosition& GetPosition() noexcept { return m_Position; }; [[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }; - [[nodiscard]] ActionContext& GetActionContext() noexcept { return m_ActionContext; }; private: StripUiPosition m_Position; From b89488bb02bdafea836c28291f1e94a8c57107ab Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 13:16:21 -0600 Subject: [PATCH 08/22] simplify default behavior id initialization --- .../ControlBehaviorMessages/BehaviorMessageBase.cpp | 11 ++++------- .../ControlBehaviorMessages/BehaviorMessageBase.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp index 32d1dc2b5..fb26f37fe 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -4,22 +4,19 @@ #include "BehaviorStates.h" #include "dCommonVars.h" -BehaviorMessageBase::BehaviorMessageBase(const AMFArrayValue& arguments) { - m_BehaviorId = GetBehaviorIdFromArgument(arguments); -} - int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) { static constexpr std::string_view key = "BehaviorID"; const auto* const behaviorIDValue = arguments.Get(key); + int32_t behaviorId = DefaultBehaviorId; if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { - m_BehaviorId = - GeneralUtils::TryParse(behaviorIDValue->GetValue()).value_or(m_BehaviorId); + behaviorId = + GeneralUtils::TryParse(behaviorIDValue->GetValue()).value_or(behaviorId); } else if (arguments.Get(key) && arguments.Get(key)->GetValueType() != eAmf::Undefined) { throw std::invalid_argument("Unable to find behavior ID"); } - return m_BehaviorId; + return behaviorId; } int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string_view keyName) const { diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h index ec21a6791..cc8c293dd 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -16,7 +16,7 @@ enum class BehaviorState : uint32_t; class BehaviorMessageBase { public: static constexpr int32_t DefaultBehaviorId{ -1 }; - BehaviorMessageBase(const AMFArrayValue& arguments); + BehaviorMessageBase(const AMFArrayValue& arguments) : m_BehaviorId{ GetBehaviorIdFromArgument(arguments) } {} [[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; } [[nodiscard]] bool IsDefaultBehaviorId() const noexcept { return m_BehaviorId == DefaultBehaviorId; } From 0f1922aaba04296738750538880009dd549844dd Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 14:07:28 -0600 Subject: [PATCH 09/22] Fix invalidated use of Getter to set a value --- dGame/dPropertyBehaviors/ControlBehaviors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index 4e13980b4..ba979046d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -239,7 +239,7 @@ ControlBehaviors::ControlBehaviors() { if (values) { auto* value = values->FirstChildElement("Value"); while (value) { - if (value->GetText() == blockDefinition.GetDefaultValue()) blockDefinition.GetDefaultValue() = std::to_string(blockDefinition.GetMaximumValue()); + if (value->GetText() == blockDefinition.GetDefaultValue()) blockDefinition.SetDefaultValue(std::to_string(blockDefinition.GetMaximumValue())); blockDefinition.SetMaximumValue(blockDefinition.GetMaximumValue() + 1); value = value->NextSiblingElement("Value"); } From ab5ed7df4dbfbdc7ad2594f444562ce00050e53d Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 18:02:14 -0600 Subject: [PATCH 10/22] Update AddStripMessage.cpp - change push_back to emplace_back --- .../ControlBehaviorMessages/AddStripMessage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp index ff5009ccf..064ba2e9b 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp @@ -2,12 +2,12 @@ #include "Action.h" -AddStripMessage::AddStripMessage(const AMFArrayValue& arguments) +AddStripMessage::AddStripMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } , m_Position{ arguments } , m_ActionContext{ arguments } { - const auto* const strip = arguments.GetArray("strip"); + const auto* const strip = arguments->GetArray("strip"); if (!strip) return; const auto* const actions = strip->GetArray("actions"); @@ -17,9 +17,9 @@ AddStripMessage::AddStripMessage(const AMFArrayValue& arguments) const auto* const actionValue = actions->GetArray(actionNumber); if (!actionValue) continue; - m_ActionsToAdd.push_back(Action{ *actionValue }); + m_ActionsToAdd.emplace_back(actionValue); - LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().data(), m_ActionsToAdd.back().GetValueParameterName().data(), m_ActionsToAdd.back().GetValueParameterString().data(), m_ActionsToAdd.back().GetValueParameterDouble()); + LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().c_str(), m_ActionsToAdd.back().GetValueParameterName().c_str(), m_ActionsToAdd.back().GetValueParameterString().c_str(), m_ActionsToAdd.back().GetValueParameterDouble()); } LOG_DEBUG("number of actions %i", m_ActionsToAdd.size()); } From 188462e110e7768daf4a0fdb03d9c3808a75d902 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 11 Feb 2024 18:06:25 -0600 Subject: [PATCH 11/22] fix pointer to ref conversion mistake (should not have directly grabbed from the other branch commit) --- .../ControlBehaviorMessages/AddStripMessage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp index 064ba2e9b..189963244 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp @@ -2,12 +2,12 @@ #include "Action.h" -AddStripMessage::AddStripMessage(const AMFArrayValue* arguments) +AddStripMessage::AddStripMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_Position{ arguments } , m_ActionContext{ arguments } { - const auto* const strip = arguments->GetArray("strip"); + const auto* const strip = arguments.GetArray("strip"); if (!strip) return; const auto* const actions = strip->GetArray("actions"); @@ -17,9 +17,9 @@ AddStripMessage::AddStripMessage(const AMFArrayValue* arguments) const auto* const actionValue = actions->GetArray(actionNumber); if (!actionValue) continue; - m_ActionsToAdd.emplace_back(actionValue); + m_ActionsToAdd.emplace_back(*actionValue); - LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().c_str(), m_ActionsToAdd.back().GetValueParameterName().c_str(), m_ActionsToAdd.back().GetValueParameterString().c_str(), m_ActionsToAdd.back().GetValueParameterDouble()); + LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().data(), m_ActionsToAdd.back().GetValueParameterName().data(), m_ActionsToAdd.back().GetValueParameterString().data(), m_ActionsToAdd.back().GetValueParameterDouble()); } LOG_DEBUG("number of actions %i", m_ActionsToAdd.size()); } From 797eeb54542b1a447551af41ee1b435e4b584fc8 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 13 Feb 2024 20:14:11 -0600 Subject: [PATCH 12/22] deref --- dGame/dGameMessages/GameMessages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index a4708a0a2..3ed0549c2 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2505,7 +2505,7 @@ void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* e auto owner = PropertyManagementComponent::Instance()->GetOwner(); if (!owner) return; - ControlBehaviors::Instance().ProcessCommand(entity, *amfArguments.get(), command, owner); + ControlBehaviors::Instance().ProcessCommand(entity, *amfArguments, command, owner); } void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { From e381ef7e1e6a48b6e0541521e00b2290752e70d4 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 17 Feb 2024 23:57:35 -0600 Subject: [PATCH 13/22] VERY experimental testing of forward declaration of templates - probably will revert --- dCommon/AMFDeserialize.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dCommon/AMFDeserialize.h b/dCommon/AMFDeserialize.h index 5971a9616..a8e5ed0fa 100644 --- a/dCommon/AMFDeserialize.h +++ b/dCommon/AMFDeserialize.h @@ -1,12 +1,27 @@ #pragma once -#include "Amf3.h" #include "BitStream.h" #include #include #include +// Forward declarations + +template +class AMFValue; +class AMFArrayValue; +class AMFBaseValue; +extern template class AMFValue; +extern template class AMFValue; +extern template class AMFValue; +extern template class AMFValue; +extern template class AMFValue; +extern template class AMFValue; +using AMFDoubleValue = AMFValue; +using AMFIntValue = AMFValue; +using AMFStringValue = AMFValue; + class AMFDeserialize { public: /** From b2b21a81ca02502ca5a538c43078ce9bcf39ec2f Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 18 Feb 2024 00:04:10 -0600 Subject: [PATCH 14/22] Revert changes (as expected) --- dCommon/AMFDeserialize.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/dCommon/AMFDeserialize.h b/dCommon/AMFDeserialize.h index a8e5ed0fa..5971a9616 100644 --- a/dCommon/AMFDeserialize.h +++ b/dCommon/AMFDeserialize.h @@ -1,27 +1,12 @@ #pragma once +#include "Amf3.h" #include "BitStream.h" #include #include #include -// Forward declarations - -template -class AMFValue; -class AMFArrayValue; -class AMFBaseValue; -extern template class AMFValue; -extern template class AMFValue; -extern template class AMFValue; -extern template class AMFValue; -extern template class AMFValue; -extern template class AMFValue; -using AMFDoubleValue = AMFValue; -using AMFIntValue = AMFValue; -using AMFStringValue = AMFValue; - class AMFDeserialize { public: /** From cee38f56648c6af2b34b3183c6485198babfbb11 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Mon, 19 Feb 2024 07:23:34 -0600 Subject: [PATCH 15/22] Update BlockDefinition.h - remove extraneous semicolons --- dGame/dPropertyBehaviors/BlockDefinition.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dGame/dPropertyBehaviors/BlockDefinition.h b/dGame/dPropertyBehaviors/BlockDefinition.h index 31041d651..e88ab34a3 100644 --- a/dGame/dPropertyBehaviors/BlockDefinition.h +++ b/dGame/dPropertyBehaviors/BlockDefinition.h @@ -3,6 +3,7 @@ #include + class AMFArrayValue; class BlockDefinition { @@ -10,12 +11,12 @@ class BlockDefinition { BlockDefinition(const std::string_view defaultValue = "", const float minimumValue = 0.0f, const float maximumValue = 0.0f); static BlockDefinition blockDefinitionDefault; - [[nodiscard]] std::string_view GetDefaultValue() const { return m_DefaultValue; }; - [[nodiscard]] float GetMinimumValue() const noexcept { return m_MinimumValue; }; - [[nodiscard]] float GetMaximumValue() const noexcept { return m_MaximumValue; }; - void SetDefaultValue(const std::string_view value) { m_DefaultValue = std::string{ value }; }; - void SetMinimumValue(const float value) noexcept { m_MinimumValue = value; }; - void SetMaximumValue(const float value) noexcept { m_MaximumValue = value; }; + [[nodiscard]] std::string_view GetDefaultValue() const { return m_DefaultValue; } + [[nodiscard]] float GetMinimumValue() const noexcept { return m_MinimumValue; } + [[nodiscard]] float GetMaximumValue() const noexcept { return m_MaximumValue; } + void SetDefaultValue(const std::string_view value) { m_DefaultValue = std::string{ value }; } + void SetMinimumValue(const float value) noexcept { m_MinimumValue = value; } + void SetMaximumValue(const float value) noexcept { m_MaximumValue = value; } private: std::string m_DefaultValue; From c9f2b314fdda7bbdb402d161c4c9049fce5061b0 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Mon, 19 Feb 2024 07:24:09 -0600 Subject: [PATCH 16/22] Update BlockDefinition.h - remove linebreak --- dGame/dPropertyBehaviors/BlockDefinition.h | 1 - 1 file changed, 1 deletion(-) diff --git a/dGame/dPropertyBehaviors/BlockDefinition.h b/dGame/dPropertyBehaviors/BlockDefinition.h index e88ab34a3..0822a4f0d 100644 --- a/dGame/dPropertyBehaviors/BlockDefinition.h +++ b/dGame/dPropertyBehaviors/BlockDefinition.h @@ -3,7 +3,6 @@ #include - class AMFArrayValue; class BlockDefinition { From 2d7165a5b900a620432dc5cc43cb58b0def34e80 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 24 Feb 2024 21:44:44 -0600 Subject: [PATCH 17/22] Update Amf3.h member naming scheme --- dCommon/Amf3.h | 100 ++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index c3077370a..294a5b6c3 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -41,12 +41,13 @@ template class AMFValue : public AMFBaseValue { public: AMFValue() = default; - AMFValue(const ValueType value) { m_Data = value; } + AMFValue(const ValueType value) : m_Data{ value } {} virtual ~AMFValue() override = default; [[nodiscard]] constexpr eAmf GetValueType() const noexcept override; [[nodiscard]] const ValueType& GetValue() const { return m_Data; } + void SetValue(const ValueType value) { m_Data = value; } protected: @@ -54,7 +55,7 @@ class AMFValue : public AMFBaseValue { }; // Explicit template class instantiations -template class AMFValue; +template class AMFValue; template class AMFValue; template class AMFValue; template class AMFValue; @@ -110,7 +111,7 @@ class AMFArrayValue : public AMFBaseValue { [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Array; } ~AMFArrayValue() override { - for (auto valueToDelete : GetDense()) { + for (const auto* valueToDelete : GetDense()) { if (valueToDelete) { delete valueToDelete; valueToDelete = nullptr; @@ -127,12 +128,12 @@ class AMFArrayValue : public AMFBaseValue { /** * Returns the Associative portion of the object */ - [[nodiscard]] inline const AMFAssociative& GetAssociative() const noexcept { return this->associative; } + [[nodiscard]] inline const AMFAssociative& GetAssociative() const noexcept { return m_Associative; } /** * Returns the dense portion of the object */ - [[nodiscard]] inline const AMFDense& GetDense() const noexcept { return this->dense; } + [[nodiscard]] inline const AMFDense& GetDense() const noexcept { return m_Dense; } /** * Inserts an AMFValue into the associative portion with the given key. @@ -150,12 +151,12 @@ class AMFArrayValue : public AMFBaseValue { */ template [[maybe_unused]] std::pair*, bool> Insert(const std::string& key, const ValueType value) { - auto element = associative.find(key); + const auto element = m_Associative.find(key); AMFValue* val = nullptr; bool found = true; - if (element == associative.end()) { + if (element == m_Associative.cend()) { val = new AMFValue(value); - associative.insert(std::make_pair(key, val)); + m_Associative.emplace(key, val); } else { val = dynamic_cast*>(element->second); found = false; @@ -165,12 +166,12 @@ class AMFArrayValue : public AMFBaseValue { // Associates an array with a string key [[maybe_unused]] std::pair Insert(const std::string& key) { - auto element = associative.find(key); + const auto element = m_Associative.find(key); AMFArrayValue* val = nullptr; bool found = true; - if (element == associative.end()) { + if (element == m_Associative.cend()) { val = new AMFArrayValue(); - associative.insert(std::make_pair(key, val)); + m_Associative.emplace(key, val); } else { val = dynamic_cast(element->second); found = false; @@ -182,13 +183,13 @@ class AMFArrayValue : public AMFBaseValue { [[maybe_unused]] std::pair Insert(const size_t index) { AMFArrayValue* val = nullptr; bool inserted = false; - if (index >= dense.size()) { - dense.resize(index + 1); + if (index >= m_Dense.size()) { + m_Dense.resize(index + 1); val = new AMFArrayValue(); - dense.at(index) = val; + m_Dense.at(index) = val; inserted = true; } - return std::make_pair(dynamic_cast(dense.at(index)), inserted); + return std::make_pair(dynamic_cast(m_Dense.at(index)), inserted); } /** @@ -205,13 +206,13 @@ class AMFArrayValue : public AMFBaseValue { [[maybe_unused]] std::pair*, bool> Insert(const size_t index, const ValueType value) { AMFValue* val = nullptr; bool inserted = false; - if (index >= this->dense.size()) { - this->dense.resize(index + 1); + if (index >= m_Dense.size()) { + m_Dense.resize(index + 1); val = new AMFValue(value); - this->dense.at(index) = val; + m_Dense.at(index) = val; inserted = true; } - return std::make_pair(dynamic_cast*>(this->dense.at(index)), inserted); + return std::make_pair(dynamic_cast*>(m_Dense.at(index)), inserted); } /** @@ -224,12 +225,12 @@ class AMFArrayValue : public AMFBaseValue { * @param value The value to insert */ void Insert(const std::string& key, AMFBaseValue* const value) { - auto element = associative.find(key); - if (element != associative.end() && element->second) { + const auto element = m_Associative.find(key); + if (element != m_Associative.cend() && element->second) { delete element->second; element->second = value; } else { - associative.insert(std::make_pair(key, value)); + m_Associative.emplace(key, value); } } @@ -243,13 +244,13 @@ class AMFArrayValue : public AMFBaseValue { * @param value The value to insert */ void Insert(const size_t index, AMFBaseValue* const value) { - if (index < dense.size()) { - AMFDense::iterator itr = dense.begin() + index; - if (*itr) delete dense.at(index); + if (index < m_Dense.size()) { + const AMFDense::const_iterator itr = m_Dense.cbegin() + index; + if (*itr) delete m_Dense.at(index); } else { - dense.resize(index + 1); + m_Dense.resize(index + 1); } - dense.at(index) = value; + m_Dense.at(index) = value; } /** @@ -264,7 +265,7 @@ class AMFArrayValue : public AMFBaseValue { */ template [[maybe_unused]] inline AMFValue* Push(const ValueType value) { - return Insert(this->dense.size(), value).first; + return Insert(m_Dense.size(), value).first; } /** @@ -275,10 +276,10 @@ class AMFArrayValue : public AMFBaseValue { * @param key The key to remove from the associative portion */ void Remove(const std::string& key, const bool deleteValue = true) { - AMFAssociative::iterator it = this->associative.find(key); - if (it != this->associative.end()) { + const AMFAssociative::const_iterator it = m_Associative.find(key); + if (it != m_Associative.cend()) { if (deleteValue) delete it->second; - this->associative.erase(it); + m_Associative.erase(it); } } @@ -286,27 +287,24 @@ class AMFArrayValue : public AMFBaseValue { * Pops the last element in the dense portion, deleting it in the process. */ void Remove(const size_t index) { - if (!this->dense.empty() && index < this->dense.size()) { - auto itr = this->dense.begin() + index; + if (!m_Dense.empty() && index < m_Dense.size()) { + const auto itr = m_Dense.cbegin() + index; if (*itr) delete (*itr); - this->dense.erase(itr); + m_Dense.erase(itr); } } void Pop() { - if (!this->dense.empty()) Remove(this->dense.size() - 1); + if (!m_Dense.empty()) Remove(m_Dense.size() - 1); } [[nodiscard]] AMFArrayValue* GetArray(const std::string& key) const { - AMFAssociative::const_iterator it = this->associative.find(key); - if (it != this->associative.end()) { - return dynamic_cast(it->second); - } - return nullptr; + const AMFAssociative::const_iterator it = m_Associative.find(key); + return it != m_Associative.cend() ? dynamic_cast(it->second) : nullptr; } [[nodiscard]] AMFArrayValue* GetArray(const size_t index) const { - return index >= this->dense.size() ? nullptr : dynamic_cast(this->dense.at(index)); + return index < m_Dense.size() ? dynamic_cast(m_Dense.at(index)) : nullptr; } [[maybe_unused]] inline AMFArrayValue* InsertArray(const std::string& key) { @@ -318,7 +316,7 @@ class AMFArrayValue : public AMFBaseValue { } [[maybe_unused]] inline AMFArrayValue* PushArray() { - return static_cast(Insert(this->dense.size()).first); + return static_cast(Insert(m_Dense.size()).first); } /** @@ -332,16 +330,16 @@ class AMFArrayValue : public AMFBaseValue { */ template [[nodiscard]] AMFValue* Get(const std::string& key) const { - AMFAssociative::const_iterator it = this->associative.find(key); - return it != this->associative.end() ? + const AMFAssociative::const_iterator it = m_Associative.find(key); + return it != m_Associative.cend() ? dynamic_cast*>(it->second) : nullptr; } // Get from the array but dont cast it [[nodiscard]] AMFBaseValue* Get(const std::string& key) const { - AMFAssociative::const_iterator it = this->associative.find(key); - return it != this->associative.end() ? it->second : nullptr; + const AMFAssociative::const_iterator it = m_Associative.find(key); + return it != m_Associative.cend() ? it->second : nullptr; } /** @@ -355,27 +353,27 @@ class AMFArrayValue : public AMFBaseValue { */ template [[nodiscard]] AMFValue* Get(const size_t index) const { - return index < this->dense.size() ? - dynamic_cast*>(this->dense.at(index)) : + return index < m_Dense.size() ? + dynamic_cast*>(m_Dense.at(index)) : nullptr; } // Get from the dense but dont cast it [[nodiscard]] AMFBaseValue* Get(const size_t index) const { - return index < this->dense.size() ? this->dense.at(index) : nullptr; + return index < m_Dense.size() ? m_Dense.at(index) : nullptr; } private: /** * The associative portion. These values are key'd with strings to an AMFValue. */ - AMFAssociative associative; + AMFAssociative m_Associative; /** * The dense portion. These AMFValue's are stored one after * another with the most recent addition being at the back. */ - AMFDense dense; + AMFDense m_Dense; }; #endif //!__AMF3__H__ From da613ad12f6213280dd19c6dddaaf7b78e78fb3a Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 24 Feb 2024 23:18:33 -0600 Subject: [PATCH 18/22] fix duplicated code --- dCommon/Amf3.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index d103471dc..c86659e71 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -153,7 +153,7 @@ class AMFArrayValue : public AMFBaseValue { return std::make_pair(val, found); } - // Associates an array with a string keys + // Associates an array with a string key [[maybe_unused]] std::pair Insert(const std::string_view key) { const auto element = m_Associative.find(key); AMFArrayValue* val = nullptr; @@ -211,7 +211,7 @@ class AMFArrayValue : public AMFBaseValue { * @param value The value to insert */ void Insert(const std::string_view key, std::unique_ptr value) { - auto element = m_Associative.find(key); + const auto element = m_Associative.find(key); if (element != m_Associative.end() && element->second) { element->second = std::move(value); } else { @@ -276,7 +276,6 @@ class AMFArrayValue : public AMFBaseValue { void Pop() { if (!m_Dense.empty()) Remove(m_Dense.size() - 1); - if (!m_Dense.empty()) Remove(m_Dense.size() - 1); } [[nodiscard]] AMFArrayValue* GetArray(const std::string_view key) const { From 939eb6177af5f09d9a9c2ba3c52bb6877c85f6b1 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 24 Feb 2024 23:23:37 -0600 Subject: [PATCH 19/22] const iterators --- dCommon/Amf3.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index c86659e71..21a3c0c74 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -142,7 +142,7 @@ class AMFArrayValue : public AMFBaseValue { const auto element = m_Associative.find(key); AMFValue* val = nullptr; bool found = true; - if (element == m_Associative.end()) { + if (element == m_Associative.cend()) { auto newVal = std::make_unique>(value); val = newVal.get(); m_Associative.emplace(key, std::move(newVal)); @@ -158,7 +158,7 @@ class AMFArrayValue : public AMFBaseValue { const auto element = m_Associative.find(key); AMFArrayValue* val = nullptr; bool found = true; - if (element == m_Associative.end()) { + if (element == m_Associative.cend()) { auto newVal = std::make_unique(); val = newVal.get(); m_Associative.emplace(key, std::move(newVal)); @@ -212,7 +212,7 @@ class AMFArrayValue : public AMFBaseValue { */ void Insert(const std::string_view key, std::unique_ptr value) { const auto element = m_Associative.find(key); - if (element != m_Associative.end() && element->second) { + if (element != m_Associative.cend() && element->second) { element->second = std::move(value); } else { m_Associative.emplace(key, std::move(value)); From 9f8cff83b75f4aaa3196699f67ab42e7129f522c Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 24 Feb 2024 23:48:07 -0600 Subject: [PATCH 20/22] const pointers --- dGame/dGameMessages/GameMessages.cpp | 2 +- dGame/dPropertyBehaviors/ControlBehaviors.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index d0bd756c4..0157c6405 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2502,7 +2502,7 @@ void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* e command.push_back(character); } - auto owner = PropertyManagementComponent::Instance()->GetOwner(); + auto* const owner = PropertyManagementComponent::Instance()->GetOwner(); if (!owner) return; ControlBehaviors::Instance().ProcessCommand(entity, *amfArguments, command, owner); diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index a166cae9b..55a8c591c 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -95,7 +95,7 @@ void ControlBehaviors::UpdateAction(const AMFArrayValue& arguments) { } } -void ControlBehaviors::ProcessCommand(Entity* modelEntity, const AMFArrayValue& arguments, std::string_view command, Entity* modelOwner) { +void ControlBehaviors::ProcessCommand(Entity* modelEntity, const AMFArrayValue& arguments, const std::string_view command, Entity* const modelOwner) { if (!isInitialized || !modelEntity || !modelOwner) return; auto* const modelComponent = modelEntity->GetComponent(); From 42d3c73cb1d9afa3a8920a64017ffc3d0e7c8998 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 17 Nov 2024 21:45:05 -0600 Subject: [PATCH 21/22] reviving this branch --- .../dGameMessagesTests/GameMessageTests.cpp | 61 +++++++++++++++---- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp index 528136e17..7c33c6d0f 100644 --- a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp @@ -88,7 +88,10 @@ TEST_F(GameMessageTests, SendBlueprintLoadItemResponse) { TEST_F(GameMessageTests, ControlBehaviorAddStrip) { auto data = ReadFromFile("addStrip"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - AddStripMessage addStrip(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + AddStripMessage addStrip(*arr); + ASSERT_FLOAT_EQ(addStrip.GetPosition().GetX(), 50.65); ASSERT_FLOAT_EQ(addStrip.GetPosition().GetY(), 178.05); ASSERT_EQ(addStrip.GetActionContext().GetStripId(), 0); @@ -103,7 +106,10 @@ TEST_F(GameMessageTests, ControlBehaviorAddStrip) { TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) { auto data = ReadFromFile("removeStrip"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - RemoveStripMessage removeStrip(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + RemoveStripMessage removeStrip(*arr); + ASSERT_EQ(static_cast(removeStrip.GetActionContext().GetStripId()), 1); ASSERT_EQ(static_cast(removeStrip.GetActionContext().GetStateId()), 0); ASSERT_EQ(removeStrip.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); @@ -112,7 +118,10 @@ TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) { TEST_F(GameMessageTests, ControlBehaviorMergeStrips) { auto data = ReadFromFile("mergeStrips"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - MergeStripsMessage mergeStrips(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + MergeStripsMessage mergeStrips(*arr); + ASSERT_EQ(mergeStrips.GetSourceActionContext().GetStripId(), 2); ASSERT_EQ(mergeStrips.GetDestinationActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(mergeStrips.GetSourceActionContext().GetStateId()), 0); @@ -124,9 +133,11 @@ TEST_F(GameMessageTests, ControlBehaviorMergeStrips) { TEST_F(GameMessageTests, ControlBehaviorSplitStrip) { auto data = ReadFromFile("splitStrip"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - SplitStripMessage splitStrip(ReadArrayFromBitStream(inStream)); - ASSERT_EQ(splitStrip.GetBehaviorId(), -1); + const auto arr = ReadArrayFromBitStream(inStream); + SplitStripMessage splitStrip(*arr); + + ASSERT_EQ(splitStrip.GetBehaviorId(), -1); ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetX(), 275.65); ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetY(), 28.7); ASSERT_EQ(splitStrip.GetSourceActionContext().GetStripId(), 0); @@ -139,7 +150,10 @@ TEST_F(GameMessageTests, ControlBehaviorSplitStrip) { TEST_F(GameMessageTests, ControlBehaviorUpdateStripUI) { auto data = ReadFromFile("updateStripUI"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - UpdateStripUiMessage updateStripUi(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + UpdateStripUiMessage updateStripUi(*arr); + ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetX(), 116.65); ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetY(), 35.35); ASSERT_EQ(updateStripUi.GetActionContext().GetStripId(), 0); @@ -150,7 +164,10 @@ TEST_F(GameMessageTests, ControlBehaviorUpdateStripUI) { TEST_F(GameMessageTests, ControlBehaviorAddAction) { auto data = ReadFromFile("addAction"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - AddActionMessage addAction(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + AddActionMessage addAction(*arr); + ASSERT_EQ(addAction.GetActionIndex(), 3); ASSERT_EQ(addAction.GetActionContext().GetStripId(), 0); ASSERT_EQ(static_cast(addAction.GetActionContext().GetStateId()), 0); @@ -164,7 +181,10 @@ TEST_F(GameMessageTests, ControlBehaviorAddAction) { TEST_F(GameMessageTests, ControlBehaviorMigrateActions) { auto data = ReadFromFile("migrateActions"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - MigrateActionsMessage migrateActions(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + MigrateActionsMessage migrateActions(*arr); + ASSERT_EQ(migrateActions.GetSrcActionIndex(), 1); ASSERT_EQ(migrateActions.GetDstActionIndex(), 2); ASSERT_EQ(migrateActions.GetSourceActionContext().GetStripId(), 1); @@ -177,7 +197,10 @@ TEST_F(GameMessageTests, ControlBehaviorMigrateActions) { TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) { auto data = ReadFromFile("rearrangeStrip"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - RearrangeStripMessage rearrangeStrip(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + RearrangeStripMessage rearrangeStrip(*arr); + ASSERT_EQ(rearrangeStrip.GetSrcActionIndex(), 2); ASSERT_EQ(rearrangeStrip.GetDstActionIndex(), 1); ASSERT_EQ(rearrangeStrip.GetActionContext().GetStripId(), 0); @@ -188,7 +211,10 @@ TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) { TEST_F(GameMessageTests, ControlBehaviorAdd) { auto data = ReadFromFile("add"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - AddMessage add(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + AddMessage add(*arr); + ASSERT_EQ(add.GetBehaviorId(), 10446); ASSERT_EQ(add.GetBehaviorIndex(), 0); } @@ -196,7 +222,10 @@ TEST_F(GameMessageTests, ControlBehaviorAdd) { TEST_F(GameMessageTests, ControlBehaviorRemoveActions) { auto data = ReadFromFile("removeActions"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - RemoveActionsMessage removeActions(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + RemoveActionsMessage removeActions(*arr); + ASSERT_EQ(removeActions.GetBehaviorId(), -1); ASSERT_EQ(removeActions.GetActionIndex(), 1); ASSERT_EQ(removeActions.GetActionContext().GetStripId(), 0); @@ -206,7 +235,10 @@ TEST_F(GameMessageTests, ControlBehaviorRemoveActions) { TEST_F(GameMessageTests, ControlBehaviorRename) { auto data = ReadFromFile("rename"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - RenameMessage rename(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + RenameMessage rename(*arr); + ASSERT_EQ(rename.GetName(), "test"); ASSERT_EQ(rename.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } @@ -214,7 +246,10 @@ TEST_F(GameMessageTests, ControlBehaviorRename) { TEST_F(GameMessageTests, ControlBehaviorUpdateAction) { auto data = ReadFromFile("updateAction"); RakNet::BitStream inStream(reinterpret_cast(&data[0]), data.length(), true); - UpdateActionMessage updateAction(ReadArrayFromBitStream(inStream)); + + const auto arr = ReadArrayFromBitStream(inStream); + UpdateActionMessage updateAction(*arr); + ASSERT_EQ(updateAction.GetAction().GetType(), "FlyDown"); ASSERT_EQ(updateAction.GetAction().GetValueParameterName(), "Distance"); ASSERT_EQ(updateAction.GetAction().GetValueParameterString(), ""); From 2f97e8be601aa2d1d4809d2457f54fb6d28e678a Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 17 Nov 2024 22:37:06 -0600 Subject: [PATCH 22/22] update read switch cases --- .editorconfig | 2 +- dCommon/AMFDeserialize.cpp | 71 ++++++++++++++------------------------ 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/.editorconfig b/.editorconfig index ebdfa7ac1..a63178f1c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -73,4 +73,4 @@ cpp_space_around_assignment_operator=insert cpp_space_pointer_reference_alignment=left cpp_space_around_ternary_operator=insert cpp_wrap_preserve_blocks=one_liners -cpp_indent_comment=fasle +cpp_indent_comment=false diff --git a/dCommon/AMFDeserialize.cpp b/dCommon/AMFDeserialize.cpp index b551dbda6..884a0784f 100644 --- a/dCommon/AMFDeserialize.cpp +++ b/dCommon/AMFDeserialize.cpp @@ -10,72 +10,53 @@ */ std::unique_ptr AMFDeserialize::Read(RakNet::BitStream& inStream) { - std::unique_ptr returnValue = nullptr; // Read in the value type from the bitStream eAmf marker; inStream.Read(marker); // Based on the typing, create the value associated with that and return the base value class switch (marker) { - case eAmf::Undefined: { - returnValue = std::make_unique(); - break; - } - - case eAmf::Null: { - returnValue = std::make_unique(); - break; - } - - case eAmf::False: { - returnValue = std::make_unique(false); - break; - } - - case eAmf::True: { - returnValue = std::make_unique(true); - break; - } - - case eAmf::Integer: { - returnValue = ReadAmfInteger(inStream); - break; - } - - case eAmf::Double: { - returnValue = ReadAmfDouble(inStream); - break; - } - - case eAmf::String: { - returnValue = ReadAmfString(inStream); - break; - } - - case eAmf::Array: { - returnValue = ReadAmfArray(inStream); - break; - } + case eAmf::Undefined: + return std::make_unique(); + case eAmf::Null: + return std::make_unique(); + case eAmf::False: + return std::make_unique(false); + case eAmf::True: + return std::make_unique(true); + case eAmf::Integer: + return ReadAmfInteger(inStream); + case eAmf::Double: + return ReadAmfDouble(inStream); + case eAmf::String: + return ReadAmfString(inStream); + case eAmf::Array: + return ReadAmfArray(inStream); // These values are unimplemented in the live client and will remain unimplemented // unless someone modifies the client to allow serializing of these values. case eAmf::XMLDoc: + [[fallthrough]]; case eAmf::Date: + [[fallthrough]]; case eAmf::Object: + [[fallthrough]]; case eAmf::XML: + [[fallthrough]]; case eAmf::ByteArray: + [[fallthrough]]; case eAmf::VectorInt: + [[fallthrough]]; case eAmf::VectorUInt: + [[fallthrough]]; case eAmf::VectorDouble: + [[fallthrough]]; case eAmf::VectorObject: - case eAmf::Dictionary: { + [[fallthrough]]; + case eAmf::Dictionary: throw marker; - break; - } default: throw std::invalid_argument("Invalid AMF3 marker" + std::to_string(static_cast(marker))); - break; } - return returnValue; } uint32_t AMFDeserialize::ReadU29(RakNet::BitStream& inStream) {