Post integration fixes and additional changes for entity aliases in spawnables.
Signed-off-by: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Asset/AssetSerializer.h>
|
||||
#include <AzCore/RTTI/ReflectContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/std/sort.h>
|
||||
@@ -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;
|
||||
|
||||
@@ -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<int32_t> m_lockState{ LockState::Unlocked };
|
||||
mutable AZStd::atomic<int32_t> m_shareState{ ShareState::NotShared };
|
||||
};
|
||||
} // namespace AzFramework
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user