From 424d54b98c5ef72cd1ef72050eda4c0a26cf6062 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 27 Feb 2024 01:29:51 -0600 Subject: [PATCH] squash commits (#1479) --- dCommon/AMFDeserialize.cpp | 4 +- dCommon/AMFDeserialize.h | 2 +- dCommon/Amf3.h | 1 + dGame/dComponents/ModelComponent.h | 2 +- dGame/dGameMessages/GameMessages.cpp | 9 +- .../ControlBehaviorMessages/Action.cpp | 4 +- .../ControlBehaviorMessages/Action.h | 2 +- .../ControlBehaviorMessages/ActionContext.cpp | 10 +-- .../ControlBehaviorMessages/ActionContext.h | 6 +- .../AddActionMessage.cpp | 6 +- .../AddActionMessage.h | 2 +- .../ControlBehaviorMessages/AddMessage.cpp | 4 +- .../ControlBehaviorMessages/AddMessage.h | 2 +- .../AddStripMessage.cpp | 8 +- .../ControlBehaviorMessages/AddStripMessage.h | 2 +- .../BehaviorMessageBase.cpp | 10 +-- .../BehaviorMessageBase.h | 6 +- .../MergeStripsMessage.cpp | 2 +- .../MergeStripsMessage.h | 2 +- .../MigrateActionsMessage.cpp | 2 +- .../MigrateActionsMessage.h | 2 +- .../MoveToInventoryMessage.cpp | 4 +- .../MoveToInventoryMessage.h | 2 +- .../RearrangeStripMessage.cpp | 2 +- .../RearrangeStripMessage.h | 2 +- .../RemoveActionsMessage.cpp | 2 +- .../RemoveActionsMessage.h | 2 +- .../RemoveStripMessage.cpp | 2 +- .../RemoveStripMessage.h | 2 +- .../ControlBehaviorMessages/RenameMessage.cpp | 4 +- .../ControlBehaviorMessages/RenameMessage.h | 2 +- .../SplitStripMessage.cpp | 2 +- .../SplitStripMessage.h | 2 +- .../StripUiPosition.cpp | 4 +- .../ControlBehaviorMessages/StripUiPosition.h | 2 +- .../UpdateActionMessage.cpp | 6 +- .../UpdateActionMessage.h | 2 +- .../UpdateStripUiMessage.cpp | 2 +- .../UpdateStripUiMessage.h | 2 +- dGame/dPropertyBehaviors/ControlBehaviors.cpp | 8 +- dGame/dPropertyBehaviors/ControlBehaviors.h | 10 +-- tests/dCommonTests/AMFDeserializeTests.cpp | 88 +++++++++---------- .../dGameMessagesTests/GameMessageTests.cpp | 22 ++--- 43 files changed, 132 insertions(+), 130 deletions(-) diff --git a/dCommon/AMFDeserialize.cpp b/dCommon/AMFDeserialize.cpp index 1b7a9dcf..130ebc4a 100644 --- a/dCommon/AMFDeserialize.cpp +++ b/dCommon/AMFDeserialize.cpp @@ -128,10 +128,10 @@ AMFBaseValue* AMFDeserialize::ReadAmfArray(RakNet::BitStream& inStream) { auto arrayValue = new AMFArrayValue(); // 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)); diff --git a/dCommon/AMFDeserialize.h b/dCommon/AMFDeserialize.h index 3e3e07ec..e204976d 100644 --- a/dCommon/AMFDeserialize.h +++ b/dCommon/AMFDeserialize.h @@ -23,7 +23,7 @@ private: * @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 diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 294a5b6c..9fe728c0 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -42,6 +42,7 @@ class AMFValue : public AMFBaseValue { public: AMFValue() = default; AMFValue(const ValueType value) : m_Data{ value } {} + virtual ~AMFValue() override = default; [[nodiscard]] constexpr eAmf GetValueType() const noexcept override; diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 9d2a4e3f..dc6810eb 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -61,7 +61,7 @@ public: * @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) { diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index c7ffe418..77f4e908 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2489,23 +2489,24 @@ 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)) }; 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); } - auto owner = PropertyManagementComponent::Instance()->GetOwner(); + auto* const owner = PropertyManagementComponent::Instance()->GetOwner(); if (!owner) return; - ControlBehaviors::Instance().ProcessCommand(entity, static_cast(amfArguments.get()), command, owner); + ControlBehaviors::Instance().ProcessCommand(entity, *amfArguments, command, owner); } void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) { diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp index f9d3cec8..3e62a2d7 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp @@ -1,8 +1,8 @@ #include "Action.h" #include "Amf3.h" -Action::Action(const AMFArrayValue* arguments) { - for (const 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; m_Type = static_cast(paramValue)->GetValue(); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h index c2bb7ed7..988e616c 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h @@ -12,7 +12,7 @@ class AMFArrayValue; class Action { public: Action() = default; - Action(const AMFArrayValue* arguments); + Action(const AMFArrayValue& arguments); [[nodiscard]] const std::string& GetType() const { return m_Type; }; [[nodiscard]] const std::string& GetValueParameterName() const { return m_ValueParameterName; }; [[nodiscard]] const std::string& GetValueParameterString() const { return m_ValueParameterString; }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp index 0cdfbddd..36da8d73 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp @@ -4,20 +4,20 @@ #include "Amf3.h" -ActionContext::ActionContext(const AMFArrayValue* arguments, const std::string& customStateKey, const std::string& customStripKey) +ActionContext::ActionContext(const AMFArrayValue& arguments, const std::string& customStateKey, const std::string& customStripKey) : m_StripId{ GetStripIdFromArgument(arguments, customStripKey) } , m_StateId{ GetBehaviorStateFromArgument(arguments, customStateKey) } { } -BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue* arguments, const std::string& key) const { - const auto* const stateIDValue = arguments->Get(key); +BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue& arguments, const std::string& key) const { + const auto* const stateIDValue = arguments.Get(key); if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\""); return static_cast(stateIDValue->GetValue()); } -StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue* arguments, const std::string& key) const { - const auto* const stripIdValue = arguments->Get(key); +StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue& arguments, const std::string& key) const { + const auto* const stripIdValue = arguments.Get(key); if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\""); return static_cast(stripIdValue->GetValue()); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h index 7013e84e..8ecea8a2 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h @@ -13,13 +13,13 @@ class AMFArrayValue; class ActionContext { public: ActionContext() noexcept = default; - ActionContext(const AMFArrayValue* arguments, const std::string& customStateKey = "stateID", const std::string& customStripKey = "stripID"); + ActionContext(const AMFArrayValue& arguments, const std::string& customStateKey = "stateID", const std::string& customStripKey = "stripID"); [[nodiscard]] StripId GetStripId() const noexcept { return m_StripId; }; [[nodiscard]] BehaviorState GetStateId() const noexcept { return m_StateId; }; private: - [[nodiscard]] BehaviorState GetBehaviorStateFromArgument(const AMFArrayValue* arguments, const std::string& key) const; - [[nodiscard]] StripId GetStripIdFromArgument(const AMFArrayValue* arguments, const std::string& key) const; + [[nodiscard]] BehaviorState GetBehaviorStateFromArgument(const AMFArrayValue& arguments, const std::string& key) const; + [[nodiscard]] StripId GetStripIdFromArgument(const AMFArrayValue& arguments, const std::string& key) const; StripId m_StripId{ 0 }; BehaviorState m_StateId{ BehaviorState::HOME_STATE }; }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp index 44b1e9ab..35b9cf0d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp @@ -1,14 +1,14 @@ #include "AddActionMessage.h" -AddActionMessage::AddActionMessage(const AMFArrayValue* arguments) +AddActionMessage::AddActionMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_ActionIndex{ GetActionIndexFromArgument(arguments) } , m_ActionContext{ arguments } { - const auto* const actionValue = arguments->GetArray("action"); + const auto* const actionValue = arguments.GetArray("action"); if (!actionValue) return; - m_Action = Action{ actionValue }; + m_Action = Action{ *actionValue }; 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().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), m_Action.GetValueParameterDouble(), m_BehaviorId); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h index a8737dd7..7f94820d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h @@ -13,7 +13,7 @@ class AMFArrayValue; */ class AddActionMessage : public BehaviorMessageBase { public: - AddActionMessage(const AMFArrayValue* arguments); + AddActionMessage(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp index 9c103334..45e3d974 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp @@ -1,7 +1,7 @@ #include "AddMessage.h" -AddMessage::AddMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } { - const auto* const behaviorIndexValue = arguments->Get("BehaviorIndex"); +AddMessage::AddMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } { + const auto* const behaviorIndexValue = arguments.Get("BehaviorIndex"); if (!behaviorIndexValue) return; m_BehaviorIndex = static_cast(behaviorIndexValue->GetValue()); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h index 0832d687..8bf0b70c 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h @@ -9,7 +9,7 @@ */ class AddMessage : public BehaviorMessageBase { public: - AddMessage(const AMFArrayValue* arguments); + AddMessage(const AMFArrayValue& arguments); [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; }; private: diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp index 064ba2e9..c7207b33 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp @@ -2,22 +2,22 @@ #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"); if (!actions) return; - for (uint32_t actionNumber = 0; actionNumber < actions->GetDense().size(); actionNumber++) { + for (size_t actionNumber = 0; actionNumber < actions->GetDense().size(); ++actionNumber) { 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()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h index dbd70421..a5361034 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h @@ -18,7 +18,7 @@ class AMFArrayValue; */ class AddStripMessage : public BehaviorMessageBase { public: - AddStripMessage(const AMFArrayValue* arguments); + AddStripMessage(const AMFArrayValue& arguments); [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp index f7688e1a..a1cbb064 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -4,23 +4,23 @@ #include "BehaviorStates.h" #include "dCommonVars.h" -int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue* arguments) { +int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) { static constexpr const char* key = "BehaviorID"; - const auto* const behaviorIDValue = arguments->Get(key); + const auto* const behaviorIDValue = arguments.Get(key); int32_t behaviorId = DefaultBehaviorId; if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { behaviorId = GeneralUtils::TryParse(behaviorIDValue->GetValue()).value_or(behaviorId); - } else if (arguments->Get(key) && arguments->Get(key)->GetValueType() != eAmf::Undefined) { + } else if (arguments.Get(key) && arguments.Get(key)->GetValueType() != eAmf::Undefined) { throw std::invalid_argument("Unable to find behavior ID"); } return behaviorId; } -int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue* arguments, const std::string& keyName) const { - const auto* const actionIndexAmf = arguments->Get(keyName); +int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string& 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 cadf33bf..bb251a74 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -16,13 +16,13 @@ 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) : 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(const AMFArrayValue* arguments); - [[nodiscard]] int32_t GetActionIndexFromArgument(const AMFArrayValue* arguments, const std::string& keyName = "actionIndex") const; + [[nodiscard]] int32_t GetBehaviorIdFromArgument(const AMFArrayValue& arguments); + [[nodiscard]] int32_t GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string& keyName = "actionIndex") const; int32_t m_BehaviorId{ DefaultBehaviorId }; }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp index d5a83714..1efc5aee 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp @@ -1,6 +1,6 @@ #include "MergeStripsMessage.h" -MergeStripsMessage::MergeStripsMessage(const AMFArrayValue* arguments) +MergeStripsMessage::MergeStripsMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } , m_SourceActionContext{ arguments, "srcStateID", "srcStripID" } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h index 970a744d..d778d632 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h @@ -13,7 +13,7 @@ class AMFArrayValue; */ class MergeStripsMessage : public BehaviorMessageBase { public: - MergeStripsMessage(const AMFArrayValue* arguments); + MergeStripsMessage(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp index 8fa2cb5b..9791bc2a 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp @@ -1,6 +1,6 @@ #include "MigrateActionsMessage.h" -MigrateActionsMessage::MigrateActionsMessage(const AMFArrayValue* arguments) +MigrateActionsMessage::MigrateActionsMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h index e3671185..9813fbf4 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h @@ -13,7 +13,7 @@ class AMFArrayValue; */ class MigrateActionsMessage : public BehaviorMessageBase { public: - MigrateActionsMessage(const AMFArrayValue* arguments); + MigrateActionsMessage(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp index 01709f70..cab5c4a3 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp @@ -1,7 +1,7 @@ #include "MoveToInventoryMessage.h" -MoveToInventoryMessage::MoveToInventoryMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } { - const auto* const behaviorIndexValue = arguments->Get("BehaviorIndex"); +MoveToInventoryMessage::MoveToInventoryMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } { + const auto* const behaviorIndexValue = arguments.Get("BehaviorIndex"); if (!behaviorIndexValue) return; m_BehaviorIndex = static_cast(behaviorIndexValue->GetValue()); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h index 9a383469..e1f88713 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h @@ -11,7 +11,7 @@ class AMFArrayValue; #pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.") class MoveToInventoryMessage : public BehaviorMessageBase { public: - MoveToInventoryMessage(const AMFArrayValue* arguments); + MoveToInventoryMessage(const AMFArrayValue& arguments); [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; }; private: diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp index 0c3689fa..99fe6f6a 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp @@ -1,6 +1,6 @@ #include "RearrangeStripMessage.h" -RearrangeStripMessage::RearrangeStripMessage(const AMFArrayValue* arguments) +RearrangeStripMessage::RearrangeStripMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } , m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h index 054fbf3e..629757bf 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h @@ -10,7 +10,7 @@ */ class RearrangeStripMessage : public BehaviorMessageBase { public: - RearrangeStripMessage(const AMFArrayValue* arguments); + RearrangeStripMessage(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp index ab13cd20..15407012 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp @@ -1,6 +1,6 @@ #include "RemoveActionsMessage.h" -RemoveActionsMessage::RemoveActionsMessage(const AMFArrayValue* arguments) +RemoveActionsMessage::RemoveActionsMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_ActionIndex{ GetActionIndexFromArgument(arguments) } , m_ActionContext{ arguments } { diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h index 7e212206..2caa6366 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h @@ -12,7 +12,7 @@ class AMFArrayValue; */ class RemoveActionsMessage : public BehaviorMessageBase { public: - RemoveActionsMessage(const AMFArrayValue* arguments); + RemoveActionsMessage(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp index 371faf1c..f0275377 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp @@ -1,6 +1,6 @@ #include "RemoveStripMessage.h" -RemoveStripMessage::RemoveStripMessage(const AMFArrayValue* arguments) +RemoveStripMessage::RemoveStripMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_ActionContext{ arguments } { diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h index a65949e8..37501ea6 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h @@ -10,7 +10,7 @@ */ class RemoveStripMessage : public BehaviorMessageBase { public: - RemoveStripMessage(const AMFArrayValue* arguments); + RemoveStripMessage(const AMFArrayValue& arguments); const ActionContext& GetActionContext() const noexcept { return m_ActionContext; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp index d9c73f6a..82d88bf8 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp @@ -1,7 +1,7 @@ #include "RenameMessage.h" -RenameMessage::RenameMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } { - const auto* const nameAmf = arguments->Get("Name"); +RenameMessage::RenameMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } { + const auto* const nameAmf = arguments.Get("Name"); if (!nameAmf) return; m_Name = nameAmf->GetValue(); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h index e7174296..1f4e45c0 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h @@ -10,7 +10,7 @@ class AMFArrayValue; */ class RenameMessage : public BehaviorMessageBase { public: - RenameMessage(const AMFArrayValue* arguments); + RenameMessage(const AMFArrayValue& arguments); [[nodiscard]] const std::string& GetName() const { return m_Name; }; private: diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp index 9c35d1ba..6003c982 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp @@ -1,6 +1,6 @@ #include "SplitStripMessage.h" -SplitStripMessage::SplitStripMessage(const AMFArrayValue* arguments) +SplitStripMessage::SplitStripMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") } , m_SourceActionContext{ arguments, "srcStateID", "srcStripID" } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h index 6cdcc5c3..33d6ec6a 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h @@ -14,7 +14,7 @@ class AMFArrayValue; */ class SplitStripMessage : public BehaviorMessageBase { public: - SplitStripMessage(const AMFArrayValue* arguments); + SplitStripMessage(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp index 0acbfb3f..56dc43ff 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp @@ -2,8 +2,8 @@ #include "Amf3.h" -StripUiPosition::StripUiPosition(const AMFArrayValue* arguments, const std::string& uiKeyName) { - const auto* const uiArray = arguments->GetArray(uiKeyName); +StripUiPosition::StripUiPosition(const AMFArrayValue& arguments, const std::string& uiKeyName) { + const auto* const uiArray = arguments.GetArray(uiKeyName); if (!uiArray) return; const auto* const xPositionValue = uiArray->Get("x"); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h index 6371b465..f202210d 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h @@ -10,7 +10,7 @@ class AMFArrayValue; class StripUiPosition { public: StripUiPosition() noexcept = default; - StripUiPosition(const AMFArrayValue* arguments, const std::string& uiKeyName = "ui"); + StripUiPosition(const AMFArrayValue& arguments, const std::string& uiKeyName = "ui"); void SendBehaviorBlocksToClient(AMFArrayValue& args) const; [[nodiscard]] double GetX() const noexcept { return m_XPosition; } [[nodiscard]] double GetY() const noexcept { return m_YPosition; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp index 68b97917..fabf2726 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp @@ -2,15 +2,15 @@ #include "Action.h" -UpdateActionMessage::UpdateActionMessage(const AMFArrayValue* arguments) +UpdateActionMessage::UpdateActionMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_ActionIndex{ GetActionIndexFromArgument(arguments) } , m_ActionContext{ arguments } { - const auto* const actionValue = arguments->GetArray("action"); + const auto* const actionValue = arguments.GetArray("action"); if (!actionValue) return; - m_Action = Action{ actionValue }; + m_Action = Action{ *actionValue }; LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", m_Action.GetType().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), 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 cfa9dd4d..c53a4d47 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h @@ -13,7 +13,7 @@ class AMFArrayValue; */ class UpdateActionMessage : public BehaviorMessageBase { public: - UpdateActionMessage(const AMFArrayValue* arguments); + UpdateActionMessage(const AMFArrayValue& arguments); [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp index 593673b6..badb8c7a 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp @@ -1,6 +1,6 @@ #include "UpdateStripUiMessage.h" -UpdateStripUiMessage::UpdateStripUiMessage(const AMFArrayValue* arguments) +UpdateStripUiMessage::UpdateStripUiMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ arguments } , m_Position{ arguments } , m_ActionContext{ arguments } { diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h index 85ca5d54..e684fd4a 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h @@ -13,7 +13,7 @@ class AMFArrayValue; */ class UpdateStripUiMessage : public BehaviorMessageBase { public: - UpdateStripUiMessage(const AMFArrayValue* arguments); + UpdateStripUiMessage(const AMFArrayValue& arguments); [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; }; diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index c4d22482..2e074409 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -71,7 +71,7 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& contex GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorBlocks", behavior); } -void ControlBehaviors::UpdateAction(const AMFArrayValue* arguments) { +void ControlBehaviors::UpdateAction(const AMFArrayValue& arguments) { UpdateActionMessage updateActionMessage{ arguments }; auto blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType()); @@ -95,8 +95,8 @@ void ControlBehaviors::UpdateAction(const AMFArrayValue* arguments) { } } -void ControlBehaviors::ProcessCommand(Entity* modelEntity, AMFArrayValue* arguments, std::string& command, Entity* modelOwner) { - if (!isInitialized || !modelEntity || !modelOwner || !arguments) return; +void ControlBehaviors::ProcessCommand(Entity* const modelEntity, const AMFArrayValue& arguments, const std::string& command, Entity* const modelOwner) { + if (!isInitialized || !modelEntity || !modelOwner) return; auto* const modelComponent = modelEntity->GetComponent(); if (!modelComponent) return; @@ -106,7 +106,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, AMFArrayValue* argume if (command == "sendBehaviorListToClient") { SendBehaviorListToClient(context); } else if (command == "modelTypeChanged") { - auto* const modelType = arguments->Get("ModelType"); + const auto* const modelType = arguments.Get("ModelType"); if (!modelType) return; modelEntity->SetVar(u"modelType", modelType->GetValue()); diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.h b/dGame/dPropertyBehaviors/ControlBehaviors.h index 4eab5367..f176a070 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.h +++ b/dGame/dPropertyBehaviors/ControlBehaviors.h @@ -19,15 +19,15 @@ class SystemAddress; typedef std::string BlockName; //! A block name struct ControlBehaviorContext { - ControlBehaviorContext(AMFArrayValue* args, ModelComponent* modelComponent, Entity* modelOwner) noexcept + 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; + std::reference_wrapper arguments; ModelComponent* modelComponent; Entity* modelOwner; }; @@ -43,7 +43,7 @@ public: * @param command The command to perform * @param modelOwner The owner of the model which sent this command */ - void ProcessCommand(Entity* modelEntity, AMFArrayValue* arguments, std::string& command, Entity* modelOwner); + void ProcessCommand(Entity* const modelEntity, const AMFArrayValue& arguments, const std::string& command, Entity* const modelOwner); /** * @brief Gets a blocks parameter values by the name @@ -58,7 +58,7 @@ private: void RequestUpdatedID(ControlBehaviorContext& context); void SendBehaviorListToClient(const ControlBehaviorContext& context); void SendBehaviorBlocksToClient(ControlBehaviorContext& context); - void UpdateAction(const AMFArrayValue* arguments); + void UpdateAction(const AMFArrayValue& arguments); std::map> blockTypes{}; // If false, property behaviors will not be able to be edited. diff --git a/tests/dCommonTests/AMFDeserializeTests.cpp b/tests/dCommonTests/AMFDeserializeTests.cpp index 02c6b072..c949ae50 100644 --- a/tests/dCommonTests/AMFDeserializeTests.cpp +++ b/tests/dCommonTests/AMFDeserializeTests.cpp @@ -11,10 +11,10 @@ /** * 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{ returnValue }; } /** @@ -23,7 +23,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 +34,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 +44,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 +54,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 +67,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 +76,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 +90,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 +102,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 +116,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 +130,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 +145,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 +164,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 +238,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]); - 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]); - 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]); - 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]); - 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]); - 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]); - 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 c223bf78..5bcdddef 100644 --- a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp @@ -38,11 +38,11 @@ protected: } return readFile; } - AMFArrayValue* ReadArrayFromBitStream(RakNet::BitStream& inStream) { + const AMFArrayValue& ReadArrayFromBitStream(RakNet::BitStream& inStream) { AMFDeserialize des; AMFBaseValue* readArray = des.Read(inStream); EXPECT_EQ(readArray->GetValueType(), eAmf::Array); - return static_cast(readArray); + return static_cast(*readArray); } }; @@ -93,7 +93,7 @@ TEST_F(GameMessageTests, ControlBehaviorAddStrip) { 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(), ""); @@ -106,7 +106,7 @@ TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) { RemoveStripMessage removeStrip(ReadArrayFromBitStream(inStream)); 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) { @@ -118,7 +118,7 @@ TEST_F(GameMessageTests, ControlBehaviorMergeStrips) { 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) { @@ -144,7 +144,7 @@ TEST_F(GameMessageTests, ControlBehaviorUpdateStripUI) { 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) { @@ -158,7 +158,7 @@ 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) { @@ -171,7 +171,7 @@ TEST_F(GameMessageTests, ControlBehaviorMigrateActions) { 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) { @@ -181,7 +181,7 @@ TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) { 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); } @@ -208,7 +208,7 @@ TEST_F(GameMessageTests, ControlBehaviorRename) { RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RenameMessage rename(ReadArrayFromBitStream(inStream)); ASSERT_EQ(rename.GetName(), "test"); - ASSERT_EQ(rename.GetBehaviorId(), -1); + ASSERT_EQ(rename.GetBehaviorId(), BehaviorMessageBase::DefaultBehaviorId); } TEST_F(GameMessageTests, ControlBehaviorUpdateAction) { @@ -219,7 +219,7 @@ TEST_F(GameMessageTests, ControlBehaviorUpdateAction) { 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);