From 15ea380d3988bd79471c38a2e7524f7a3934bdb1 Mon Sep 17 00:00:00 2001 From: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com> Date: Tue, 26 Oct 2021 10:43:27 -0700 Subject: [PATCH] Post integration fixes and additional changes for entity aliases in spawnables. Signed-off-by: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com> --- .../AzFramework/Spawnable/Spawnable.cpp | 43 ++++++------------- .../AzFramework/Spawnable/Spawnable.h | 17 +++----- .../Spawnable/SpawnableEntitiesManager.cpp | 7 --- 3 files changed, 18 insertions(+), 49 deletions(-) diff --git a/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.cpp b/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.cpp index 92728a4575..48662fae99 100644 --- a/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.cpp +++ b/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.cpp @@ -6,6 +6,7 @@ * */ +#include #include #include #include @@ -138,9 +139,9 @@ namespace AzFramework Optimize(); AZ_Assert( - m_owner.m_lockState == LockState::Locked, "Attempting to unlock a spawnable that's not in the locked state (%i).", - m_owner.m_lockState.load()); - m_owner.m_lockState = LockState::Unlocked; + m_owner.m_shareState == ShareState::ReadWrite, "Attempting to unlock a spawnable that's not in the locked state (%i).", + m_owner.m_shareState.load()); + m_owner.m_shareState = ShareState::NotShared; } } @@ -397,9 +398,9 @@ namespace AzFramework if (HasLock()) { AZ_Assert( - m_owner.m_lockState < 0, "Attempting to unlock a read shared spawnable that was not in a read shared mode (%i).", - m_owner.m_lockState.load()); - m_owner.m_lockState++; + m_owner.m_shareState <= ShareState::Read, "Attempting to unlock a read shared spawnable that was not in a read shared mode (%i).", + m_owner.m_shareState.load()); + m_owner.m_shareState++; } } @@ -471,15 +472,15 @@ namespace AzFramework auto Spawnable::TryGetAliasesConst() const -> EntityAliasConstVisitor { - int32_t expected = LockState::Unlocked; + int32_t expected = ShareState::NotShared; do { // Try to set the lock to a negative number to indicate a shared read. - if (m_lockState.compare_exchange_strong(expected, expected - 1)) + if (m_shareState.compare_exchange_strong(expected, expected - 1)) { return EntityAliasConstVisitor(*this, &m_entityAliases); } - // as long as the value is negative keep trying to get a shared read lock. + // as long as the value is negative or not shared then keep trying to get a shared read lock. } while (expected <= 0); return EntityAliasConstVisitor(*this, nullptr); } @@ -491,9 +492,9 @@ namespace AzFramework auto Spawnable::TryGetAliases() -> EntityAliasVisitor { - int32_t expected = LockState::Unlocked; - return m_lockState.compare_exchange_strong(expected, LockState::Locked) ? EntityAliasVisitor(*this, &m_entityAliases) - : EntityAliasVisitor(*this, nullptr); + int32_t expected = ShareState::NotShared; + return m_shareState.compare_exchange_strong(expected, ShareState::ReadWrite) ? EntityAliasVisitor(*this, &m_entityAliases) + : EntityAliasVisitor(*this, nullptr); } bool Spawnable::IsEmpty() const @@ -501,24 +502,6 @@ namespace AzFramework return m_entities.empty(); } - bool Spawnable::IsPermanentlyLocked() const - { - return m_lockState == LockState::PermanentLock; - } - - bool Spawnable::LockPermanently() - { - if (!IsPermanentlyLocked()) - { - int32_t expected = LockState::Unlocked; - return m_lockState.compare_exchange_strong(expected, LockState::PermanentLock); - } - else - { - return true; - } - } - SpawnableMetaData& Spawnable::GetMetaData() { return m_metaData; diff --git a/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.h b/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.h index 05ae10e580..4fb1f84b6f 100644 --- a/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.h +++ b/Code/Framework/AzFramework/AzFramework/Spawnable/Spawnable.h @@ -41,11 +41,11 @@ namespace AzFramework //!< maintaining a valid component list. }; - enum LockState : int32_t + enum ShareState : int32_t { - Unlocked, - Locked, - PermanentLock + Read = -1, + NotShared = 0, + ReadWrite = 1 }; //! An entity alias redirects the spawning of an entity to another entity, possibly in another spawnable. @@ -183,13 +183,6 @@ namespace AzFramework EntityAliasVisitor TryGetAliases(); bool IsEmpty() const; - //! Whether or not the spawnable is permanently locked. If so then parts of the spawnable can no longer be modified. - bool IsPermanentlyLocked() const; - //! Permanently locks access to parts of the spawnable from being modified. - //! @return True if the spawnable could be locked. If false is returned another operation is still making modifications. In this case - //! call this again at a later point in time. - bool LockPermanently(); - SpawnableMetaData& GetMetaData(); const SpawnableMetaData& GetMetaData() const; @@ -204,6 +197,6 @@ namespace AzFramework // Includes both direct and nested entities of the prefab. EntityList m_entities; - mutable AZStd::atomic m_lockState{ LockState::Unlocked }; + mutable AZStd::atomic m_shareState{ ShareState::NotShared }; }; } // namespace AzFramework diff --git a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp index 0ac80c3ed6..22918b7173 100644 --- a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp +++ b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp @@ -857,13 +857,6 @@ namespace AzFramework ticket.m_currentRequestId++; return CommandResult::Executed; } - else - { - AZ_Assert( - ticket.m_spawnable->IsPermanentlyLocked(), - "An request to UpdateEntityAliasTypes on the Spawnables Entities Manager was processed on a spawnable that's permanently " - "locked."); - } } return CommandResult::Requeue; }