Merge pull request #3014 from aws-lumberyard-dev/burelc/removeMCoreAlignedArray
Replace `MCore::AlignedArray` with `AZStd::vector`
This commit is contained in:
@@ -24,10 +24,6 @@ namespace EMotionFX
|
||||
m_actorInstance = nullptr;
|
||||
m_actor = nullptr;
|
||||
m_skeleton = nullptr;
|
||||
m_localSpaceTransforms.SetMemoryCategory(EMFX_MEMCATEGORY_ANIMGRAPH_POSE);
|
||||
m_modelSpaceTransforms.SetMemoryCategory(EMFX_MEMCATEGORY_ANIMGRAPH_POSE);
|
||||
m_flags.SetMemoryCategory(EMFX_MEMCATEGORY_ANIMGRAPH_POSE);
|
||||
m_morphWeights.SetMemoryCategory(EMFX_MEMCATEGORY_ANIMGRAPH_POSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,10 +51,10 @@ namespace EMotionFX
|
||||
|
||||
// resize the buffers
|
||||
const size_t numTransforms = m_actor->GetSkeleton()->GetNumNodes();
|
||||
m_localSpaceTransforms.ResizeFast(numTransforms);
|
||||
m_modelSpaceTransforms.ResizeFast(numTransforms);
|
||||
m_flags.ResizeFast(numTransforms);
|
||||
m_morphWeights.ResizeFast(actorInstance->GetMorphSetupInstance()->GetNumMorphTargets());
|
||||
m_localSpaceTransforms.resize_no_construct(numTransforms);
|
||||
m_modelSpaceTransforms.resize_no_construct(numTransforms);
|
||||
m_flags.resize_no_construct(numTransforms);
|
||||
m_morphWeights.resize_no_construct(actorInstance->GetMorphSetupInstance()->GetNumMorphTargets());
|
||||
|
||||
for (const auto& poseDataItem : m_poseDatas)
|
||||
{
|
||||
@@ -79,11 +75,11 @@ namespace EMotionFX
|
||||
|
||||
// resize the buffers
|
||||
const size_t numTransforms = m_actor->GetSkeleton()->GetNumNodes();
|
||||
m_localSpaceTransforms.ResizeFast(numTransforms);
|
||||
m_modelSpaceTransforms.ResizeFast(numTransforms);
|
||||
m_localSpaceTransforms.resize_no_construct(numTransforms);
|
||||
m_modelSpaceTransforms.resize_no_construct(numTransforms);
|
||||
|
||||
const size_t oldSize = m_flags.GetLength();
|
||||
m_flags.ResizeFast(numTransforms);
|
||||
const size_t oldSize = m_flags.size();
|
||||
m_flags.resize_no_construct(numTransforms);
|
||||
if (oldSize < numTransforms && clearAllFlags == false)
|
||||
{
|
||||
for (size_t i = oldSize; i < numTransforms; ++i)
|
||||
@@ -93,7 +89,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
MorphSetup* morphSetup = m_actor->GetMorphSetup(0);
|
||||
m_morphWeights.ResizeFast((morphSetup) ? morphSetup->GetNumMorphTargets() : 0);
|
||||
m_morphWeights.resize_no_construct((morphSetup) ? morphSetup->GetNumMorphTargets() : 0);
|
||||
|
||||
for (const auto& poseDataItem : m_poseDatas)
|
||||
{
|
||||
@@ -111,11 +107,11 @@ namespace EMotionFX
|
||||
void Pose::SetNumTransforms(size_t numTransforms)
|
||||
{
|
||||
// resize the buffers
|
||||
m_localSpaceTransforms.ResizeFast(numTransforms);
|
||||
m_modelSpaceTransforms.ResizeFast(numTransforms);
|
||||
m_localSpaceTransforms.resize_no_construct(numTransforms);
|
||||
m_modelSpaceTransforms.resize_no_construct(numTransforms);
|
||||
|
||||
const size_t oldSize = m_flags.GetLength();
|
||||
m_flags.ResizeFast(numTransforms);
|
||||
const size_t oldSize = m_flags.size();
|
||||
m_flags.resize_no_construct(numTransforms);
|
||||
|
||||
for (size_t i = oldSize; i < numTransforms; ++i)
|
||||
{
|
||||
@@ -127,10 +123,18 @@ namespace EMotionFX
|
||||
|
||||
void Pose::Clear(bool clearMem)
|
||||
{
|
||||
m_localSpaceTransforms.Clear(clearMem);
|
||||
m_modelSpaceTransforms.Clear(clearMem);
|
||||
m_flags.Clear(clearMem);
|
||||
m_morphWeights.Clear(clearMem);
|
||||
const auto clear = [clearMem](auto& vector)
|
||||
{
|
||||
vector.clear();
|
||||
if (clearMem)
|
||||
{
|
||||
vector.shrink_to_fit();
|
||||
}
|
||||
};
|
||||
clear(m_localSpaceTransforms);
|
||||
clear(m_modelSpaceTransforms);
|
||||
clear(m_flags);
|
||||
clear(m_morphWeights);
|
||||
|
||||
ClearPoseDatas();
|
||||
}
|
||||
@@ -139,7 +143,7 @@ namespace EMotionFX
|
||||
// clear the pose flags
|
||||
void Pose::ClearFlags(uint8 newFlags)
|
||||
{
|
||||
MCore::MemSet((uint8*)m_flags.GetPtr(), newFlags, sizeof(uint8) * m_flags.GetLength());
|
||||
MCore::MemSet((uint8*)m_flags.data(), newFlags, sizeof(uint8) * m_flags.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -398,30 +402,27 @@ namespace EMotionFX
|
||||
// invalidate all local transforms
|
||||
void Pose::InvalidateAllLocalSpaceTransforms()
|
||||
{
|
||||
const size_t numFlags = m_flags.GetLength();
|
||||
for (size_t i = 0; i < numFlags; ++i)
|
||||
for (uint8& flag : m_flags)
|
||||
{
|
||||
m_flags[i] &= ~FLAG_LOCALTRANSFORMREADY;
|
||||
flag &= ~FLAG_LOCALTRANSFORMREADY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Pose::InvalidateAllModelSpaceTransforms()
|
||||
{
|
||||
const size_t numFlags = m_flags.GetLength();
|
||||
for (size_t i = 0; i < numFlags; ++i)
|
||||
for (uint8& flag : m_flags)
|
||||
{
|
||||
m_flags[i] &= ~FLAG_MODELTRANSFORMREADY;
|
||||
flag &= ~FLAG_MODELTRANSFORMREADY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Pose::InvalidateAllLocalAndModelSpaceTransforms()
|
||||
{
|
||||
const size_t numFlags = m_flags.GetLength();
|
||||
for (size_t i = 0; i < numFlags; ++i)
|
||||
for (uint8& flag : m_flags)
|
||||
{
|
||||
m_flags[i] &= ~(FLAG_LOCALTRANSFORMREADY | FLAG_MODELTRANSFORMREADY);
|
||||
flag &= ~(FLAG_LOCALTRANSFORMREADY | FLAG_MODELTRANSFORMREADY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,8 +470,8 @@ namespace EMotionFX
|
||||
// make sure the number of transforms are equal
|
||||
MCORE_ASSERT(destPose);
|
||||
MCORE_ASSERT(outPose);
|
||||
MCORE_ASSERT(m_localSpaceTransforms.GetLength() == destPose->m_localSpaceTransforms.GetLength());
|
||||
MCORE_ASSERT(m_localSpaceTransforms.GetLength() == outPose->m_localSpaceTransforms.GetLength());
|
||||
MCORE_ASSERT(m_localSpaceTransforms.size() == destPose->m_localSpaceTransforms.size());
|
||||
MCORE_ASSERT(m_localSpaceTransforms.size() == outPose->m_localSpaceTransforms.size());
|
||||
MCORE_ASSERT(instance->GetIsMixing() == false);
|
||||
|
||||
// get some motion instance properties which we use to decide the optimized blending routine
|
||||
@@ -509,7 +510,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -533,7 +534,7 @@ namespace EMotionFX
|
||||
outPose->InvalidateAllModelSpaceTransforms();
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -550,8 +551,8 @@ namespace EMotionFX
|
||||
// make sure the number of transforms are equal
|
||||
MCORE_ASSERT(destPose);
|
||||
MCORE_ASSERT(outPose);
|
||||
MCORE_ASSERT(m_localSpaceTransforms.GetLength() == destPose->m_localSpaceTransforms.GetLength());
|
||||
MCORE_ASSERT(m_localSpaceTransforms.GetLength() == outPose->m_localSpaceTransforms.GetLength());
|
||||
MCORE_ASSERT(m_localSpaceTransforms.size() == destPose->m_localSpaceTransforms.size());
|
||||
MCORE_ASSERT(m_localSpaceTransforms.size() == outPose->m_localSpaceTransforms.size());
|
||||
MCORE_ASSERT(instance->GetIsMixing());
|
||||
|
||||
const bool additive = (instance->GetBlendMode() == BLENDMODE_ADDITIVE);
|
||||
@@ -564,7 +565,7 @@ namespace EMotionFX
|
||||
Transform result;
|
||||
|
||||
const MotionLinkData* motionLinkData = instance->GetMotion()->GetMotionData()->FindMotionLinkData(actorInstance->GetActor());
|
||||
AZ_Assert(motionLinkData->GetJointDataLinks().size() == m_localSpaceTransforms.GetLength(), "Expecting there to be the same amount of motion links as pose transforms.");
|
||||
AZ_Assert(motionLinkData->GetJointDataLinks().size() == m_localSpaceTransforms.size(), "Expecting there to be the same amount of motion links as pose transforms.");
|
||||
|
||||
// blend all transforms
|
||||
if (!additive)
|
||||
@@ -589,7 +590,7 @@ namespace EMotionFX
|
||||
outPose->InvalidateAllModelSpaceTransforms();
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -619,7 +620,7 @@ namespace EMotionFX
|
||||
outPose->InvalidateAllModelSpaceTransforms();
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -647,10 +648,10 @@ namespace EMotionFX
|
||||
return;
|
||||
}
|
||||
|
||||
m_modelSpaceTransforms.MemCopyContentsFrom(sourcePose->m_modelSpaceTransforms);
|
||||
m_localSpaceTransforms.MemCopyContentsFrom(sourcePose->m_localSpaceTransforms);
|
||||
m_flags.MemCopyContentsFrom(sourcePose->m_flags);
|
||||
m_morphWeights.MemCopyContentsFrom(sourcePose->m_morphWeights);
|
||||
m_modelSpaceTransforms = sourcePose->m_modelSpaceTransforms;
|
||||
m_localSpaceTransforms = sourcePose->m_localSpaceTransforms;
|
||||
m_flags = sourcePose->m_flags;
|
||||
m_morphWeights = sourcePose->m_morphWeights;
|
||||
|
||||
// Deactivate pose datas from the current pose that are not in the source that we copy from.
|
||||
// This is needed in order to prevent leftover pose datas and to avoid de-/allocations.
|
||||
@@ -727,11 +728,11 @@ namespace EMotionFX
|
||||
m_localSpaceTransforms[nodeNr].Zero();
|
||||
}
|
||||
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
for (float& morphWeight : m_morphWeights)
|
||||
{
|
||||
m_morphWeights[i] = 0.0f;
|
||||
morphWeight = 0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -742,11 +743,11 @@ namespace EMotionFX
|
||||
m_localSpaceTransforms[i].Zero();
|
||||
}
|
||||
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actor->GetMorphSetup(0)->GetNumMorphTargets() == numMorphs);
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
for (float& morphWeight : m_morphWeights)
|
||||
{
|
||||
m_morphWeights[i] = 0.0f;
|
||||
morphWeight = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +796,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == other->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -814,7 +815,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actor->GetMorphSetup(0)->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == other->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -841,7 +842,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -865,7 +866,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actor->GetMorphSetup(0)->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -886,7 +887,7 @@ namespace EMotionFX
|
||||
|
||||
Pose& Pose::MakeRelativeTo(const Pose& other)
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == other.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == other.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
const size_t numNodes = m_actorInstance->GetNumEnabledNodes();
|
||||
@@ -899,7 +900,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t numNodes = m_localSpaceTransforms.GetLength();
|
||||
const size_t numNodes = m_localSpaceTransforms.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
Transform& transform = const_cast<Transform&>(GetLocalSpaceTransform(i));
|
||||
@@ -907,7 +908,7 @@ namespace EMotionFX
|
||||
}
|
||||
}
|
||||
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
AZ_Assert(numMorphs == other.GetNumMorphWeights(), "Number of morphs in the pose doesn't match the number of morphs inside the provided input pose.");
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
{
|
||||
@@ -921,7 +922,7 @@ namespace EMotionFX
|
||||
|
||||
Pose& Pose::ApplyAdditive(const Pose& additivePose, float weight)
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == additivePose.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == additivePose.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
AZ_Assert(weight > -MCore::Math::epsilon && weight < (1 + MCore::Math::epsilon), "Expected weight to be between 0..1");
|
||||
@@ -939,7 +940,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == additivePose.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == additivePose.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
const size_t numNodes = m_actorInstance->GetNumEnabledNodes();
|
||||
@@ -959,7 +960,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t numNodes = m_localSpaceTransforms.GetLength();
|
||||
const size_t numNodes = m_localSpaceTransforms.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
Transform& transform = const_cast<Transform&>(GetLocalSpaceTransform(i));
|
||||
@@ -974,7 +975,7 @@ namespace EMotionFX
|
||||
}
|
||||
}
|
||||
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
AZ_Assert(numMorphs == additivePose.GetNumMorphWeights(), "Number of morphs in the pose doesn't match the number of morphs inside the provided input pose.");
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
{
|
||||
@@ -989,7 +990,7 @@ namespace EMotionFX
|
||||
|
||||
Pose& Pose::ApplyAdditive(const Pose& additivePose)
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == additivePose.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == additivePose.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
const size_t numNodes = m_actorInstance->GetNumEnabledNodes();
|
||||
@@ -1009,7 +1010,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t numNodes = m_localSpaceTransforms.GetLength();
|
||||
const size_t numNodes = m_localSpaceTransforms.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
Transform& transform = const_cast<Transform&>(GetLocalSpaceTransform(i));
|
||||
@@ -1024,7 +1025,7 @@ namespace EMotionFX
|
||||
}
|
||||
}
|
||||
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
AZ_Assert(numMorphs == additivePose.GetNumMorphWeights(), "Number of morphs in the pose doesn't match the number of morphs inside the provided input pose.");
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
{
|
||||
@@ -1038,7 +1039,7 @@ namespace EMotionFX
|
||||
|
||||
Pose& Pose::MakeAdditive(const Pose& refPose)
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == refPose.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == refPose.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
const size_t numNodes = m_actorInstance->GetNumEnabledNodes();
|
||||
@@ -1057,7 +1058,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t numNodes = m_localSpaceTransforms.GetLength();
|
||||
const size_t numNodes = m_localSpaceTransforms.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
Transform& transform = const_cast<Transform&>(GetLocalSpaceTransform(i));
|
||||
@@ -1071,7 +1072,7 @@ namespace EMotionFX
|
||||
}
|
||||
}
|
||||
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
AZ_Assert(numMorphs == refPose.GetNumMorphWeights(), "Number of morphs in the pose doesn't match the number of morphs inside the provided input pose.");
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
{
|
||||
@@ -1101,7 +1102,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actorInstance->GetMorphSetupInstance()->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -1123,7 +1124,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// blend the morph weights
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
const size_t numMorphs = m_morphWeights.size();
|
||||
MCORE_ASSERT(m_actor->GetMorphSetup(0)->GetNumMorphTargets() == numMorphs);
|
||||
MCORE_ASSERT(numMorphs == destPose->GetNumMorphWeights());
|
||||
for (size_t i = 0; i < numMorphs; ++i)
|
||||
@@ -1274,23 +1275,19 @@ namespace EMotionFX
|
||||
// zero all morph weights
|
||||
void Pose::ZeroMorphWeights()
|
||||
{
|
||||
const size_t numMorphs = m_morphWeights.GetLength();
|
||||
for (size_t m = 0; m < numMorphs; ++m)
|
||||
{
|
||||
m_morphWeights[m] = 0.0f;
|
||||
}
|
||||
AZStd::fill(begin(m_morphWeights), end(m_morphWeights), 0.0f);
|
||||
}
|
||||
|
||||
|
||||
void Pose::ResizeNumMorphs(size_t numMorphTargets)
|
||||
{
|
||||
m_morphWeights.Resize(numMorphTargets);
|
||||
m_morphWeights.resize(numMorphTargets);
|
||||
}
|
||||
|
||||
|
||||
Pose& Pose::PreMultiply(const Pose& other)
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == other.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == other.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
const size_t numNodes = m_actorInstance->GetNumEnabledNodes();
|
||||
@@ -1304,7 +1301,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t numNodes = m_localSpaceTransforms.GetLength();
|
||||
const size_t numNodes = m_localSpaceTransforms.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
Transform& transform = const_cast<Transform&>(GetLocalSpaceTransform(i));
|
||||
@@ -1320,7 +1317,7 @@ namespace EMotionFX
|
||||
|
||||
Pose& Pose::Multiply(const Pose& other)
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == other.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == other.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
const size_t numNodes = m_actorInstance->GetNumEnabledNodes();
|
||||
@@ -1333,7 +1330,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t numNodes = m_localSpaceTransforms.GetLength();
|
||||
const size_t numNodes = m_localSpaceTransforms.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
Transform& transform = const_cast<Transform&>(GetLocalSpaceTransform(i));
|
||||
@@ -1348,7 +1345,7 @@ namespace EMotionFX
|
||||
|
||||
Pose& Pose::MultiplyInverse(const Pose& other)
|
||||
{
|
||||
AZ_Assert(m_localSpaceTransforms.GetLength() == other.m_localSpaceTransforms.GetLength(), "Poses must be of the same size");
|
||||
AZ_Assert(m_localSpaceTransforms.size() == other.m_localSpaceTransforms.size(), "Poses must be of the same size");
|
||||
if (m_actorInstance)
|
||||
{
|
||||
const size_t numNodes = m_actorInstance->GetNumEnabledNodes();
|
||||
@@ -1363,7 +1360,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t numNodes = m_localSpaceTransforms.GetLength();
|
||||
const size_t numNodes = m_localSpaceTransforms.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
Transform& transform = const_cast<Transform&>(GetLocalSpaceTransform(i));
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
#include <MCore/Source/AlignedArray.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <EMotionFX/Source/PoseData.h>
|
||||
#include <EMotionFX/Source/Transform.h>
|
||||
|
||||
@@ -98,9 +98,9 @@ namespace EMotionFX
|
||||
|
||||
Transform CalcTrajectoryTransform() const;
|
||||
|
||||
MCORE_INLINE const Transform* GetLocalSpaceTransforms() const { return m_localSpaceTransforms.GetReadPtr(); }
|
||||
MCORE_INLINE const Transform* GetModelSpaceTransforms() const { return m_modelSpaceTransforms.GetReadPtr(); }
|
||||
MCORE_INLINE size_t GetNumTransforms() const { return m_localSpaceTransforms.GetLength(); }
|
||||
MCORE_INLINE const Transform* GetLocalSpaceTransforms() const { return m_localSpaceTransforms.data(); }
|
||||
MCORE_INLINE const Transform* GetModelSpaceTransforms() const { return m_modelSpaceTransforms.data(); }
|
||||
MCORE_INLINE size_t GetNumTransforms() const { return m_localSpaceTransforms.size(); }
|
||||
MCORE_INLINE const ActorInstance* GetActorInstance() const { return m_actorInstance; }
|
||||
MCORE_INLINE const Actor* GetActor() const { return m_actor; }
|
||||
MCORE_INLINE const Skeleton* GetSkeleton() const { return m_skeleton; }
|
||||
@@ -116,7 +116,7 @@ namespace EMotionFX
|
||||
|
||||
MCORE_INLINE void SetMorphWeight(size_t index, float weight) { m_morphWeights[index] = weight; }
|
||||
MCORE_INLINE float GetMorphWeight(size_t index) const { return m_morphWeights[index]; }
|
||||
MCORE_INLINE size_t GetNumMorphWeights() const { return m_morphWeights.GetLength(); }
|
||||
MCORE_INLINE size_t GetNumMorphWeights() const { return m_morphWeights.size(); }
|
||||
void ResizeNumMorphs(size_t numMorphTargets);
|
||||
|
||||
/**
|
||||
@@ -193,11 +193,11 @@ namespace EMotionFX
|
||||
T* GetAndPreparePoseData(ActorInstance* linkToActorInstance) { return azdynamic_cast<T*>(GetAndPreparePoseData(azrtti_typeid<T>(), linkToActorInstance)); }
|
||||
|
||||
private:
|
||||
mutable MCore::AlignedArray<Transform, 16> m_localSpaceTransforms;
|
||||
mutable MCore::AlignedArray<Transform, 16> m_modelSpaceTransforms;
|
||||
mutable MCore::AlignedArray<uint8, 16> m_flags;
|
||||
mutable AZStd::vector<Transform> m_localSpaceTransforms;
|
||||
mutable AZStd::vector<Transform> m_modelSpaceTransforms;
|
||||
mutable AZStd::vector<uint8> m_flags;
|
||||
AZStd::unordered_map<AZ::TypeId, AZStd::unique_ptr<PoseData> > m_poseDatas;
|
||||
MCore::AlignedArray<float, 16> m_morphWeights; /**< The morph target weights. */
|
||||
AZStd::vector<float> m_morphWeights; /**< The morph target weights. */
|
||||
const ActorInstance* m_actorInstance;
|
||||
const Actor* m_actor;
|
||||
const Skeleton* m_skeleton;
|
||||
|
||||
@@ -1,783 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "StandardHeaders.h"
|
||||
#include "MCoreSystem.h"
|
||||
#include "Algorithms.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
|
||||
namespace MCore
|
||||
{
|
||||
/**
|
||||
* Dynamic array template, using aligned memory allocations.
|
||||
* This array template allows dynamic sizing. It also stores the memory category of the data.
|
||||
* It can theoretically store 18446744073709551614 items (maximum size_t value - 1 for the invalid index).
|
||||
*/
|
||||
template <typename T, uint32 alignment>
|
||||
class AlignedArray
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* The memory block ID, used inside the memory manager.
|
||||
* This will make all arrays remain in the same memory blocks, which is more efficient in a lot of cases.
|
||||
* However, array data can still remain in other blocks.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
MEMORYBLOCK_ID = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Initializes the array so it's empty and has no memory allocated.
|
||||
*/
|
||||
MCORE_INLINE AlignedArray()
|
||||
: m_data(nullptr)
|
||||
, m_length(0)
|
||||
, m_maxLength(0)
|
||||
, m_memCategory(MCORE_MEMCATEGORY_ARRAY) {}
|
||||
|
||||
/**
|
||||
* Constructor which creates a given number of elements.
|
||||
* @param elems The element data.
|
||||
* @param num The number of elements in 'elems'.
|
||||
* @param memCategory The memory category the array is in.
|
||||
*/
|
||||
MCORE_INLINE explicit AlignedArray(T* elems, size_t num, uint16 memCategory = MCORE_MEMCATEGORY_ARRAY)
|
||||
: m_length(num)
|
||||
, m_maxLength(AllocSize(num))
|
||||
, m_memCategory(memCategory)
|
||||
{
|
||||
m_data = (T*)AlignedAllocate(m_maxLength * sizeof(T), alignment, m_memCategory, MEMORYBLOCK_ID, MCORE_FILE, MCORE_LINE);
|
||||
for (size_t i = 0; i < m_length; ++i)
|
||||
{
|
||||
Construct(i, elems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which initializes the length of the array on a given number.
|
||||
* @param initSize The number of ellements to allocate space for.
|
||||
* @param memCategory The memory category the array is in.
|
||||
*/
|
||||
MCORE_INLINE explicit AlignedArray(size_t initSize, uint16 memCategory = MCORE_MEMCATEGORY_ARRAY)
|
||||
: m_data(nullptr)
|
||||
, m_length(initSize)
|
||||
, m_maxLength(initSize)
|
||||
, m_memCategory(memCategory)
|
||||
{
|
||||
if (m_maxLength > 0)
|
||||
{
|
||||
m_data = (T*)AlignedAllocate(m_maxLength * sizeof(T), alignment, m_memCategory, MEMORYBLOCK_ID, MCORE_FILE, MCORE_LINE);
|
||||
for (size_t i = 0; i < m_length; ++i)
|
||||
{
|
||||
Construct(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param other The other array to copy the data from.
|
||||
*/
|
||||
AlignedArray(const AlignedArray<T, alignment>& other)
|
||||
: m_data(nullptr)
|
||||
, m_length(0)
|
||||
, m_maxLength(0)
|
||||
, m_memCategory(MCORE_MEMCATEGORY_ARRAY) { *this = other; }
|
||||
|
||||
/**
|
||||
* Move constructor.
|
||||
* @param other The array to move the data from.
|
||||
*/
|
||||
AlignedArray(AlignedArray<T, alignment>&& other) { m_data = other.m_data; m_length = other.m_length; m_maxLength = other.m_maxLength; m_memCategory = other.m_memCategory; other.m_data = nullptr; other.m_length = 0; other.m_maxLength = 0; }
|
||||
|
||||
/**
|
||||
* Destructor. Deletes all entry data.
|
||||
* However, if you store pointers to objects, these objects won't be deleted.<br>
|
||||
* Example:<br>
|
||||
* <pre>
|
||||
* AlignedArray< Object*, 16 > data;
|
||||
* for (size_t i=0; i<10; i++)
|
||||
* data.Add( new Object() );
|
||||
* </pre>
|
||||
* Now when the array 'data' will be destructed, it will NOT free up the memory of the integers which you allocated by hand, using new.
|
||||
* In order to free up this memory, you can do this:
|
||||
* <pre>
|
||||
* for (size_t i=0; i<data.GetLength(); ++i)
|
||||
* delete data[i];
|
||||
* data.Clear();
|
||||
* </pre>
|
||||
*/
|
||||
~AlignedArray()
|
||||
{
|
||||
for (size_t i = 0; i < m_length; ++i)
|
||||
{
|
||||
Destruct(i);
|
||||
}
|
||||
if (m_data)
|
||||
{
|
||||
AlignedFree(m_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the memory category ID where allocations made by this array belong to.
|
||||
* On default the memory category is 0, which means unknown.
|
||||
* @result The memory category ID.
|
||||
*/
|
||||
MCORE_INLINE uint16 GetMemoryCategory() const { return m_memCategory; }
|
||||
|
||||
/**
|
||||
* Set the memory category ID, where allocations made by this array will belong to.
|
||||
* On default, after construction of the array, the category ID is 0, which means it is unknown.
|
||||
* @param categoryID The memory category ID where this arrays allocations belong to.
|
||||
*/
|
||||
MCORE_INLINE void SetMemoryCategory(uint16 categoryID) { m_memCategory = categoryID; }
|
||||
|
||||
/**
|
||||
* Get a pointer to the first element.
|
||||
* @result A pointer to the first element.
|
||||
*/
|
||||
MCORE_INLINE T* GetPtr() { return m_data; }
|
||||
|
||||
/**
|
||||
* Get a pointer to the first element.
|
||||
* @result A pointer to the first element.
|
||||
*/
|
||||
MCORE_INLINE T* GetPtr() const { return m_data; }
|
||||
|
||||
/**
|
||||
* Get a given item/element.
|
||||
* @param pos The item/element number.
|
||||
* @result A reference to the element.
|
||||
*/
|
||||
MCORE_INLINE T& GetItem(size_t pos) { return m_data[pos]; }
|
||||
|
||||
/**
|
||||
* Get the first element.
|
||||
* @result A reference to the first element.
|
||||
*/
|
||||
MCORE_INLINE T& GetFirst() { return m_data[0]; }
|
||||
|
||||
/**
|
||||
* Get the last element.
|
||||
* @result A reference to the last element.
|
||||
*/
|
||||
MCORE_INLINE T& GetLast() { return m_data[m_length - 1]; }
|
||||
|
||||
/**
|
||||
* Get a read-only pointer to the first element.
|
||||
* @result A read-only pointer to the first element.
|
||||
*/
|
||||
MCORE_INLINE const T* GetReadPtr() const { return m_data; }
|
||||
|
||||
/**
|
||||
* Get a read-only reference to a given element number.
|
||||
* @param pos The element number.
|
||||
* @result A read-only reference to the given element.
|
||||
*/
|
||||
MCORE_INLINE const T& GetItem(size_t pos) const { return m_data[pos]; }
|
||||
|
||||
/**
|
||||
* Get a read-only reference to the first element.
|
||||
* @result A read-only reference to the first element.
|
||||
*/
|
||||
MCORE_INLINE const T& GetFirst() const { return m_data[0]; }
|
||||
|
||||
/**
|
||||
* Get a read-only reference to the last element.
|
||||
* @result A read-only reference to the last element.
|
||||
*/
|
||||
MCORE_INLINE const T& GetLast() const { return m_data[m_length - 1]; }
|
||||
|
||||
/**
|
||||
* Check if the array is empty or not.
|
||||
* @result Returns true when there are no elements in the array, otherwise false is returned.
|
||||
*/
|
||||
MCORE_INLINE bool GetIsEmpty() const { return (m_length == 0); }
|
||||
|
||||
/**
|
||||
* Checks if the passed index is in the array's range.
|
||||
* @param index The index to check.
|
||||
* @return True if the passed index is valid, false if not.
|
||||
*/
|
||||
MCORE_INLINE bool GetIsValidIndex(size_t index) const { return (index < m_length); }
|
||||
|
||||
/**
|
||||
* Get the number of elements in the array.
|
||||
* @result The number of elements in the array.
|
||||
*/
|
||||
MCORE_INLINE size_t GetLength() const { return m_length; }
|
||||
|
||||
/**
|
||||
* Get the maximum number of elements. This is the number of elements there currently is space for to store.
|
||||
* However, never use this to make for-loops to iterate through all elements. Use GetLength() instead for that.
|
||||
* This purely has to do with pre-allocating, to reduce the number of reallocs.
|
||||
* @result The maximum array length.
|
||||
*/
|
||||
MCORE_INLINE size_t GetMaxLength() const { return m_maxLength; }
|
||||
|
||||
/**
|
||||
* Calculates the memory usage used by this array.
|
||||
* @param includeMembers Include the class members in the calculation? (default=true).
|
||||
* @result The number of bytes allocated by this array.
|
||||
*/
|
||||
MCORE_INLINE size_t CalcMemoryUsage(bool includeMembers = true) const
|
||||
{
|
||||
size_t result = m_maxLength * sizeof(T);
|
||||
if (includeMembers)
|
||||
{
|
||||
result += sizeof(AlignedArray<T, alignment>);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a given element to a given value.
|
||||
* @param pos The element number.
|
||||
* @param value The value to store at that element number.
|
||||
*/
|
||||
MCORE_INLINE void SetElem(size_t pos, const T& value) { m_data[pos] = value; }
|
||||
|
||||
/**
|
||||
* Add a given element to the back of the array.
|
||||
* @param x The element to add.
|
||||
*/
|
||||
MCORE_INLINE void Add(const T& x) { Grow(++m_length); Construct(m_length - 1, x); }
|
||||
|
||||
/**
|
||||
* Add a given element to the back of the array, but without pre-allocation caching.
|
||||
* @param x The element to add.
|
||||
*/
|
||||
MCORE_INLINE void AddExact(const T& x) { GrowExact(++m_length); Construct(m_length - 1, x); }
|
||||
|
||||
/**
|
||||
* Add a given array to the back of this array.
|
||||
* @param a The array to add.
|
||||
*/
|
||||
MCORE_INLINE void Add(const AlignedArray<T, alignment>& a)
|
||||
{
|
||||
size_t l = m_length;
|
||||
Grow(m_length + a.m_length);
|
||||
for (size_t i = 0; i < a.GetLength(); ++i)
|
||||
{
|
||||
Construct(l + i, a[i]);
|
||||
}
|
||||
} // TODO: a.GetLength() can be precaled before loop?
|
||||
|
||||
/**
|
||||
* Add an empty (default constructed) element to the back of the array.
|
||||
*/
|
||||
MCORE_INLINE void AddEmpty() { Grow(++m_length); Construct(m_length - 1); }
|
||||
|
||||
/**
|
||||
* Add an empty (default constructed) element to the back of the array, but without pre-allocation caching.
|
||||
*/
|
||||
MCORE_INLINE void AddEmptyExact() { GrowExact(++m_length); Construct(m_length - 1); }
|
||||
|
||||
/**
|
||||
* Remove the first array element.
|
||||
*/
|
||||
MCORE_INLINE void RemoveFirst()
|
||||
{
|
||||
if (m_length > 0)
|
||||
{
|
||||
Remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the last array element.
|
||||
*/
|
||||
MCORE_INLINE void RemoveLast()
|
||||
{
|
||||
if (m_length > 0)
|
||||
{
|
||||
Destruct(--m_length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert an empty element (default constructed) at a given position in the array.
|
||||
* @param pos The position to create the empty element.
|
||||
*/
|
||||
MCORE_INLINE void Insert(size_t pos) { Grow(m_length + 1); MoveElements(pos + 1, pos, m_length - pos - 1); Construct(pos); }
|
||||
|
||||
/**
|
||||
* Insert a given element at a given position in the array.
|
||||
* @param pos The position to insert the empty element.
|
||||
* @param x The element to store at this position.
|
||||
*/
|
||||
MCORE_INLINE void Insert(size_t pos, const T& x) { Grow(m_length + 1); MoveElements(pos + 1, pos, m_length - pos - 1); Construct(pos, x); }
|
||||
|
||||
/**
|
||||
* Remove an element at a given position.
|
||||
* @param pos The element number to remove.
|
||||
*/
|
||||
MCORE_INLINE void Remove(size_t pos)
|
||||
{
|
||||
Destruct(pos);
|
||||
if (m_length > 1)
|
||||
{
|
||||
MoveElements(pos, pos + 1, m_length - pos - 1);
|
||||
}
|
||||
m_length--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given number of elements starting at a given position in the array.
|
||||
* @param pos The start element, so to start removing from.
|
||||
* @param num The number of elements to remove from this position.
|
||||
*/
|
||||
MCORE_INLINE void Remove(size_t pos, size_t num)
|
||||
{
|
||||
for (size_t i = pos; i < pos + num; ++i)
|
||||
{
|
||||
Destruct(i);
|
||||
}
|
||||
MoveElements(pos, pos + num, m_length - pos - num);
|
||||
m_length -= num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given element with a given value.
|
||||
* Only the first element with the given value will be removed.
|
||||
* @param item The item/element to remove.
|
||||
*/
|
||||
MCORE_INLINE bool RemoveByValue(const T& item)
|
||||
{
|
||||
size_t index = Find(item);
|
||||
if (index == InvalidIndex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Remove(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given element in the array and place the last element in the array at the created empty position.
|
||||
* So if we have an array with the following characters : ABCDEFG<br>
|
||||
* And we perform a SwapRemove(2), we will remove element C and place the last element (G) at the empty created position where C was located.
|
||||
* So we will get this:<br>
|
||||
* AB.DEFG [where . is empty, after we did the SwapRemove(2)]<br>
|
||||
* ABGDEF [this is the result. G has been moved to the empty position].
|
||||
*/
|
||||
MCORE_INLINE void SwapRemove(size_t pos)
|
||||
{
|
||||
Destruct(pos);
|
||||
if (pos != m_length - 1)
|
||||
{
|
||||
Construct(pos, m_data[m_length - 1]);
|
||||
Destruct(m_length - 1);
|
||||
}
|
||||
m_length--;
|
||||
} // remove element at <pos> and place the last element of the array in that position
|
||||
|
||||
/**
|
||||
* Swap two elements.
|
||||
* @param pos1 The first element number.
|
||||
* @param pos2 The second element number.
|
||||
*/
|
||||
MCORE_INLINE void Swap(size_t pos1, size_t pos2)
|
||||
{
|
||||
if (pos1 != pos2)
|
||||
{
|
||||
Swap(GetItem(pos1), GetItem(pos2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the array contents. So GetLength() will return 0 after performing this method.
|
||||
* @param clearMem If set to true (default) the allocated memory will also be released. If set to false, GetMaxLength() will still return the number of elements
|
||||
* which the array contained before calling the Clear() method.
|
||||
*/
|
||||
MCORE_INLINE void Clear(bool clearMem = true)
|
||||
{
|
||||
for (size_t i = 0; i < m_length; ++i)
|
||||
{
|
||||
Destruct(i);
|
||||
}
|
||||
m_length = 0;
|
||||
if (clearMem)
|
||||
{
|
||||
this->Free();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the array has enough space to store a given number of elements.
|
||||
* @param newLength The number of elements we want to make sure that will fit in the array.
|
||||
*/
|
||||
MCORE_INLINE void AssureSize(size_t newLength)
|
||||
{
|
||||
if (m_length >= newLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
size_t oldLen = m_length;
|
||||
Grow(newLength);
|
||||
for (size_t i = oldLen; i < newLength; ++i)
|
||||
{
|
||||
Construct(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure this array has enough allocated storage to grow to a given number of elements elements without having to realloc.
|
||||
* @param minLength The minimum length the array should have (actually the minimum maxLength, because this has no influence on what GetLength() will return).
|
||||
*/
|
||||
MCORE_INLINE void Reserve(size_t minLength)
|
||||
{
|
||||
if (m_maxLength < minLength)
|
||||
{
|
||||
Realloc(minLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the array as small as possible. So remove all extra pre-allocated data, so that the array consumes the least possible amount of memory.
|
||||
*/
|
||||
MCORE_INLINE void Shrink()
|
||||
{
|
||||
if (m_length == m_maxLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MCORE_ASSERT(m_maxLength >= m_length);
|
||||
Realloc(m_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the array contains a given element.
|
||||
* @param x The element to check.
|
||||
* @result Returns true when the array contains the element, otherwise false is returned.
|
||||
*/
|
||||
MCORE_INLINE bool Contains(const T& x) const { return (Find(x) != InvalidIndex); }
|
||||
|
||||
/**
|
||||
* Find the position of a given element.
|
||||
* @param x The element to find.
|
||||
* @result Returns the index in the array, ranging from [0 to GetLength()-1] when found, otherwise InvalidIndex is returned.
|
||||
*/
|
||||
MCORE_INLINE size_t Find(const T& x) const
|
||||
{
|
||||
for (size_t i = 0; i < m_length; ++i)
|
||||
{
|
||||
if (m_data[i] == x)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return InvalidIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the contents of another array into this one using a direct memory copy.
|
||||
* This does not call copy constructors of the objects, but just copies the raw memory data.
|
||||
* This resizes this array to be the exact length of the array we will copy the data from.
|
||||
* @param other The array to copy the data from.
|
||||
*/
|
||||
MCORE_INLINE void MemCopyContentsFrom(const AlignedArray<T, alignment>& other) { Resize(other.GetLength()); MemCopy((uint8*)m_data, (uint8*)other.m_data, sizeof(T) * other.m_length); }
|
||||
|
||||
// sort function and standard sort function
|
||||
typedef int32 (MCORE_CDECL * CmpFunc)(const T& itemA, const T& itemB);
|
||||
static int32 MCORE_CDECL StdCmp(const T& itemA, const T& itemB)
|
||||
{
|
||||
if (itemA < itemB)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (itemA == itemB)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
static int32 MCORE_CDECL StdPtrObjCmp(const T& itemA, const T& itemB)
|
||||
{
|
||||
if (*itemA < *itemB)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (*itemA == *itemB)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the complete array using a given sort function.
|
||||
* @param cmp The sort function to use.
|
||||
*/
|
||||
MCORE_INLINE void Sort(CmpFunc cmp) { InnerSort(0, m_length - 1, cmp); }
|
||||
|
||||
/**
|
||||
* Sort a given part of the array using a given sort function.
|
||||
* The default parameters are set so that it will sort the compelete array with a default compare function (which uses the < and > operators).
|
||||
* The method will sort all elements between the given 'first' and 'last' element (first and last are also included in the sort).
|
||||
* @param first The first element to start sorting.
|
||||
* @param last The last element to sort (when set to InvalidIndex, GetLength()-1 will be used).
|
||||
* @param cmp The compare function.
|
||||
*/
|
||||
MCORE_INLINE void Sort(size_t first = 0, size_t last = InvalidIndex, CmpFunc cmp = StdCmp)
|
||||
{
|
||||
if (last == InvalidIndex)
|
||||
{
|
||||
last = m_length - 1;
|
||||
}
|
||||
InnerSort(first, last, cmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a sort on a given part of the array.
|
||||
* @param first The first element to start the sorting at.
|
||||
* @param last The last element to end the sorting.
|
||||
* @param cmp The compare function.
|
||||
*/
|
||||
MCORE_INLINE void InnerSort(int32 first, int32 last, CmpFunc cmp)
|
||||
{
|
||||
if (first >= last)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int32 split = Partition(first, last, cmp);
|
||||
InnerSort(first, split - 1, cmp);
|
||||
InnerSort(split + 1, last, cmp);
|
||||
}
|
||||
|
||||
// resize in a fast way that doesn't call constructors or destructors
|
||||
void ResizeFast(size_t newLength)
|
||||
{
|
||||
if (m_length == newLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (newLength > m_length)
|
||||
{
|
||||
GrowExact(newLength);
|
||||
}
|
||||
|
||||
m_length = newLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the array to a given size.
|
||||
* This does not mean an actual realloc will be made. This will only happen when the new length is bigger than the maxLength of the array.
|
||||
* @param newLength The new length the array should be.
|
||||
*/
|
||||
void Resize(size_t newLength)
|
||||
{
|
||||
if (m_length == newLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// check for growing or shrinking array
|
||||
if (newLength > m_length)
|
||||
{
|
||||
// growing array, construct empty elements at end of array
|
||||
const size_t oldLen = m_length;
|
||||
GrowExact(newLength);
|
||||
for (size_t i = oldLen; i < newLength; ++i)
|
||||
{
|
||||
Construct(i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// shrinking array, destruct elements at end of array
|
||||
for (size_t i = newLength; i < m_length; ++i)
|
||||
{
|
||||
Destruct(i);
|
||||
}
|
||||
|
||||
m_length = newLength;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move "numElements" elements starting from the source index, to the dest index.
|
||||
* Please note thate the array has to be large enough. You can't move data past the end of the array.
|
||||
* @param destIndex The destination index.
|
||||
* @param sourceIndex The source index, where the source elements start.
|
||||
* @param numElements The number of elements to move.
|
||||
*/
|
||||
MCORE_INLINE void MoveElements(size_t destIndex, size_t sourceIndex, size_t numElements)
|
||||
{
|
||||
if (numElements > 0)
|
||||
{
|
||||
MemMove(m_data + destIndex, m_data + sourceIndex, numElements * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
// operators
|
||||
bool operator==(const AlignedArray<T, alignment>& other) const
|
||||
{
|
||||
if (m_length != other.m_length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < m_length; ++i)
|
||||
{
|
||||
if (m_data[i] != other.m_data[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
AlignedArray<T, alignment>& operator= (const AlignedArray<T, alignment>& other)
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
Clear(false);
|
||||
m_memCategory = other.m_memCategory;
|
||||
Grow(other.m_length);
|
||||
for (size_t i = 0; i < m_length; ++i)
|
||||
{
|
||||
Construct(i, other.m_data[i]);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
AlignedArray<T, alignment>& operator= (AlignedArray<T, alignment>&& other)
|
||||
{
|
||||
MCORE_ASSERT(&other != this);
|
||||
if (m_data)
|
||||
{
|
||||
AlignedFree(m_data);
|
||||
}
|
||||
m_data = other.m_data;
|
||||
m_memCategory = other.m_memCategory;
|
||||
m_length = other.m_length;
|
||||
m_maxLength = other.m_maxLength;
|
||||
other.m_data = nullptr;
|
||||
other.m_length = 0;
|
||||
other.m_maxLength = 0;
|
||||
return *this;
|
||||
}
|
||||
AlignedArray<T, alignment>& operator+=(const T& other) { Add(other); return *this; }
|
||||
AlignedArray<T, alignment>& operator+=(const AlignedArray<T, alignment>& other) { Add(other); return *this; }
|
||||
MCORE_INLINE T& operator[](size_t index) { MCORE_ASSERT(index < m_length); return m_data[index]; }
|
||||
MCORE_INLINE const T& operator[](size_t index) const { MCORE_ASSERT(index < m_length); return m_data[index]; }
|
||||
|
||||
private:
|
||||
T* m_data; /**< The element data. */
|
||||
size_t m_length; /**< The number of used elements in the array. */
|
||||
size_t m_maxLength; /**< The number of elements that we have allocated memory for. */
|
||||
uint16 m_memCategory; /**< The memory category ID. */
|
||||
|
||||
// private functions
|
||||
MCORE_INLINE void Grow(size_t newLength)
|
||||
{
|
||||
m_length = newLength;
|
||||
if (m_maxLength >= newLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Realloc(AllocSize(newLength));
|
||||
}
|
||||
MCORE_INLINE void GrowExact(size_t newLength)
|
||||
{
|
||||
m_length = newLength;
|
||||
if (m_maxLength < newLength)
|
||||
{
|
||||
Realloc(newLength);
|
||||
}
|
||||
}
|
||||
MCORE_INLINE size_t AllocSize(size_t num) { return 1 + num /*+num/8*/; }
|
||||
MCORE_INLINE void Alloc(size_t num) { m_data = (T*)AlignedAllocate(num * sizeof(T), alignment, m_memCategory, MEMORYBLOCK_ID, MCORE_FILE, MCORE_LINE); }
|
||||
MCORE_INLINE void Realloc(size_t newSize)
|
||||
{
|
||||
if (newSize == 0)
|
||||
{
|
||||
this->Free();
|
||||
return;
|
||||
}
|
||||
if (m_data)
|
||||
{
|
||||
m_data = (T*)AlignedRealloc(m_data, newSize * sizeof(T), m_maxLength * sizeof(T), alignment, m_memCategory, MEMORYBLOCK_ID, MCORE_FILE, MCORE_LINE);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data = (T*)AlignedAllocate(newSize * sizeof(T), alignment, m_memCategory, MEMORYBLOCK_ID, MCORE_FILE, MCORE_LINE);
|
||||
}
|
||||
|
||||
m_maxLength = newSize;
|
||||
}
|
||||
void Free()
|
||||
{
|
||||
m_length = 0;
|
||||
m_maxLength = 0;
|
||||
if (m_data)
|
||||
{
|
||||
AlignedFree(m_data);
|
||||
m_data = nullptr;
|
||||
}
|
||||
}
|
||||
MCORE_INLINE void Construct(size_t index, const T& original) { ::new(m_data + index)T(original); } // copy-construct an element at <index> which is a copy of <original>
|
||||
MCORE_INLINE void Construct(size_t index) { ::new(m_data + index)T; } // construct an element at place <index>
|
||||
MCORE_INLINE void Destruct(size_t index)
|
||||
{
|
||||
#if (MCORE_COMPILER == MCORE_COMPILER_MSVC)
|
||||
MCORE_UNUSED(index); // work around an MSVC compiler bug, where it triggers a warning that parameter 'index' is unused
|
||||
#endif
|
||||
(m_data + index)->~T();
|
||||
}
|
||||
|
||||
// partition part of array (for sorting)
|
||||
int32 Partition(int32 left, int32 right, CmpFunc cmp)
|
||||
{
|
||||
::MCore::Swap(m_data[left], m_data[ (left + right) >> 1 ]);
|
||||
|
||||
T& target = m_data[right];
|
||||
int32 i = left - 1;
|
||||
int32 j = right;
|
||||
|
||||
bool neverQuit = true; // workaround to disable a "warning C4127: conditional expression is constant"
|
||||
while (neverQuit)
|
||||
{
|
||||
while (i < j)
|
||||
{
|
||||
if (cmp(m_data[++i], target) >= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (j > i)
|
||||
{
|
||||
if (cmp(m_data[--j], target) <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= j)
|
||||
{
|
||||
break;
|
||||
}
|
||||
::MCore::Swap(m_data[i], m_data[j]);
|
||||
}
|
||||
|
||||
::MCore::Swap(m_data[i], m_data[right]);
|
||||
return i;
|
||||
}
|
||||
};
|
||||
} // namespace MCore
|
||||
@@ -11,7 +11,6 @@ set(FILES
|
||||
Source/Algorithms.cpp
|
||||
Source/Algorithms.h
|
||||
Source/Algorithms.inl
|
||||
Source/AlignedArray.h
|
||||
Source/Array2D.h
|
||||
Source/Array2D.inl
|
||||
Source/Attribute.cpp
|
||||
|
||||
Reference in New Issue
Block a user