From f25dd7ca9ebeea3dff41af06aa46f3a1f575fd33 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 3 Feb 2024 01:58:49 -0600 Subject: [PATCH 01/12] Moved unrelated changes out of the TryParse PR branch --- dChatServer/PlayerContainer.cpp | 9 --- dChatServer/PlayerContainer.h | 8 +- dCommon/LDFFormat.h | 2 +- dCommon/dEnums/dCommonVars.h | 94 +++++++++++------------ dGame/dComponents/QuickBuildComponent.cpp | 50 ++++++------ dGame/dComponents/QuickBuildComponent.h | 52 ++++++------- 6 files changed, 100 insertions(+), 115 deletions(-) diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 95bafd8b..7f26ec4b 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -10,7 +10,6 @@ #include "Database.h" #include "eConnectionType.h" #include "eChatInternalMessageType.h" -#include "eGameMasterLevel.h" #include "ChatPackets.h" #include "dConfig.h" @@ -19,14 +18,6 @@ void PlayerContainer::Initialize() { GeneralUtils::TryParse(Game::config->GetValue("max_number_of_friends"), m_MaxNumberOfFriends); } -PlayerContainer::~PlayerContainer() { - m_Players.clear(); -} - -PlayerData::PlayerData() { - gmLevel = eGameMasterLevel::CIVILIAN; -} - TeamData::TeamData() { lootFlag = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1; } diff --git a/dChatServer/PlayerContainer.h b/dChatServer/PlayerContainer.h index f34b1e54..b95f7f19 100644 --- a/dChatServer/PlayerContainer.h +++ b/dChatServer/PlayerContainer.h @@ -1,14 +1,13 @@ #pragma once #include #include "dCommonVars.h" +#include "eGameMasterLevel.h" #include "RakString.h" #include #include "Game.h" #include "dServer.h" #include -enum class eGameMasterLevel : uint8_t; - struct IgnoreData { IgnoreData(const std::string& name, const LWOOBJID& id) : playerName(name), playerId(id) {} inline bool operator==(const std::string& other) const noexcept { @@ -24,7 +23,6 @@ struct IgnoreData { }; struct PlayerData { - PlayerData(); operator bool() const noexcept { return playerID != LWOOBJID_EMPTY; } @@ -45,7 +43,7 @@ struct PlayerData { std::string playerName; std::vector friends; std::vector ignoredPlayers; - eGameMasterLevel gmLevel; + eGameMasterLevel gmLevel = eGameMasterLevel::CIVILIAN; bool isFTP = false; }; @@ -61,8 +59,6 @@ struct TeamData { class PlayerContainer { public: - ~PlayerContainer(); - void Initialize(); void InsertPlayer(Packet* packet); void RemovePlayer(Packet* packet); diff --git a/dCommon/LDFFormat.h b/dCommon/LDFFormat.h index 7bcc91a2..3a4f2ea7 100644 --- a/dCommon/LDFFormat.h +++ b/dCommon/LDFFormat.h @@ -162,7 +162,7 @@ class LDFData: public LDFBaseData { return new LDFData(key, value); } - inline static T Default = {}; + inline static const T Default = {}; }; // LDF Types diff --git a/dCommon/dEnums/dCommonVars.h b/dCommon/dEnums/dCommonVars.h index f4f8fdfb..d871e267 100644 --- a/dCommon/dEnums/dCommonVars.h +++ b/dCommon/dEnums/dCommonVars.h @@ -39,86 +39,84 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate); //=========== TYPEDEFS ========== -typedef int32_t LOT; //!< A LOT -typedef int64_t LWOOBJID; //!< An object ID (should be unsigned actually but ok) -typedef int32_t TSkillID; //!< A skill ID -typedef uint32_t LWOCLONEID; //!< Used for Clone IDs -typedef uint16_t LWOMAPID; //!< Used for Map IDs -typedef uint16_t LWOINSTANCEID; //!< Used for Instance IDs -typedef uint32_t PROPERTYCLONELIST; //!< Used for Property Clone IDs -typedef uint32_t StripId; - -const LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID -const LOT LOT_NULL = -1; //!< A null LOT -const int32_t LOOTTYPE_NONE = 0; //!< No loot type available -const float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority -const uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size -const uint32_t LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID -const uint16_t LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID -const uint16_t LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID -const uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID - -const float PI = 3.14159f; +using LOT = int32_t; //!< A LOT +using LWOOBJID = int64_t; //!< An object ID (should be unsigned actually but ok) +using TSkillID = int32_t; //!< A skill ID +using LWOCLONEID = uint32_t; //!< Used for Clone IDs +using LWOMAPID = uint16_t; //!< Used for Map IDs +using LWOINSTANCEID = uint16_t; //!< Used for Instance IDs +using PROPERTYCLONELIST = uint32_t; //!< Used for Property Clone IDs +using StripId = uint32_t; + +constexpr LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID +constexpr LOT LOT_NULL = -1; //!< A null LOT +constexpr int32_t LOOTTYPE_NONE = 0; //!< No loot type available +constexpr float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority +constexpr uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size +constexpr LWOCLONEID LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID +constexpr LWOINSTANCEID LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID +constexpr LWOMAPID LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID +constexpr uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID + +constexpr float PI = 3.14159f; //============ STRUCTS ============== struct LWOSCENEID { public: - LWOSCENEID() { m_sceneID = -1; m_layerID = 0; } - LWOSCENEID(int sceneID) { m_sceneID = sceneID; m_layerID = 0; } - LWOSCENEID(int sceneID, unsigned int layerID) { m_sceneID = sceneID; m_layerID = layerID; } + constexpr LWOSCENEID() noexcept { m_sceneID = -1; m_layerID = 0; } + constexpr LWOSCENEID(int32_t sceneID) noexcept { m_sceneID = sceneID; m_layerID = 0; } + constexpr LWOSCENEID(int32_t sceneID, uint32_t layerID) noexcept { m_sceneID = sceneID; m_layerID = layerID; } - LWOSCENEID& operator=(const LWOSCENEID& rhs) { m_sceneID = rhs.m_sceneID; m_layerID = rhs.m_layerID; return *this; } - LWOSCENEID& operator=(const int rhs) { m_sceneID = rhs; m_layerID = 0; return *this; } + constexpr LWOSCENEID& operator=(const LWOSCENEID& rhs) noexcept { m_sceneID = rhs.m_sceneID; m_layerID = rhs.m_layerID; return *this; } + constexpr LWOSCENEID& operator=(const int32_t rhs) noexcept { m_sceneID = rhs; m_layerID = 0; return *this; } - bool operator<(const LWOSCENEID& rhs) const { return (m_sceneID < rhs.m_sceneID || (m_sceneID == rhs.m_sceneID && m_layerID < rhs.m_layerID)); } - bool operator<(const int rhs) const { return m_sceneID < rhs; } + constexpr bool operator<(const LWOSCENEID& rhs) const noexcept { return (m_sceneID < rhs.m_sceneID || (m_sceneID == rhs.m_sceneID && m_layerID < rhs.m_layerID)); } + constexpr bool operator<(const int32_t rhs) const noexcept { return m_sceneID < rhs; } - bool operator==(const LWOSCENEID& rhs) const { return (m_sceneID == rhs.m_sceneID && m_layerID == rhs.m_layerID); } - bool operator==(const int rhs) const { return m_sceneID == rhs; } + constexpr bool operator==(const LWOSCENEID& rhs) const noexcept { return (m_sceneID == rhs.m_sceneID && m_layerID == rhs.m_layerID); } + constexpr bool operator==(const int32_t rhs) const noexcept { return m_sceneID == rhs; } - const int GetSceneID() const { return m_sceneID; } - const unsigned int GetLayerID() const { return m_layerID; } + constexpr int32_t GetSceneID() const noexcept { return m_sceneID; } + constexpr uint32_t GetLayerID() const noexcept { return m_layerID; } - void SetSceneID(const int sceneID) { m_sceneID = sceneID; } - void SetLayerID(const unsigned int layerID) { m_layerID = layerID; } + constexpr void SetSceneID(const int32_t sceneID) noexcept { m_sceneID = sceneID; } + constexpr void SetLayerID(const uint32_t layerID) noexcept { m_layerID = layerID; } private: - int m_sceneID; - unsigned int m_layerID; + int32_t m_sceneID; + uint32_t m_layerID; }; struct LWOZONEID { public: - const LWOMAPID& GetMapID() const { return m_MapID; } - const LWOINSTANCEID& GetInstanceID() const { return m_InstanceID; } - const LWOCLONEID& GetCloneID() const { return m_CloneID; } + constexpr const LWOMAPID& GetMapID() const noexcept { return m_MapID; } + constexpr const LWOINSTANCEID& GetInstanceID() const noexcept { return m_InstanceID; } + constexpr const LWOCLONEID& GetCloneID() const noexcept { return m_CloneID; } //In order: def constr, constr, assign op - LWOZONEID() { m_MapID = LWOMAPID_INVALID; m_InstanceID = LWOINSTANCEID_INVALID; m_CloneID = LWOCLONEID_INVALID; } - LWOZONEID(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) { m_MapID = mapID; m_InstanceID = instanceID; m_CloneID = cloneID; } - LWOZONEID(const LWOZONEID& replacement) { *this = replacement; } + constexpr LWOZONEID() noexcept = default; + constexpr LWOZONEID(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) noexcept { m_MapID = mapID; m_InstanceID = instanceID; m_CloneID = cloneID; } + constexpr LWOZONEID(const LWOZONEID& replacement) noexcept { *this = replacement; } private: - LWOMAPID m_MapID; //1000 for VE, 1100 for AG, etc... - LWOINSTANCEID m_InstanceID; //Instances host the same world, but on a different dWorld process. - LWOCLONEID m_CloneID; //To differentiate between "your property" and "my property". Always 0 for non-prop worlds. + LWOMAPID m_MapID = LWOMAPID_INVALID; //1000 for VE, 1100 for AG, etc... + LWOINSTANCEID m_InstanceID = LWOINSTANCEID_INVALID; //Instances host the same world, but on a different dWorld process. + LWOCLONEID m_CloneID = LWOCLONEID_INVALID; //To differentiate between "your property" and "my property". Always 0 for non-prop worlds. }; -const LWOSCENEID LWOSCENEID_INVALID = -1; +constexpr LWOSCENEID LWOSCENEID_INVALID = -1; struct LWONameValue { uint32_t length = 0; //!< The length of the name std::u16string name; //!< The name - LWONameValue(void) {} + LWONameValue() = default; LWONameValue(const std::u16string& name) { this->name = name; this->length = static_cast(name.length()); } - - ~LWONameValue(void) {} }; struct FriendData { diff --git a/dGame/dComponents/QuickBuildComponent.cpp b/dGame/dComponents/QuickBuildComponent.cpp index 1e745d8a..e770757f 100644 --- a/dGame/dComponents/QuickBuildComponent.cpp +++ b/dGame/dComponents/QuickBuildComponent.cpp @@ -23,7 +23,7 @@ #include "CppScripts.h" -QuickBuildComponent::QuickBuildComponent(Entity* entity) : Component(entity) { +QuickBuildComponent::QuickBuildComponent(Entity* const entity) : Component{ entity } { std::u16string checkPreconditions = entity->GetVar(u"CheckPrecondition"); if (!checkPreconditions.empty()) { @@ -284,51 +284,51 @@ void QuickBuildComponent::DespawnActivator() { } } -Entity* QuickBuildComponent::GetActivator() { +Entity* QuickBuildComponent::GetActivator() const { return Game::entityManager->GetEntity(m_ActivatorId); } -NiPoint3 QuickBuildComponent::GetActivatorPosition() { +NiPoint3 QuickBuildComponent::GetActivatorPosition() const noexcept { return m_ActivatorPosition; } -float QuickBuildComponent::GetResetTime() { +float QuickBuildComponent::GetResetTime() const noexcept { return m_ResetTime; } -float QuickBuildComponent::GetCompleteTime() { +float QuickBuildComponent::GetCompleteTime() const noexcept { return m_CompleteTime; } -int QuickBuildComponent::GetTakeImagination() { +int QuickBuildComponent::GetTakeImagination() const noexcept { return m_TakeImagination; } -bool QuickBuildComponent::GetInterruptible() { +bool QuickBuildComponent::GetInterruptible() const noexcept { return m_Interruptible; } -bool QuickBuildComponent::GetSelfActivator() { +bool QuickBuildComponent::GetSelfActivator() const noexcept { return m_SelfActivator; } -std::vector QuickBuildComponent::GetCustomModules() { +std::vector QuickBuildComponent::GetCustomModules() const noexcept { return m_CustomModules; } -int QuickBuildComponent::GetActivityId() { +int QuickBuildComponent::GetActivityId() const noexcept { return m_ActivityId; } -int QuickBuildComponent::GetPostImaginationCost() { +int QuickBuildComponent::GetPostImaginationCost() const noexcept { return m_PostImaginationCost; } -float QuickBuildComponent::GetTimeBeforeSmash() { +float QuickBuildComponent::GetTimeBeforeSmash() const noexcept { return m_TimeBeforeSmash; } -eQuickBuildState QuickBuildComponent::GetState() { +eQuickBuildState QuickBuildComponent::GetState() const noexcept { return m_State; } @@ -338,19 +338,19 @@ Entity* QuickBuildComponent::GetBuilder() const { return builder; } -bool QuickBuildComponent::GetRepositionPlayer() const { +bool QuickBuildComponent::GetRepositionPlayer() const noexcept { return m_RepositionPlayer; } -void QuickBuildComponent::SetActivatorPosition(NiPoint3 value) { +void QuickBuildComponent::SetActivatorPosition(NiPoint3 value) noexcept { m_ActivatorPosition = value; } -void QuickBuildComponent::SetResetTime(float value) { +void QuickBuildComponent::SetResetTime(float value) noexcept { m_ResetTime = value; } -void QuickBuildComponent::SetCompleteTime(float value) { +void QuickBuildComponent::SetCompleteTime(float value) noexcept { if (value < 0) { m_CompleteTime = 4.5f; } else { @@ -358,31 +358,31 @@ void QuickBuildComponent::SetCompleteTime(float value) { } } -void QuickBuildComponent::SetTakeImagination(int value) { +void QuickBuildComponent::SetTakeImagination(int value) noexcept { m_TakeImagination = value; } -void QuickBuildComponent::SetInterruptible(bool value) { +void QuickBuildComponent::SetInterruptible(bool value) noexcept { m_Interruptible = value; } -void QuickBuildComponent::SetSelfActivator(bool value) { +void QuickBuildComponent::SetSelfActivator(bool value) noexcept { m_SelfActivator = value; } -void QuickBuildComponent::SetCustomModules(std::vector value) { +void QuickBuildComponent::SetCustomModules(std::vector value) noexcept { m_CustomModules = value; } -void QuickBuildComponent::SetActivityId(int value) { +void QuickBuildComponent::SetActivityId(int value) noexcept { m_ActivityId = value; } -void QuickBuildComponent::SetPostImaginationCost(int value) { +void QuickBuildComponent::SetPostImaginationCost(int value) noexcept { m_PostImaginationCost = value; } -void QuickBuildComponent::SetTimeBeforeSmash(float value) { +void QuickBuildComponent::SetTimeBeforeSmash(float value) noexcept { if (value < 0) { m_TimeBeforeSmash = 10.0f; } else { @@ -390,7 +390,7 @@ void QuickBuildComponent::SetTimeBeforeSmash(float value) { } } -void QuickBuildComponent::SetRepositionPlayer(bool value) { +void QuickBuildComponent::SetRepositionPlayer(bool value) noexcept { m_RepositionPlayer = value; } diff --git a/dGame/dComponents/QuickBuildComponent.h b/dGame/dComponents/QuickBuildComponent.h index d989bc51..f15ef67a 100644 --- a/dGame/dComponents/QuickBuildComponent.h +++ b/dGame/dComponents/QuickBuildComponent.h @@ -24,7 +24,7 @@ class QuickBuildComponent final : public Component { public: static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD; - QuickBuildComponent(Entity* entity); + QuickBuildComponent(Entity* const entity); ~QuickBuildComponent() override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; @@ -50,148 +50,148 @@ class QuickBuildComponent final : public Component { * Returns the entity that acts as the activator for this quickbuild * @return the entity that acts as the activator for this quickbuild */ - Entity* GetActivator(); + [[nodiscard]] Entity* GetActivator() const; /** * Returns the spawn position of the activator for this quickbuild, if any * @return the spawn position of the activator for this quickbuild, if any */ - NiPoint3 GetActivatorPosition(); + [[nodiscard]] NiPoint3 GetActivatorPosition() const noexcept; /** * Sets the spawn position for the activator of this quickbuild * @param value the spawn position to set for the activator */ - void SetActivatorPosition(NiPoint3 value); + void SetActivatorPosition(NiPoint3 value) noexcept; /** * Returns the time it takes for the quickbuild to reset after being built * @return the time it takes for the quickbuild to reset after being built */ - float GetResetTime(); + [[nodiscard]] float GetResetTime() const noexcept; /** * Sets the time it takes for the quickbuild to reset after being built * @param value the reset time to set */ - void SetResetTime(float value); + void SetResetTime(float value) noexcept; /** * Returns the time it takes to complete the quickbuild * @return the time it takes to complete the quickbuild */ - float GetCompleteTime(); + [[nodiscard]] float GetCompleteTime() const noexcept; /** * Sets the time it takes to complete the quickbuild * @param value the completion time to set */ - void SetCompleteTime(float value); + void SetCompleteTime(float value) noexcept; /** * Returns the imagination that's taken when completing the quickbuild * @return the imagination that's taken when completing the quickbuild */ - int GetTakeImagination(); + [[nodiscard]] int GetTakeImagination() const noexcept; /** * Sets the imagination that's taken when completing the quickbuild * @param value the imagination deduction to set */ - void SetTakeImagination(int value); + void SetTakeImagination(int value) noexcept; /** * Returns if the quickbuild can be interrupted, currently unused * @return if the quickbuild can be interrupted */ - bool GetInterruptible(); + [[nodiscard]] bool GetInterruptible() const noexcept; /** * Sets whether or not the quickbuild can be interrupted, currently unused * @param value true if the quickbuild may be interrupted, false otherwise */ - void SetInterruptible(bool value); + void SetInterruptible(bool value) noexcept; /** * Returns whether or not this entity contains a built-in activator * @return whether or not this entity contains a built-in activator */ - bool GetSelfActivator(); + [[nodiscard]] bool GetSelfActivator() const noexcept; /** * Sets whether or not this entity contains a built-in activator. If set to false this will spawn activators on * each new quickbuild. * @param value whether or not this entity contains a built-in activator */ - void SetSelfActivator(bool value); + void SetSelfActivator(bool value) noexcept; /** * Currently unused */ - std::vector GetCustomModules(); + [[nodiscard]] std::vector GetCustomModules() const noexcept; /** * Currently unused */ - void SetCustomModules(std::vector value); + void SetCustomModules(std::vector value) noexcept; /** * Returns the activity ID for participating in this quickbuild * @return the activity ID for participating in this quickbuild */ - int GetActivityId(); + [[nodiscard]] int GetActivityId() const noexcept; /** * Sets the activity ID for participating in this quickbuild * @param value the activity ID to set */ - void SetActivityId(int value); + void SetActivityId(int value) noexcept; /** * Currently unused */ - int GetPostImaginationCost(); + [[nodiscard]] int GetPostImaginationCost() const noexcept; /** * Currently unused */ - void SetPostImaginationCost(int value); + void SetPostImaginationCost(int value) noexcept; /** * Returns the time it takes for an incomplete quickbuild to be smashed automatically * @return the time it takes for an incomplete quickbuild to be smashed automatically */ - float GetTimeBeforeSmash(); + [[nodiscard]] float GetTimeBeforeSmash() const noexcept; /** * Sets the time it takes for an incomplete quickbuild to be smashed automatically * @param value the time to set */ - void SetTimeBeforeSmash(float value); + void SetTimeBeforeSmash(float value) noexcept; /** * Returns the current quickbuild state * @return the current quickbuild state */ - eQuickBuildState GetState(); + [[nodiscard]] eQuickBuildState GetState() const noexcept; /** * Returns the player that is currently building this quickbuild * @return the player that is currently building this quickbuild */ - Entity* GetBuilder() const; + [[nodiscard]] Entity* GetBuilder() const; /** * Returns whether or not the player is repositioned when initiating the quickbuild * @return whether or not the player is repositioned when initiating the quickbuild */ - bool GetRepositionPlayer() const; + [[nodiscard]] bool GetRepositionPlayer() const noexcept; /** * Sets whether or not the player is repositioned when initiating the quickbuild * @param value whether or not the player is repositioned when initiating the quickbuild */ - void SetRepositionPlayer(bool value); + void SetRepositionPlayer(bool value) noexcept; /** * Adds a callback that is called when the quickbuild is completed From 04bd106dfab27eab852c1dabdfb34e90e6570d0a Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 3 Feb 2024 02:25:08 -0600 Subject: [PATCH 02/12] const correctness and cstdint type usage --- dGame/dComponents/QuickBuildComponent.cpp | 48 ++++++++++---------- dGame/dComponents/QuickBuildComponent.h | 54 +++++++++++------------ 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/dGame/dComponents/QuickBuildComponent.cpp b/dGame/dComponents/QuickBuildComponent.cpp index e770757f..e665d6d1 100644 --- a/dGame/dComponents/QuickBuildComponent.cpp +++ b/dGame/dComponents/QuickBuildComponent.cpp @@ -109,7 +109,7 @@ void QuickBuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIni m_StateDirty = false; } -void QuickBuildComponent::Update(float deltaTime) { +void QuickBuildComponent::Update(const float deltaTime) { m_Activator = GetActivator(); // Serialize the quickbuild every so often, fixes the odd bug where the quickbuild is not buildable @@ -240,7 +240,7 @@ void QuickBuildComponent::Update(float deltaTime) { } } -void QuickBuildComponent::OnUse(Entity* originator) { +void QuickBuildComponent::OnUse(Entity* const originator) { if (GetBuilder() != nullptr || m_State == eQuickBuildState::COMPLETED) { return; } @@ -300,7 +300,7 @@ float QuickBuildComponent::GetCompleteTime() const noexcept { return m_CompleteTime; } -int QuickBuildComponent::GetTakeImagination() const noexcept { +int32_t QuickBuildComponent::GetTakeImagination() const noexcept { return m_TakeImagination; } @@ -312,15 +312,15 @@ bool QuickBuildComponent::GetSelfActivator() const noexcept { return m_SelfActivator; } -std::vector QuickBuildComponent::GetCustomModules() const noexcept { +std::vector QuickBuildComponent::GetCustomModules() const noexcept { return m_CustomModules; } -int QuickBuildComponent::GetActivityId() const noexcept { +int32_t QuickBuildComponent::GetActivityId() const noexcept { return m_ActivityId; } -int QuickBuildComponent::GetPostImaginationCost() const noexcept { +int32_t QuickBuildComponent::GetPostImaginationCost() const noexcept { return m_PostImaginationCost; } @@ -333,7 +333,7 @@ eQuickBuildState QuickBuildComponent::GetState() const noexcept { } Entity* QuickBuildComponent::GetBuilder() const { - auto* builder = Game::entityManager->GetEntity(m_Builder); + auto* const builder = Game::entityManager->GetEntity(m_Builder); return builder; } @@ -342,15 +342,15 @@ bool QuickBuildComponent::GetRepositionPlayer() const noexcept { return m_RepositionPlayer; } -void QuickBuildComponent::SetActivatorPosition(NiPoint3 value) noexcept { +void QuickBuildComponent::SetActivatorPosition(const NiPoint3& value) noexcept { m_ActivatorPosition = value; } -void QuickBuildComponent::SetResetTime(float value) noexcept { +void QuickBuildComponent::SetResetTime(const float value) noexcept { m_ResetTime = value; } -void QuickBuildComponent::SetCompleteTime(float value) noexcept { +void QuickBuildComponent::SetCompleteTime(const float value) noexcept { if (value < 0) { m_CompleteTime = 4.5f; } else { @@ -358,31 +358,31 @@ void QuickBuildComponent::SetCompleteTime(float value) noexcept { } } -void QuickBuildComponent::SetTakeImagination(int value) noexcept { +void QuickBuildComponent::SetTakeImagination(const int32_t value) noexcept { m_TakeImagination = value; } -void QuickBuildComponent::SetInterruptible(bool value) noexcept { +void QuickBuildComponent::SetInterruptible(const bool value) noexcept { m_Interruptible = value; } -void QuickBuildComponent::SetSelfActivator(bool value) noexcept { +void QuickBuildComponent::SetSelfActivator(const bool value) noexcept { m_SelfActivator = value; } -void QuickBuildComponent::SetCustomModules(std::vector value) noexcept { +void QuickBuildComponent::SetCustomModules(const std::vector& value) noexcept { m_CustomModules = value; } -void QuickBuildComponent::SetActivityId(int value) noexcept { +void QuickBuildComponent::SetActivityId(const int32_t value) noexcept { m_ActivityId = value; } -void QuickBuildComponent::SetPostImaginationCost(int value) noexcept { +void QuickBuildComponent::SetPostImaginationCost(const int32_t value) noexcept { m_PostImaginationCost = value; } -void QuickBuildComponent::SetTimeBeforeSmash(float value) noexcept { +void QuickBuildComponent::SetTimeBeforeSmash(const float value) noexcept { if (value < 0) { m_TimeBeforeSmash = 10.0f; } else { @@ -390,11 +390,11 @@ void QuickBuildComponent::SetTimeBeforeSmash(float value) noexcept { } } -void QuickBuildComponent::SetRepositionPlayer(bool value) noexcept { +void QuickBuildComponent::SetRepositionPlayer(const bool value) noexcept { m_RepositionPlayer = value; } -void QuickBuildComponent::StartQuickBuild(Entity* user) { +void QuickBuildComponent::StartQuickBuild(Entity* const user) { if (m_State == eQuickBuildState::OPEN || m_State == eQuickBuildState::COMPLETED || m_State == eQuickBuildState::INCOMPLETE) { m_Builder = user->GetObjectID(); @@ -427,7 +427,7 @@ void QuickBuildComponent::StartQuickBuild(Entity* user) { } } -void QuickBuildComponent::CompleteQuickBuild(Entity* user) { +void QuickBuildComponent::CompleteQuickBuild(Entity* const user) { if (user == nullptr) { return; } @@ -519,7 +519,7 @@ void QuickBuildComponent::CompleteQuickBuild(Entity* user) { RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f); } -void QuickBuildComponent::ResetQuickBuild(bool failed) { +void QuickBuildComponent::ResetQuickBuild(const bool failed) { Entity* builder = GetBuilder(); if (m_State == eQuickBuildState::BUILDING && builder) { @@ -554,7 +554,7 @@ void QuickBuildComponent::ResetQuickBuild(bool failed) { } } -void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason failReason, bool skipChecks) { +void QuickBuildComponent::CancelQuickBuild(Entity* const entity, const eQuickBuildFailReason failReason, const bool skipChecks) { if (m_State != eQuickBuildState::COMPLETED || skipChecks) { m_Builder = LWOOBJID_EMPTY; @@ -582,9 +582,7 @@ void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason Game::entityManager->SerializeEntity(m_Parent); } - if (entity == nullptr) { - return; - } + if (!entity) return; CharacterComponent* characterComponent = entity->GetComponent(); if (characterComponent) { diff --git a/dGame/dComponents/QuickBuildComponent.h b/dGame/dComponents/QuickBuildComponent.h index f15ef67a..a25bdddd 100644 --- a/dGame/dComponents/QuickBuildComponent.h +++ b/dGame/dComponents/QuickBuildComponent.h @@ -28,13 +28,13 @@ class QuickBuildComponent final : public Component { ~QuickBuildComponent() override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; - void Update(float deltaTime) override; + void Update(const float deltaTime) override; /** * Handles a OnUse event from some entity, initiating the quick build * @param originator the entity that triggered the event */ - void OnUse(Entity* originator) override; + void OnUse(Entity* const originator) override; /** * Spawns the activator that can be used to initiate the quickbuild @@ -62,7 +62,7 @@ class QuickBuildComponent final : public Component { * Sets the spawn position for the activator of this quickbuild * @param value the spawn position to set for the activator */ - void SetActivatorPosition(NiPoint3 value) noexcept; + void SetActivatorPosition(const NiPoint3& value) noexcept; /** * Returns the time it takes for the quickbuild to reset after being built @@ -74,7 +74,7 @@ class QuickBuildComponent final : public Component { * Sets the time it takes for the quickbuild to reset after being built * @param value the reset time to set */ - void SetResetTime(float value) noexcept; + void SetResetTime(const float value) noexcept; /** * Returns the time it takes to complete the quickbuild @@ -86,19 +86,19 @@ class QuickBuildComponent final : public Component { * Sets the time it takes to complete the quickbuild * @param value the completion time to set */ - void SetCompleteTime(float value) noexcept; + void SetCompleteTime(const float value) noexcept; /** * Returns the imagination that's taken when completing the quickbuild * @return the imagination that's taken when completing the quickbuild */ - [[nodiscard]] int GetTakeImagination() const noexcept; + [[nodiscard]] int32_t GetTakeImagination() const noexcept; /** * Sets the imagination that's taken when completing the quickbuild * @param value the imagination deduction to set */ - void SetTakeImagination(int value) noexcept; + void SetTakeImagination(const int32_t value) noexcept; /** * Returns if the quickbuild can be interrupted, currently unused @@ -110,7 +110,7 @@ class QuickBuildComponent final : public Component { * Sets whether or not the quickbuild can be interrupted, currently unused * @param value true if the quickbuild may be interrupted, false otherwise */ - void SetInterruptible(bool value) noexcept; + void SetInterruptible(const bool value) noexcept; /** * Returns whether or not this entity contains a built-in activator @@ -123,39 +123,39 @@ class QuickBuildComponent final : public Component { * each new quickbuild. * @param value whether or not this entity contains a built-in activator */ - void SetSelfActivator(bool value) noexcept; + void SetSelfActivator(const bool value) noexcept; /** * Currently unused */ - [[nodiscard]] std::vector GetCustomModules() const noexcept; + [[nodiscard]] std::vector GetCustomModules() const noexcept; /** * Currently unused */ - void SetCustomModules(std::vector value) noexcept; + void SetCustomModules(const std::vector& value) noexcept; /** * Returns the activity ID for participating in this quickbuild * @return the activity ID for participating in this quickbuild */ - [[nodiscard]] int GetActivityId() const noexcept; + [[nodiscard]] int32_t GetActivityId() const noexcept; /** * Sets the activity ID for participating in this quickbuild * @param value the activity ID to set */ - void SetActivityId(int value) noexcept; + void SetActivityId(const int32_t value) noexcept; /** * Currently unused */ - [[nodiscard]] int GetPostImaginationCost() const noexcept; + [[nodiscard]] int32_t GetPostImaginationCost() const noexcept; /** * Currently unused */ - void SetPostImaginationCost(int value) noexcept; + void SetPostImaginationCost(const int32_t value) noexcept; /** * Returns the time it takes for an incomplete quickbuild to be smashed automatically @@ -167,7 +167,7 @@ class QuickBuildComponent final : public Component { * Sets the time it takes for an incomplete quickbuild to be smashed automatically * @param value the time to set */ - void SetTimeBeforeSmash(float value) noexcept; + void SetTimeBeforeSmash(const float value) noexcept; /** * Returns the current quickbuild state @@ -191,7 +191,7 @@ class QuickBuildComponent final : public Component { * Sets whether or not the player is repositioned when initiating the quickbuild * @param value whether or not the player is repositioned when initiating the quickbuild */ - void SetRepositionPlayer(bool value) noexcept; + void SetRepositionPlayer(const bool value) noexcept; /** * Adds a callback that is called when the quickbuild is completed @@ -209,7 +209,7 @@ class QuickBuildComponent final : public Component { * Resets the quickbuild * @param failed whether or not the player failed to complete the quickbuild, triggers an extra animation */ - void ResetQuickBuild(bool failed); + void ResetQuickBuild(const bool failed); /** * Cancels the quickbuild if it wasn't completed @@ -217,7 +217,7 @@ class QuickBuildComponent final : public Component { * @param failReason the reason the quickbuild was cancelled * @param skipChecks whether or not to skip the check for the quickbuild not being completed */ - void CancelQuickBuild(Entity* builder, eQuickBuildFailReason failReason, bool skipChecks = false); + void CancelQuickBuild(Entity* const builder, const eQuickBuildFailReason failReason, const bool skipChecks = false); private: /** * Whether or not the quickbuild state has been changed since we last serialized it. @@ -287,7 +287,7 @@ class QuickBuildComponent final : public Component { /** * The imagination that's deducted when completing the quickbuild */ - int m_TakeImagination = 0; + int32_t m_TakeImagination = 0; /** * Currently unused @@ -302,17 +302,17 @@ class QuickBuildComponent final : public Component { /** * Currently unused */ - std::vector m_CustomModules{}; + std::vector m_CustomModules{}; /** * The activity ID that players partake in when doing this quickbuild */ - int m_ActivityId = 0; + int32_t m_ActivityId = 0; /** * Currently unused */ - int m_PostImaginationCost = 0; + int32_t m_PostImaginationCost = 0; /** * The time it takes for the quickbuild to reset when it's not completed yet @@ -327,7 +327,7 @@ class QuickBuildComponent final : public Component { /** * The amount of imagination that was drained when building this quickbuild */ - int m_DrainedImagination = 0; + int32_t m_DrainedImagination = 0; /** * Whether to reposition the player or not when building @@ -337,7 +337,7 @@ class QuickBuildComponent final : public Component { /** * Currently unused */ - float m_SoftTimer = 0; + int32_t m_SoftTimer = 0; /** * The ID of the entity that's currently building the quickbuild @@ -353,13 +353,13 @@ class QuickBuildComponent final : public Component { * Starts the quickbuild for a certain entity * @param user the entity to start the quickbuild */ - void StartQuickBuild(Entity* user); + void StartQuickBuild(Entity* const user); /** * Completes the quickbuild for an entity, dropping loot and despawning the activator * @param user the entity that completed the quickbuild */ - void CompleteQuickBuild(Entity* user); + void CompleteQuickBuild(Entity* const user); }; #endif // QUICKBUILDCOMPONENT_H From 93a60683e97bdc8f90a48ff7f36c6c82c3a022a8 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 3 Feb 2024 02:28:53 -0600 Subject: [PATCH 03/12] removing a few "== nullptr" --- dGame/dComponents/QuickBuildComponent.cpp | 4 +--- dScripts/02_server/Map/AM/AmDropshipComputer.cpp | 12 +++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/dGame/dComponents/QuickBuildComponent.cpp b/dGame/dComponents/QuickBuildComponent.cpp index e665d6d1..b38ba4d9 100644 --- a/dGame/dComponents/QuickBuildComponent.cpp +++ b/dGame/dComponents/QuickBuildComponent.cpp @@ -428,9 +428,7 @@ void QuickBuildComponent::StartQuickBuild(Entity* const user) { } void QuickBuildComponent::CompleteQuickBuild(Entity* const user) { - if (user == nullptr) { - return; - } + if (!user) return; auto* characterComponent = user->GetComponent(); if (characterComponent != nullptr) { diff --git a/dScripts/02_server/Map/AM/AmDropshipComputer.cpp b/dScripts/02_server/Map/AM/AmDropshipComputer.cpp index 60b750cf..822ff595 100644 --- a/dScripts/02_server/Map/AM/AmDropshipComputer.cpp +++ b/dScripts/02_server/Map/AM/AmDropshipComputer.cpp @@ -12,16 +12,12 @@ void AmDropshipComputer::OnStartup(Entity* self) { void AmDropshipComputer::OnUse(Entity* self, Entity* user) { auto* quickBuildComponent = self->GetComponent(); - if (quickBuildComponent == nullptr || quickBuildComponent->GetState() != eQuickBuildState::COMPLETED) { - return; - } + if (!quickBuildComponent || quickBuildComponent->GetState() != eQuickBuildState::COMPLETED) return; auto* missionComponent = user->GetComponent(); auto* inventoryComponent = user->GetComponent(); - if (missionComponent == nullptr || inventoryComponent == nullptr) { - return; - } + if (!missionComponent || !inventoryComponent) return; if (inventoryComponent->GetLotCount(m_NexusTalonDataCard) != 0 || missionComponent->GetMission(979)->GetMissionState() == eMissionState::COMPLETE) { return; @@ -72,9 +68,7 @@ void AmDropshipComputer::OnDie(Entity* self, Entity* killer) { void AmDropshipComputer::OnTimerDone(Entity* self, std::string timerName) { auto* quickBuildComponent = self->GetComponent(); - if (quickBuildComponent == nullptr) { - return; - } + if (!quickBuildComponent) return; if (timerName == "reset" && quickBuildComponent->GetState() == eQuickBuildState::OPEN) { self->Smash(self->GetObjectID(), eKillType::SILENT); From 0f21003238df4657c9838073319991e8daaa8016 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 3 Feb 2024 17:40:33 -0600 Subject: [PATCH 04/12] amf constexpr, const-correctness, and attrib tagging --- dCommon/Amf3.h | 111 +++++++++--------- .../AddStripMessage.cpp | 2 +- .../ControlBehaviorMessages/AddStripMessage.h | 2 +- .../BehaviorMessageBase.cpp | 16 ++- .../BehaviorMessageBase.h | 12 +- 5 files changed, 71 insertions(+), 72 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 967313c7..6a7ec5b4 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -31,54 +31,55 @@ enum class eAmf : uint8_t { class AMFBaseValue { public: - virtual eAmf GetValueType() { return eAmf::Undefined; }; - AMFBaseValue() {}; - virtual ~AMFBaseValue() {}; + [[nodiscard]] constexpr virtual eAmf GetValueType() const noexcept { return eAmf::Undefined; }; + constexpr AMFBaseValue() noexcept = default; + constexpr virtual ~AMFBaseValue() noexcept = default; }; template class AMFValue : public AMFBaseValue { public: - AMFValue() {}; - AMFValue(ValueType value) { SetValue(value); }; - virtual ~AMFValue() override {}; + AMFValue() = default; + AMFValue(const ValueType value) { m_Data = value; }; + virtual ~AMFValue() override = default; - eAmf GetValueType() override { return eAmf::Undefined; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Undefined; }; + + [[nodiscard]] const ValueType& GetValue() const { return m_Data; }; + void SetValue(const ValueType value) { m_Data = value; }; - const ValueType& GetValue() { return data; }; - void SetValue(ValueType value) { data = value; }; protected: - ValueType data; + ValueType m_Data; }; // As a string this is much easier to write and read from a BitStream. template<> class AMFValue : public AMFBaseValue { public: - AMFValue() {}; - AMFValue(const char* value) { SetValue(std::string(value)); }; - virtual ~AMFValue() override {}; + AMFValue() = default; + AMFValue(const char* value) { m_Data = value; }; + virtual ~AMFValue() override = default; - eAmf GetValueType() override { return eAmf::String; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::String; }; - const std::string& GetValue() { return data; }; - void SetValue(std::string value) { data = value; }; + [[nodiscard]] const std::string& GetValue() const { return m_Data; }; + void SetValue(const std::string& value) { m_Data = value; }; protected: - std::string data; + std::string m_Data; }; -typedef AMFValue AMFNullValue; -typedef AMFValue AMFBoolValue; -typedef AMFValue AMFIntValue; -typedef AMFValue AMFStringValue; -typedef AMFValue AMFDoubleValue; +using AMFNullValue = AMFValue; +using AMFBoolValue = AMFValue; +using AMFIntValue = AMFValue; +using AMFStringValue = AMFValue; +using AMFDoubleValue = AMFValue; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Null; }; -template<> inline eAmf AMFValue::GetValueType() { return this->data ? eAmf::True : eAmf::False; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Integer; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Integer; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::String; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Double; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; }; /** * The AMFArrayValue object holds 2 types of lists: @@ -89,12 +90,11 @@ template<> inline eAmf AMFValue::GetValueType() { return eAmf::Double; } * and are not to be deleted by a caller. */ class AMFArrayValue : public AMFBaseValue { - - typedef std::unordered_map AMFAssociative; - typedef std::vector AMFDense; + using AMFAssociative = std::unordered_map; + using AMFDense = std::vector; public: - eAmf GetValueType() override { return eAmf::Array; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Array; }; ~AMFArrayValue() override { for (auto valueToDelete : GetDense()) { @@ -114,12 +114,12 @@ class AMFArrayValue : public AMFBaseValue { /** * Returns the Associative portion of the object */ - inline AMFAssociative& GetAssociative() { return this->associative; }; + [[nodiscard]] inline AMFAssociative& GetAssociative() noexcept { return this->associative; }; /** * Returns the dense portion of the object */ - inline AMFDense& GetDense() { return this->dense; }; + [[nodiscard]] inline AMFDense& GetDense() noexcept { return this->dense; }; /** * Inserts an AMFValue into the associative portion with the given key. @@ -135,8 +135,8 @@ class AMFArrayValue : public AMFBaseValue { * @return The inserted element if the type matched, * or nullptr if a key existed and was not the same type */ - template - std::pair*, bool> Insert(const std::string& key, ValueType value) { + template + [[maybe_unused]] std::pair*, bool> Insert(const std::string& key, const ValueType value) { auto element = associative.find(key); AMFValue* val = nullptr; bool found = true; @@ -151,7 +151,7 @@ class AMFArrayValue : public AMFBaseValue { }; // Associates an array with a string key - std::pair Insert(const std::string& key) { + [[maybe_unused]] std::pair Insert(const std::string& key) { auto element = associative.find(key); AMFArrayValue* val = nullptr; bool found = true; @@ -166,7 +166,7 @@ class AMFArrayValue : public AMFBaseValue { }; // Associates an array with an integer key - std::pair Insert(const uint32_t& index) { + [[maybe_unused]] std::pair Insert(const size_t index) { AMFArrayValue* val = nullptr; bool inserted = false; if (index >= dense.size()) { @@ -188,8 +188,8 @@ class AMFArrayValue : public AMFBaseValue { * @return The inserted element, or nullptr if the type did not match * what was at the index. */ - template - std::pair*, bool> Insert(const uint32_t& index, ValueType value) { + 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()) { @@ -210,7 +210,7 @@ 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* value) { + void Insert(const std::string& key, AMFBaseValue* const value) { auto element = associative.find(key); if (element != associative.end() && element->second) { delete element->second; @@ -229,7 +229,7 @@ class AMFArrayValue : public AMFBaseValue { * @param key The key to associate with the value * @param value The value to insert */ - void Insert(const uint32_t index, AMFBaseValue* value) { + 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); @@ -249,8 +249,8 @@ class AMFArrayValue : public AMFBaseValue { * * @return The inserted pointer, or nullptr should the key already be in use. */ - template - inline AMFValue* Push(ValueType value) { + template + [[maybe_unused]] inline AMFValue* Push(const ValueType value) { return Insert(this->dense.size(), value).first; }; @@ -261,7 +261,7 @@ class AMFArrayValue : public AMFBaseValue { * * @param key The key to remove from the associative portion */ - void Remove(const std::string& key, bool deleteValue = true) { + 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; @@ -272,7 +272,7 @@ class AMFArrayValue : public AMFBaseValue { /** * Pops the last element in the dense portion, deleting it in the process. */ - void Remove(const uint32_t index) { + void Remove(const size_t index) { if (!this->dense.empty() && index < this->dense.size()) { auto itr = this->dense.begin() + index; if (*itr) delete (*itr); @@ -284,7 +284,7 @@ class AMFArrayValue : public AMFBaseValue { if (!this->dense.empty()) Remove(this->dense.size() - 1); } - AMFArrayValue* GetArray(const std::string& key) { + [[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); @@ -292,19 +292,19 @@ class AMFArrayValue : public AMFBaseValue { return nullptr; }; - AMFArrayValue* GetArray(const uint32_t index) { + [[nodiscard]] AMFArrayValue* GetArray(const size_t index) { return index >= this->dense.size() ? nullptr : dynamic_cast(this->dense.at(index)); }; - inline AMFArrayValue* InsertArray(const std::string& key) { + [[maybe_unused]] inline AMFArrayValue* InsertArray(const std::string& key) { return static_cast(Insert(key).first); }; - inline AMFArrayValue* InsertArray(const uint32_t index) { + [[maybe_unused]] inline AMFArrayValue* InsertArray(const size_t index) { return static_cast(Insert(index).first); }; - inline AMFArrayValue* PushArray() { + [[maybe_unused]] inline AMFArrayValue* PushArray() { return static_cast(Insert(this->dense.size()).first); }; @@ -318,7 +318,7 @@ class AMFArrayValue : public AMFBaseValue { * @return The AMFValue */ template - AMFValue* Get(const std::string& key) const { + [[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) : @@ -326,7 +326,7 @@ class AMFArrayValue : public AMFBaseValue { }; // Get from the array but dont cast it - AMFBaseValue* Get(const std::string& key) const { + [[nodiscard]] AMFBaseValue* Get(const std::string& key) const { AMFAssociative::const_iterator it = this->associative.find(key); return it != this->associative.end() ? it->second : nullptr; }; @@ -341,16 +341,17 @@ class AMFArrayValue : public AMFBaseValue { * @return The casted object, or nullptr. */ template - AMFValue* Get(uint32_t index) const { + [[nodiscard]] AMFValue* Get(const size_t index) const { return index < this->dense.size() ? dynamic_cast*>(this->dense.at(index)) : nullptr; }; // Get from the dense but dont cast it - AMFBaseValue* Get(const uint32_t index) const { + [[nodiscard]] AMFBaseValue* Get(const size_t index) const { return index < this->dense.size() ? this->dense.at(index) : nullptr; }; + private: /** * The associative portion. These values are key'd with strings to an AMFValue. diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp index 6f0741dd..ac6e8db7 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp @@ -2,7 +2,7 @@ #include "Action.h" -AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { +AddStripMessage::AddStripMessage(AMFArrayValue* const arguments) : BehaviorMessageBase{ arguments } { actionContext = ActionContext(arguments); position = StripUiPosition(arguments); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h index 5cceb510..2e2bf9a0 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(AMFArrayValue* arguments); + AddStripMessage(AMFArrayValue* const arguments); StripUiPosition GetPosition() const { return position; }; ActionContext GetActionContext() const { return actionContext; }; std::vector GetActionsToAdd() const; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp index cc817cd7..cdffe7fe 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -4,13 +4,13 @@ #include "BehaviorStates.h" #include "dCommonVars.h" -BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) { +BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* const arguments) { behaviorId = GetBehaviorIdFromArgument(arguments); } -int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) { - const auto* key = "BehaviorID"; - auto* behaviorIDValue = arguments->Get(key); +int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* const arguments) { + const char* const key = "BehaviorID"; + const auto* const behaviorIDValue = arguments->Get(key); if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { GeneralUtils::TryParse(behaviorIDValue->GetValue(), behaviorId); @@ -21,11 +21,9 @@ int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) return behaviorId; } -int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) { - auto* actionIndexAmf = arguments->Get(keyName); - if (!actionIndexAmf) { - throw std::invalid_argument("Unable to find actionIndex"); - } +int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* const 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 8a841d7f..f55fde8e 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -15,13 +15,13 @@ enum class BehaviorState : uint32_t; */ class BehaviorMessageBase { public: - static inline int32_t DefaultBehaviorId = -1; - const int32_t GetBehaviorId() const { return behaviorId; }; - bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; - BehaviorMessageBase(AMFArrayValue* arguments); + static constexpr int32_t DefaultBehaviorId = -1; + [[nodiscard]] int32_t GetBehaviorId() const { return behaviorId; }; + [[nodiscard]] bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; + BehaviorMessageBase(AMFArrayValue* const arguments); protected: - int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments); - int32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex"); + [[nodiscard]] int32_t GetBehaviorIdFromArgument(AMFArrayValue* const arguments); + [[nodiscard]] int32_t GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName = "actionIndex") const; int32_t behaviorId = DefaultBehaviorId; }; From a38b061e5f28fc774b500ff5e742126b1b4f4020 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 3 Feb 2024 17:47:43 -0600 Subject: [PATCH 05/12] update to account for feedback --- dChatServer/PlayerContainer.h | 6 ++++-- dGame/dComponents/QuickBuildComponent.cpp | 4 ++-- dGame/dComponents/QuickBuildComponent.h | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dChatServer/PlayerContainer.h b/dChatServer/PlayerContainer.h index b95f7f19..254974bf 100644 --- a/dChatServer/PlayerContainer.h +++ b/dChatServer/PlayerContainer.h @@ -8,8 +8,10 @@ #include "dServer.h" #include +enum class eGameMasterLevel : uint8_t; + struct IgnoreData { - IgnoreData(const std::string& name, const LWOOBJID& id) : playerName(name), playerId(id) {} + IgnoreData(const std::string& name, const LWOOBJID& id) : playerName{ name }, playerId{ id } {} inline bool operator==(const std::string& other) const noexcept { return playerName == other; } @@ -43,7 +45,7 @@ struct PlayerData { std::string playerName; std::vector friends; std::vector ignoredPlayers; - eGameMasterLevel gmLevel = eGameMasterLevel::CIVILIAN; + eGameMasterLevel gmLevel = static_cast(0); bool isFTP = false; }; diff --git a/dGame/dComponents/QuickBuildComponent.cpp b/dGame/dComponents/QuickBuildComponent.cpp index b38ba4d9..69b0c22a 100644 --- a/dGame/dComponents/QuickBuildComponent.cpp +++ b/dGame/dComponents/QuickBuildComponent.cpp @@ -109,7 +109,7 @@ void QuickBuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIni m_StateDirty = false; } -void QuickBuildComponent::Update(const float deltaTime) { +void QuickBuildComponent::Update(float deltaTime) { m_Activator = GetActivator(); // Serialize the quickbuild every so often, fixes the odd bug where the quickbuild is not buildable @@ -240,7 +240,7 @@ void QuickBuildComponent::Update(const float deltaTime) { } } -void QuickBuildComponent::OnUse(Entity* const originator) { +void QuickBuildComponent::OnUse(Entity* originator) { if (GetBuilder() != nullptr || m_State == eQuickBuildState::COMPLETED) { return; } diff --git a/dGame/dComponents/QuickBuildComponent.h b/dGame/dComponents/QuickBuildComponent.h index a25bdddd..556264a8 100644 --- a/dGame/dComponents/QuickBuildComponent.h +++ b/dGame/dComponents/QuickBuildComponent.h @@ -28,13 +28,13 @@ class QuickBuildComponent final : public Component { ~QuickBuildComponent() override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; - void Update(const float deltaTime) override; + void Update(float deltaTime) override; /** * Handles a OnUse event from some entity, initiating the quick build * @param originator the entity that triggered the event */ - void OnUse(Entity* const originator) override; + void OnUse(Entity* originator) override; /** * Spawns the activator that can be used to initiate the quickbuild From 8a2d7ae74c71516400dd5420cf114fec80b90835 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 4 Feb 2024 14:15:38 -0600 Subject: [PATCH 06/12] Fixing accidentally included header and hopefully fixing the MacOS issue too --- dChatServer/PlayerContainer.h | 3 +-- dCommon/Amf3.h | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dChatServer/PlayerContainer.h b/dChatServer/PlayerContainer.h index 254974bf..3f2d783a 100644 --- a/dChatServer/PlayerContainer.h +++ b/dChatServer/PlayerContainer.h @@ -1,7 +1,6 @@ #pragma once #include #include "dCommonVars.h" -#include "eGameMasterLevel.h" #include "RakString.h" #include #include "Game.h" @@ -45,7 +44,7 @@ struct PlayerData { std::string playerName; std::vector friends; std::vector ignoredPlayers; - eGameMasterLevel gmLevel = static_cast(0); + eGameMasterLevel gmLevel = static_cast(0); // CIVILLIAN bool isFTP = false; }; diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 6a7ec5b4..2b8db416 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -68,12 +68,6 @@ class AMFValue : public AMFBaseValue { std::string m_Data; }; -using AMFNullValue = AMFValue; -using AMFBoolValue = AMFValue; -using AMFIntValue = AMFValue; -using AMFStringValue = AMFValue; -using AMFDoubleValue = AMFValue; - template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; }; template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }; template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; @@ -81,6 +75,12 @@ template<> constexpr eAmf AMFValue::GetValueType() const noexcept { re template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; }; template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; }; +using AMFNullValue = AMFValue; +using AMFBoolValue = AMFValue; +using AMFIntValue = AMFValue; +using AMFStringValue = AMFValue; +using AMFDoubleValue = AMFValue; + /** * The AMFArrayValue object holds 2 types of lists: * An associative list where a key maps to a value From 748eb0b64b745921136b6971faec5fba7513cfe7 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 4 Feb 2024 22:58:17 -0600 Subject: [PATCH 07/12] try reordering the amf3 specializations to fix the MacOS issue again --- dCommon/Amf3.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 2b8db416..d84f19a2 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -52,6 +52,13 @@ class AMFValue : public AMFBaseValue { ValueType m_Data; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; }; +template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; }; + // As a string this is much easier to write and read from a BitStream. template<> class AMFValue : public AMFBaseValue { @@ -68,13 +75,6 @@ class AMFValue : public AMFBaseValue { std::string m_Data; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; }; - using AMFNullValue = AMFValue; using AMFBoolValue = AMFValue; using AMFIntValue = AMFValue; From 10adfd70a598495a5725baa2d30499917b6d8fcc Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 9 Feb 2024 00:42:57 -0600 Subject: [PATCH 08/12] Amf3 template class member func instantiation fix --- dCommon/Amf3.h | 86 ++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index d84f19a2..39d27054 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -31,46 +31,58 @@ enum class eAmf : uint8_t { class AMFBaseValue { public: - [[nodiscard]] constexpr virtual eAmf GetValueType() const noexcept { return eAmf::Undefined; }; + [[nodiscard]] constexpr virtual eAmf GetValueType() const noexcept { return eAmf::Undefined; } constexpr AMFBaseValue() noexcept = default; constexpr virtual ~AMFBaseValue() noexcept = default; }; -template +// AMFValue template class instantiations +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 { return eAmf::Undefined; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override; - [[nodiscard]] const ValueType& GetValue() const { return m_Data; }; - void SetValue(const ValueType value) { m_Data = value; }; + [[nodiscard]] const ValueType& GetValue() const { return m_Data; } + void SetValue(const ValueType value) { m_Data = value; } protected: ValueType m_Data; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; }; -template<> constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; }; +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; + +// AMFValue template class member function instantiations +template +[[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Undefined; } + +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; } // As a string this is much easier to write and read from a BitStream. -template<> +template <> class AMFValue : public AMFBaseValue { public: AMFValue() = default; - AMFValue(const char* value) { m_Data = value; }; + AMFValue(const char* value) { m_Data = value; } virtual ~AMFValue() override = default; - [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::String; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::String; } - [[nodiscard]] const std::string& GetValue() const { return m_Data; }; - void SetValue(const std::string& value) { m_Data = value; }; + [[nodiscard]] const std::string& GetValue() const { return m_Data; } + void SetValue(const std::string& value) { m_Data = value; } protected: std::string m_Data; }; @@ -94,7 +106,7 @@ class AMFArrayValue : public AMFBaseValue { using AMFDense = std::vector; public: - [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Array; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Array; } ~AMFArrayValue() override { for (auto valueToDelete : GetDense()) { @@ -109,17 +121,17 @@ class AMFArrayValue : public AMFBaseValue { valueToDelete.second = nullptr; } } - }; + } /** * Returns the Associative portion of the object */ - [[nodiscard]] inline AMFAssociative& GetAssociative() noexcept { return this->associative; }; + [[nodiscard]] inline AMFAssociative& GetAssociative() noexcept { return this->associative; } /** * Returns the dense portion of the object */ - [[nodiscard]] inline AMFDense& GetDense() noexcept { return this->dense; }; + [[nodiscard]] inline AMFDense& GetDense() noexcept { return this->dense; } /** * Inserts an AMFValue into the associative portion with the given key. @@ -148,7 +160,7 @@ class AMFArrayValue : public AMFBaseValue { found = false; } return std::make_pair(val, found); - }; + } // Associates an array with a string key [[maybe_unused]] std::pair Insert(const std::string& key) { @@ -163,7 +175,7 @@ class AMFArrayValue : public AMFBaseValue { found = false; } return std::make_pair(val, found); - }; + } // Associates an array with an integer key [[maybe_unused]] std::pair Insert(const size_t index) { @@ -176,7 +188,7 @@ class AMFArrayValue : public AMFBaseValue { inserted = true; } return std::make_pair(dynamic_cast(dense.at(index)), inserted); - }; + } /** * @brief Inserts an AMFValue into the AMFArray key'd by index. @@ -199,7 +211,7 @@ class AMFArrayValue : public AMFBaseValue { inserted = true; } return std::make_pair(dynamic_cast*>(this->dense.at(index)), inserted); - }; + } /** * Inserts an AMFValue into the associative portion with the given key. @@ -218,7 +230,7 @@ class AMFArrayValue : public AMFBaseValue { } else { associative.insert(std::make_pair(key, value)); } - }; + } /** * Inserts an AMFValue into the associative portion with the given index. @@ -237,7 +249,7 @@ class AMFArrayValue : public AMFBaseValue { dense.resize(index + 1); } dense.at(index) = value; - }; + } /** * Pushes an AMFValue into the back of the dense portion. @@ -252,7 +264,7 @@ class AMFArrayValue : public AMFBaseValue { template [[maybe_unused]] inline AMFValue* Push(const ValueType value) { return Insert(this->dense.size(), value).first; - }; + } /** * Removes the key from the associative portion @@ -290,23 +302,23 @@ class AMFArrayValue : public AMFBaseValue { return dynamic_cast(it->second); } return nullptr; - }; + } [[nodiscard]] AMFArrayValue* GetArray(const size_t index) { return index >= this->dense.size() ? nullptr : dynamic_cast(this->dense.at(index)); - }; + } [[maybe_unused]] inline AMFArrayValue* InsertArray(const std::string& key) { return static_cast(Insert(key).first); - }; + } [[maybe_unused]] inline AMFArrayValue* InsertArray(const size_t index) { return static_cast(Insert(index).first); - }; + } [[maybe_unused]] inline AMFArrayValue* PushArray() { return static_cast(Insert(this->dense.size()).first); - }; + } /** * Gets an AMFValue by the key from the associative portion and converts it @@ -323,13 +335,13 @@ class AMFArrayValue : public AMFBaseValue { return it != this->associative.end() ? 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; - }; + } /** * @brief Get an AMFValue object at a position in the dense portion. @@ -345,12 +357,12 @@ class AMFArrayValue : public AMFBaseValue { return index < this->dense.size() ? dynamic_cast*>(this->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; - }; + } private: /** From 2a625376b6cbe6730c64afffd71f81456b425791 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 9 Feb 2024 00:55:08 -0600 Subject: [PATCH 09/12] try including only on macos --- dCommon/Amf3.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 39d27054..01ac2be6 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -2,6 +2,7 @@ #define __AMF3__H__ #include "dCommonVars.h" +#include "dPlatforms.h" #include "Logger.h" #include "Game.h" @@ -53,12 +54,14 @@ class AMFValue : public AMFBaseValue { ValueType m_Data; }; +#ifdef DARKFLAME_PLATFORM_MACOS template class AMFValue; template class AMFValue; template class AMFValue; template class AMFValue; template class AMFValue; template class AMFValue; +#endif // AMFValue template class member function instantiations template From 4544c6477ebb8aaf15c8e8fbe8d977746e662689 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 9 Feb 2024 14:05:17 -0600 Subject: [PATCH 10/12] Using if constexpr rather than specialization --- dCommon/Amf3.h | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 01ac2be6..31c9fcdf 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -45,7 +45,26 @@ class AMFValue : public AMFBaseValue { AMFValue(const ValueType value) { m_Data = value; } virtual ~AMFValue() override = default; - [[nodiscard]] constexpr eAmf GetValueType() const noexcept override; + // Can be used to determine the type of the AMFValue + template + static constexpr bool is_type = std::disjunction_v...>; + + // Had to use this instead of specialization + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { + if constexpr (is_type) { + return eAmf::Null; + } else if constexpr (is_type) { + return m_Data ? eAmf::True : eAmf::False; + } else if constexpr (is_type) { + return eAmf::Integer; + } else if constexpr (is_type) { + return eAmf::String; + } else if constexpr (is_type) { + return eAmf::Double; + } else { + return eAmf::Undefined; + } + } [[nodiscard]] const ValueType& GetValue() const { return m_Data; } void SetValue(const ValueType value) { m_Data = value; } @@ -54,26 +73,6 @@ class AMFValue : public AMFBaseValue { ValueType m_Data; }; -#ifdef DARKFLAME_PLATFORM_MACOS -template class AMFValue; -template class AMFValue; -template class AMFValue; -template class AMFValue; -template class AMFValue; -template class AMFValue; -#endif - -// AMFValue template class member function instantiations -template -[[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Undefined; } - -template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; } -template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; } -template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } -template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } -template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; } -template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; } - // As a string this is much easier to write and read from a BitStream. template <> class AMFValue : public AMFBaseValue { From 41aecbd33449c510ab4e8abc162beac7b2cc2008 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 9 Feb 2024 15:30:06 -0600 Subject: [PATCH 11/12] Trying a different solution for the instantiation problem --- dCommon/Amf3.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 31c9fcdf..b54ed029 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -45,26 +45,7 @@ class AMFValue : public AMFBaseValue { AMFValue(const ValueType value) { m_Data = value; } virtual ~AMFValue() override = default; - // Can be used to determine the type of the AMFValue - template - static constexpr bool is_type = std::disjunction_v...>; - - // Had to use this instead of specialization - [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { - if constexpr (is_type) { - return eAmf::Null; - } else if constexpr (is_type) { - return m_Data ? eAmf::True : eAmf::False; - } else if constexpr (is_type) { - return eAmf::Integer; - } else if constexpr (is_type) { - return eAmf::String; - } else if constexpr (is_type) { - return eAmf::Double; - } else { - return eAmf::Undefined; - } - } + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override; [[nodiscard]] const ValueType& GetValue() const { return m_Data; } void SetValue(const ValueType value) { m_Data = value; } @@ -73,6 +54,25 @@ class AMFValue : public AMFBaseValue { ValueType m_Data; }; +// Explicit template class instantiations +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; + +// AMFValue template class member function instantiations +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; } + +template +[[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Undefined; } + // As a string this is much easier to write and read from a BitStream. template <> class AMFValue : public AMFBaseValue { From 7132ad2d3666c3192ac50641b082548ea9d3eac6 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 10 Feb 2024 00:11:13 -0600 Subject: [PATCH 12/12] Remove #include "dPlatforms.h" --- dCommon/Amf3.h | 1 - 1 file changed, 1 deletion(-) diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index b54ed029..dbafba1f 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -2,7 +2,6 @@ #define __AMF3__H__ #include "dCommonVars.h" -#include "dPlatforms.h" #include "Logger.h" #include "Game.h"