Merge branch 'main' of https://github.com/aws-lumberyard/o3de into ly-as-sdk/LYN-2948-phistere
This commit is contained in:
@@ -20,10 +20,12 @@
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
//! Simple class for verifying that no concurrent access is occuring.
|
||||
//! Simple class for verifying that no concurrent access is occurring.
|
||||
//! This is *not* a synchronization primitive, and is intended simply for checking that no concurrency issues exist.
|
||||
//! It will be compiled out in release builds.
|
||||
//! Use concurrency_checker like a mutex (i.e. call soft_lock() and soft_unlock() around all instances of your data access).
|
||||
//! Use soft_lock_shared and soft_unlock_shared around places where multiple threads are allowed to have read access
|
||||
//! at the same time as long as nothing else already has a soft lock
|
||||
//! It will assert if there are multiple threads accessing the locked code/data at the same time.
|
||||
//! Expected use case is for defensive programming: when you do not expect any concurrent access within a system,
|
||||
//! but want to verify that it stays that way in the future, without incurring the overhead of a mutex.
|
||||
@@ -34,7 +36,7 @@ namespace AZStd
|
||||
{
|
||||
#ifdef AZ_CONCURRENCY_CHECKER_ENABLED
|
||||
uint32_t count = ++m_concurrencyCounter;
|
||||
AZ_Assert(count == 1, "Concurrency check failed. Multiple threads are trying to access data at the same time, or there is a lock/unlock mismatch.");
|
||||
AZ_Assert(count == 1 && m_sharedConcurrencyCounter == 0, "Concurrency check failed. Multiple threads are trying to access data at the same time, or there is a lock/unlock mismatch.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -46,9 +48,27 @@ namespace AZStd
|
||||
#endif
|
||||
}
|
||||
|
||||
AZ_FORCE_INLINE void soft_lock_shared()
|
||||
{
|
||||
#ifdef AZ_CONCURRENCY_CHECKER_ENABLED
|
||||
AZ_Assert(m_concurrencyCounter == 0, "Concurrency check failed. A soft_lock_shared was attempted when there was already a soft_lock.");
|
||||
++m_sharedConcurrencyCounter;
|
||||
#endif
|
||||
}
|
||||
|
||||
AZ_FORCE_INLINE void soft_unlock_shared()
|
||||
{
|
||||
#ifdef AZ_CONCURRENCY_CHECKER_ENABLED
|
||||
AZ_Assert(m_sharedConcurrencyCounter != 0, "Concurrency check failed. There is a shared_lock/shared_unlock mismatch.");
|
||||
--m_sharedConcurrencyCounter;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
#ifdef AZ_CONCURRENCY_CHECKER_ENABLED
|
||||
AZStd::atomic_uint32_t m_concurrencyCounter = 0;
|
||||
AZStd::atomic_uint32_t m_sharedConcurrencyCounter = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -293,15 +293,12 @@ namespace UnitTest
|
||||
{
|
||||
array_view<int> view({ 1,2,3,4 });
|
||||
|
||||
UnitTest::TestRunner::Instance().StartAssertTests();
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
|
||||
EXPECT_EQ(0, UnitTest::TestRunner::Instance().m_numAssertsFailed);
|
||||
view[4];
|
||||
EXPECT_EQ(1, UnitTest::TestRunner::Instance().m_numAssertsFailed);
|
||||
view[5];
|
||||
EXPECT_EQ(2, UnitTest::TestRunner::Instance().m_numAssertsFailed);
|
||||
|
||||
UnitTest::TestRunner::Instance().StopAssertTests();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AtomCore/std/parallel/concurrency_checker.h>
|
||||
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
|
||||
using namespace AZStd;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
class ConcurrencyCheckerTestFixture
|
||||
: public AllocatorsTestFixture
|
||||
{
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
AllocatorsFixture::SetUp();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(AllocatorsTestFixture, SoftLock_NoContention_NoAsserts)
|
||||
{
|
||||
concurrency_checker concurrencyChecker;
|
||||
concurrencyChecker.soft_lock();
|
||||
concurrencyChecker.soft_unlock();
|
||||
concurrencyChecker.soft_lock();
|
||||
concurrencyChecker.soft_unlock();
|
||||
}
|
||||
|
||||
TEST_F(AllocatorsTestFixture, SoftLock_AlreadyLocked_Assert)
|
||||
{
|
||||
concurrency_checker concurrencyChecker;
|
||||
concurrencyChecker.soft_lock();
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
concurrencyChecker.soft_lock();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
}
|
||||
|
||||
TEST_F(AllocatorsTestFixture, SoftUnlock_NotAlreadyLocked_Assert)
|
||||
{
|
||||
concurrency_checker concurrencyChecker;
|
||||
concurrencyChecker.soft_lock();
|
||||
concurrencyChecker.soft_unlock();
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
concurrencyChecker.soft_unlock();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
}
|
||||
|
||||
TEST_F(AllocatorsTestFixture, SoftLockShared_NoContention_NoAsserts)
|
||||
{
|
||||
concurrency_checker concurrencyChecker;
|
||||
// Multiple shared locks can be made at once,
|
||||
// as long as they are all unlocked before the next soft_lock
|
||||
concurrencyChecker.soft_lock_shared();
|
||||
concurrencyChecker.soft_lock_shared();
|
||||
concurrencyChecker.soft_unlock_shared();
|
||||
concurrencyChecker.soft_unlock_shared();
|
||||
|
||||
concurrencyChecker.soft_lock();
|
||||
concurrencyChecker.soft_unlock();
|
||||
|
||||
concurrencyChecker.soft_lock_shared();
|
||||
concurrencyChecker.soft_lock_shared();
|
||||
concurrencyChecker.soft_unlock_shared();
|
||||
concurrencyChecker.soft_unlock_shared();
|
||||
|
||||
concurrencyChecker.soft_lock();
|
||||
concurrencyChecker.soft_unlock();
|
||||
}
|
||||
|
||||
TEST_F(AllocatorsTestFixture, SoftLockShared_SharedLockAfterSoftLock_Assert)
|
||||
{
|
||||
concurrency_checker concurrencyChecker;
|
||||
|
||||
concurrencyChecker.soft_lock();
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
concurrencyChecker.soft_lock_shared();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
}
|
||||
|
||||
TEST_F(AllocatorsTestFixture, SoftUnlockShared_NotAlreadyLocked_Assert)
|
||||
{
|
||||
concurrency_checker concurrencyChecker;
|
||||
concurrencyChecker.soft_lock_shared();
|
||||
concurrencyChecker.soft_unlock_shared();
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
concurrencyChecker.soft_unlock_shared();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
set(FILES
|
||||
ArrayView.cpp
|
||||
ConcurrencyCheckerTests.cpp
|
||||
InstanceDatabase.cpp
|
||||
JsonSerializationUtilsTests.cpp
|
||||
lru_cache.cpp
|
||||
|
||||
@@ -307,6 +307,8 @@ namespace AZ
|
||||
Asset(AssetLoadBehavior loadBehavior = AssetLoadBehavior::Default);
|
||||
/// Create an asset from a valid asset data (created asset), might not be loaded or currently loading.
|
||||
Asset(AssetData* assetData, AssetLoadBehavior loadBehavior);
|
||||
/// Create an asset from a valid asset data (created asset) and set the asset id for both, might not be loaded or currently loading.
|
||||
Asset(const AZ::Data::AssetId& id, AssetData* assetData, AssetLoadBehavior loadBehavior);
|
||||
/// Initialize asset pointer with id, type, and hint. No data construction will occur until QueueLoad is called.
|
||||
Asset(const AZ::Data::AssetId& id, const AZ::Data::AssetType& type, const AZStd::string& hint = AZStd::string());
|
||||
|
||||
@@ -787,6 +789,18 @@ namespace AZ
|
||||
SetData(assetData);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
template<class T>
|
||||
Asset<T>::Asset(const AssetId& id, AssetData* assetData, AssetLoadBehavior loadBehavior)
|
||||
: m_assetId(id)
|
||||
, m_assetType(azrtti_typeid<T>())
|
||||
, m_loadBehavior(loadBehavior)
|
||||
{
|
||||
AZ_Assert(!assetData->m_assetId.IsValid(), "Asset data already has an ID set.");
|
||||
assetData->m_assetId = id;
|
||||
SetData(assetData);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
template<class T>
|
||||
Asset<T>::Asset(const AssetId& id, const AZ::Data::AssetType& type, const AZStd::string& hint)
|
||||
|
||||
@@ -133,7 +133,15 @@ namespace AZ
|
||||
if (!id.m_guid.IsNull())
|
||||
{
|
||||
*instance = AssetManager::Instance().FindOrCreateAsset(id, instance->GetType(), instance->GetAutoLoadBehavior());
|
||||
|
||||
if (!instance->GetId().IsValid())
|
||||
{
|
||||
// If the asset failed to be created, FindOrCreateAsset returns an asset instance with a null
|
||||
// id. To preserve the asset id in the source json, reset the asset to an empty one, but with
|
||||
// the right id.
|
||||
const auto loadBehavior = instance->GetAutoLoadBehavior();
|
||||
*instance = Asset<AssetData>(id, instance->GetType());
|
||||
instance->SetAutoLoadBehavior(loadBehavior);
|
||||
}
|
||||
|
||||
result.Combine(context.Report(result, "Successfully created Asset<T> with id."));
|
||||
}
|
||||
|
||||
@@ -287,71 +287,28 @@ namespace AZ
|
||||
|
||||
//! Scale modifiers
|
||||
//! @{
|
||||
//! @deprecated Use SetLocalScale()
|
||||
//! Scales the entity along the world's axes. The origin of the axes is the entity's position in the world.
|
||||
//! @param scale A three-dimensional vector that represents the multipliers with which to scale the entity in world space.
|
||||
virtual void SetScale([[maybe_unused]] const AZ::Vector3& scale) {}
|
||||
|
||||
//! @deprecated Use SetLocalScaleX()
|
||||
//! Scales the entity along the world's X axis. The origin of the axis is the entity's position in the world.
|
||||
//! @param scaleX The multiplier by which to scale the entity along the X axis in world space.
|
||||
virtual void SetScaleX([[maybe_unused]] float scaleX) {}
|
||||
|
||||
//! @deprecated Use SetLocalScaleY()
|
||||
//! Scales the entity along the world's Y axis. The origin of the axis is the entity's position in the world.
|
||||
//! @param scaleY The multiplier by which to scale the entity along the Y axis in world space.
|
||||
virtual void SetScaleY([[maybe_unused]] float scaleY) {}
|
||||
|
||||
//! @deprecated Use SetLocalScaleZ()
|
||||
//! Scales the entity along the world's Z axis. The origin of the axis is the entity's position in the world.
|
||||
//! @param scaleZ The multiplier by which to scale the entity along the Z axis in world space.
|
||||
virtual void SetScaleZ([[maybe_unused]] float scaleZ) {}
|
||||
|
||||
//! @deprecated Use GetLocalScale()
|
||||
//! Gets the scale of the entity in world space.
|
||||
//! @return A three-dimensional vector that represents the scale of the entity in world space.
|
||||
virtual AZ::Vector3 GetScale() { return AZ::Vector3(FLT_MAX); }
|
||||
|
||||
//! @deprecated Use GetLocalScale()
|
||||
//! Gets the amount by which an entity is scaled along the world's X axis.
|
||||
//! @return The amount by which an entity is scaled along the X axis in world space.
|
||||
virtual float GetScaleX() { return FLT_MAX; }
|
||||
|
||||
//! @deprecated Use GetLocalScale()
|
||||
//! Gets the amount by which an entity is scaled along the world's Y axis.
|
||||
//! @return The amount by which an entity is scaled along the Y axis in world space.
|
||||
virtual float GetScaleY() { return FLT_MAX; }
|
||||
|
||||
//! @deprecated Use GetLocalScale()
|
||||
//! Gets the amount by which an entity is scaled along the world's Z axis.
|
||||
//! @return The amount by which an entity is scaled along the Z axis in world space.
|
||||
virtual float GetScaleZ() { return FLT_MAX; }
|
||||
|
||||
//! Set local scale of the transform.
|
||||
//! @param scale The new scale to set along three local axes.
|
||||
//! @param scale The new scale to set.
|
||||
virtual void SetLocalScale([[maybe_unused]] const AZ::Vector3& scale) {}
|
||||
|
||||
//! Set local scale of the transform on x-axis.
|
||||
//! @param scaleX The new x-axis scale to set.
|
||||
virtual void SetLocalScaleX([[maybe_unused]] float scaleX) {}
|
||||
|
||||
//! Set local scale of the transform on y-axis.
|
||||
//! @param scaleY The new y-axis scale to set.
|
||||
virtual void SetLocalScaleY([[maybe_unused]] float scaleY) {}
|
||||
|
||||
//! Set local scale of the transform on z-axis.
|
||||
//! @param scaleZ The new z-axis scale to set.
|
||||
virtual void SetLocalScaleZ([[maybe_unused]] float scaleZ) {}
|
||||
|
||||
//! Get the scale value on each axis in local space
|
||||
//! @return The scale value of type Vector3 along each axis in local space.
|
||||
//! Get the scale value in local space.
|
||||
//! @return The scale value in local space.
|
||||
virtual AZ::Vector3 GetLocalScale() { return AZ::Vector3(FLT_MAX); }
|
||||
|
||||
//! Get the scale value on each axis in world space.
|
||||
//! Note the transform will be skewed when it is rotated and has a parent transform scaled, in which
|
||||
//! case the returned world-scale from this function will be inaccurate.
|
||||
//! @return The scale value of type Vector3 along each axis in world space.
|
||||
//! Get the scale value in world space.
|
||||
//! @return The scale value in world space.
|
||||
virtual AZ::Vector3 GetWorldScale() { return AZ::Vector3(FLT_MAX); }
|
||||
|
||||
//! Set the uniform scale value in local space.
|
||||
virtual void SetLocalUniformScale([[maybe_unused]] float scale) {}
|
||||
|
||||
//! Get the uniform scale value in local space.
|
||||
//! @return The uniform scale value in local space.
|
||||
virtual float GetLocalUniformScale() { return FLT_MAX; }
|
||||
|
||||
//! Get the uniform scale value in world space.
|
||||
//! @return The uniform scale value in world space.
|
||||
virtual float GetWorldUniformScale() { return FLT_MAX; }
|
||||
//! @}
|
||||
|
||||
//! Transform hierarchy
|
||||
|
||||
@@ -348,13 +348,20 @@ namespace AZ
|
||||
return result.GetW() >= 0.0f ? result : -result;
|
||||
}
|
||||
|
||||
const Quaternion Quaternion::CreateFromEulerAnglesDegrees(Vector3& anglesInDegrees)
|
||||
const Quaternion Quaternion::CreateFromEulerAnglesDegrees(const Vector3& anglesInDegrees)
|
||||
{
|
||||
Quaternion result;
|
||||
result.SetFromEulerDegrees(anglesInDegrees);
|
||||
return result;
|
||||
}
|
||||
|
||||
const Quaternion Quaternion::CreateFromEulerAnglesRadians(const Vector3& anglesInRadians)
|
||||
{
|
||||
Quaternion result;
|
||||
result.SetFromEulerRadians(anglesInRadians);
|
||||
return result;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Slerp(const Quaternion& dest, float t) const
|
||||
{
|
||||
const float DestDot = Dot(dest);
|
||||
|
||||
@@ -83,8 +83,11 @@ namespace AZ
|
||||
|
||||
static Quaternion CreateShortestArc(const Vector3& v1, const Vector3& v2);
|
||||
|
||||
/// Creates a quaternion using rotation in degrees about the axes. First rotated about the X axis, followed by the Y axis, then the Z axis.
|
||||
static const Quaternion CreateFromEulerAnglesDegrees(Vector3& anglesInDegrees);
|
||||
//! Creates a quaternion using rotation in degrees about the axes. First rotated about the X axis, followed by the Y axis, then the Z axis.
|
||||
static const Quaternion CreateFromEulerAnglesDegrees(const Vector3& anglesInDegrees);
|
||||
|
||||
//! Creates a quaternion using rotation in radians about the axes. First rotated about the X axis, followed by the Y axis, then the Z axis.
|
||||
static const Quaternion CreateFromEulerAnglesRadians(const Vector3& anglesInRadians);
|
||||
|
||||
//! Stores the vector to an array of 4 floats. The floats need only be 4 byte aligned, 16 byte alignment is not required.
|
||||
void StoreToFloat4(float* values) const;
|
||||
|
||||
@@ -86,4 +86,94 @@ namespace AZ
|
||||
Normal,
|
||||
UniformReal
|
||||
};
|
||||
|
||||
//! Halton sequences are deterministic, quasi-random sequences with low discrepancy. They
|
||||
//! are useful for generating evenly distributed points.
|
||||
//! See https://en.wikipedia.org/wiki/Halton_sequence for more information.
|
||||
|
||||
//! Returns a single halton number.
|
||||
//! @param index The index of the number. Indices start at 1. Using index 0 will return 0.
|
||||
//! @param base The numerical base of the halton number.
|
||||
inline float GetHaltonNumber(uint32_t index, uint32_t base)
|
||||
{
|
||||
float fraction = 1.0f;
|
||||
float result = 0.0f;
|
||||
|
||||
while (index > 0)
|
||||
{
|
||||
fraction = fraction / base;
|
||||
result += fraction * (index % base);
|
||||
index = aznumeric_cast<uint32_t>(index / base);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//! A helper class for generating arrays of Halton sequences in n dimensions.
|
||||
//! The class holds the state of which bases to use, the starting offset
|
||||
//! of each dimension and how much to increment between each index for each
|
||||
//! dimension.
|
||||
template <uint8_t Dimensions>
|
||||
class HaltonSequence
|
||||
{
|
||||
public:
|
||||
|
||||
//! Initializes a Halton sequence with some bases. By default there is no
|
||||
//! offset and the index increments by 1 between each number.
|
||||
HaltonSequence(AZStd::array<uint32_t, Dimensions> bases)
|
||||
: m_bases(bases)
|
||||
{
|
||||
m_offsets.fill(1); // Halton sequences start at index 1.
|
||||
m_increments.fill(1); // By default increment by 1 between each number.
|
||||
}
|
||||
|
||||
//! Returns a Halton sequence in an array of N length
|
||||
template<uint32_t N>
|
||||
AZStd::array<AZStd::array<float, Dimensions>, N> GetHaltonSequence()
|
||||
{
|
||||
AZStd::array<AZStd::array<float, Dimensions>, N> result;
|
||||
|
||||
AZStd::array<uint32_t, Dimensions> indices = m_offsets;
|
||||
|
||||
// Generator that returns the Halton number for all bases for a single entry.
|
||||
auto f = [&] ()
|
||||
{
|
||||
AZStd::array<float, Dimensions> item;
|
||||
for (auto d = 0; d < Dimensions; ++d)
|
||||
{
|
||||
item[d] = GetHaltonNumber(indices[d], m_bases[d]);
|
||||
indices[d] += m_increments[d];
|
||||
}
|
||||
return item;
|
||||
};
|
||||
|
||||
AZStd::generate(result.begin(), result.end(), f);
|
||||
return result;
|
||||
}
|
||||
|
||||
//! Sets the offsets per dimension to start generating a sequence from.
|
||||
//! By default, there is no offset (offset of 0 corresponds to starting at index 1)
|
||||
void SetOffsets(AZStd::array<uint32_t, Dimensions> offsets)
|
||||
{
|
||||
m_offsets = offsets;
|
||||
|
||||
// Halton sequences start at index 1, so increment all the indices.
|
||||
AZStd::for_each(m_offsets.begin(), m_offsets.end(), [](uint32_t &n){ n++; });
|
||||
}
|
||||
|
||||
//! Sets the increment between numbers in the halton sequence per dimension
|
||||
//! By default this is 1, meaning that no numbers are skipped. Can be negative
|
||||
//! to generate numbers in reverse order.
|
||||
void SetIncrements(AZStd::array<int32_t, Dimensions> increments)
|
||||
{
|
||||
m_increments = increments;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
AZStd::array<uint32_t, Dimensions> m_bases;
|
||||
AZStd::array<uint32_t, Dimensions> m_offsets;
|
||||
AZStd::array<int32_t, Dimensions> m_increments;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -441,10 +441,10 @@ namespace AZ
|
||||
const Transform& worldFromLocal, const Vector3& src, const Vector3& dir, const Spline& spline)
|
||||
{
|
||||
Transform worldFromLocalNormalized = worldFromLocal;
|
||||
const Vector3 scale = worldFromLocalNormalized.ExtractScale();
|
||||
const float scale = worldFromLocalNormalized.ExtractUniformScale();
|
||||
const Transform localFromWorldNormalized = worldFromLocalNormalized.GetInverse();
|
||||
|
||||
const Vector3 localRayOrigin = localFromWorldNormalized.TransformPoint(src) * scale.GetReciprocal();
|
||||
const Vector3 localRayOrigin = localFromWorldNormalized.TransformPoint(src) / scale;
|
||||
const Vector3 localRayDirection = localFromWorldNormalized.TransformVector(dir);
|
||||
return spline.GetNearestAddressRay(localRayOrigin, localRayDirection);
|
||||
}
|
||||
|
||||
@@ -284,10 +284,15 @@ namespace AZ
|
||||
Method("GetRotation", &Transform::GetRotation)->
|
||||
Method<void (Transform::*)(const Quaternion&)>("SetRotation", &Transform::SetRotation)->
|
||||
Method("GetScale", &Transform::GetScale)->
|
||||
Method<void (Transform::*)(const Vector3&)>("SetScale", &Transform::SetScale)->
|
||||
Method("GetUniformScale", &Transform::GetUniformScale)->
|
||||
Method("SetScale", &Transform::SetScale)->
|
||||
Method("SetUniformScale", &Transform::SetUniformScale)->
|
||||
Method("ExtractScale", &Transform::ExtractScale)->
|
||||
Attribute(Script::Attributes::ExcludeFrom, Script::Attributes::ExcludeFlags::All)->
|
||||
Method("ExtractUniformScale", &Transform::ExtractUniformScale)->
|
||||
Attribute(Script::Attributes::ExcludeFrom, Script::Attributes::ExcludeFlags::All)->
|
||||
Method("MultiplyByScale", &Transform::MultiplyByScale)->
|
||||
Method("MultiplyByUniformScale", &Transform::MultiplyByUniformScale)->
|
||||
Method("GetInverse", &Transform::GetInverse)->
|
||||
Method("Invert", &Transform::Invert)->
|
||||
Attribute(Script::Attributes::ExcludeFrom, Script::Attributes::ExcludeFlags::All)->
|
||||
@@ -306,6 +311,7 @@ namespace AZ
|
||||
Method("CreateFromMatrix3x3", &Transform::CreateFromMatrix3x3)->
|
||||
Method("CreateFromMatrix3x3AndTranslation", &Transform::CreateFromMatrix3x3AndTranslation)->
|
||||
Method("CreateScale", &Transform::CreateScale)->
|
||||
Method("CreateUniformScale", &Transform::CreateUniformScale)->
|
||||
Method("CreateTranslation", &Transform::CreateTranslation)->
|
||||
Method("ConstructFromValuesNumeric", &Internal::ConstructTransformFromValues);
|
||||
}
|
||||
|
||||
@@ -89,8 +89,11 @@ namespace AZ
|
||||
|
||||
static Transform CreateFromMatrix3x4(const Matrix3x4& value);
|
||||
|
||||
//! Sets the matrix to be a scale matrix, translation is set to zero.
|
||||
static Transform CreateScale(const Vector3& scale);
|
||||
//! Sets the transform to apply scale only, no rotation or translation.
|
||||
static Transform CreateScale(const AZ::Vector3& scale);
|
||||
|
||||
//! Sets the transform to apply (uniform) scale only, no rotation or translation.
|
||||
static Transform CreateUniformScale(const float scale);
|
||||
|
||||
//! Sets the matrix to be a translation matrix, rotation part is set to identity.
|
||||
static Transform CreateTranslation(const Vector3& translation);
|
||||
@@ -119,13 +122,19 @@ namespace AZ
|
||||
const Quaternion& GetRotation() const;
|
||||
void SetRotation(const Quaternion& rotation);
|
||||
|
||||
const Vector3& GetScale() const;
|
||||
Vector3 GetScale() const;
|
||||
float GetUniformScale() const;
|
||||
void SetScale(const Vector3& v);
|
||||
void SetUniformScale(const float scale);
|
||||
|
||||
//! Sets the transforms scale to a unit value and returns the previous scale value.
|
||||
//! Sets the transform's scale to a unit value and returns the previous scale value.
|
||||
Vector3 ExtractScale();
|
||||
|
||||
void MultiplyByScale(const Vector3& scale);
|
||||
//! Sets the transform's scale to a unit value and returns the previous scale value.
|
||||
float ExtractUniformScale();
|
||||
|
||||
void MultiplyByScale(const AZ::Vector3& scale);
|
||||
void MultiplyByUniformScale(float scale);
|
||||
|
||||
Transform operator*(const Transform& rhs) const;
|
||||
Transform& operator*=(const Transform& rhs);
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace AZ
|
||||
|
||||
AZ_MATH_INLINE Transform Transform::CreateScale(const Vector3& scale)
|
||||
{
|
||||
AZ_WarningOnce("Transform", false, "CreateScale is deprecated, please use CreateUniformScale instead.");
|
||||
Transform result;
|
||||
result.m_rotation = Quaternion::CreateIdentity();
|
||||
result.m_scale = scale;
|
||||
@@ -72,6 +73,15 @@ namespace AZ
|
||||
return result;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE Transform Transform::CreateUniformScale(float scale)
|
||||
{
|
||||
Transform result;
|
||||
result.m_rotation = Quaternion::CreateIdentity();
|
||||
result.m_scale = Vector3(scale);
|
||||
result.m_translation = Vector3::CreateZero();
|
||||
return result;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE Transform Transform::CreateTranslation(const Vector3& translation)
|
||||
{
|
||||
Transform result;
|
||||
@@ -150,24 +160,50 @@ namespace AZ
|
||||
m_rotation = rotation;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE const Vector3& Transform::GetScale() const
|
||||
AZ_MATH_INLINE Vector3 Transform::GetScale() const
|
||||
{
|
||||
AZ_WarningOnce("Transform", false, "GetScale is deprecated, please use GetUniformScale instead.");
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE float Transform::GetUniformScale() const
|
||||
{
|
||||
return m_scale.GetMaxElement();
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE void Transform::SetScale(const Vector3& scale)
|
||||
{
|
||||
AZ_WarningOnce("Transform", false, "SetScale is deprecated, please use SetUniformScale instead.");
|
||||
m_scale = scale;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE void Transform::SetUniformScale(const float scale)
|
||||
{
|
||||
m_scale = Vector3(scale);
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE Vector3 Transform::ExtractScale()
|
||||
{
|
||||
AZ_WarningOnce("Transform", false, "ExtractScale is deprecated, please use ExtractUniformScale instead.");
|
||||
const Vector3 scale = m_scale;
|
||||
m_scale = Vector3::CreateOne();
|
||||
return scale;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE float Transform::ExtractUniformScale()
|
||||
{
|
||||
const float scale = m_scale.GetMaxElement();
|
||||
m_scale = Vector3::CreateOne();
|
||||
return scale;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE void Transform::MultiplyByScale(const Vector3& scale)
|
||||
{
|
||||
AZ_WarningOnce("Transform", false, "MultiplyByScale is deprecated, please use MultiplyByUniformScale instead.");
|
||||
m_scale *= scale;
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE void Transform::MultiplyByUniformScale(float scale)
|
||||
{
|
||||
m_scale *= scale;
|
||||
}
|
||||
@@ -233,7 +269,7 @@ namespace AZ
|
||||
|
||||
AZ_MATH_INLINE void Transform::Orthogonalize()
|
||||
{
|
||||
*this = GetOrthogonalized();
|
||||
m_scale = Vector3::CreateOne();
|
||||
}
|
||||
|
||||
AZ_MATH_INLINE bool Transform::IsClose(const Transform& rhs, float tolerance) const
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace AZ
|
||||
{
|
||||
// Scale is transitioning to a single uniform scale value, but since it's still internally represented as a Vector3,
|
||||
// we need to pick one number to use for load/store operations.
|
||||
float scale = transformInstance->GetScale().GetMaxElement();
|
||||
float scale = transformInstance->GetUniformScale();
|
||||
|
||||
JSR::ResultCode loadResult =
|
||||
ContinueLoadingFromJsonObjectField(&scale, azrtti_typeid<decltype(scale)>(), inputValue, ScaleTag, context);
|
||||
@@ -124,8 +124,8 @@ namespace AZ
|
||||
|
||||
// Scale is transitioning to a single uniform scale value, but since it's still internally represented as a Vector3,
|
||||
// we need to pick one number to use for load/store operations.
|
||||
float scale = transformInstance->GetScale().GetMaxElement();
|
||||
float defaultScale = defaultTransformInstance ? defaultTransformInstance->GetScale().GetMaxElement() : 0.0f;
|
||||
float scale = transformInstance->GetUniformScale();
|
||||
float defaultScale = defaultTransformInstance ? defaultTransformInstance->GetUniformScale() : 0.0f;
|
||||
|
||||
JSR::ResultCode storeResult = ContinueStoringToJsonObjectField(
|
||||
outputValue, ScaleTag, &scale, defaultTransformInstance ? &defaultScale : nullptr, azrtti_typeid<decltype(scale)>(),
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a pointer to the beginning of master vector of SmallAllocationGroups.
|
||||
/// Returns a pointer to the beginning of vector of SmallAllocationGroups.
|
||||
SmallAllocationGroup* ArrayHead()
|
||||
{
|
||||
return this - m_index;
|
||||
@@ -169,7 +169,7 @@ namespace AZ
|
||||
return m_marker == MARKER;
|
||||
}
|
||||
|
||||
/// Returns the master index of the SmallAllocationGroup containing this allocation
|
||||
/// Returns the index of the SmallAllocationGroup containing this allocation
|
||||
uint32_t GetSmallAllocationIndex() const
|
||||
{
|
||||
return (uint32_t)(m_data & 0xFFFFFFFF);
|
||||
|
||||
@@ -1020,29 +1020,60 @@ namespace AZ
|
||||
}
|
||||
};
|
||||
|
||||
/// OnDemand reflection for AZStd::set
|
||||
|
||||
template<class t_Key, class t_Hasher, class t_EqualKey, class t_Allocator>
|
||||
class Iterator_VM<AZStd::unordered_set<t_Key, t_Hasher, t_EqualKey, t_Allocator>>
|
||||
{
|
||||
public:
|
||||
using ContainerType = AZStd::unordered_set<t_Key, t_Hasher, t_EqualKey, t_Allocator>;
|
||||
using IteratorType = typename ContainerType::iterator;
|
||||
Iterator_VM(ContainerType& container)
|
||||
: m_iterator(container.begin())
|
||||
, m_end(container.end())
|
||||
{}
|
||||
|
||||
const t_Key& GetKeyUnchecked() const
|
||||
{
|
||||
return *m_iterator;
|
||||
}
|
||||
|
||||
bool IsNotAtEnd() const
|
||||
{
|
||||
return m_iterator != m_end;
|
||||
}
|
||||
|
||||
t_Key& ModValueUnchecked()
|
||||
{
|
||||
return *m_iterator;
|
||||
}
|
||||
|
||||
void Next()
|
||||
{
|
||||
++m_iterator;
|
||||
}
|
||||
|
||||
private:
|
||||
IteratorType m_iterator;
|
||||
IteratorType m_end;
|
||||
};
|
||||
|
||||
/// OnDemand reflection for AZStd::unordered_set
|
||||
template<class Key, class Hasher, class EqualKey, class Allocator>
|
||||
struct OnDemandReflection< AZStd::unordered_set<Key, Hasher, EqualKey, Allocator> >
|
||||
{
|
||||
using ContainerType = AZStd::unordered_set<Key, Hasher, EqualKey, Allocator>;
|
||||
using KeyListType = AZStd::vector<Key, Allocator>;
|
||||
|
||||
static AZ::Outcome<void, void> Erase(ContainerType& thisMap, Key& key)
|
||||
using ValueIteratorType = Iterator_VM<ContainerType>;
|
||||
|
||||
static bool EraseCheck_VM(ContainerType& thisSet, Key& key)
|
||||
{
|
||||
const auto result = thisMap.erase(key);
|
||||
if (result)
|
||||
{
|
||||
return AZ::Success();
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZ::Failure();
|
||||
}
|
||||
return thisSet.erase(key) != 0;
|
||||
}
|
||||
|
||||
static void Insert(ContainerType& thisSet, Key& key)
|
||||
static ContainerType& ErasePost_VM(ContainerType& thisSet, [[maybe_unused]] Key&)
|
||||
{
|
||||
thisSet.insert(key);
|
||||
return thisSet;
|
||||
}
|
||||
|
||||
static KeyListType GetKeys(ContainerType& thisSet)
|
||||
@@ -1055,6 +1086,17 @@ namespace AZ
|
||||
return keys;
|
||||
}
|
||||
|
||||
static ContainerType& Insert(ContainerType& thisSet, Key& key)
|
||||
{
|
||||
thisSet.insert(key);
|
||||
return thisSet;
|
||||
}
|
||||
|
||||
static ValueIteratorType Iterate_VM(ContainerType& thisContainer)
|
||||
{
|
||||
return ValueIteratorType(thisContainer);
|
||||
}
|
||||
|
||||
static void Swap(ContainerType& thisSet, ContainerType& otherSet)
|
||||
{
|
||||
thisSet.swap(otherSet);
|
||||
@@ -1064,33 +1106,68 @@ namespace AZ
|
||||
{
|
||||
if (BehaviorContext* behaviorContext = azrtti_cast<BehaviorContext*>(context))
|
||||
{
|
||||
BranchOnResultInfo emptyBranchInfo;
|
||||
emptyBranchInfo.m_returnResultInBranches = true;
|
||||
emptyBranchInfo.m_trueToolTip = "The container is empty";
|
||||
emptyBranchInfo.m_falseToolTip = "The container is not empty";
|
||||
|
||||
auto ContainsTransparent = [](const ContainerType& containerType, typename ContainerType::key_type& key)->bool
|
||||
{
|
||||
return containerType.contains(key);
|
||||
};
|
||||
|
||||
ExplicitOverloadInfo explicitOverloadInfo;
|
||||
behaviorContext->Class<ContainerType>()
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)
|
||||
->Attribute(AZ::ScriptCanvasAttributes::PrettyName, ScriptCanvasOnDemandReflection::OnDemandPrettyName<ContainerType>::Get(*behaviorContext))
|
||||
->Attribute(AZ::Script::Attributes::ToolTip, ScriptCanvasOnDemandReflection::OnDemandToolTip<ContainerType>::Get(*behaviorContext))
|
||||
->Attribute(AZ::Script::Attributes::Category, ScriptCanvasOnDemandReflection::OnDemandCategoryName<ContainerType>::Get(*behaviorContext))
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::ScriptOwn)
|
||||
->Method("BucketCount", static_cast<typename ContainerType::size_type(ContainerType::*)() const>(&ContainerType::bucket_count))
|
||||
->Method("Erase", &Erase)
|
||||
->Method("Empty", [](ContainerType& thisSet)->bool { return thisSet.empty(); })
|
||||
->Method("Empty", static_cast<bool(ContainerType::*)() const>(&ContainerType::empty), { { { "Container", "The container to check if it is empty", nullptr, {} } } })
|
||||
->Attribute(AZ::ScriptCanvasAttributes::ExplicitOverloadCrc, ExplicitOverloadInfo("Is Empty", "Containers"))
|
||||
->Attribute(AZ::ScriptCanvasAttributes::BranchOnResult, emptyBranchInfo)
|
||||
->Method("EraseCheck_VM", &EraseCheck_VM)
|
||||
->Attribute(AZ::Script::Attributes::TreatAsMemberFunction, AZ::AttributeIsValid::IfPresent)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Method("Erase", &ErasePost_VM)
|
||||
->Attribute(AZ::Script::Attributes::TreatAsMemberFunction, AZ::AttributeIsValid::IfPresent)
|
||||
->Attribute(AZ::ScriptCanvasAttributes::ExplicitOverloadCrc, ExplicitOverloadInfo("Erase", "Containers"))
|
||||
->Attribute(AZ::ScriptCanvasAttributes::CheckedOperation, CheckedOperationInfo("EraseCheck_VM", {}, "Out", "Key Not Found", true))
|
||||
->Attribute(AZ::ScriptCanvasAttributes::OverloadArgumentGroup, AZ::OverloadArgumentGroupInfo({ "ContainerGroup", "" }, { "ContainerGroup" }))
|
||||
->Method("contains", ContainsTransparent)
|
||||
->Attribute(AZ::ScriptCanvasAttributes::ExplicitOverloadCrc, ExplicitOverloadInfo("Has Key", "Containers"))
|
||||
->Attribute(AZ::Script::Attributes::TreatAsMemberFunction, AZ::AttributeIsValid::IfPresent)
|
||||
->Method("Insert", &Insert)
|
||||
->Attribute(AZ::Script::Attributes::TreatAsMemberFunction, AZ::AttributeIsValid::IfPresent)
|
||||
->Attribute(AZ::ScriptCanvasAttributes::ExplicitOverloadCrc, ExplicitOverloadInfo("Insert", "Containers"))
|
||||
->Attribute(AZ::ScriptCanvasAttributes::OverloadArgumentGroup, AZ::OverloadArgumentGroupInfo({ "ContainerGroup", "", "" }, { "ContainerGroup" }))
|
||||
->Method(k_sizeName, [](ContainerType* thisPtr) { return aznumeric_cast<int>(thisPtr->size()); })
|
||||
->Attribute(AZ::Script::Attributes::Operator, AZ::Script::Attributes::OperatorType::Length)
|
||||
->Method("GetKeys", &GetKeys)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Method("GetSize", [](ContainerType& thisPtr) { return aznumeric_cast<int>(thisPtr.size()); })
|
||||
->Attribute(AZ::ScriptCanvasAttributes::ExplicitOverloadCrc, ExplicitOverloadInfo("Get Size", "Containers"))
|
||||
->Attribute(AZ::Script::Attributes::TreatAsMemberFunction, AZ::AttributeIsValid::IfPresent)
|
||||
->Method("Reserve", static_cast<void(ContainerType::*)(typename ContainerType::size_type)>(&ContainerType::reserve))
|
||||
->Method("Swap", &Swap)
|
||||
->Method("Clear", [](ContainerType& thisContainer)->ContainerType& { thisContainer.clear(); return thisContainer; })
|
||||
->Attribute(AZ::Script::Attributes::TreatAsMemberFunction, AZ::AttributeIsValid::IfPresent)
|
||||
->Attribute(AZ::ScriptCanvasAttributes::ExplicitOverloadCrc, ExplicitOverloadInfo("Clear All Elements", "Containers"))
|
||||
->Attribute(AZ::ScriptCanvasAttributes::OverloadArgumentGroup, AZ::OverloadArgumentGroupInfo({ "ContainerGroup" }, { "ContainerGroup" }))
|
||||
->Method(k_iteratorConstructorName, &Iterate_VM)
|
||||
;
|
||||
|
||||
behaviorContext->Class<ValueIteratorType>()
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::ScriptOwn)
|
||||
->Method(k_iteratorGetKeyName, &ValueIteratorType::GetKeyUnchecked)
|
||||
->Method(k_iteratorModValueName, &ValueIteratorType::ModValueUnchecked)
|
||||
->Method(k_iteratorIsNotAtEndName, &ValueIteratorType::IsNotAtEnd)
|
||||
->Method(k_iteratorNextName, &ValueIteratorType::Next)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace AZ
|
||||
|
||||
if (HasResult() != overload->HasResult())
|
||||
{
|
||||
AZ_Error("Reflection", false, "Overload failure, all methods must have the same result, or none at all");
|
||||
AZ_Error("Reflection", false, "Overload failure, all methods must have the same result, or none at all: %s", m_name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace AZ
|
||||
|
||||
if (!(methodResult->m_typeId == overloadResult->m_typeId && methodResult->m_traits == overloadResult->m_traits))
|
||||
{
|
||||
AZ_Error("Reflection", false, "Overload failure, all methods must have the same result, or none at all");
|
||||
AZ_Error("Reflection", false, "Overload failure, all methods must have the same result, or none at all: %s", m_name.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -575,7 +575,7 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error("BehaviorContext", false, "safety check declared for method %s but it was not found in the class");
|
||||
AZ_Error("BehaviorContext", false, "Method: %s, declared safety check: %s, but it was not found in class: %s", method.m_name.c_str(), m_name.c_str(), checkedOperationInfo.m_safetyCheckName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,17 @@ namespace BehaviorContextUtilitiesCPP
|
||||
using argument_type = const BehaviorParameter*;
|
||||
using result_type = size_t;
|
||||
result_type operator()(const argument_type& value) const
|
||||
{
|
||||
result_type result = AZStd::hash<Uuid>()(value->m_typeId);
|
||||
AZStd::hash_combine(result, CleanTraits(value->m_traits));
|
||||
return result;
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
result_type result = AZStd::hash<Uuid>()(value->m_typeId);
|
||||
AZStd::hash_combine(result, CleanTraits(value->m_traits));
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,7 +52,11 @@ namespace BehaviorContextUtilitiesCPP
|
||||
{
|
||||
bool operator()(const BehaviorParameter* left, const BehaviorParameter* right) const
|
||||
{
|
||||
return left->m_typeId == right->m_typeId && CleanTraits(left->m_traits) == CleanTraits(right->m_traits);
|
||||
return (left == nullptr && right == nullptr)
|
||||
|| (left != nullptr
|
||||
&& right != nullptr
|
||||
&& left->m_typeId == right->m_typeId
|
||||
&& CleanTraits(left->m_traits) == CleanTraits(right->m_traits));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -137,7 +148,7 @@ namespace AZ
|
||||
for (size_t argIndex = 0, argSentinel = overload.GetNumArguments(); argIndex < argSentinel; ++argIndex)
|
||||
{
|
||||
auto overloadedArgIter = variance.m_input.find(argIndex);
|
||||
if (overloadedArgIter != variance.m_input.end())
|
||||
if (overloadedArgIter != variance.m_input.end() && overloadedArgIter->second[overloadIndex])
|
||||
{
|
||||
// if this doesn't work try the type name
|
||||
overloadName += ReplaceCppArtifacts(overloadedArgIter->second[overloadIndex]->m_name);
|
||||
@@ -185,16 +196,24 @@ namespace AZ
|
||||
{
|
||||
auto argument = overloads[overloadIndex].first->GetArgument(0);
|
||||
|
||||
const bool isThisPointer
|
||||
= (argument->m_traits & AZ::BehaviorParameter::Traits::TR_THIS_PTR) != 0
|
||||
|| AZ::FindAttribute(AZ::Script::Attributes::TreatAsMemberFunction, overloads[overloadIndex].first->m_attributes);
|
||||
if (argument)
|
||||
{
|
||||
const bool isThisPointer
|
||||
= (argument->m_traits & AZ::BehaviorParameter::Traits::TR_THIS_PTR) != 0
|
||||
|| AZ::FindAttribute(AZ::Script::Attributes::TreatAsMemberFunction, overloads[overloadIndex].first->m_attributes);
|
||||
|
||||
oneArgIsThisPointer = oneArgIsThisPointer || isThisPointer;
|
||||
oneArgIsThisPointer = oneArgIsThisPointer || isThisPointer;
|
||||
}
|
||||
|
||||
types.insert(argument);
|
||||
stripedArgs.emplace_back(argument);
|
||||
}
|
||||
|
||||
if (types.size() == overloads.size())
|
||||
{
|
||||
variance.m_unambiguousInput.insert(0);
|
||||
}
|
||||
|
||||
if (types.size() > 1 && (onThis == VariantOnThis::Yes || !oneArgIsThisPointer))
|
||||
{
|
||||
variance.m_input.insert(AZStd::make_pair(0, stripedArgs));
|
||||
@@ -210,11 +229,15 @@ namespace AZ
|
||||
for (size_t overloadIndex = 0, overloadSentinel = overloads.size(); overloadIndex < overloadSentinel; ++overloadIndex)
|
||||
{
|
||||
auto argument = overloads[overloadIndex].first->GetArgument(argIndex);
|
||||
|
||||
types.insert(argument);
|
||||
stripedArgs.emplace_back(argument);
|
||||
}
|
||||
|
||||
if (types.size() == overloads.size())
|
||||
{
|
||||
variance.m_unambiguousInput.insert(0);
|
||||
}
|
||||
|
||||
if (types.size() > 1)
|
||||
{
|
||||
variance.m_input.insert(AZStd::make_pair(argIndex, stripedArgs));
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace AZ
|
||||
struct OverloadVariance
|
||||
{
|
||||
AZStd::unordered_map<size_t, AZStd::vector<const BehaviorParameter*>> m_input;
|
||||
// the indices of inputs that make selection of overload unambiguous
|
||||
AZStd::unordered_set<size_t> m_unambiguousInput;
|
||||
AZStd::vector<const BehaviorParameter*> m_output;
|
||||
};
|
||||
|
||||
|
||||
@@ -2048,10 +2048,6 @@ LUA_API const Node* lua_getDummyNode()
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Warning("Script", false, "Index %d is not a function!", functionIndex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -2078,7 +2074,6 @@ LUA_API const Node* lua_getDummyNode()
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Warning("Script", lua_isnil(m_nativeContext, -1), "Name %s exists but is not a function!", functionName);
|
||||
lua_pop(m_nativeContext, 1);
|
||||
}
|
||||
|
||||
@@ -5888,7 +5883,6 @@ LUA_API const Node* lua_getDummyNode()
|
||||
else
|
||||
{
|
||||
lua_pop(m_impl->m_lua, 1);
|
||||
AZ_Warning("Script", false, "%s is not a function!", functionName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -5906,7 +5900,6 @@ LUA_API const Node* lua_getDummyNode()
|
||||
else
|
||||
{
|
||||
lua_pop(m_impl->m_lua, 1);
|
||||
AZ_Warning("Script", false, "CacheIndex %d is not a function!", cachedIndex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "AzCore/RTTI/TypeInfo.h"
|
||||
#include <AzCore/Math/UuidSerializer.h>
|
||||
#include <AzCore/RTTI/AttributeReader.h>
|
||||
#include <AzCore/Serialization/Json/CastingHelpers.h>
|
||||
@@ -61,6 +62,13 @@ namespace AZ
|
||||
|
||||
if (classData->m_azRtti && classData->m_azRtti->GetGenericTypeId() != typeId)
|
||||
{
|
||||
if (((classData->m_azRtti->GetTypeTraits() & (AZ::TypeTraits::is_signed | AZ::TypeTraits::is_unsigned)) != AZ::TypeTraits{0}) &&
|
||||
context.GetSerializeContext()->GetUnderlyingTypeId(typeId) == classData->m_typeId)
|
||||
{
|
||||
// This value is from an enum, where a field has been reflected using ClassBuilder::Field, but the enum
|
||||
// type itself has not been reflected using EnumBuilder. Treat it as an enum.
|
||||
return LoadEnum(object, *classData, value, context);
|
||||
}
|
||||
serializer = context.GetRegistrationContext()->GetSerializerForType(classData->m_azRtti->GetGenericTypeId());
|
||||
if (serializer)
|
||||
{
|
||||
@@ -77,21 +85,18 @@ namespace AZ
|
||||
{
|
||||
return LoadEnum(object, *classData, value, context);
|
||||
}
|
||||
else if (classData->m_container)
|
||||
if (classData->m_container)
|
||||
{
|
||||
return context.Report(Tasks::ReadField, Outcomes::Unsupported,
|
||||
"The Json Serializer uses custom serializers to load containers. If this message is encountered "
|
||||
"then a serializer for the target containers is missing, isn't registered or doesn't exist.");
|
||||
}
|
||||
else if (value.IsObject())
|
||||
if (value.IsObject())
|
||||
{
|
||||
return LoadClass(object, *classData, value, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Report(Tasks::ReadField, Outcomes::Unsupported,
|
||||
AZStd::string::format("Reading into targets of type '%s' is not supported.", classData->m_name));
|
||||
}
|
||||
return context.Report(Tasks::ReadField, Outcomes::Unsupported,
|
||||
AZStd::string::format("Reading into targets of type '%s' is not supported.", classData->m_name));
|
||||
}
|
||||
|
||||
JsonSerializationResult::ResultCode JsonDeserializer::LoadToPointer(void* object, const Uuid& typeId,
|
||||
@@ -233,8 +238,16 @@ namespace AZ
|
||||
AZ::TypeId underlyingTypeId = AZ::TypeId::CreateNull();
|
||||
if (!attributeReader.Read<AZ::TypeId>(underlyingTypeId))
|
||||
{
|
||||
return context.Report(Tasks::RetrieveInfo, Outcomes::Unknown,
|
||||
"Unable to find underlying type of enum in class data.");
|
||||
// for non-reflected enums, the passed-in classData already represents the enum's underlying type
|
||||
if (context.GetSerializeContext()->GetUnderlyingTypeId(classData.m_typeId) == classData.m_typeId)
|
||||
{
|
||||
underlyingTypeId = classData.m_typeId;
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Report(Tasks::RetrieveInfo, Outcomes::Unknown,
|
||||
"Unable to find underlying type of enum in class data.");
|
||||
}
|
||||
}
|
||||
|
||||
const SerializeContext::ClassData* underlyingClassData = context.GetSerializeContext()->FindClassData(underlyingTypeId);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <cerrno>
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <AzCore/JSON/error/en.h>
|
||||
#include <AzCore/NativeUI//NativeUIRequests.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/Json/StackedString.h>
|
||||
#include <AzCore/Settings/SettingsRegistryImpl.h>
|
||||
@@ -880,6 +881,13 @@ namespace AZ
|
||||
const Specializations& specializations, const rapidjson::Pointer& historyPointer, AZStd::string_view folderPath)
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
if (&lhs == &rhs)
|
||||
{
|
||||
// Early return to avoid setting the collisionFound reference to true
|
||||
// std::sort is allowed to pass in the same memory address for the left and right elements
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ_Assert(!lhs.m_tags.empty(), "Comparing a settings file without at least a name tag.");
|
||||
AZ_Assert(!rhs.m_tags.empty(), "Comparing a settings file without at least a name tag.");
|
||||
@@ -1054,15 +1062,23 @@ namespace AZ
|
||||
jsonPatch.ParseInsitu<flags>(scratchBuffer.data());
|
||||
if (jsonPatch.HasParseError())
|
||||
{
|
||||
auto nativeUI = AZ::Interface<NativeUI::NativeUIRequests>::Get();
|
||||
if (jsonPatch.GetParseError() == rapidjson::kParseErrorDocumentEmpty)
|
||||
{
|
||||
AZ_Warning("Settings Registry", false, R"(Unable to parse registry file "%s" due to json error "%s" at offset %llu.)",
|
||||
AZ_Warning("Settings Registry", false, R"(Unable to parse registry file "%s" due to json error "%s" at offset %zu.)",
|
||||
path, GetParseError_En(jsonPatch.GetParseError()), jsonPatch.GetErrorOffset());
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error("Settings Registry", false, R"(Unable to parse registry file "%s" due to json error "%s" at offset %llu.)", path,
|
||||
using ErrorString = AZStd::fixed_string<4096>;
|
||||
auto jsonError = ErrorString::format(R"(Unable to parse registry file "%s" due to json error "%s" at offset %zu.)", path,
|
||||
GetParseError_En(jsonPatch.GetParseError()), jsonPatch.GetErrorOffset());
|
||||
AZ_Error("Settings Registry", false, "%s", jsonError.c_str());
|
||||
|
||||
if (nativeUI)
|
||||
{
|
||||
nativeUI->DisplayOkDialog("Setreg(Patch) Merge Issue", AZStd::string_view(jsonError), false);
|
||||
}
|
||||
}
|
||||
|
||||
pointer.Create(m_settings, m_settings.GetAllocator()).SetObject()
|
||||
|
||||
@@ -1740,7 +1740,10 @@ namespace AZ
|
||||
if (!iter->IsInstantiated())
|
||||
{
|
||||
#if defined(AZ_ENABLE_TRACING)
|
||||
Data::Asset<SliceAsset> thisAsset = Data::AssetManager::Instance().FindAsset(GetMyAsset()->GetId(), AZ::Data::AssetLoadBehavior::Default);
|
||||
Data::Asset<SliceAsset> thisAsset = GetMyAsset()
|
||||
? Data::Asset<SliceAsset>(Data::AssetManager::Instance().FindAsset(
|
||||
GetMyAsset()->GetId(), AZ::Data::AssetLoadBehavior::Default))
|
||||
: Data::Asset<SliceAsset>();
|
||||
AZ_Warning("Slice", false, "Removing %d instances of slice asset %s from parent asset %s due to failed instantiation. "
|
||||
"Saving parent asset will result in loss of slice data.",
|
||||
iter->GetInstances().size(),
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#include <AzCore/std/string/osstring.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
namespace AZ
|
||||
|
||||
@@ -41,10 +41,6 @@ namespace AZ
|
||||
if (const char* homePath = std::getenv("HOME"); homePath != nullptr)
|
||||
{
|
||||
AZ::IO::FixedMaxPath path{homePath};
|
||||
if (!path.empty())
|
||||
{
|
||||
path /= ".o3de";
|
||||
}
|
||||
return path.Native();
|
||||
}
|
||||
return {};
|
||||
|
||||
@@ -39,8 +39,8 @@ namespace AZ
|
||||
// Append .framework to the name of full path
|
||||
// Afterwards use the AZ::IO::Path Append function append the filename as a child
|
||||
// of the framework directory
|
||||
AZ::IO::FixedMaxPathString fileName = fullPath.Filename().Native();
|
||||
fullPath.ReplaceFilename(fileName + ".framework");
|
||||
AZ::IO::FixedMaxPathString fileName{ fullPath.Filename().Native() };
|
||||
fullPath.ReplaceFilename(AZ::IO::PathView(AZStd::string_view(fileName + ".framework")));
|
||||
fullPath /= fileName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace UnitTest
|
||||
ErrorHandler::ErrorHandler(const char* errorPattern)
|
||||
: m_errorCount(0)
|
||||
, m_warningCount(0)
|
||||
, m_expectedErrorCount(0)
|
||||
, m_expectedWarningCount(0)
|
||||
, m_errorPattern(errorPattern)
|
||||
{
|
||||
AZ::Debug::TraceMessageBus::Handler::BusConnect();
|
||||
@@ -51,6 +53,16 @@ namespace UnitTest
|
||||
return m_warningCount;
|
||||
}
|
||||
|
||||
int ErrorHandler::GetExpectedErrorCount() const
|
||||
{
|
||||
return m_expectedErrorCount;
|
||||
}
|
||||
|
||||
int ErrorHandler::GetExpectedWarningCount() const
|
||||
{
|
||||
return m_expectedWarningCount;
|
||||
}
|
||||
|
||||
bool ErrorHandler::SuppressExpectedErrors([[maybe_unused]] const char* window, const char* message)
|
||||
{
|
||||
return AZStd::string(message).find(m_errorPattern) != AZStd::string::npos;
|
||||
@@ -61,7 +73,9 @@ namespace UnitTest
|
||||
[[maybe_unused]] const char* func, const char* message)
|
||||
{
|
||||
m_errorCount++;
|
||||
return SuppressExpectedErrors(window, message);
|
||||
bool suppress = SuppressExpectedErrors(window, message);
|
||||
m_expectedErrorCount += suppress;
|
||||
return suppress;
|
||||
}
|
||||
|
||||
bool ErrorHandler::OnPreWarning(
|
||||
@@ -69,7 +83,9 @@ namespace UnitTest
|
||||
[[maybe_unused]] const char* func, const char* message)
|
||||
{
|
||||
m_warningCount++;
|
||||
return SuppressExpectedErrors(window, message);
|
||||
bool suppress = SuppressExpectedErrors(window, message);
|
||||
m_expectedWarningCount += suppress;
|
||||
return suppress;
|
||||
}
|
||||
|
||||
bool ErrorHandler::OnPrintf(const char* window, const char* message)
|
||||
|
||||
@@ -30,8 +30,14 @@ namespace UnitTest
|
||||
public:
|
||||
explicit ErrorHandler(const char* errorPattern);
|
||||
~ErrorHandler();
|
||||
//! Returns the total number of errors encountered (including those which match the expected pattern).
|
||||
int GetErrorCount() const;
|
||||
//! Returns the total number of warnings encountered (including those which match the expected pattern).
|
||||
int GetWarningCount() const;
|
||||
//! Returns the number of errors encountered which matched the expected pattern.
|
||||
int GetExpectedErrorCount() const;
|
||||
//! Returns the number of warnings encountered which matched the expected pattern.
|
||||
int GetExpectedWarningCount() const;
|
||||
bool SuppressExpectedErrors(const char* window, const char* message);
|
||||
|
||||
// AZ::Debug::TraceMessageBus
|
||||
@@ -44,6 +50,8 @@ namespace UnitTest
|
||||
AZStd::string m_errorPattern;
|
||||
int m_errorCount;
|
||||
int m_warningCount;
|
||||
int m_expectedErrorCount;
|
||||
int m_expectedWarningCount;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ namespace MathTestData
|
||||
};
|
||||
|
||||
static const AZ::Transform NonOrthogonalTransforms[] = {
|
||||
AZ::Transform::CreateScale(AZ::Vector3(2.4f, 0.3f, 1.7f)),
|
||||
AZ::Transform::CreateRotationX(2.2f) * AZ::Transform::CreateScale(AZ::Vector3(0.2f, 0.8f, 1.4f))
|
||||
AZ::Transform::CreateUniformScale(2.4f),
|
||||
AZ::Transform::CreateRotationX(2.2f) * AZ::Transform::CreateUniformScale(0.8f)
|
||||
};
|
||||
|
||||
static const AZ::Transform OrthogonalTransforms[] = {
|
||||
|
||||
@@ -59,11 +59,11 @@ namespace UnitTest
|
||||
TEST(MATH_Obb, TestScaleTransform)
|
||||
{
|
||||
Obb obb = Obb::CreateFromPositionRotationAndHalfLengths(position, rotation, halfLengths);
|
||||
Vector3 scaleFactors = Vector3(1.0f, 2.0f, 3.0f);
|
||||
Transform transform = Transform::CreateScale(scaleFactors);
|
||||
float scale = 3.0f;
|
||||
Transform transform = Transform::CreateUniformScale(scale);
|
||||
obb = transform * obb;
|
||||
EXPECT_THAT(obb.GetPosition(), IsClose(Vector3(1.0f, 4.0f, 9.0f)));
|
||||
EXPECT_THAT(obb.GetHalfLengths(), IsClose(Vector3(0.5f, 1.0f, 1.5f)));
|
||||
EXPECT_THAT(obb.GetPosition(), IsClose(Vector3(3.0f, 6.0f, 9.0f)));
|
||||
EXPECT_THAT(obb.GetHalfLengths(), IsClose(Vector3(1.5f, 1.5f, 1.5f)));
|
||||
}
|
||||
|
||||
TEST(MATH_Obb, TestSetPosition)
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Math/Random.h>
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
TEST(MATH_Random, GetHaltonNumber)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(0.5, GetHaltonNumber(1, 2));
|
||||
EXPECT_FLOAT_EQ(898.0f / 2187.0f, GetHaltonNumber(1234, 3));
|
||||
EXPECT_FLOAT_EQ(5981.0f / 15625.0f, GetHaltonNumber(4321, 5));
|
||||
}
|
||||
|
||||
TEST(MATH_Random, HaltonSequence)
|
||||
{
|
||||
HaltonSequence<3> sequence({ 2, 3, 5 });
|
||||
auto regularSequence = sequence.GetHaltonSequence<5>();
|
||||
|
||||
EXPECT_FLOAT_EQ(1.0f / 2.0f, regularSequence[0][0]);
|
||||
EXPECT_FLOAT_EQ(1.0f / 3.0f, regularSequence[0][1]);
|
||||
EXPECT_FLOAT_EQ(1.0f / 5.0f, regularSequence[0][2]);
|
||||
|
||||
EXPECT_FLOAT_EQ(1.0f / 4.0f, regularSequence[1][0]);
|
||||
EXPECT_FLOAT_EQ(2.0f / 3.0f, regularSequence[1][1]);
|
||||
EXPECT_FLOAT_EQ(2.0f / 5.0f, regularSequence[1][2]);
|
||||
|
||||
EXPECT_FLOAT_EQ(3.0f / 4.0f, regularSequence[2][0]);
|
||||
EXPECT_FLOAT_EQ(1.0f / 9.0f, regularSequence[2][1]);
|
||||
EXPECT_FLOAT_EQ(3.0f / 5.0f, regularSequence[2][2]);
|
||||
|
||||
EXPECT_FLOAT_EQ(1.0f / 8.0f, regularSequence[3][0]);
|
||||
EXPECT_FLOAT_EQ(4.0f / 9.0f, regularSequence[3][1]);
|
||||
EXPECT_FLOAT_EQ(4.0f / 5.0f, regularSequence[3][2]);
|
||||
|
||||
EXPECT_FLOAT_EQ(5.0f / 8.0f, regularSequence[4][0]);
|
||||
EXPECT_FLOAT_EQ(7.0f / 9.0f, regularSequence[4][1]);
|
||||
EXPECT_FLOAT_EQ(1.0f / 25.0f, regularSequence[4][2]);
|
||||
|
||||
sequence.SetOffsets({ 1, 2, 3 });
|
||||
auto offsetSequence = sequence.GetHaltonSequence<2>();
|
||||
|
||||
EXPECT_FLOAT_EQ(1.0f / 4.0f, offsetSequence[0][0]);
|
||||
EXPECT_FLOAT_EQ(1.0f / 9.0f, offsetSequence[0][1]);
|
||||
EXPECT_FLOAT_EQ(4.0f / 5.0f, offsetSequence[0][2]);
|
||||
|
||||
EXPECT_FLOAT_EQ(3.0f / 4.0f, offsetSequence[1][0]);
|
||||
EXPECT_FLOAT_EQ(4.0f / 9.0f, offsetSequence[1][1]);
|
||||
EXPECT_FLOAT_EQ(1.0f / 25.0f, offsetSequence[1][2]);
|
||||
|
||||
sequence.SetIncrements({ 1, 2, 3 });
|
||||
auto incrementedSequence = sequence.GetHaltonSequence<2>();
|
||||
|
||||
EXPECT_FLOAT_EQ(1.0f / 4.0f, incrementedSequence[0][0]);
|
||||
EXPECT_FLOAT_EQ(1.0f / 9.0f, incrementedSequence[0][1]);
|
||||
EXPECT_FLOAT_EQ(4.0f / 5.0f, incrementedSequence[0][2]);
|
||||
|
||||
EXPECT_FLOAT_EQ(3.0f / 4.0f, incrementedSequence[1][0]);
|
||||
EXPECT_FLOAT_EQ(7.0f / 9.0f, incrementedSequence[1][1]);
|
||||
EXPECT_FLOAT_EQ(11.0f / 25.0f, incrementedSequence[1][2]);
|
||||
}
|
||||
}
|
||||
@@ -180,13 +180,13 @@ namespace Benchmark
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(BM_MathTransform, CreateScale)(benchmark::State& state)
|
||||
BENCHMARK_F(BM_MathTransform, CreateUniformScale)(benchmark::State& state)
|
||||
{
|
||||
for (auto _ : state)
|
||||
{
|
||||
for (auto& testData : m_testDataArray)
|
||||
{
|
||||
AZ::Transform result = AZ::Transform::CreateScale(testData.v3);
|
||||
AZ::Transform result = AZ::Transform::CreateUniformScale(testData.value[0]);
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
@@ -344,39 +344,39 @@ namespace Benchmark
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(BM_MathTransform, GetScale)(benchmark::State& state)
|
||||
BENCHMARK_F(BM_MathTransform, GetUniformScale)(benchmark::State& state)
|
||||
{
|
||||
for (auto _ : state)
|
||||
{
|
||||
for (auto& testData : m_testDataArray)
|
||||
{
|
||||
AZ::Vector3 result = testData.t1.GetScale();
|
||||
float result = testData.t1.GetUniformScale();
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(BM_MathTransform, SetScale)(benchmark::State& state)
|
||||
BENCHMARK_F(BM_MathTransform, SetUniformScale)(benchmark::State& state)
|
||||
{
|
||||
for (auto _ : state)
|
||||
{
|
||||
for (auto& testData : m_testDataArray)
|
||||
{
|
||||
AZ::Transform testTransform = testData.t2;
|
||||
testTransform.SetScale(testData.v3);
|
||||
testTransform.SetUniformScale(testData.value[0]);
|
||||
benchmark::DoNotOptimize(testTransform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(BM_MathTransform, ExtractScale)(benchmark::State& state)
|
||||
BENCHMARK_F(BM_MathTransform, ExtractUniformScale)(benchmark::State& state)
|
||||
{
|
||||
for (auto _ : state)
|
||||
{
|
||||
for (auto& testData : m_testDataArray)
|
||||
{
|
||||
AZ::Transform testTransform = testData.t2;
|
||||
AZ::Vector3 result = testTransform.ExtractScale();
|
||||
float result = testTransform.ExtractUniformScale();
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,37 +159,14 @@ namespace UnitTest
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MATH_Transform, TransformCreateFromQuaternionFixture, ::testing::ValuesIn(MathTestData::UnitQuaternions));
|
||||
|
||||
using TransformCreateFromMatrix3x3Fixture = ::testing::TestWithParam<AZ::Matrix3x3>;
|
||||
|
||||
TEST_P(TransformCreateFromMatrix3x3Fixture, CreateFromMatrix3x3)
|
||||
TEST(MATH_Transform, CreateUniformScale)
|
||||
{
|
||||
const AZ::Matrix3x3 matrix3x3 = GetParam();
|
||||
const AZ::Transform transform = AZ::Transform::CreateFromMatrix3x3(matrix3x3);
|
||||
EXPECT_THAT(transform.GetTranslation(), IsClose(AZ::Vector3::CreateZero()));
|
||||
const AZ::Vector3 vector(2.3f, -0.6, 1.8f);
|
||||
EXPECT_THAT(transform.TransformPoint(vector), IsClose(matrix3x3 * vector));
|
||||
}
|
||||
|
||||
TEST_P(TransformCreateFromMatrix3x3Fixture, CreateFromMatrix3x3AndTranslation)
|
||||
{
|
||||
const AZ::Matrix3x3 matrix3x3 = GetParam();
|
||||
const AZ::Vector3 translation(-2.6f, 1.7f, 0.8f);
|
||||
const AZ::Transform transform = AZ::Transform::CreateFromMatrix3x3AndTranslation(matrix3x3, translation);
|
||||
EXPECT_THAT(transform.GetTranslation(), IsClose(translation));
|
||||
const AZ::Vector3 vector(2.3f, -0.6, 1.8f);
|
||||
EXPECT_THAT(transform.TransformPoint(vector), IsClose(matrix3x3 * vector + translation));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MATH_Transform, TransformCreateFromMatrix3x3Fixture, ::testing::ValuesIn(MathTestData::Matrix3x3s));
|
||||
|
||||
TEST(MATH_Transform, CreateScale)
|
||||
{
|
||||
const AZ::Vector3 scale(1.7f, 0.3f, 2.4f);
|
||||
const AZ::Transform transform = AZ::Transform::CreateScale(scale);
|
||||
const float scale = 1.7f;
|
||||
const AZ::Transform transform = AZ::Transform::CreateUniformScale(scale);
|
||||
const AZ::Vector3 vector(0.2f, -1.6f, 0.4f);
|
||||
EXPECT_THAT(transform.GetTranslation(), IsClose(AZ::Vector3::CreateZero()));
|
||||
const AZ::Vector3 transformedVector = transform.TransformPoint(vector);
|
||||
const AZ::Vector3 expected(0.34f, -0.48f, 0.96f);
|
||||
const AZ::Vector3 expected(0.34f, -2.72f, 0.68f);
|
||||
EXPECT_THAT(transformedVector, IsClose(expected));
|
||||
}
|
||||
|
||||
@@ -237,10 +214,10 @@ namespace UnitTest
|
||||
TEST(MATH_Transform, MultiplyByTransform)
|
||||
{
|
||||
const AZ::Transform transform1 = AZ::Transform::CreateRotationY(0.3f);
|
||||
const AZ::Transform transform2 = AZ::Transform::CreateScale(AZ::Vector3(1.3f, 1.5f, 0.4f));
|
||||
const AZ::Transform transform2 = AZ::Transform::CreateUniformScale(1.3f);
|
||||
const AZ::Transform transform3 = AZ::Transform::CreateFromQuaternionAndTranslation(
|
||||
AZ::Quaternion(0.42f, 0.46f, -0.66f, 0.42f), AZ::Vector3(2.8f, -3.7f, 1.6f));
|
||||
const AZ::Transform transform4 = AZ::Transform::CreateRotationX(-0.7f) * AZ::Transform::CreateScale(AZ::Vector3(0.6f, 1.3f, 0.7f));
|
||||
const AZ::Transform transform4 = AZ::Transform::CreateRotationX(-0.7f) * AZ::Transform::CreateUniformScale(0.6f);
|
||||
AZ::Transform transform5 = transform1;
|
||||
transform5 *= transform4;
|
||||
const AZ::Vector3 vector(1.9f, 2.3f, 0.2f);
|
||||
@@ -254,14 +231,14 @@ namespace UnitTest
|
||||
TEST(MATH_Transform, TranslationCorrectInTransformHierarchy)
|
||||
{
|
||||
AZ::Transform parent = AZ::Transform::CreateRotationZ(AZ::DegToRad(45.0f));
|
||||
parent.SetScale(AZ::Vector3(3.0f, 2.0f, 1.0f));
|
||||
parent.SetUniformScale(3.0f);
|
||||
parent.SetTranslation(AZ::Vector3(0.2f, 0.3f, 0.4f));
|
||||
AZ::Transform child = AZ::Transform::CreateRotationZ(AZ::DegToRad(90.0f));
|
||||
child.SetTranslation(AZ::Vector3(0.5f, 0.6f, 0.7f));
|
||||
const AZ::Transform overallTransform = parent * child;
|
||||
const AZ::Vector3 overallTranslation = overallTransform.GetTranslation();
|
||||
const AZ::Vector3 expectedTranslation(0.412132f, 2.20919f, 1.1f);
|
||||
EXPECT_THAT(overallTranslation, IsClose(AZ::Vector3(0.412132f, 2.20919f, 1.1f)));
|
||||
const AZ::Vector3 expectedTranslation(-0.012132f, 2.633452f, 2.5f);
|
||||
EXPECT_THAT(overallTranslation, IsClose(expectedTranslation));
|
||||
}
|
||||
|
||||
TEST(MATH_Transform, TransformPointVector3)
|
||||
@@ -337,14 +314,14 @@ namespace UnitTest
|
||||
TEST_P(TransformScaleFixture, Scale)
|
||||
{
|
||||
const AZ::Transform orthogonalTransform = GetParam();
|
||||
EXPECT_THAT(orthogonalTransform.GetScale(), IsClose(AZ::Vector3::CreateOne()));
|
||||
EXPECT_NEAR(orthogonalTransform.GetUniformScale(), 1.0f, AZ::Constants::Tolerance);
|
||||
AZ::Transform unscaledTransform = orthogonalTransform;
|
||||
unscaledTransform.ExtractScale();
|
||||
EXPECT_THAT(unscaledTransform.GetScale(), IsClose(AZ::Vector3::CreateOne()));
|
||||
const AZ::Vector3 scale(2.8f, 0.7f, 1.3f);
|
||||
unscaledTransform.ExtractUniformScale();
|
||||
EXPECT_NEAR(unscaledTransform.GetUniformScale(), 1.0f, AZ::Constants::Tolerance);
|
||||
const float scale = 2.8f;
|
||||
AZ::Transform scaledTransform = orthogonalTransform;
|
||||
scaledTransform.MultiplyByScale(scale);
|
||||
EXPECT_THAT(scaledTransform.GetScale(), IsClose(scale));
|
||||
scaledTransform.MultiplyByUniformScale(scale);
|
||||
EXPECT_NEAR(scaledTransform.GetUniformScale(), scale, AZ::Constants::Tolerance);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MATH_Transform, TransformScaleFixture, ::testing::ValuesIn(MathTestData::OrthogonalTransforms));
|
||||
@@ -353,24 +330,11 @@ namespace UnitTest
|
||||
{
|
||||
EXPECT_TRUE(AZ::Transform::CreateIdentity().IsOrthogonal());
|
||||
EXPECT_TRUE(AZ::Transform::CreateRotationZ(0.3f).IsOrthogonal());
|
||||
EXPECT_FALSE(AZ::Transform::CreateScale(AZ::Vector3(0.8f, 0.3f, 1.2f)).IsOrthogonal());
|
||||
EXPECT_FALSE(AZ::Transform::CreateUniformScale(0.8f).IsOrthogonal());
|
||||
EXPECT_TRUE(AZ::Transform::CreateFromQuaternion(AZ::Quaternion(-0.52f, -0.08f, 0.56f, 0.64f)).IsOrthogonal());
|
||||
AZ::Transform transform;
|
||||
transform.SetFromEulerRadians(AZ::Vector3(0.2f, 0.4f, 0.1f));
|
||||
EXPECT_TRUE(transform.IsOrthogonal());
|
||||
|
||||
// want to test each possible way the transform could fail to be orthogonal, which we can do by testing for one
|
||||
// axis, then using a rotation which cycles the axes
|
||||
const AZ::Transform axisCycle = AZ::Transform::CreateFromQuaternion(AZ::Quaternion(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
|
||||
// a transform which is normalized in 2 axes, but not the third
|
||||
AZ::Transform nonOrthogonalTransform1 = AZ::Transform::CreateScale(AZ::Vector3(1.0f, 1.0f, 2.0f));
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
EXPECT_FALSE(nonOrthogonalTransform1.IsOrthogonal());
|
||||
nonOrthogonalTransform1 = axisCycle * nonOrthogonalTransform1;
|
||||
}
|
||||
}
|
||||
|
||||
using TransformSetFromEulerDegreesFixture = ::testing::TestWithParam<AZ::Vector3>;
|
||||
@@ -459,16 +423,17 @@ namespace UnitTest
|
||||
{
|
||||
const char* objectStreamBuffer =
|
||||
R"DELIMITER(<ObjectStream version="3">
|
||||
<Class name="Transform" field="m_data" value="0.79429845 0.8545947 -0.94273965 -0.05367075 0.3899708 0.30828915 1.0097652 -0.31084164 0.56899188 513.7845459 492.5420837 32.0000000" type="{5D9958E9-9F1E-4985-B532-FFFDE75FEDFD}"/>
|
||||
<Class name="Transform" field="m_data" value="0.79429845 0.8545947 -0.94273965 -0.1610121 1.1699124 0.92486745 1.2622065 -0.3885522 0.71123985 513.7845459 492.5420837 32.0000000" type="{5D9958E9-9F1E-4985-B532-FFFDE75FEDFD}"/>
|
||||
</ObjectStream>)DELIMITER";
|
||||
|
||||
AZ::Transform* deserializedTransform = AZ::Utils::LoadObjectFromBuffer<AZ::Transform>(objectStreamBuffer, strlen(objectStreamBuffer) + 1);
|
||||
|
||||
const AZ::Vector3 expectedTranslation(513.7845459f, 492.5420837f, 32.0000000f);
|
||||
const AZ::Vector3 expectedScale(1.5f, 0.5f, 1.2f);
|
||||
const float expectedScale = 1.5f;
|
||||
const AZ::Quaternion expectedRotation(0.2624075f, 0.4405251f, 0.2029076f, 0.8342113f);
|
||||
const AZ::Transform expectedTransform =
|
||||
AZ::Transform::CreateFromQuaternionAndTranslation(expectedRotation, expectedTranslation) * AZ::Transform::CreateScale(expectedScale);
|
||||
AZ::Transform::CreateFromQuaternionAndTranslation(expectedRotation, expectedTranslation) *
|
||||
AZ::Transform::CreateUniformScale(expectedScale);
|
||||
|
||||
EXPECT_TRUE(deserializedTransform->IsClose(expectedTransform));
|
||||
azfree(deserializedTransform);
|
||||
|
||||
@@ -1275,10 +1275,10 @@ namespace UnitTest
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(1, 0, 0)):IsClose(Vector3(1, 0, 0)))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(0, 1, 0)):IsClose(Vector3(0, 0.866, 0.5)))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(0, 0, 1)):IsClose(Vector3(0, -0.5, 0.866)))");
|
||||
script->Execute("t1 = Transform.CreateScale(Vector3(1, 2, 3))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(1, 0, 0)):IsClose(Vector3(1, 0, 0)))");
|
||||
script->Execute("t1 = Transform.CreateUniformScale(2)");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(1, 0, 0)):IsClose(Vector3(2, 0, 0)))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(0, 1, 0)):IsClose(Vector3(0, 2, 0)))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(0, 0, 1)):IsClose(Vector3(0, 0, 3)))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(0, 0, 1)):IsClose(Vector3(0, 0, 2)))");
|
||||
script->Execute("t1 = Transform.CreateTranslation(Vector3(1, 2, 3))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(1, 0, 0)):IsClose(Vector3(1, 0, 0)))");
|
||||
script->Execute("AZTestAssert(t1:TransformVector(Vector3(0, 1, 0)):IsClose(Vector3(0, 1, 0)))");
|
||||
@@ -1341,19 +1341,19 @@ namespace UnitTest
|
||||
script->Execute("AZTestAssert(t3:GetTranslation():IsClose(Vector3(-5.90, 25.415, 19.645), 0.001))");
|
||||
|
||||
////test inverse, should handle non-orthogonal matrices
|
||||
script->Execute("t1 = Transform.CreateRotationX(1) * Transform.CreateScale(Vector3(1, 2, 3))");
|
||||
script->Execute("t1 = Transform.CreateRotationX(1) * Transform.CreateUniformScale(2)");
|
||||
script->Execute("AZTestAssert((t1*t1:GetInverse()):IsClose(Transform.CreateIdentity()))");
|
||||
|
||||
////scale access
|
||||
script->Execute("t1 = Transform.CreateRotationX(Math.DegToRad(40)) * Transform.CreateScale(Vector3(2, 3, 4))");
|
||||
script->Execute("AZTestAssert(t1:GetScale():IsClose(Vector3(2, 3, 4)))");
|
||||
script->Execute("AZTestAssert(t1:ExtractScale():IsClose(Vector3(2, 3, 4)))");
|
||||
script->Execute("AZTestAssert(t1:GetScale():IsClose(Vector3.CreateOne()))");
|
||||
script->Execute("t1:MultiplyByScale(Vector3(3, 4, 5))");
|
||||
script->Execute("AZTestAssert(t1:GetScale():IsClose(Vector3(3, 4, 5)))");
|
||||
script->Execute("t1 = Transform.CreateRotationX(Math.DegToRad(40)) * Transform.CreateUniformScale(3)");
|
||||
script->Execute("AZTestAssertFloatClose(t1:GetUniformScale(), 3)");
|
||||
script->Execute("AZTestAssertFloatClose(t1:ExtractUniformScale(), 3)");
|
||||
script->Execute("AZTestAssertFloatClose(t1:GetUniformScale(), 1)");
|
||||
script->Execute("t1:MultiplyByUniformScale(2)");
|
||||
script->Execute("AZTestAssertFloatClose(t1:GetUniformScale(), 2)");
|
||||
|
||||
////orthogonalize
|
||||
script->Execute("t1 = Transform.CreateRotationX(Math.DegToRad(30)) * Transform.CreateScale(Vector3(2, 3, 4))");
|
||||
script->Execute("t1 = Transform.CreateRotationX(Math.DegToRad(30)) * Transform.CreateUniformScale(3)");
|
||||
script->Execute("t1:SetTranslation(Vector3(1,2,3))");
|
||||
script->Execute("t2 = t1:GetOrthogonalized()");
|
||||
script->Execute("AZTestAssertFloatClose(t2:GetBasisX():GetLength(), 1)");
|
||||
@@ -1372,7 +1372,7 @@ namespace UnitTest
|
||||
script->Execute("t1 = Transform.CreateRotationX(Math.DegToRad(30))");
|
||||
script->Execute("t1:SetTranslation(Vector3(1, 2, 3))");
|
||||
script->Execute("AZTestAssert(t1:IsOrthogonal(0.05))");
|
||||
script->Execute("t1 = Transform.CreateRotationX(Math.DegToRad(30)) * Transform.CreateScale(Vector3(2, 3, 4))");
|
||||
script->Execute("t1 = Transform.CreateRotationX(Math.DegToRad(30)) * Transform.CreateUniformScale(2)");
|
||||
script->Execute("AZTestAssert( not t1:IsOrthogonal(0.05))");
|
||||
|
||||
////IsClose
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace JsonSerializationTests
|
||||
{
|
||||
using JsonSerializationTestCases = ::testing::Types<
|
||||
// Structures
|
||||
SimpleClass, SimpleInheritence, MultipleInheritence, SimpleNested, SimpleEnumWrapper,
|
||||
SimpleClass, SimpleInheritence, MultipleInheritence, SimpleNested, SimpleEnumWrapper, NonReflectedEnumWrapper,
|
||||
// Pointers
|
||||
SimpleNullPointer, SimpleAssignedPointer, ComplexAssignedPointer, ComplexNullInheritedPointer,
|
||||
ComplexAssignedDifferentInheritedPointer, ComplexAssignedSameInheritedPointer,
|
||||
|
||||
@@ -373,6 +373,57 @@ namespace JsonSerializationTests
|
||||
return MakeInstanceWithoutDefaults(AZStd::move(instance), json);
|
||||
}
|
||||
|
||||
// NonReflectedEnumWrapper
|
||||
bool NonReflectedEnumWrapper::Equals(const NonReflectedEnumWrapper& rhs, bool fullReflection) const
|
||||
{
|
||||
return !fullReflection || (m_enumClass == rhs.m_enumClass && m_rawEnum== rhs.m_rawEnum);
|
||||
}
|
||||
|
||||
void NonReflectedEnumWrapper::Reflect(AZStd::unique_ptr<AZ::SerializeContext>& context, bool fullReflection)
|
||||
{
|
||||
if (fullReflection)
|
||||
{
|
||||
// Note that the enums are not reflected using context->Enum<>
|
||||
|
||||
context->Class<NonReflectedEnumWrapper>()
|
||||
->Field("enumClass", &NonReflectedEnumWrapper::m_enumClass)
|
||||
->Field("rawEnum", &NonReflectedEnumWrapper::m_rawEnum);
|
||||
}
|
||||
}
|
||||
|
||||
InstanceWithSomeDefaults<NonReflectedEnumWrapper> NonReflectedEnumWrapper::GetInstanceWithSomeDefaults()
|
||||
{
|
||||
auto instance = AZStd::make_unique<NonReflectedEnumWrapper>();
|
||||
instance->m_enumClass = NonReflectedEnumWrapper::SimpleEnumClass::Option2;
|
||||
|
||||
const char* strippedDefaults = R"(
|
||||
{
|
||||
"enumClass": 2
|
||||
})";
|
||||
const char* keptDefaults = R"(
|
||||
{
|
||||
"enumClass": 2,
|
||||
"rawEnum": 0
|
||||
})";
|
||||
|
||||
return MakeInstanceWithSomeDefaults(AZStd::move(instance),
|
||||
strippedDefaults, keptDefaults);
|
||||
}
|
||||
|
||||
InstanceWithoutDefaults<NonReflectedEnumWrapper> NonReflectedEnumWrapper::GetInstanceWithoutDefaults()
|
||||
{
|
||||
auto instance = AZStd::make_unique<NonReflectedEnumWrapper>();
|
||||
instance->m_enumClass = NonReflectedEnumWrapper::SimpleEnumClass::Option2;
|
||||
instance->m_rawEnum = NonReflectedEnumWrapper::SimpleRawEnum::RawOption1;
|
||||
|
||||
const char* json = R"(
|
||||
{
|
||||
"enumClass": 2,
|
||||
"rawEnum": 1
|
||||
})";
|
||||
return MakeInstanceWithoutDefaults(AZStd::move(instance), json);
|
||||
}
|
||||
|
||||
// TemplatedClass<int>
|
||||
|
||||
bool TemplatedClass<int>::Equals(const TemplatedClass<int>& rhs, bool fullReflection) const
|
||||
|
||||
@@ -134,6 +134,35 @@ namespace JsonSerializationTests
|
||||
SimpleRawEnum m_rawEnum{};
|
||||
};
|
||||
|
||||
struct NonReflectedEnumWrapper
|
||||
{
|
||||
enum class SimpleEnumClass
|
||||
{
|
||||
Option1 = 1,
|
||||
Option2,
|
||||
};
|
||||
enum SimpleRawEnum
|
||||
{
|
||||
RawOption1 = 1,
|
||||
RawOption2,
|
||||
};
|
||||
AZ_CLASS_ALLOCATOR(NonReflectedEnumWrapper, AZ::SystemAllocator, 0);
|
||||
AZ_RTTI(NonReflectedEnumWrapper, "{A80D5B6B-2FD1-46E9-A7A9-44C5E2650526}");
|
||||
|
||||
static constexpr bool SupportsPartialDefaults = true;
|
||||
|
||||
NonReflectedEnumWrapper() = default;
|
||||
virtual ~NonReflectedEnumWrapper() = default;
|
||||
|
||||
bool Equals(const NonReflectedEnumWrapper& rhs, bool fullReflection) const;
|
||||
static void Reflect(AZStd::unique_ptr<AZ::SerializeContext>& context, bool fullReflection);
|
||||
static InstanceWithSomeDefaults<NonReflectedEnumWrapper> GetInstanceWithSomeDefaults();
|
||||
static InstanceWithoutDefaults<NonReflectedEnumWrapper> GetInstanceWithoutDefaults();
|
||||
|
||||
SimpleEnumClass m_enumClass{};
|
||||
SimpleRawEnum m_rawEnum{};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct TemplatedClass
|
||||
{
|
||||
@@ -158,5 +187,7 @@ namespace AZ
|
||||
{
|
||||
AZ_TYPE_INFO_SPECIALIZE(JsonSerializationTests::SimpleEnumWrapper::SimpleEnumClass, "{AF6F1964-5B20-4689-BF23-F36B9C9AAE6A}");
|
||||
AZ_TYPE_INFO_SPECIALIZE(JsonSerializationTests::SimpleEnumWrapper::SimpleRawEnum, "{EB24207F-B48F-4D8B-940D-3CD06A371739}");
|
||||
AZ_TYPE_INFO_SPECIALIZE(JsonSerializationTests::NonReflectedEnumWrapper::SimpleEnumClass, "{E80E4A41-B29E-4B7C-B630-3B599172C837}");
|
||||
AZ_TYPE_INFO_SPECIALIZE(JsonSerializationTests::NonReflectedEnumWrapper::SimpleRawEnum, "{C42AF28D-4F84-4540-972A-5B6EEFAB13FF}");
|
||||
AZ_TYPE_INFO_TEMPLATE(JsonSerializationTests::TemplatedClass, "{CA4ADF74-66E7-4D16-B4AC-F71278C60EC7}", AZ_TYPE_INFO_TYPENAME);
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace JsonSerializationTests
|
||||
TEST_F(JsonTransformSerializerTests, Load_FullySetTransform_ReturnsSuccessWithOnlyScale)
|
||||
{
|
||||
AZ::Transform testTransform = AZ::Transform::CreateIdentity();
|
||||
AZ::Transform expectedTransform = AZ::Transform::CreateScale(AZ::Vector3(5.5f));
|
||||
AZ::Transform expectedTransform = AZ::Transform::CreateUniformScale(5.5f);
|
||||
|
||||
rapidjson::Document json;
|
||||
json.Parse(R"({ "Scale" : 5.5 })");
|
||||
|
||||
@@ -152,6 +152,7 @@ set(FILES
|
||||
Math/PlaneTests.cpp
|
||||
Math/QuaternionPerformanceTests.cpp
|
||||
Math/QuaternionTests.cpp
|
||||
Math/RandomTests.cpp
|
||||
Math/ShapeIntersectionPerformanceTests.cpp
|
||||
Math/ShapeIntersectionTests.cpp
|
||||
Math/SfmtTests.cpp
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace AZ::IO
|
||||
// If used, the source path will be treated as the destination path
|
||||
// and no transformations will be done. Pass this flag when the path is to be the actual
|
||||
// path on the disk/in the packs and doesn't need adjustment (or after it has come through adjustments already)
|
||||
// if this is set, AdjustFileName will not map the input path into the master folder (Ex: Shaders will not be converted to Game\Shaders)
|
||||
// if this is set, AdjustFileName will not map the input path into the folder (Ex: Shaders will not be converted to Game\Shaders)
|
||||
FLAGS_PATH_REAL = 1 << 16,
|
||||
|
||||
// AdjustFileName will always copy the file path to the destination path:
|
||||
@@ -318,7 +318,6 @@ namespace AZ::IO
|
||||
virtual ArchiveFileIterator FindFirst(AZStd::string_view pDir, uint32_t nFlags = 0, bool bAllowUseFileSystem = false) = 0;
|
||||
virtual ArchiveFileIterator FindNext(AZ::IO::ArchiveFileIterator handle) = 0;
|
||||
virtual bool FindClose(AZ::IO::ArchiveFileIterator handle) = 0;
|
||||
// virtual bool IsOutOfDate(const char * szCompiledName, const char * szMasterFile)=0;
|
||||
//returns file modification time
|
||||
virtual IArchive::FileTime GetModificationTime(AZ::IO::HandleType fileHandle) = 0;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace AZ::IO
|
||||
enum EPakFlags
|
||||
{
|
||||
// support for absolute and other complex path specifications -
|
||||
// all paths will be treated relatively to the current directory (normally MasterCD)
|
||||
// all paths will be treated relatively to the current directory
|
||||
FLAGS_ABSOLUTE_PATHS = 1,
|
||||
|
||||
// if this is set, the object will only understand relative to the zip file paths,
|
||||
|
||||
@@ -432,46 +432,26 @@ namespace AzFramework
|
||||
|
||||
void TransformComponent::SetLocalRotation(const AZ::Vector3& eulerRadianAngles)
|
||||
{
|
||||
AZ::Transform newLocalTM = AZ::ConvertEulerRadiansToTransform(eulerRadianAngles);
|
||||
newLocalTM.SetScale(m_localTM.GetScale());
|
||||
newLocalTM.SetTranslation(m_localTM.GetTranslation());
|
||||
AZ::Transform newLocalTM = m_localTM;
|
||||
newLocalTM.SetRotation(AZ::Quaternion::CreateFromEulerAnglesRadians(eulerRadianAngles));
|
||||
SetLocalTM(newLocalTM);
|
||||
}
|
||||
|
||||
void TransformComponent::SetLocalRotationQuaternion(const AZ::Quaternion& quaternion)
|
||||
{
|
||||
AZ::Transform newLocalTM;
|
||||
newLocalTM.SetScale(m_localTM.GetScale());
|
||||
newLocalTM.SetTranslation(m_localTM.GetTranslation());
|
||||
AZ::Transform newLocalTM = m_localTM;
|
||||
newLocalTM.SetRotation(quaternion);
|
||||
SetLocalTM(newLocalTM);
|
||||
}
|
||||
|
||||
static AZ::Transform RotateAroundLocalHelper(float eulerAngleRadian, const AZ::Transform& localTM, AZ::Vector3 axis)
|
||||
{
|
||||
//get the existing translation and scale
|
||||
AZ::Vector3 translation = localTM.GetTranslation();
|
||||
AZ::Vector3 scale = localTM.GetScale();
|
||||
|
||||
//normalize the axis before creating rotation
|
||||
axis.Normalize();
|
||||
AZ::Quaternion rotate = AZ::Quaternion::CreateFromAxisAngle(axis, eulerAngleRadian);
|
||||
|
||||
//create new rotation transform
|
||||
AZ::Quaternion currentRotate = localTM.GetRotation();
|
||||
AZ::Quaternion newRotate = rotate * currentRotate;
|
||||
newRotate.Normalize();
|
||||
|
||||
//scale
|
||||
AZ::Transform newLocalTM = AZ::Transform::CreateScale(scale);
|
||||
|
||||
//rotate
|
||||
AZ::Transform rotateLocalTM = AZ::Transform::CreateFromQuaternion(newRotate);
|
||||
newLocalTM = rotateLocalTM * newLocalTM;
|
||||
|
||||
//translate
|
||||
newLocalTM.SetTranslation(translation);
|
||||
|
||||
AZ::Transform newLocalTM = localTM;
|
||||
newLocalTM.SetRotation((rotate * localTM.GetRotation()).GetNormalized());
|
||||
return newLocalTM;
|
||||
}
|
||||
|
||||
@@ -512,75 +492,6 @@ namespace AzFramework
|
||||
return m_localTM.GetRotation();
|
||||
}
|
||||
|
||||
void TransformComponent::SetScale(const AZ::Vector3& scale)
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "SetScale is deprecated, please use SetLocalScale");
|
||||
|
||||
if (!m_worldTM.GetScale().IsClose(scale))
|
||||
{
|
||||
AZ::Transform newWorldTransform = m_worldTM;
|
||||
newWorldTransform.SetScale(scale);
|
||||
SetWorldTM(newWorldTransform);
|
||||
}
|
||||
}
|
||||
|
||||
void TransformComponent::SetScaleX(float scaleX)
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "SetScaleX is deprecated, please use SetLocalScaleX");
|
||||
|
||||
AZ::Vector3 newScale = m_worldTM.GetScale();
|
||||
newScale.SetX(scaleX);
|
||||
AZ::Transform newWorldTransform = m_worldTM;
|
||||
newWorldTransform.SetScale(newScale);
|
||||
SetWorldTM(newWorldTransform);
|
||||
}
|
||||
|
||||
void TransformComponent::SetScaleY(float scaleY)
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "SetScaleY is deprecated, please use SetLocalScaleY");
|
||||
|
||||
AZ::Vector3 newScale = m_worldTM.GetScale();
|
||||
newScale.SetY(scaleY);
|
||||
AZ::Transform newWorldTransform = m_worldTM;
|
||||
newWorldTransform.SetScale(newScale);
|
||||
SetWorldTM(newWorldTransform);
|
||||
}
|
||||
|
||||
void TransformComponent::SetScaleZ(float scaleZ)
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "SetScaleZ is deprecated, please use SetLocalScaleZ");
|
||||
|
||||
AZ::Vector3 newScale = m_worldTM.GetScale();
|
||||
newScale.SetZ(scaleZ);
|
||||
AZ::Transform newWorldTransform = m_worldTM;
|
||||
newWorldTransform.SetScale(newScale);
|
||||
SetWorldTM(newWorldTransform);
|
||||
}
|
||||
|
||||
AZ::Vector3 TransformComponent::GetScale()
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "GetScale is deprecated, please use GetLocalScale");
|
||||
return m_worldTM.GetScale();
|
||||
}
|
||||
|
||||
float TransformComponent::GetScaleX()
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "GetScaleX is deprecated, please use GetLocalScale");
|
||||
return m_worldTM.GetScale().GetX();
|
||||
}
|
||||
|
||||
float TransformComponent::GetScaleY()
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "GetScaleY is deprecated, please use GetLocalScale");
|
||||
return m_worldTM.GetScale().GetY();
|
||||
}
|
||||
|
||||
float TransformComponent::GetScaleZ()
|
||||
{
|
||||
AZ_Warning("TransformComponent", false, "GetScaleZ is deprecated, please use GetLocalScale");
|
||||
return m_worldTM.GetScale().GetZ();
|
||||
}
|
||||
|
||||
void TransformComponent::SetLocalScale(const AZ::Vector3& scale)
|
||||
{
|
||||
AZ::Transform newLocalTM = m_localTM;
|
||||
@@ -588,33 +499,6 @@ namespace AzFramework
|
||||
SetLocalTM(newLocalTM);
|
||||
}
|
||||
|
||||
void TransformComponent::SetLocalScaleX(float scaleX)
|
||||
{
|
||||
AZ::Transform newLocalTM = m_localTM;
|
||||
AZ::Vector3 newScale = newLocalTM.GetScale();
|
||||
newScale.SetX(scaleX);
|
||||
newLocalTM.SetScale(newScale);
|
||||
SetLocalTM(newLocalTM);
|
||||
}
|
||||
|
||||
void TransformComponent::SetLocalScaleY(float scaleY)
|
||||
{
|
||||
AZ::Transform newLocalTM = m_localTM;
|
||||
AZ::Vector3 newScale = newLocalTM.GetScale();
|
||||
newScale.SetY(scaleY);
|
||||
newLocalTM.SetScale(newScale);
|
||||
SetLocalTM(newLocalTM);
|
||||
}
|
||||
|
||||
void TransformComponent::SetLocalScaleZ(float scaleZ)
|
||||
{
|
||||
AZ::Transform newLocalTM = m_localTM;
|
||||
AZ::Vector3 newScale = newLocalTM.GetScale();
|
||||
newScale.SetZ(scaleZ);
|
||||
newLocalTM.SetScale(newScale);
|
||||
SetLocalTM(newLocalTM);
|
||||
}
|
||||
|
||||
AZ::Vector3 TransformComponent::GetLocalScale()
|
||||
{
|
||||
return m_localTM.GetScale();
|
||||
@@ -625,6 +509,23 @@ namespace AzFramework
|
||||
return m_worldTM.GetScale();
|
||||
}
|
||||
|
||||
void TransformComponent::SetLocalUniformScale(float scale)
|
||||
{
|
||||
AZ::Transform newLocalTM = m_localTM;
|
||||
newLocalTM.SetUniformScale(scale);
|
||||
SetLocalTM(newLocalTM);
|
||||
}
|
||||
|
||||
float TransformComponent::GetLocalUniformScale()
|
||||
{
|
||||
return m_localTM.GetUniformScale();
|
||||
}
|
||||
|
||||
float TransformComponent::GetWorldUniformScale()
|
||||
{
|
||||
return m_worldTM.GetUniformScale();
|
||||
}
|
||||
|
||||
AZStd::vector<AZ::EntityId> TransformComponent::GetChildren()
|
||||
{
|
||||
AZStd::vector<AZ::EntityId> children;
|
||||
@@ -979,34 +880,7 @@ namespace AzFramework
|
||||
->Event("GetLocalRotationQuaternion", &AZ::TransformBus::Events::GetLocalRotationQuaternion)
|
||||
->Attribute("Rotation", AZ::Edit::Attributes::PropertyRotation)
|
||||
->VirtualProperty("Rotation", "GetLocalRotationQuaternion", "SetLocalRotationQuaternion")
|
||||
->Event("SetScale", &AZ::TransformBus::Events::SetScale)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("SetScaleX", &AZ::TransformBus::Events::SetScaleX)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("SetScaleY", &AZ::TransformBus::Events::SetScaleY)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("SetScaleZ", &AZ::TransformBus::Events::SetScaleZ)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("GetScale", &AZ::TransformBus::Events::GetScale)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("GetScaleX", &AZ::TransformBus::Events::GetScaleX)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("GetScaleY", &AZ::TransformBus::Events::GetScaleY)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("GetScaleZ", &AZ::TransformBus::Events::GetScaleZ)
|
||||
->Attribute(AZ::Script::Attributes::Deprecated, true)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Event("SetLocalScale", &AZ::TransformBus::Events::SetLocalScale)
|
||||
->Event("SetLocalScaleX", &AZ::TransformBus::Events::SetLocalScaleX)
|
||||
->Event("SetLocalScaleY", &AZ::TransformBus::Events::SetLocalScaleY)
|
||||
->Event("SetLocalScaleZ", &AZ::TransformBus::Events::SetLocalScaleZ)
|
||||
->Event("GetLocalScale", &AZ::TransformBus::Events::GetLocalScale)
|
||||
->Attribute("Scale", AZ::Edit::Attributes::PropertyScale)
|
||||
->VirtualProperty("Scale", "GetLocalScale", "SetLocalScale")
|
||||
|
||||
@@ -143,24 +143,14 @@ namespace AzFramework
|
||||
AZ::Quaternion GetLocalRotationQuaternion() override;
|
||||
|
||||
// Scale Modifiers
|
||||
void SetScale(const AZ::Vector3& scale) override;
|
||||
void SetScaleX(float scaleX) override;
|
||||
void SetScaleY(float scaleY) override;
|
||||
void SetScaleZ(float scaleZ) override;
|
||||
|
||||
AZ::Vector3 GetScale() override;
|
||||
float GetScaleX() override;
|
||||
float GetScaleY() override;
|
||||
float GetScaleZ() override;
|
||||
|
||||
void SetLocalScale(const AZ::Vector3& scale) override;
|
||||
void SetLocalScaleX(float scaleX) override;
|
||||
void SetLocalScaleY(float scaleY) override;
|
||||
void SetLocalScaleZ(float scaleZ) override;
|
||||
|
||||
AZ::Vector3 GetLocalScale() override;
|
||||
AZ::Vector3 GetWorldScale() override;
|
||||
|
||||
void SetLocalUniformScale(float scale) override;
|
||||
float GetLocalUniformScale() override;
|
||||
float GetWorldUniformScale() override;
|
||||
|
||||
// Transform hierarchy
|
||||
AZStd::vector<AZ::EntityId> GetChildren() override;
|
||||
AZStd::vector<AZ::EntityId> GetAllDescendants() override;
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace AzFramework
|
||||
virtual void DrawTrianglesIndexed(const AZStd::vector<AZ::Vector3>& vertices, const AZStd::vector<AZ::u32>& indices, const AZ::Color& color) { (void)vertices; (void)indices, (void)color; }
|
||||
virtual void DrawWireBox(const AZ::Vector3& min, const AZ::Vector3& max) { (void)min; (void)max; }
|
||||
virtual void DrawSolidBox(const AZ::Vector3& min, const AZ::Vector3& max) { (void)min; (void)max; }
|
||||
virtual void DrawWireOBB(const AZ::Vector3& center, const AZ::Vector3& axisX, const AZ::Vector3& axisY, const AZ::Vector3& axisZ, const AZ::Vector3& halfExtents) { (void)center; (void)axisX; (void)axisY; (void)axisZ; (void)halfExtents; }
|
||||
virtual void DrawSolidOBB(const AZ::Vector3& center, const AZ::Vector3& axisX, const AZ::Vector3& axisY, const AZ::Vector3& axisZ, const AZ::Vector3& halfExtents) { (void)center; (void)axisX; (void)axisY; (void)axisZ; (void)halfExtents; }
|
||||
virtual void DrawPoint(const AZ::Vector3& p, int nSize = 1) { (void)p; (void)nSize; }
|
||||
virtual void DrawLine(const AZ::Vector3& p1, const AZ::Vector3& p2) { (void)p1; (void)p2; }
|
||||
@@ -70,18 +71,15 @@ namespace AzFramework
|
||||
virtual void DrawLine2d(const AZ::Vector2& p1, const AZ::Vector2& p2, float z) { (void)p1; (void)p2; (void)z; }
|
||||
virtual void DrawLine2dGradient(const AZ::Vector2& p1, const AZ::Vector2& p2, float z, const AZ::Vector4& firstColor, const AZ::Vector4& secondColor) { (void)p1; (void)p2; (void)z; (void)firstColor; (void)secondColor; }
|
||||
virtual void DrawWireCircle2d(const AZ::Vector2& center, float radius, float z) { (void)center; (void)radius; (void)z; }
|
||||
virtual void DrawTerrainCircle(const AZ::Vector3& worldPos, float radius, float height) { (void)worldPos; (void)radius; (void)height; }
|
||||
virtual void DrawTerrainCircle(const AZ::Vector3& center, float radius, float angle1, float angle2, float height) { (void)center; (void)radius; (void)angle1; (void)angle2; (void)height; }
|
||||
virtual void DrawArc(const AZ::Vector3& pos, float radius, float startAngleDegrees, float sweepAngleDegrees, float angularStepDegrees, int referenceAxis = 2) { (void)pos; (void)radius; (void)startAngleDegrees; (void)sweepAngleDegrees; (void)angularStepDegrees; (void)referenceAxis; }
|
||||
virtual void DrawArc(const AZ::Vector3& pos, float radius, float startAngleDegrees, float sweepAngleDegrees, float angularStepDegrees, const AZ::Vector3& fixedAxis) { (void)pos; (void)radius; (void)startAngleDegrees; (void)sweepAngleDegrees; (void)angularStepDegrees; (void)fixedAxis; }
|
||||
virtual void DrawCircle(const AZ::Vector3& pos, float radius, int nUnchangedAxis = 2 /*z axis*/) { (void)pos; (void)radius; (void)nUnchangedAxis; }
|
||||
virtual void DrawHalfDottedCircle(const AZ::Vector3& pos, float radius, const AZ::Vector3& viewPos, int nUnchangedAxis = 2 /*z axis*/) { (void)pos; (void)radius; (void)viewPos; (void)nUnchangedAxis; }
|
||||
virtual void DrawCone(const AZ::Vector3& pos, const AZ::Vector3& dir, float radius, float height, bool drawShaded = true) { (void)pos; (void)dir; (void)radius; (void)height; (void)drawShaded; }
|
||||
virtual void DrawWireCone(const AZ::Vector3& pos, const AZ::Vector3& dir, float radius, float height) { (void)pos; (void)dir; (void)radius; (void)height; }
|
||||
virtual void DrawSolidCone(const AZ::Vector3& pos, const AZ::Vector3& dir, float radius, float height, bool drawShaded = true) { (void)pos; (void)dir; (void)radius; (void)height; (void)drawShaded; }
|
||||
virtual void DrawWireCylinder(const AZ::Vector3& center, const AZ::Vector3& axis, float radius, float height) { (void)center; (void)axis; (void)radius; (void)height; }
|
||||
virtual void DrawSolidCylinder(const AZ::Vector3& center, const AZ::Vector3& axis, float radius, float height, bool drawShaded = true) { (void)center; (void)axis; (void)radius; (void)height; (void)drawShaded; }
|
||||
virtual void DrawWireCapsule(const AZ::Vector3& center, const AZ::Vector3& axis, float radius, float heightStraightSection) { (void)center; (void)axis; (void)radius; (void)heightStraightSection; }
|
||||
virtual void DrawTerrainRect(float x1, float y1, float x2, float y2, float height) { (void)x1; (void)y1; (void)x2; (void)y2; (void)height; }
|
||||
virtual void DrawTerrainLine(AZ::Vector3 worldPos1, AZ::Vector3 worldPos2) { (void)worldPos1; (void)worldPos2; }
|
||||
virtual void DrawWireSphere(const AZ::Vector3& pos, float radius) { (void)pos; (void)radius; }
|
||||
virtual void DrawWireSphere(const AZ::Vector3& pos, const AZ::Vector3 radius) { (void)pos; (void)radius; }
|
||||
virtual void DrawWireDisk(const AZ::Vector3& pos, const AZ::Vector3& dir, float radius) { (void)pos; (void)dir; (void)radius; }
|
||||
@@ -91,11 +89,8 @@ namespace AzFramework
|
||||
virtual void DrawTextLabel(const AZ::Vector3& pos, float size, const char* text, const bool bCenter = false, int srcOffsetX = 0, int srcOffsetY = 0) { (void)pos; (void)size; (void)text; (void)bCenter; (void)srcOffsetX; (void)srcOffsetY; }
|
||||
virtual void Draw2dTextLabel(float x, float y, float size, const char* text, bool bCenter = false) { (void)x; (void)y; (void)size; (void)text; (void)bCenter; }
|
||||
virtual void DrawTextOn2DBox(const AZ::Vector3& pos, const char* text, float textScale, const AZ::Vector4& TextColor, const AZ::Vector4& TextBackColor) { (void)pos; (void)text; (void)textScale; (void)TextColor; (void)TextBackColor; }
|
||||
virtual void DrawTextureLabel(ITexture* texture, const AZ::Vector3& pos, float sizeX, float sizeY, int texIconFlags) { (void)texture; (void)pos; (void)sizeX; (void)sizeY; (void)texIconFlags; }
|
||||
virtual void DrawTextureLabel(int textureId, const AZ::Vector3& pos, float sizeX, float sizeY, int texIconFlags) { (void)textureId; (void)pos; (void)sizeX; (void)sizeY; (void)texIconFlags; }
|
||||
virtual void SetLineWidth(float width) { (void)width; }
|
||||
virtual bool IsVisible(const AZ::Aabb& bounds) { (void)bounds; return false; }
|
||||
virtual int SetFillMode(int nFillMode) { (void)nFillMode; return 0; }
|
||||
virtual float GetLineWidth() { return 0.0f; }
|
||||
virtual float GetAspectRatio() { return 0.0f; }
|
||||
virtual void DepthTestOff() {}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <AzFramework/Physics/Collision/CollisionGroups.h>
|
||||
#include <AzFramework/Physics/Collision/CollisionLayers.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsTypes.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
|
||||
#include <AzFramework/Physics/Configuration/SimulatedBodyConfiguration.h>
|
||||
|
||||
@@ -36,7 +37,7 @@ namespace Physics
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
AZStd::string m_name;
|
||||
ShapeConfigurationList m_shapes;
|
||||
AzPhysics::ShapeColliderPairList m_shapes;
|
||||
};
|
||||
|
||||
class CharacterColliderConfiguration
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Physics
|
||||
classElement.RemoveElement(shapesIndex);
|
||||
|
||||
// add a new vector in the new format
|
||||
const int newShapesIndex = classElement.AddElement<ShapeConfigurationList>(context, "shapes");
|
||||
const int newShapesIndex = classElement.AddElement<AzPhysics::ShapeColliderPairList>(context, "shapes");
|
||||
if (newShapesIndex != -1)
|
||||
{
|
||||
AZ::SerializeContext::DataElementNode& newShapesElement = classElement.GetSubElement(newShapesIndex);
|
||||
@@ -65,7 +65,9 @@ namespace Physics
|
||||
// convert the old shapes into the new format and add to the vector
|
||||
for (AZ::SerializeContext::DataElementNode shape : shapesCopy)
|
||||
{
|
||||
const int pairIndex = newShapesElement.AddElementWithData<ShapeConfigurationPair>(context, "element", ShapeConfigurationPair());
|
||||
const int pairIndex = newShapesElement.AddElementWithData<AzPhysics::ShapeColliderPair>(
|
||||
context, "element", AzPhysics::ShapeColliderPair());
|
||||
|
||||
AZ::SerializeContext::DataElementNode& pairElement = newShapesElement.GetSubElement(pairIndex);
|
||||
|
||||
ColliderConfiguration colliderConfig;
|
||||
@@ -131,8 +133,8 @@ namespace Physics
|
||||
AZ::SerializeContext::DataElementNode* baseBaseClass1 = baseClass1->FindSubElement(AZ_CRC("BaseClass1", 0xd4925735));
|
||||
if (baseBaseClass1 && baseBaseClass1->FindSubElementAndGetData<AZStd::string>(AZ_CRC("name", 0x5e237e06), name))
|
||||
{
|
||||
ShapeConfigurationList shapes;
|
||||
if (nodeElement.FindSubElementAndGetData<ShapeConfigurationList>(AZ_CRC("shapes", 0x93dba512), shapes))
|
||||
AzPhysics::ShapeColliderPairList shapes;
|
||||
if (nodeElement.FindSubElementAndGetData<AzPhysics::ShapeColliderPairList>(AZ_CRC("shapes", 0x93dba512), shapes))
|
||||
{
|
||||
CharacterColliderNodeConfiguration newColliderNodeConfig;
|
||||
newColliderNodeConfig.m_name = name;
|
||||
|
||||
@@ -70,7 +70,10 @@ namespace AzPhysics
|
||||
using SimulatedBodyHandleList = AZStd::vector<SimulatedBodyHandle>;
|
||||
|
||||
//! Helper used for pairing the ShapeConfiguration and ColliderConfiguration together which is used when creating a Simulated Body.
|
||||
using ShapeColliderPair = AZStd::pair<Physics::ColliderConfiguration*, Physics::ShapeConfiguration*>;
|
||||
using ShapeColliderPair = AZStd::pair<
|
||||
AZStd::shared_ptr<Physics::ColliderConfiguration>,
|
||||
AZStd::shared_ptr<Physics::ShapeConfiguration>>;
|
||||
using ShapeColliderPairList = AZStd::vector<ShapeColliderPair>;
|
||||
|
||||
//! Flags used to specifying which properties of a body to compute.
|
||||
enum class MassComputeFlags : AZ::u8
|
||||
|
||||
+11
-2
@@ -30,6 +30,16 @@ namespace AzPhysics
|
||||
classElement.AddElementWithData(context, "name", name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimulatedBodyVersionConverter([[maybe_unused]] AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
|
||||
{
|
||||
if (classElement.GetVersion() <= 1)
|
||||
{
|
||||
classElement.RemoveElementByName(AZ_CRC_CE("scale"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(SimulatedBodyConfiguration, AZ::SystemAllocator, 0);
|
||||
@@ -40,11 +50,10 @@ namespace AzPhysics
|
||||
{
|
||||
serializeContext->ClassDeprecate("WorldBodyConfiguration", "{6EEB377C-DC60-4E10-AF12-9626C0763B2D}", &Internal::DeprecateWorldBodyConfiguration);
|
||||
serializeContext->Class<SimulatedBodyConfiguration>()
|
||||
->Version(1)
|
||||
->Version(2, &Internal::SimulatedBodyVersionConverter)
|
||||
->Field("name", &SimulatedBodyConfiguration::m_debugName)
|
||||
->Field("position", &SimulatedBodyConfiguration::m_position)
|
||||
->Field("orientation", &SimulatedBodyConfiguration::m_orientation)
|
||||
->Field("scale", &SimulatedBodyConfiguration::m_scale)
|
||||
->Field("entityId", &SimulatedBodyConfiguration::m_entityId)
|
||||
->Field("startSimulationEnabled", &SimulatedBodyConfiguration::m_startSimulationEnabled)
|
||||
;
|
||||
|
||||
-1
@@ -38,7 +38,6 @@ namespace AzPhysics
|
||||
// Basic initial settings.
|
||||
AZ::Vector3 m_position = AZ::Vector3::CreateZero();
|
||||
AZ::Quaternion m_orientation = AZ::Quaternion::CreateIdentity();
|
||||
AZ::Vector3 m_scale = AZ::Vector3::CreateOne();
|
||||
bool m_startSimulationEnabled = true;
|
||||
|
||||
// Entity/object association.
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ namespace AzPhysics
|
||||
namespace
|
||||
{
|
||||
const float TimestepMin = 0.001f; //1000fps
|
||||
const float TimestepMax = 0.05f; //20fps
|
||||
const float TimestepMax = 0.1f; //10fps
|
||||
}
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(SystemConfiguration, AZ::SystemAllocator, 0);
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace AzPhysics
|
||||
|
||||
static constexpr float DefaultFixedTimestep = 0.0166667f; //! Value represents 1/60th or 60 FPS.
|
||||
|
||||
float m_maxTimestep = 1.f / 20.f; //!< Maximum fixed timestep in seconds to run the physics update.
|
||||
float m_maxTimestep = 0.1f; //!< Maximum fixed timestep in seconds to run the physics update (10FPS).
|
||||
float m_fixedTimestep = DefaultFixedTimestep; //!< Timestep in seconds to run the physics update. See DefaultFixedTimestep.
|
||||
|
||||
AZ::u64 m_raycastBufferSize = 32; //!< Maximum number of hits that will be returned from a raycast.
|
||||
|
||||
@@ -80,9 +80,6 @@ namespace Physics
|
||||
void OnContactOffsetChanged();
|
||||
};
|
||||
|
||||
using ShapeConfigurationPair = AZStd::pair<AZStd::shared_ptr<ColliderConfiguration>, AZStd::shared_ptr<ShapeConfiguration>>;
|
||||
using ShapeConfigurationList = AZStd::vector<ShapeConfigurationPair>;
|
||||
|
||||
struct RayCastRequest;
|
||||
|
||||
class Shape
|
||||
|
||||
@@ -99,51 +99,18 @@ namespace AzFramework::ProjectManager
|
||||
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
|
||||
}
|
||||
{
|
||||
const char projectsScript[] = "projects.py";
|
||||
AZStd::string filename = "o3de";
|
||||
AZ::IO::FixedMaxPath executablePath = AZ::Utils::GetExecutableDirectory();
|
||||
executablePath /= filename + AZ_TRAIT_OS_EXECUTABLE_EXTENSION;
|
||||
|
||||
AZ_Warning("ProjectManager", false, "No project provided - launching project selector.");
|
||||
|
||||
if (engineRootPath.empty())
|
||||
if (!AZ::IO::SystemFile::Exists(executablePath.c_str()))
|
||||
{
|
||||
AZ_Error("ProjectManager", false, "Couldn't find engine root");
|
||||
AZ_Error("ProjectManager", false, "%s not found", executablePath.c_str());
|
||||
return false;
|
||||
}
|
||||
auto projectManagerPath = engineRootPath / "scripts" / "project_manager";
|
||||
|
||||
if (!AZ::IO::SystemFile::Exists((projectManagerPath / projectsScript).c_str()))
|
||||
{
|
||||
AZ_Error("ProjectManager", false, "%s not found at %s!", projectsScript, projectManagerPath.c_str());
|
||||
return false;
|
||||
}
|
||||
AZ::IO::FixedMaxPathString executablePath;
|
||||
AZ::Utils::GetExecutablePathReturnType result = AZ::Utils::GetExecutablePath(executablePath.data(), executablePath.capacity());
|
||||
if (result.m_pathStored != AZ::Utils::ExecutablePathResult::Success)
|
||||
{
|
||||
AZ_Error("ProjectManager", false, "Could not determine executable path!");
|
||||
return false;
|
||||
}
|
||||
AZ::IO::FixedMaxPath parentPath(executablePath.c_str());
|
||||
auto exeFolder = parentPath.ParentPath();
|
||||
AZStd::fixed_string<8> debugOption;
|
||||
auto lastSep = exeFolder.Native().find_last_of(AZ_CORRECT_FILESYSTEM_SEPARATOR);
|
||||
if (lastSep != AZStd::string_view::npos)
|
||||
{
|
||||
exeFolder = exeFolder.Native().substr(lastSep + 1);
|
||||
}
|
||||
if (exeFolder == "debug")
|
||||
{
|
||||
// We need to use the debug version of the python interpreter to load up our debug version of our libraries which work with the debug version of QT living in this folder
|
||||
debugOption = "debug ";
|
||||
}
|
||||
AZ::IO::FixedMaxPath pythonPath = engineRootPath / "python";
|
||||
pythonPath /= AZ_TRAIT_AZFRAMEWORK_PYTHON_SHELL;
|
||||
auto cmdPath = AZ::IO::FixedMaxPathString::format("%s %s%s --executable_path=%s --parent_pid=%" PRIu32, pythonPath.Native().c_str(),
|
||||
debugOption.c_str(), (projectManagerPath / projectsScript).c_str(), executablePath.c_str(), AZ::Platform::GetCurrentProcessId());
|
||||
|
||||
AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
|
||||
|
||||
processLaunchInfo.m_commandlineParameters = cmdPath;
|
||||
processLaunchInfo.m_showWindow = false;
|
||||
processLaunchInfo.m_commandlineParameters = executablePath.String();
|
||||
launchSuccess = AzFramework::ProcessLauncher::LaunchUnwatchedProcess(processLaunchInfo);
|
||||
}
|
||||
if (ownsSystemAllocator)
|
||||
|
||||
@@ -264,12 +264,12 @@ namespace AzFramework
|
||||
// SampleRPC =
|
||||
// {
|
||||
// // Two callbacks can be registered to the NetRPC
|
||||
// // A function to be invoked on the Master - OnMaster
|
||||
// // A function to be invoked on the main server - OnServer
|
||||
// // and a function to be invoked on the Proxy - OnProxy
|
||||
// //
|
||||
// // Every NetRPC needs to have a valid OnMaster function, while OnProxy is optional.
|
||||
// OnMaster = function()
|
||||
// Debug.Log("Function to be invoked on the Master.");
|
||||
// // Every NetRPC needs to have a valid OnServer function, while OnProxy is optional.
|
||||
// OnServer = function()
|
||||
// Debug.Log("Function to be invoked on the server.");
|
||||
// end
|
||||
//
|
||||
// OnProxy = function()
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
//! SessionConnectionConfig
|
||||
//! The properties for handling join session request.
|
||||
struct SessionConnectionConfig
|
||||
{
|
||||
// A unique identifier for registered player in session.
|
||||
AZStd::string m_playerSessionId;
|
||||
|
||||
// The DNS identifier assigned to the instance that is running the session.
|
||||
AZStd::string m_dnsName;
|
||||
|
||||
// The IP address of the session.
|
||||
AZStd::string m_ipAddress;
|
||||
|
||||
// The port number for the session.
|
||||
uint16_t m_port;
|
||||
};
|
||||
|
||||
//! SessionConnectionConfig
|
||||
//! The properties for handling player connect/disconnect
|
||||
struct PlayerConnectionConfig
|
||||
{
|
||||
// A unique identifier for player connection.
|
||||
uint32_t m_playerConnectionId;
|
||||
|
||||
// A unique identifier for registered player in session.
|
||||
AZStd::string m_playerSessionId;
|
||||
};
|
||||
|
||||
//! ISessionHandlingClientRequests
|
||||
//! The session handling events to invoke multiplayer component handle the work on client side
|
||||
class ISessionHandlingClientRequests
|
||||
{
|
||||
public:
|
||||
// Handle the player join session process
|
||||
// @param sessionConnectionConfig The required properties to handle the player join session process
|
||||
// @return The result of player join session process
|
||||
virtual bool HandlePlayerJoinSession(const SessionConnectionConfig& sessionConnectionConfig) = 0;
|
||||
|
||||
// Handle the player leave session process
|
||||
virtual void HandlePlayerLeaveSession() = 0;
|
||||
};
|
||||
|
||||
//! ISessionHandlingServerRequests
|
||||
//! The session handling events to invoke server provider handle the work on server side
|
||||
class ISessionHandlingServerRequests
|
||||
{
|
||||
public:
|
||||
// Handle the destroy session process
|
||||
virtual void HandleDestroySession() = 0;
|
||||
|
||||
// Validate the player join session process
|
||||
// @param playerConnectionConfig The required properties to validate the player join session process
|
||||
// @return The result of player join session validation
|
||||
virtual bool ValidatePlayerJoinSession(const PlayerConnectionConfig& playerConnectionConfig) = 0;
|
||||
|
||||
// Handle the player leave session process
|
||||
// @param playerConnectionConfig The required properties to handle the player leave session process
|
||||
virtual void HandlePlayerLeaveSession(const PlayerConnectionConfig& playerConnectionConfig) = 0;
|
||||
};
|
||||
} // namespace AzFramework
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzFramework/Session/ISessionRequests.h>
|
||||
#include <AzFramework/Session/SessionConfig.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
void CreateSessionRequest::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<CreateSessionRequest>()
|
||||
->Version(0)
|
||||
->Field("creatorId", &CreateSessionRequest::m_creatorId)
|
||||
->Field("sessionProperties", &CreateSessionRequest::m_sessionProperties)
|
||||
->Field("sessionName", &CreateSessionRequest::m_sessionName)
|
||||
->Field("maxPlayer", &CreateSessionRequest::m_maxPlayer)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<CreateSessionRequest>("CreateSessionRequest", "The container for CreateSession request parameters")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_creatorId,
|
||||
"CreatorId", "A unique identifier for a player or entity creating the session")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_sessionProperties,
|
||||
"SessionProperties", "A collection of custom properties for a session")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_sessionName,
|
||||
"SessionName", "A descriptive label that is associated with a session")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_maxPlayer,
|
||||
"MaxPlayer", "The maximum number of players that can be connected simultaneously to the session")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SearchSessionsRequest::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<SearchSessionsRequest>()
|
||||
->Version(0)
|
||||
->Field("filterExpression", &SearchSessionsRequest::m_filterExpression)
|
||||
->Field("sortExpression", &SearchSessionsRequest::m_sortExpression)
|
||||
->Field("maxResult", &SearchSessionsRequest::m_maxResult)
|
||||
->Field("nextToken", &SearchSessionsRequest::m_nextToken)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<SearchSessionsRequest>("SearchSessionsRequest", "The container for SearchSessions request parameters")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_filterExpression,
|
||||
"FilterExpression", "String containing the search criteria for the session search")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_sortExpression,
|
||||
"SortExpression", "Instructions on how to sort the search results")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_maxResult,
|
||||
"MaxResult", "The maximum number of results to return")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_nextToken,
|
||||
"NextToken", "A token that indicates the start of the next sequential page of results")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SearchSessionsResponse::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<SearchSessionsResponse>()
|
||||
->Version(0)
|
||||
->Field("sessionConfigs", &SearchSessionsResponse::m_sessionConfigs)
|
||||
->Field("nextToken", &SearchSessionsResponse::m_nextToken)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<SearchSessionsResponse>("SearchSessionsResponse", "The container for SearchSession request results")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsResponse::m_sessionConfigs,
|
||||
"SessionConfigs", "A collection of sessions that match the search criteria and sorted in specific order")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsResponse::m_nextToken,
|
||||
"NextToken", "A token that indicates the start of the next sequential page of results")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JoinSessionRequest::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<JoinSessionRequest>()
|
||||
->Version(0)
|
||||
->Field("sessionId", &JoinSessionRequest::m_sessionId)
|
||||
->Field("playerId", &JoinSessionRequest::m_playerId)
|
||||
->Field("playerData", &JoinSessionRequest::m_playerData)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<JoinSessionRequest>("JoinSessionRequest", "The container for JoinSession request parameters")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &JoinSessionRequest::m_sessionId,
|
||||
"SessionId", "A unique identifier for the session")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &JoinSessionRequest::m_playerId,
|
||||
"PlayerId", "A unique identifier for a player. Player IDs are developer-defined")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &JoinSessionRequest::m_playerData,
|
||||
"PlayerData", "Developer-defined information related to a player")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace AzFramework
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
#include <AzCore/RTTI/ReflectContext.h>
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <AzCore/Outcome/Outcome.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
struct SessionConfig;
|
||||
|
||||
//! CreateSessionRequest
|
||||
//! The container for CreateSession request parameters.
|
||||
struct CreateSessionRequest
|
||||
{
|
||||
AZ_RTTI(CreateSessionRequest, "{E39C2A45-89C9-4CFB-B337-9734DC798930}");
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
CreateSessionRequest() = default;
|
||||
virtual ~CreateSessionRequest() = default;
|
||||
|
||||
// A unique identifier for a player or entity creating the session.
|
||||
AZStd::string m_creatorId;
|
||||
|
||||
// A collection of custom properties for a session.
|
||||
AZStd::unordered_map<AZStd::string, AZStd::string> m_sessionProperties;
|
||||
|
||||
// A descriptive label that is associated with a session.
|
||||
AZStd::string m_sessionName;
|
||||
|
||||
// The maximum number of players that can be connected simultaneously to the session.
|
||||
uint64_t m_maxPlayer;
|
||||
};
|
||||
|
||||
//! SearchSessionsRequest
|
||||
//! The container for SearchSessions request parameters.
|
||||
struct SearchSessionsRequest
|
||||
{
|
||||
AZ_RTTI(SearchSessionsRequest, "{B49207A8-8549-4ADB-B7D9-D7A4932F9B4B}");
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
SearchSessionsRequest() = default;
|
||||
virtual ~SearchSessionsRequest() = default;
|
||||
|
||||
// String containing the search criteria for the session search. If no filter expression is included, the request returns results
|
||||
// for all active sessions.
|
||||
AZStd::string m_filterExpression;
|
||||
|
||||
// Instructions on how to sort the search results. If no sort expression is included, the request returns results in random order.
|
||||
AZStd::string m_sortExpression;
|
||||
|
||||
// The maximum number of results to return.
|
||||
uint8_t m_maxResult;
|
||||
|
||||
// A token that indicates the start of the next sequential page of results.
|
||||
AZStd::string m_nextToken;
|
||||
};
|
||||
|
||||
//! SearchSessionsResponse
|
||||
//! The container for SearchSession request results.
|
||||
struct SearchSessionsResponse
|
||||
{
|
||||
AZ_RTTI(SearchSessionsResponse, "{F93DE7DC-D381-4E08-8A3B-0B08F7C38714}");
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
SearchSessionsResponse() = default;
|
||||
virtual ~SearchSessionsResponse() = default;
|
||||
|
||||
// A collection of sessions that match the search criteria and sorted in specific order.
|
||||
AZStd::vector<SessionConfig> m_sessionConfigs;
|
||||
|
||||
// A token that indicates the start of the next sequential page of results.
|
||||
AZStd::string m_nextToken;
|
||||
};
|
||||
|
||||
//! JoinSessionRequest
|
||||
//! The container for JoinSession request parameters.
|
||||
struct JoinSessionRequest
|
||||
{
|
||||
AZ_RTTI(JoinSessionRequest, "{519769E8-3CDE-4385-A0D7-24DBB3685657}");
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
JoinSessionRequest() = default;
|
||||
virtual ~JoinSessionRequest() = default;
|
||||
|
||||
// A unique identifier for the session.
|
||||
AZStd::string m_sessionId;
|
||||
|
||||
// A unique identifier for a player. Player IDs are developer-defined.
|
||||
AZStd::string m_playerId;
|
||||
|
||||
// Developer-defined information related to a player.
|
||||
AZStd::string m_playerData;
|
||||
};
|
||||
|
||||
//! ISessionRequests
|
||||
//! Pure virtual session interface class to abstract the details of session handling from application code.
|
||||
class ISessionRequests
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(ISessionRequests, "{D6C41A71-DD8D-47FE-8515-FAF90670AE2F}");
|
||||
|
||||
ISessionRequests() = default;
|
||||
virtual ~ISessionRequests() = default;
|
||||
|
||||
// Create a session for players to find and join.
|
||||
// @param createSessionRequest The request of CreateSession operation
|
||||
// @return The request id if session creation request succeeds; empty if it fails
|
||||
virtual AZStd::string CreateSession(const CreateSessionRequest& createSessionRequest) = 0;
|
||||
|
||||
// Retrieve all active sessions that match the given search criteria and sorted in specific order.
|
||||
// @param searchSessionsRequest The request of SearchSessions operation
|
||||
// @return The response of SearchSessions operation
|
||||
virtual SearchSessionsResponse SearchSessions(const SearchSessionsRequest& searchSessionsRequest) const = 0;
|
||||
|
||||
// Reserve an open player slot in a session, and perform connection from client to server.
|
||||
// @param joinSessionRequest The request of JoinSession operation
|
||||
// @return True if joining session succeeds; False otherwise
|
||||
virtual bool JoinSession(const JoinSessionRequest& joinSessionRequest) = 0;
|
||||
|
||||
// Disconnect player from session.
|
||||
virtual void LeaveSession() = 0;
|
||||
};
|
||||
|
||||
//! ISessionAsyncRequests
|
||||
//! Async version of ISessionRequests
|
||||
class ISessionAsyncRequests
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(ISessionAsyncRequests, "{471542AF-96B9-4930-82FE-242A4E68432D}");
|
||||
|
||||
ISessionAsyncRequests() = default;
|
||||
virtual ~ISessionAsyncRequests() = default;
|
||||
|
||||
// CreateSession Async
|
||||
// @param createSessionRequest The request of CreateSession operation
|
||||
virtual void CreateSessionAsync(const CreateSessionRequest& createSessionRequest) = 0;
|
||||
|
||||
// SearchSessions Async
|
||||
// @param searchSessionsRequest The request of SearchSessions operation
|
||||
virtual void SearchSessionsAsync(const SearchSessionsRequest& searchSessionsRequest) const = 0;
|
||||
|
||||
// JoinSession Async
|
||||
// @param joinSessionRequest The request of JoinSession operation
|
||||
virtual void JoinSessionAsync(const JoinSessionRequest& joinSessionRequest) = 0;
|
||||
|
||||
// LeaveSession Async
|
||||
virtual void LeaveSessionAsync() = 0;
|
||||
};
|
||||
|
||||
//! SessionAsyncRequestNotifications
|
||||
//! The notifications correspond to session async requests
|
||||
class SessionAsyncRequestNotifications
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// OnCreateSessionAsyncComplete is fired once CreateSessionAsync completes
|
||||
// @param createSessionResponse The request id if session creation request succeeds; empty if it fails
|
||||
virtual void OnCreateSessionAsyncComplete(const AZStd::string& createSessionReponse) = 0;
|
||||
|
||||
// OnSearchSessionsAsyncComplete is fired once SearchSessionsAsync completes
|
||||
// @param searchSessionsResponse The response of SearchSessions call
|
||||
virtual void OnSearchSessionsAsyncComplete(const SearchSessionsResponse& searchSessionsResponse) = 0;
|
||||
|
||||
// OnJoinSessionAsyncComplete is fired once JoinSessionAsync completes
|
||||
// @param joinSessionsResponse True if joining session succeeds; False otherwise
|
||||
virtual void OnJoinSessionAsyncComplete(bool joinSessionsResponse) = 0;
|
||||
|
||||
// OnLeaveSessionAsyncComplete is fired once LeaveSessionAsync completes
|
||||
virtual void OnLeaveSessionAsyncComplete() = 0;
|
||||
};
|
||||
using SessionAsyncRequestNotificationBus = AZ::EBus<SessionAsyncRequestNotifications>;
|
||||
} // namespace AzFramework
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzFramework/Session/SessionConfig.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
void SessionConfig::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<SessionConfig>()
|
||||
->Version(0)
|
||||
->Field("creationTime", &SessionConfig::m_creationTime)
|
||||
->Field("terminationTime", &SessionConfig::m_terminationTime)
|
||||
->Field("creatorId", &SessionConfig::m_creatorId)
|
||||
->Field("sessionProperties", &SessionConfig::m_sessionProperties)
|
||||
->Field("sessionId", &SessionConfig::m_sessionId)
|
||||
->Field("sessionName", &SessionConfig::m_sessionName)
|
||||
->Field("dnsName", &SessionConfig::m_dnsName)
|
||||
->Field("ipAddress", &SessionConfig::m_ipAddress)
|
||||
->Field("port", &SessionConfig::m_port)
|
||||
->Field("maxPlayer", &SessionConfig::m_maxPlayer)
|
||||
->Field("currentPlayer", &SessionConfig::m_currentPlayer)
|
||||
->Field("status", &SessionConfig::m_status)
|
||||
->Field("statusReason", &SessionConfig::m_statusReason)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<SessionConfig>("SessionConfig", "Properties describing a session")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_creationTime,
|
||||
"CreationTime", "A time stamp indicating when this session was created. Format is a number expressed in Unix time as milliseconds.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_terminationTime,
|
||||
"TerminationTime", "A time stamp indicating when this data object was terminated. Same format as creation time.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_creatorId,
|
||||
"CreatorId", "A unique identifier for a player or entity creating the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_sessionProperties,
|
||||
"SessionProperties", "A collection of custom properties for a session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_sessionId,
|
||||
"SessionId", "A unique identifier for the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_sessionName,
|
||||
"SessionName", "A descriptive label that is associated with a session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_dnsName,
|
||||
"DnsName", "The DNS identifier assigned to the instance that is running the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_ipAddress,
|
||||
"IpAddress", "The IP address of the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_port,
|
||||
"Port", "The port number for the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_maxPlayer,
|
||||
"MaxPlayer", "The maximum number of players that can be connected simultaneously to the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_currentPlayer,
|
||||
"CurrentPlayer", "Number of players currently in the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_status,
|
||||
"Status", "Current status of the session.")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &AzFramework::SessionConfig::m_statusReason,
|
||||
"StatusReason", "Provides additional information about session status.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace AzFramework
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/RTTI/ReflectContext.h>
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
//! SessionConfig
|
||||
//! Properties describing a session.
|
||||
struct SessionConfig
|
||||
{
|
||||
AZ_RTTI(SessionConfig, "{992DD4BE-8BA5-4071-8818-B99FD2952086}");
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
SessionConfig() = default;
|
||||
virtual ~SessionConfig() = default;
|
||||
|
||||
// A time stamp indicating when this session was created. Format is a number expressed in Unix time as milliseconds.
|
||||
uint64_t m_creationTime;
|
||||
|
||||
// A time stamp indicating when this data object was terminated. Same format as creation time.
|
||||
uint64_t m_terminationTime;
|
||||
|
||||
// A unique identifier for a player or entity creating the session.
|
||||
AZStd::string m_creatorId;
|
||||
|
||||
// A collection of custom properties for a session.
|
||||
AZStd::unordered_map<AZStd::string, AZStd::string> m_sessionProperties;
|
||||
|
||||
// A unique identifier for the session.
|
||||
AZStd::string m_sessionId;
|
||||
|
||||
// A descriptive label that is associated with a session.
|
||||
AZStd::string m_sessionName;
|
||||
|
||||
// The DNS identifier assigned to the instance that is running the session.
|
||||
AZStd::string m_dnsName;
|
||||
|
||||
// The IP address of the session.
|
||||
AZStd::string m_ipAddress;
|
||||
|
||||
// The port number for the session.
|
||||
uint16_t m_port;
|
||||
|
||||
// The maximum number of players that can be connected simultaneously to the session.
|
||||
uint64_t m_maxPlayer;
|
||||
|
||||
// Number of players currently in the session.
|
||||
uint64_t m_currentPlayer;
|
||||
|
||||
// Current status of the session.
|
||||
AZStd::string m_status;
|
||||
|
||||
// Provides additional information about session status.
|
||||
AZStd::string m_statusReason;
|
||||
};
|
||||
} // namespace AzFramework
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
struct SessionConfig;
|
||||
|
||||
//! SessionNotifications
|
||||
//! The session notifications to listen for performing required operations
|
||||
class SessionNotifications
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// OnSessionHealthCheck is fired in health check process
|
||||
// @return The result of all OnSessionHealthCheck
|
||||
virtual bool OnSessionHealthCheck() = 0;
|
||||
|
||||
// OnCreateSessionBegin is fired at the beginning of session creation
|
||||
// @param sessionConfig The properties to describe a session
|
||||
// @return The result of all OnCreateSessionBegin notifications
|
||||
virtual bool OnCreateSessionBegin(const SessionConfig& sessionConfig) = 0;
|
||||
|
||||
// OnDestroySessionBegin is fired at the beginning of session termination
|
||||
// @return The result of all OnDestroySessionBegin notifications
|
||||
virtual bool OnDestroySessionBegin() = 0;
|
||||
};
|
||||
using SessionNotificationBus = AZ::EBus<SessionNotifications>;
|
||||
} // namespace AzFramework
|
||||
@@ -84,6 +84,7 @@ namespace AzFramework
|
||||
};
|
||||
|
||||
using EntitySpawnCallback = AZStd::function<void(EntitySpawnTicket&, SpawnableConstEntityContainerView)>;
|
||||
using EntityPreInsertionCallback = AZStd::function<void(EntitySpawnTicket&, SpawnableEntityContainerView)>;
|
||||
using EntityDespawnCallback = AZStd::function<void(EntitySpawnTicket&)>;
|
||||
using ReloadSpawnableCallback = AZStd::function<void(EntitySpawnTicket&, SpawnableConstEntityContainerView)>;
|
||||
using ListEntitiesCallback = AZStd::function<void(EntitySpawnTicket&, SpawnableConstEntityContainerView)>;
|
||||
@@ -110,7 +111,8 @@ namespace AzFramework
|
||||
//! @param completionCallback Optional callback that's called when spawning entities has completed. This can be called from
|
||||
//! a different thread than the one that made the function call. The returned list of entities contains all the newly
|
||||
//! created entities.
|
||||
virtual void SpawnAllEntities(EntitySpawnTicket& ticket, EntitySpawnCallback completionCallback = {}) = 0;
|
||||
virtual void SpawnAllEntities(EntitySpawnTicket& ticket, EntityPreInsertionCallback preInsertionCallback = {},
|
||||
EntitySpawnCallback completionCallback = {}) = 0;
|
||||
//! Spawn instances of some entities in the spawnable.
|
||||
//! @param ticket Stores the results of the call. Use this ticket to spawn additional entities or to despawn them.
|
||||
//! @param entityIndices The indices into the template entities stored in the spawnable that will be used to spawn entities from.
|
||||
@@ -118,7 +120,7 @@ namespace AzFramework
|
||||
//! a different thread than the one that made this function call. The returned list of entities contains all the newly
|
||||
//! created entities.
|
||||
virtual void SpawnEntities(EntitySpawnTicket& ticket, AZStd::vector<size_t> entityIndices,
|
||||
EntitySpawnCallback completionCallback = {}) = 0;
|
||||
EntityPreInsertionCallback preInsertionCallback = {}, EntitySpawnCallback completionCallback = {}) = 0;
|
||||
//! Removes all entities in the provided list from the environment.
|
||||
//! @param ticket The ticket previously used to spawn entities with.
|
||||
//! @param completionCallback Optional callback that's called when despawning entities has completed. This can be called from
|
||||
|
||||
@@ -11,20 +11,24 @@
|
||||
*/
|
||||
|
||||
#include <AzCore/Component/ComponentApplicationBus.h>
|
||||
#include <AzCore/Serialization/IdUtils.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/std/parallel/scoped_lock.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzFramework/Components/TransformComponent.h>
|
||||
#include <AzFramework/Entity/GameEntityContextBus.h>
|
||||
#include <AzFramework/Spawnable/Spawnable.h>
|
||||
#include <AzFramework/Spawnable/SpawnableEntitiesManager.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
void SpawnableEntitiesManager::SpawnAllEntities(EntitySpawnTicket& ticket, EntitySpawnCallback completionCallback)
|
||||
void SpawnableEntitiesManager::SpawnAllEntities(EntitySpawnTicket& ticket, EntityPreInsertionCallback preInsertionCallback,
|
||||
EntitySpawnCallback completionCallback)
|
||||
{
|
||||
SpawnAllEntitiesCommand queueEntry;
|
||||
queueEntry.m_ticket = &ticket;
|
||||
queueEntry.m_completionCallback = AZStd::move(completionCallback);
|
||||
queueEntry.m_preInsertionCallback = AZStd::move(preInsertionCallback);
|
||||
{
|
||||
AZStd::scoped_lock queueLock(m_pendingRequestQueueMutex);
|
||||
queueEntry.m_ticketId = GetTicketPayload<Ticket>(ticket).m_nextTicketId++;
|
||||
@@ -32,13 +36,15 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnableEntitiesManager::SpawnEntities(EntitySpawnTicket& ticket, AZStd::vector<size_t> entityIndices,
|
||||
EntitySpawnCallback completionCallback)
|
||||
void SpawnableEntitiesManager::SpawnEntities(
|
||||
EntitySpawnTicket& ticket, AZStd::vector<size_t> entityIndices,
|
||||
EntityPreInsertionCallback preInsertionCallback, EntitySpawnCallback completionCallback)
|
||||
{
|
||||
SpawnEntitiesCommand queueEntry;
|
||||
queueEntry.m_ticket = &ticket;
|
||||
queueEntry.m_entityIndices = AZStd::move(entityIndices);
|
||||
queueEntry.m_completionCallback = AZStd::move(completionCallback);
|
||||
queueEntry.m_preInsertionCallback = AZStd::move(preInsertionCallback);
|
||||
{
|
||||
AZStd::scoped_lock queueLock(m_pendingRequestQueueMutex);
|
||||
queueEntry.m_ticketId = GetTicketPayload<Ticket>(ticket).m_nextTicketId++;
|
||||
@@ -205,32 +211,85 @@ namespace AzFramework
|
||||
AZ::Entity* clone = serializeContext.CloneObject(&entityTemplate);
|
||||
AZ_Assert(clone != nullptr, "Failed to clone spawnable entity.");
|
||||
clone->SetId(AZ::Entity::MakeId());
|
||||
|
||||
GameEntityContextRequestBus::Broadcast(&GameEntityContextRequestBus::Events::AddGameEntity, clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
AZ::Entity* SpawnableEntitiesManager::CloneSingleEntity(const AZ::Entity& entityTemplate,
|
||||
EntityIdMap& templateToCloneEntityIdMap, AZ::SerializeContext& serializeContext)
|
||||
{
|
||||
return AZ::IdUtils::Remapper<AZ::EntityId>::CloneObjectAndGenerateNewIdsAndFixRefs(
|
||||
&entityTemplate, templateToCloneEntityIdMap, &serializeContext);
|
||||
}
|
||||
|
||||
bool SpawnableEntitiesManager::ProcessRequest(SpawnAllEntitiesCommand& request, AZ::SerializeContext& serializeContext)
|
||||
{
|
||||
Ticket& ticket = GetTicketPayload<Ticket>(*request.m_ticket);
|
||||
if (ticket.m_spawnable.IsReady() && request.m_ticketId == ticket.m_currentTicketId)
|
||||
{
|
||||
size_t spawnedEntitiesCount = ticket.m_spawnedEntities.size();
|
||||
AZStd::vector<AZ::Entity*>& spawnedEntities = ticket.m_spawnedEntities;
|
||||
AZStd::vector<size_t>& spawnedEntityIndices = ticket.m_spawnedEntityIndices;
|
||||
|
||||
const Spawnable::EntityList& entities = ticket.m_spawnable->GetEntities();
|
||||
size_t entitiesSize = entities.size();
|
||||
ticket.m_spawnedEntities.reserve(ticket.m_spawnedEntities.size() + entitiesSize);
|
||||
ticket.m_spawnedEntityIndices.reserve(ticket.m_spawnedEntityIndices.size() + entitiesSize);
|
||||
// Keep track how many entities there were in the array initially
|
||||
size_t spawnedEntitiesInitialCount = spawnedEntities.size();
|
||||
|
||||
for(size_t i=0; i<entitiesSize; ++i)
|
||||
// These are 'template' entities we'll be cloning from
|
||||
const Spawnable::EntityList& entitiesToSpawn = ticket.m_spawnable->GetEntities();
|
||||
size_t entitiesToSpawnSize = entitiesToSpawn.size();
|
||||
|
||||
// Map keeps track of ids from template (spawnable) to clone (instance)
|
||||
// Allowing patch ups of fields referring to entityIds outside of a given entity
|
||||
EntityIdMap templateToCloneEntityIdMap;
|
||||
|
||||
// Reserve buffers
|
||||
spawnedEntities.reserve(spawnedEntities.size() + entitiesToSpawnSize);
|
||||
spawnedEntityIndices.reserve(spawnedEntityIndices.size() + entitiesToSpawnSize);
|
||||
templateToCloneEntityIdMap.reserve(entitiesToSpawnSize);
|
||||
|
||||
// Mark all indices as spawned
|
||||
for (size_t i = 0; i < entitiesToSpawnSize; ++i)
|
||||
{
|
||||
ticket.m_spawnedEntities.push_back(SpawnSingleEntity(*entities[i], serializeContext));
|
||||
ticket.m_spawnedEntityIndices.push_back(i);
|
||||
const AZ::Entity& entityTemplate = *entitiesToSpawn[i];
|
||||
|
||||
AZ::Entity* clone = CloneSingleEntity(entityTemplate, templateToCloneEntityIdMap, serializeContext);
|
||||
|
||||
AZ_Assert(clone != nullptr, "Failed to clone spawnable entity.");
|
||||
|
||||
spawnedEntities.emplace_back(clone);
|
||||
spawnedEntityIndices.push_back(i);
|
||||
}
|
||||
|
||||
// loadAll is true if every entity has been spawned only once
|
||||
if (spawnedEntities.size() == entitiesToSpawnSize)
|
||||
{
|
||||
ticket.m_loadAll = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case where there were already spawns from a previous request
|
||||
ticket.m_loadAll = false;
|
||||
}
|
||||
|
||||
// Let other systems know about newly spawned entities for any pre-processing before adding to the scene/game context.
|
||||
if (request.m_preInsertionCallback)
|
||||
{
|
||||
request.m_preInsertionCallback(*request.m_ticket, SpawnableEntityContainerView(
|
||||
ticket.m_spawnedEntities.begin() + spawnedEntitiesInitialCount, ticket.m_spawnedEntities.end()));
|
||||
}
|
||||
|
||||
// Add to the game context, now the entities are active
|
||||
AZStd::for_each(ticket.m_spawnedEntities.begin() + spawnedEntitiesInitialCount, ticket.m_spawnedEntities.end(),
|
||||
[](AZ::Entity* entity)
|
||||
{
|
||||
GameEntityContextRequestBus::Broadcast(&GameEntityContextRequestBus::Events::AddGameEntity, entity);
|
||||
});
|
||||
|
||||
// Let other systems know about newly spawned entities for any post-processing after adding to the scene/game context.
|
||||
if (request.m_completionCallback)
|
||||
{
|
||||
request.m_completionCallback(*request.m_ticket, SpawnableConstEntityContainerView(
|
||||
ticket.m_spawnedEntities.begin() + spawnedEntitiesCount, ticket.m_spawnedEntities.end()));
|
||||
ticket.m_spawnedEntities.begin() + spawnedEntitiesInitialCount, ticket.m_spawnedEntities.end()));
|
||||
}
|
||||
|
||||
m_onSpawnedEvent.Signal(ticket.m_spawnable);
|
||||
@@ -249,24 +308,56 @@ namespace AzFramework
|
||||
Ticket& ticket = GetTicketPayload<Ticket>(*request.m_ticket);
|
||||
if (ticket.m_spawnable.IsReady() && request.m_ticketId == ticket.m_currentTicketId)
|
||||
{
|
||||
size_t spawnedEntitiesCount = ticket.m_spawnedEntities.size();
|
||||
AZStd::vector<AZ::Entity*>& spawnedEntities = ticket.m_spawnedEntities;
|
||||
AZStd::vector<size_t>& spawnedEntityIndices = ticket.m_spawnedEntityIndices;
|
||||
|
||||
const Spawnable::EntityList& entities = ticket.m_spawnable->GetEntities();
|
||||
size_t entitiesSize = entities.size();
|
||||
ticket.m_spawnedEntities.reserve(ticket.m_spawnedEntities.size() + entitiesSize);
|
||||
ticket.m_spawnedEntityIndices.reserve(ticket.m_spawnedEntityIndices.size() + entitiesSize);
|
||||
// Keep track how many entities there were in the array initially
|
||||
size_t spawnedEntitiesInitialCount = spawnedEntities.size();
|
||||
|
||||
// These are 'template' entities we'll be cloning from
|
||||
const Spawnable::EntityList& entitiesToSpawn = ticket.m_spawnable->GetEntities();
|
||||
size_t entitiesToSpawnSize = request.m_entityIndices.size();
|
||||
|
||||
spawnedEntities.reserve(spawnedEntities.size() + entitiesToSpawnSize);
|
||||
spawnedEntityIndices.reserve(spawnedEntityIndices.size() + entitiesToSpawnSize);
|
||||
|
||||
for (size_t index : request.m_entityIndices)
|
||||
{
|
||||
ticket.m_spawnedEntities.push_back(SpawnSingleEntity(*entities[index], serializeContext));
|
||||
ticket.m_spawnedEntityIndices.push_back(index);
|
||||
if (index < entitiesToSpawn.size())
|
||||
{
|
||||
const AZ::Entity& entityTemplate = *entitiesToSpawn[index];
|
||||
|
||||
AZ::Entity* clone = serializeContext.CloneObject(&entityTemplate);
|
||||
AZ_Assert(clone != nullptr, "Failed to clone spawnable entity.");
|
||||
clone->SetId(AZ::Entity::MakeId());
|
||||
|
||||
spawnedEntities.push_back(clone);
|
||||
spawnedEntityIndices.push_back(index);
|
||||
|
||||
}
|
||||
}
|
||||
ticket.m_loadAll = false;
|
||||
|
||||
// Let other systems know about newly spawned entities for any pre-processing before adding to the scene/game context.
|
||||
if (request.m_preInsertionCallback)
|
||||
{
|
||||
request.m_preInsertionCallback(
|
||||
*request.m_ticket,
|
||||
SpawnableEntityContainerView(
|
||||
ticket.m_spawnedEntities.begin() + spawnedEntitiesInitialCount, ticket.m_spawnedEntities.end()));
|
||||
}
|
||||
|
||||
// Add to the game context, now the entities are active
|
||||
AZStd::for_each(ticket.m_spawnedEntities.begin() + spawnedEntitiesInitialCount, ticket.m_spawnedEntities.end(),
|
||||
[](AZ::Entity* entity)
|
||||
{
|
||||
GameEntityContextRequestBus::Broadcast(&GameEntityContextRequestBus::Events::AddGameEntity, entity);
|
||||
});
|
||||
|
||||
if (request.m_completionCallback)
|
||||
{
|
||||
request.m_completionCallback(*request.m_ticket, SpawnableConstEntityContainerView(
|
||||
ticket.m_spawnedEntities.begin() + spawnedEntitiesCount, ticket.m_spawnedEntities.end()));
|
||||
ticket.m_spawnedEntities.begin() + spawnedEntitiesInitialCount, ticket.m_spawnedEntities.end()));
|
||||
}
|
||||
|
||||
m_onSpawnedEvent.Signal(ticket.m_spawnable);
|
||||
@@ -343,10 +434,23 @@ namespace AzFramework
|
||||
// to load every, simply start over.
|
||||
ticket.m_spawnedEntityIndices.clear();
|
||||
|
||||
size_t entitiesSize = entities.size();
|
||||
for (size_t i = 0; i < entitiesSize; ++i)
|
||||
size_t entitiesToSpawnSize = entities.size();
|
||||
|
||||
// Map keeps track of ids from template (spawnable) to clone (instance)
|
||||
// Allowing patch ups of fields referring to entityIds outside of a given entity
|
||||
EntityIdMap templateToCloneEntityIdMap;
|
||||
templateToCloneEntityIdMap.reserve(entitiesToSpawnSize);
|
||||
|
||||
// Mark all indices as spawned
|
||||
for (size_t i = 0; i < entitiesToSpawnSize; ++i)
|
||||
{
|
||||
ticket.m_spawnedEntities.push_back(SpawnSingleEntity(*entities[i], serializeContext));
|
||||
const AZ::Entity& entityTemplate = *entities[i];
|
||||
|
||||
AZ::Entity* clone = CloneSingleEntity(entityTemplate, templateToCloneEntityIdMap, serializeContext);
|
||||
|
||||
AZ_Assert(clone != nullptr, "Failed to clone spawnable entity.");
|
||||
|
||||
ticket.m_spawnedEntities.emplace_back(clone);
|
||||
ticket.m_spawnedEntityIndices.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace AZ
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
using EntityIdMap = AZStd::unordered_map<AZ::EntityId, AZ::EntityId>;
|
||||
|
||||
class SpawnableEntitiesManager
|
||||
: public SpawnableEntitiesInterface::Registrar
|
||||
{
|
||||
@@ -47,8 +49,8 @@ namespace AzFramework
|
||||
// The following functions are thread safe
|
||||
//
|
||||
|
||||
void SpawnAllEntities(EntitySpawnTicket& ticket, EntitySpawnCallback completionCallback = {}) override;
|
||||
void SpawnEntities(EntitySpawnTicket& ticket, AZStd::vector<size_t> entityIndices,
|
||||
void SpawnAllEntities(EntitySpawnTicket& ticket, EntityPreInsertionCallback preInsertionCallback = {}, EntitySpawnCallback completionCallback = {}) override;
|
||||
void SpawnEntities(EntitySpawnTicket& ticket, AZStd::vector<size_t> entityIndices, EntityPreInsertionCallback preInsertionCallback = {},
|
||||
EntitySpawnCallback completionCallback = {}) override;
|
||||
void DespawnAllEntities(EntitySpawnTicket& ticket, EntityDespawnCallback completionCallback = {}) override;
|
||||
|
||||
@@ -90,6 +92,7 @@ namespace AzFramework
|
||||
struct SpawnAllEntitiesCommand
|
||||
{
|
||||
EntitySpawnCallback m_completionCallback;
|
||||
EntityPreInsertionCallback m_preInsertionCallback;
|
||||
EntitySpawnTicket* m_ticket;
|
||||
uint32_t m_ticketId;
|
||||
};
|
||||
@@ -97,6 +100,7 @@ namespace AzFramework
|
||||
{
|
||||
AZStd::vector<size_t> m_entityIndices;
|
||||
EntitySpawnCallback m_completionCallback;
|
||||
EntityPreInsertionCallback m_preInsertionCallback;
|
||||
EntitySpawnTicket* m_ticket;
|
||||
uint32_t m_ticketId;
|
||||
};
|
||||
@@ -140,7 +144,11 @@ namespace AzFramework
|
||||
using Requests = AZStd::variant<SpawnAllEntitiesCommand, SpawnEntitiesCommand, DespawnAllEntitiesCommand, ReloadSpawnableCommand,
|
||||
ListEntitiesCommand, ClaimEntitiesCommand, BarrierCommand, DestroyTicketCommand>;
|
||||
|
||||
AZ::Entity* SpawnSingleEntity(const AZ::Entity& entityTemplate, AZ::SerializeContext& serializeContext);
|
||||
AZ::Entity* SpawnSingleEntity(const AZ::Entity& entityTemplate,
|
||||
AZ::SerializeContext& serializeContext);
|
||||
|
||||
AZ::Entity* CloneSingleEntity(const AZ::Entity& entityTemplate,
|
||||
EntityIdMap& templateToCloneEntityIdMap, AZ::SerializeContext& serializeContext);
|
||||
|
||||
bool ProcessRequest(SpawnAllEntitiesCommand& request, AZ::SerializeContext& serializeContext);
|
||||
bool ProcessRequest(SpawnEntitiesCommand& request, AZ::SerializeContext& serializeContext);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Neighborhood {
|
||||
//---------------------------------------------------------------------
|
||||
void NeighborReplica::OnReplicaActivate(const GridMate::ReplicaContext& /*rc*/)
|
||||
{
|
||||
// TODO: Should we send the message to ourselves as well (master)?
|
||||
// TODO: Should we send the message to ourselves as well?
|
||||
if (IsProxy())
|
||||
{
|
||||
AZ_Assert(m_persistentName.Get().c_str(), "Received NeighborReplica with missing persistent name!");
|
||||
@@ -52,7 +52,7 @@ namespace Neighborhood {
|
||||
//---------------------------------------------------------------------
|
||||
void NeighborReplica::OnReplicaDeactivate(const GridMate::ReplicaContext& /*rc*/)
|
||||
{
|
||||
// TODO: Should we send the message to ourselves as well (master)?
|
||||
// TODO: Should we send the message to ourselves as well?
|
||||
if (IsProxy())
|
||||
{
|
||||
EBUS_EVENT(NeighborhoodBus, OnNodeLeft, *this);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <AzCore/std/numeric.h>
|
||||
#include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
|
||||
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
|
||||
#include <AzFramework/Windowing/WindowBus.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
@@ -30,7 +29,8 @@ namespace AzFramework
|
||||
AZ_CVAR(float, ed_cameraSystemOrbitDollyScrollSpeed, 0.02f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemOrbitDollyCursorSpeed, 0.01f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemScrollTranslateSpeed, 0.02f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemMaxOrbitDistance, 60.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemMinOrbitDistance, 6.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemMaxOrbitDistance, 50.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemLookSmoothness, 5.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemTranslateSmoothness, 5.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemRotateSpeed, 0.005f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
@@ -159,24 +159,27 @@ namespace AzFramework
|
||||
|
||||
bool CameraSystem::HandleEvents(const InputEvent& event)
|
||||
{
|
||||
if (const auto& cursor = AZStd::get_if<CursorEvent>(&event))
|
||||
if (const auto& horizonalMotion = AZStd::get_if<HorizontalMotionEvent>(&event))
|
||||
{
|
||||
m_cursorState.SetCurrentPosition(cursor->m_position);
|
||||
m_motionDelta.m_x = horizonalMotion->m_delta;
|
||||
}
|
||||
else if (const auto& verticalMotion = AZStd::get_if<VerticalMotionEvent>(&event))
|
||||
{
|
||||
m_motionDelta.m_y = verticalMotion->m_delta;
|
||||
}
|
||||
else if (const auto& scroll = AZStd::get_if<ScrollEvent>(&event))
|
||||
{
|
||||
m_scrollDelta = scroll->m_delta;
|
||||
}
|
||||
|
||||
return m_cameras.HandleEvents(event, m_cursorState.CursorDelta(), m_scrollDelta);
|
||||
return m_cameras.HandleEvents(event, m_motionDelta, m_scrollDelta);
|
||||
}
|
||||
|
||||
Camera CameraSystem::StepCamera(const Camera& targetCamera, const float deltaTime)
|
||||
{
|
||||
const auto nextCamera = m_cameras.StepCamera(targetCamera, m_cursorState.CursorDelta(), m_scrollDelta, deltaTime);
|
||||
|
||||
m_cursorState.Update();
|
||||
const auto nextCamera = m_cameras.StepCamera(targetCamera, m_motionDelta, m_scrollDelta, deltaTime);
|
||||
|
||||
m_motionDelta = ScreenVector{0, 0};
|
||||
m_scrollDelta = 0.0f;
|
||||
|
||||
return nextCamera;
|
||||
@@ -192,13 +195,12 @@ namespace AzFramework
|
||||
bool handling = false;
|
||||
for (auto& cameraInput : m_activeCameraInputs)
|
||||
{
|
||||
cameraInput->HandleEvents(event, cursorDelta, scrollDelta);
|
||||
handling = !cameraInput->Idle() || handling;
|
||||
handling = cameraInput->HandleEvents(event, cursorDelta, scrollDelta) || handling;
|
||||
}
|
||||
|
||||
for (auto& cameraInput : m_idleCameraInputs)
|
||||
{
|
||||
cameraInput->HandleEvents(event, cursorDelta, scrollDelta);
|
||||
handling = cameraInput->HandleEvents(event, cursorDelta, scrollDelta) || handling;
|
||||
}
|
||||
|
||||
return handling;
|
||||
@@ -261,17 +263,26 @@ namespace AzFramework
|
||||
{
|
||||
m_activeCameraInputs[i]->Reset();
|
||||
m_idleCameraInputs.push_back(m_activeCameraInputs[i]);
|
||||
m_activeCameraInputs[i] = m_activeCameraInputs[m_activeCameraInputs.size() - 1];
|
||||
using AZStd::swap;
|
||||
swap(m_activeCameraInputs[i], m_activeCameraInputs[m_activeCameraInputs.size() - 1]);
|
||||
m_activeCameraInputs.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void Cameras::Clear()
|
||||
{
|
||||
Reset();
|
||||
AZ_Assert(m_activeCameraInputs.empty(), "Active Camera Inputs is not empty");
|
||||
|
||||
m_idleCameraInputs.clear();
|
||||
}
|
||||
|
||||
RotateCameraInput::RotateCameraInput(const InputChannelId rotateChannelId)
|
||||
: m_rotateChannelId(rotateChannelId)
|
||||
{
|
||||
}
|
||||
|
||||
void RotateCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
bool RotateCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
{
|
||||
const ClickDetector::ClickEvent clickEvent = [&event, this] {
|
||||
if (const auto& input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
@@ -303,6 +314,11 @@ namespace AzFramework
|
||||
// noop
|
||||
break;
|
||||
}
|
||||
|
||||
// note - must also check !ending to ensure the mouse up (release) event
|
||||
// is not consumed and can be propagated to other systems.
|
||||
// (don't swallow mouse up events)
|
||||
return !Idle() && !Ending();
|
||||
}
|
||||
|
||||
Camera RotateCameraInput::StepCamera(
|
||||
@@ -329,7 +345,7 @@ namespace AzFramework
|
||||
{
|
||||
}
|
||||
|
||||
void PanCameraInput::HandleEvents(
|
||||
bool PanCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
{
|
||||
if (const auto& input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
@@ -346,6 +362,8 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !Idle();
|
||||
}
|
||||
|
||||
Camera PanCameraInput::StepCamera(
|
||||
@@ -410,7 +428,7 @@ namespace AzFramework
|
||||
{
|
||||
}
|
||||
|
||||
void TranslateCameraInput::HandleEvents(
|
||||
bool TranslateCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
{
|
||||
if (const auto& input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
@@ -428,7 +446,8 @@ namespace AzFramework
|
||||
m_boost = true;
|
||||
}
|
||||
}
|
||||
else if (input->m_state == InputChannel::State::Ended)
|
||||
// ensure we don't process end events in the idle state
|
||||
else if (input->m_state == InputChannel::State::Ended && !Idle())
|
||||
{
|
||||
m_translation &= ~(translationFromKey(input->m_channelId));
|
||||
if (m_translation == TranslationType::Nil)
|
||||
@@ -441,6 +460,8 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !Idle();
|
||||
}
|
||||
|
||||
Camera TranslateCameraInput::StepCamera(
|
||||
@@ -502,7 +523,7 @@ namespace AzFramework
|
||||
m_boost = false;
|
||||
}
|
||||
|
||||
void OrbitCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta)
|
||||
bool OrbitCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta)
|
||||
{
|
||||
if (const auto* input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
{
|
||||
@@ -521,8 +542,10 @@ namespace AzFramework
|
||||
|
||||
if (Active())
|
||||
{
|
||||
m_orbitCameras.HandleEvents(event, cursorDelta, scrollDelta);
|
||||
return m_orbitCameras.HandleEvents(event, cursorDelta, scrollDelta);
|
||||
}
|
||||
|
||||
return !Idle();
|
||||
}
|
||||
|
||||
Camera OrbitCameraInput::StepCamera(
|
||||
@@ -532,20 +555,39 @@ namespace AzFramework
|
||||
|
||||
if (Beginning())
|
||||
{
|
||||
float hit_distance = 0.0f;
|
||||
AZ::Plane::CreateFromNormalAndPoint(AZ::Vector3::CreateAxisZ(), AZ::Vector3::CreateAxisZ(ed_cameraSystemDefaultPlaneHeight))
|
||||
.CastRay(targetCamera.Translation(), targetCamera.Rotation().GetBasisY(), hit_distance);
|
||||
const auto hasLookAt = [&nextCamera, &targetCamera, &lookAtFn = m_lookAtFn] {
|
||||
if (lookAtFn)
|
||||
{
|
||||
if (const auto lookAt = lookAtFn())
|
||||
{
|
||||
auto transform = AZ::Transform::CreateLookAt(targetCamera.m_lookAt, *lookAt);
|
||||
nextCamera.m_lookDist = -lookAt->GetDistance(targetCamera.m_lookAt);
|
||||
UpdateCameraFromTransform(nextCamera, transform);
|
||||
|
||||
if (hit_distance > 0.0f)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}();
|
||||
|
||||
if (!hasLookAt)
|
||||
{
|
||||
hit_distance = AZStd::min<float>(hit_distance, ed_cameraSystemMaxOrbitDistance);
|
||||
nextCamera.m_lookDist = -hit_distance;
|
||||
nextCamera.m_lookAt = targetCamera.Translation() + targetCamera.Rotation().GetBasisY() * hit_distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextCamera.m_lookDist = -ed_cameraSystemMaxOrbitDistance;
|
||||
nextCamera.m_lookAt = targetCamera.Translation() + targetCamera.Rotation().GetBasisY() * ed_cameraSystemMaxOrbitDistance;
|
||||
float hit_distance = 0.0f;
|
||||
AZ::Plane::CreateFromNormalAndPoint(AZ::Vector3::CreateAxisZ(), AZ::Vector3::CreateAxisZ(ed_cameraSystemDefaultPlaneHeight))
|
||||
.CastRay(targetCamera.Translation(), targetCamera.Rotation().GetBasisY(), hit_distance);
|
||||
|
||||
if (hit_distance > 0.0f)
|
||||
{
|
||||
hit_distance = AZStd::min<float>(hit_distance, ed_cameraSystemMaxOrbitDistance);
|
||||
nextCamera.m_lookDist = -hit_distance;
|
||||
nextCamera.m_lookAt = targetCamera.Translation() + targetCamera.Rotation().GetBasisY() * hit_distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextCamera.m_lookDist = -ed_cameraSystemMinOrbitDistance;
|
||||
nextCamera.m_lookAt =
|
||||
targetCamera.Translation() + targetCamera.Rotation().GetBasisY() * ed_cameraSystemMinOrbitDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,13 +607,15 @@ namespace AzFramework
|
||||
return nextCamera;
|
||||
}
|
||||
|
||||
void OrbitDollyScrollCameraInput::HandleEvents(
|
||||
bool OrbitDollyScrollCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
{
|
||||
if (const auto* scroll = AZStd::get_if<ScrollEvent>(&event))
|
||||
{
|
||||
BeginActivation();
|
||||
}
|
||||
|
||||
return !Idle();
|
||||
}
|
||||
|
||||
Camera OrbitDollyScrollCameraInput::StepCamera(
|
||||
@@ -589,7 +633,7 @@ namespace AzFramework
|
||||
{
|
||||
}
|
||||
|
||||
void OrbitDollyCursorMoveCameraInput::HandleEvents(
|
||||
bool OrbitDollyCursorMoveCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
{
|
||||
if (const auto& input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
@@ -606,6 +650,8 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !Idle();
|
||||
}
|
||||
|
||||
Camera OrbitDollyCursorMoveCameraInput::StepCamera(
|
||||
@@ -617,13 +663,15 @@ namespace AzFramework
|
||||
return nextCamera;
|
||||
}
|
||||
|
||||
void ScrollTranslationCameraInput::HandleEvents(
|
||||
bool ScrollTranslationCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
{
|
||||
if (const auto* scroll = AZStd::get_if<ScrollEvent>(&event))
|
||||
{
|
||||
BeginActivation();
|
||||
}
|
||||
|
||||
return !Idle();
|
||||
}
|
||||
|
||||
Camera ScrollTranslationCameraInput::StepCamera(
|
||||
@@ -674,7 +722,7 @@ namespace AzFramework
|
||||
return camera;
|
||||
}
|
||||
|
||||
InputEvent BuildInputEvent(const InputChannel& inputChannel, const WindowSize& windowSize)
|
||||
InputEvent BuildInputEvent(const InputChannel& inputChannel)
|
||||
{
|
||||
const auto& inputChannelId = inputChannel.GetInputChannelId();
|
||||
const auto& inputDeviceId = inputChannel.GetInputDevice().GetInputDeviceId();
|
||||
@@ -684,13 +732,13 @@ namespace AzFramework
|
||||
return button == inputChannelId;
|
||||
});
|
||||
|
||||
if (inputChannelId == InputDeviceMouse::Movement::X || inputChannelId == InputDeviceMouse::Movement::Y)
|
||||
if (inputChannelId == InputDeviceMouse::Movement::X)
|
||||
{
|
||||
const auto* position = inputChannel.GetCustomData<AzFramework::InputChannel::PositionData2D>();
|
||||
AZ_Assert(position, "Expected PositionData2D but found nullptr");
|
||||
|
||||
return CursorEvent{ScreenPoint(
|
||||
position->m_normalizedPosition.GetX() * windowSize.m_width, position->m_normalizedPosition.GetY() * windowSize.m_height)};
|
||||
return HorizontalMotionEvent{(int)inputChannel.GetValue()};
|
||||
}
|
||||
else if (inputChannelId == InputDeviceMouse::Movement::Y)
|
||||
{
|
||||
return VerticalMotionEvent{(int)inputChannel.GetValue()};
|
||||
}
|
||||
else if (inputChannelId == InputDeviceMouse::Movement::Z)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <AzCore/std/optional.h>
|
||||
#include <AzFramework/Input/Channels/InputChannel.h>
|
||||
#include <AzFramework/Viewport/ClickDetector.h>
|
||||
#include <AzFramework/Viewport/CursorState.h>
|
||||
#include <AzFramework/Viewport/ScreenGeometry.h>
|
||||
#include <AzFramework/Viewport/ViewportId.h>
|
||||
|
||||
@@ -72,11 +71,16 @@ namespace AzFramework
|
||||
|
||||
void UpdateCameraFromTransform(Camera& camera, const AZ::Transform& transform);
|
||||
|
||||
struct CursorEvent
|
||||
//! Generic motion type
|
||||
template<typename MotionTag>
|
||||
struct MotionEvent
|
||||
{
|
||||
ScreenPoint m_position;
|
||||
int m_delta;
|
||||
};
|
||||
|
||||
using HorizontalMotionEvent = MotionEvent<struct HorizontalMotionTag>;
|
||||
using VerticalMotionEvent = MotionEvent<struct VerticalMotionTag>;
|
||||
|
||||
struct ScrollEvent
|
||||
{
|
||||
float m_delta;
|
||||
@@ -88,7 +92,7 @@ namespace AzFramework
|
||||
InputChannel::State m_state; //!< Channel state. (e.g. Begin/update/end event).
|
||||
};
|
||||
|
||||
using InputEvent = AZStd::variant<AZStd::monostate, CursorEvent, ScrollEvent, DiscreteInputEvent>;
|
||||
using InputEvent = AZStd::variant<AZStd::monostate, HorizontalMotionEvent, VerticalMotionEvent, ScrollEvent, DiscreteInputEvent>;
|
||||
|
||||
class CameraInput
|
||||
{
|
||||
@@ -149,7 +153,7 @@ namespace AzFramework
|
||||
ResetImpl();
|
||||
}
|
||||
|
||||
virtual void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) = 0;
|
||||
virtual bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) = 0;
|
||||
virtual Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) = 0;
|
||||
|
||||
virtual bool Exclusive() const
|
||||
@@ -171,16 +175,30 @@ namespace AzFramework
|
||||
class Cameras
|
||||
{
|
||||
public:
|
||||
void AddCamera(AZStd::shared_ptr<CameraInput> cameraInput);
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta);
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime);
|
||||
|
||||
void AddCamera(AZStd::shared_ptr<CameraInput> cameraInput);
|
||||
//! Reset the state of all cameras.
|
||||
void Reset();
|
||||
//! Remove all cameras that were added.
|
||||
void Clear();
|
||||
//! Is one of the cameras in the active camera inputs marked as 'exclusive'.
|
||||
//! @note This implies no other sibling cameras can begin while the exclusive camera is running.
|
||||
bool Exclusive() const;
|
||||
|
||||
private:
|
||||
AZStd::vector<AZStd::shared_ptr<CameraInput>> m_activeCameraInputs;
|
||||
AZStd::vector<AZStd::shared_ptr<CameraInput>> m_idleCameraInputs;
|
||||
};
|
||||
|
||||
inline bool Cameras::Exclusive() const
|
||||
{
|
||||
return AZStd::any_of(
|
||||
m_activeCameraInputs.begin(), m_activeCameraInputs.end(), [](const auto& cameraInput) { return cameraInput->Exclusive(); });
|
||||
}
|
||||
|
||||
//! Responsible for updating a series of cameras given various inputs.
|
||||
class CameraSystem
|
||||
{
|
||||
public:
|
||||
@@ -190,8 +208,8 @@ namespace AzFramework
|
||||
Cameras m_cameras;
|
||||
|
||||
private:
|
||||
CursorState m_cursorState;
|
||||
float m_scrollDelta = 0.0f;
|
||||
ScreenVector m_motionDelta; //!< The delta used for look/orbit/pan (rotation + translation) - two dimensional.
|
||||
float m_scrollDelta = 0.0f; //!< The delta used for dolly/movement (translation) - one dimensional.
|
||||
};
|
||||
|
||||
class RotateCameraInput : public CameraInput
|
||||
@@ -199,7 +217,8 @@ namespace AzFramework
|
||||
public:
|
||||
explicit RotateCameraInput(InputChannelId rotateChannelId);
|
||||
|
||||
void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
// CameraInput overrides ...
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
|
||||
|
||||
private:
|
||||
@@ -239,7 +258,8 @@ namespace AzFramework
|
||||
public:
|
||||
PanCameraInput(InputChannelId panChannelId, PanAxesFn panAxesFn);
|
||||
|
||||
void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
// CameraInput overrides ...
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
|
||||
|
||||
private:
|
||||
@@ -279,7 +299,8 @@ namespace AzFramework
|
||||
public:
|
||||
explicit TranslateCameraInput(TranslationAxesFn translationAxesFn);
|
||||
|
||||
void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
// CameraInput overrides ...
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
|
||||
void ResetImpl() override;
|
||||
|
||||
@@ -348,7 +369,8 @@ namespace AzFramework
|
||||
class OrbitDollyScrollCameraInput : public CameraInput
|
||||
{
|
||||
public:
|
||||
void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
// CameraInput overrides ...
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
|
||||
};
|
||||
|
||||
@@ -357,7 +379,8 @@ namespace AzFramework
|
||||
public:
|
||||
explicit OrbitDollyCursorMoveCameraInput(InputChannelId dollyChannelId);
|
||||
|
||||
void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
// CameraInput overrides ...
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
|
||||
|
||||
private:
|
||||
@@ -367,25 +390,40 @@ namespace AzFramework
|
||||
class ScrollTranslationCameraInput : public CameraInput
|
||||
{
|
||||
public:
|
||||
void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
// CameraInput overrides ...
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
|
||||
};
|
||||
|
||||
class OrbitCameraInput : public CameraInput
|
||||
{
|
||||
public:
|
||||
void HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
using LookAtFn = AZStd::function<AZStd::optional<AZ::Vector3>()>;
|
||||
|
||||
// CameraInput overrides ...
|
||||
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
|
||||
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
|
||||
bool Exclusive() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Exclusive() const override;
|
||||
|
||||
Cameras m_orbitCameras;
|
||||
|
||||
//! Override the default behavior for how a look-at point is calculated.
|
||||
void SetLookAtFn(const LookAtFn& lookAtFn);
|
||||
|
||||
private:
|
||||
LookAtFn m_lookAtFn;
|
||||
};
|
||||
|
||||
struct WindowSize;
|
||||
inline void OrbitCameraInput::SetLookAtFn(const LookAtFn& lookAtFn)
|
||||
{
|
||||
m_lookAtFn = lookAtFn;
|
||||
}
|
||||
|
||||
inline bool OrbitCameraInput::Exclusive() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Map from a generic InputChannel event to a camera specific InputEvent.
|
||||
InputEvent BuildInputEvent(const InputChannel& inputChannel, const WindowSize& windowSize);
|
||||
InputEvent BuildInputEvent(const InputChannel& inputChannel);
|
||||
} // namespace AzFramework
|
||||
|
||||
@@ -74,7 +74,6 @@ namespace AzFramework
|
||||
|
||||
void SetCameraClippingVolumeFromPerspectiveFovMatrixRH(CameraState& cameraState, const AZ::Matrix4x4& clipFromView)
|
||||
{
|
||||
const float m11 = clipFromView(1, 1);
|
||||
const float m22 = clipFromView(2, 2);
|
||||
const float m23 = clipFromView(2, 3);
|
||||
cameraState.m_nearClip = m23 / m22;
|
||||
@@ -84,7 +83,12 @@ namespace AzFramework
|
||||
{
|
||||
AZStd::swap(cameraState.m_nearClip, cameraState.m_farClip);
|
||||
}
|
||||
cameraState.m_fovOrZoom = 2 * (AZ::Constants::HalfPi - atanf(m11));
|
||||
cameraState.m_fovOrZoom = RetrieveFov(clipFromView);
|
||||
}
|
||||
|
||||
float RetrieveFov(const AZ::Matrix4x4& clipFromView)
|
||||
{
|
||||
return 2.0f * (AZ::Constants::HalfPi - AZStd::atan(clipFromView(1, 1)));
|
||||
}
|
||||
|
||||
void CameraState::Reflect(AZ::SerializeContext& serializeContext)
|
||||
|
||||
@@ -17,54 +17,57 @@
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
/// Represents the camera state populated by the viewport camera.
|
||||
//! Represents the camera state populated by the viewport camera.
|
||||
struct CameraState
|
||||
{
|
||||
/// @cond
|
||||
//! @cond
|
||||
AZ_TYPE_INFO(CameraState, "{D309D934-044C-4BA8-91F1-EA3A45177A52}")
|
||||
CameraState() = default;
|
||||
/// @endcond
|
||||
//! @endcond
|
||||
|
||||
static void Reflect(AZ::SerializeContext& context);
|
||||
|
||||
/// Return the vertical fov of the camera when the view is in perspective.
|
||||
//! Return the vertical fov of the camera when the view is in perspective.
|
||||
float VerticalFovRadian() const { return m_fovOrZoom; }
|
||||
/// Return the zoom amount of the camera when the view is in orthographic.
|
||||
//! Return the zoom amount of the camera when the view is in orthographic.
|
||||
float Zoom() const { return m_fovOrZoom; }
|
||||
|
||||
AZ::Vector3 m_position = AZ::Vector3::CreateZero(); ///< World position of the camera.
|
||||
AZ::Vector3 m_forward = AZ::Vector3::CreateAxisY(); ///< Forward look direction of the camera (world space).
|
||||
AZ::Vector3 m_side = AZ::Vector3::CreateAxisX(); ///< Side vector of camera (orthogonal to forward and up).
|
||||
AZ::Vector3 m_up = AZ::Vector3::CreateAxisZ(); ///< Up vector of the camera (cameras frame - world space).
|
||||
AZ::Vector2 m_viewportSize = AZ::Vector2::CreateZero(); ///< Dimensions of the viewport.
|
||||
float m_nearClip = 0.01f; ///< Near clip plane of the camera.
|
||||
float m_farClip = 100.0f; ///< Far clip plane of the camera.
|
||||
float m_fovOrZoom = 0.0f; ///< Fov or zoom of camera depending on if it is using orthographic projection or not.
|
||||
bool m_orthographic = false; ///< Is the camera using orthographic projection or not.
|
||||
AZ::Vector3 m_position = AZ::Vector3::CreateZero(); //!< World position of the camera.
|
||||
AZ::Vector3 m_forward = AZ::Vector3::CreateAxisY(); //!< Forward look direction of the camera (world space).
|
||||
AZ::Vector3 m_side = AZ::Vector3::CreateAxisX(); //!< Side vector of camera (orthogonal to forward and up).
|
||||
AZ::Vector3 m_up = AZ::Vector3::CreateAxisZ(); //!< Up vector of the camera (cameras frame - world space).
|
||||
AZ::Vector2 m_viewportSize = AZ::Vector2::CreateZero(); //!< Dimensions of the viewport.
|
||||
float m_nearClip = 0.01f; //!< Near clip plane of the camera.
|
||||
float m_farClip = 100.0f; //!< Far clip plane of the camera.
|
||||
float m_fovOrZoom = 0.0f; //!< Fov or zoom of camera depending on if it is using orthographic projection or not.
|
||||
bool m_orthographic = false; //!< Is the camera using orthographic projection or not.
|
||||
};
|
||||
|
||||
/// Create a camera at the given transform with a specific viewport size.
|
||||
/// @note The near/far clip planes and fov are sensible default values - please
|
||||
/// use SetCameraClippingVolume to override them.
|
||||
//! Create a camera at the given transform with a specific viewport size.
|
||||
//! @note The near/far clip planes and fov are sensible default values - please
|
||||
//! use SetCameraClippingVolume to override them.
|
||||
CameraState CreateDefaultCamera(const AZ::Transform& transform, const AZ::Vector2& viewportSize);
|
||||
|
||||
/// Create a camera at the given position (no orientation) with a specific viewport size.
|
||||
/// @note The near/far clip planes and fov are sensible default values - please
|
||||
/// use SetCameraClippingVolume to override them.
|
||||
//! Create a camera at the given position (no orientation) with a specific viewport size.
|
||||
//! @note The near/far clip planes and fov are sensible default values - please
|
||||
//! use SetCameraClippingVolume to override them.
|
||||
CameraState CreateIdentityDefaultCamera(const AZ::Vector3& position, const AZ::Vector2& viewportSize);
|
||||
|
||||
/// Create a camera transformed by the given view to world matrix with a specific viewport size.
|
||||
/// @note The near/far clip planes and fov are sensible default values - please
|
||||
/// use SetCameraClippingVolume to override them.
|
||||
//! Create a camera transformed by the given view to world matrix with a specific viewport size.
|
||||
//! @note The near/far clip planes and fov are sensible default values - please
|
||||
//! use SetCameraClippingVolume to override them.
|
||||
CameraState CreateCameraFromWorldFromViewMatrix(const AZ::Matrix4x4& worldFromView, const AZ::Vector2& viewportSize);
|
||||
|
||||
/// Override the default near/far clipping planes and fov of the camera.
|
||||
//! Override the default near/far clipping planes and fov of the camera.
|
||||
void SetCameraClippingVolume(CameraState& cameraState, float nearPlane, float farPlane, float fovRad);
|
||||
|
||||
/// Override the default near/far clipping planes and fov of the camera by inferring them the specified right handed transform into clip space.
|
||||
//! Override the default near/far clipping planes and fov of the camera by inferring them the specified right handed transform into clip space.
|
||||
void SetCameraClippingVolumeFromPerspectiveFovMatrixRH(CameraState& cameraState, const AZ::Matrix4x4& clipFromView);
|
||||
|
||||
/// Set the transform for an existing camera.
|
||||
//! Retrieve the field of view (Fov) from the perspective projection matrix (view space to clip space).
|
||||
float RetrieveFov(const AZ::Matrix4x4& clipFromView);
|
||||
|
||||
//! Set the transform for an existing camera.
|
||||
void SetCameraTransform(CameraState& cameraState, const AZ::Transform& transform);
|
||||
|
||||
} // namespace AzFramework
|
||||
|
||||
@@ -1,68 +1,73 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzFramework/Viewport/ClickDetector.h>
|
||||
#include <AzFramework/Viewport/ScreenGeometry.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
ClickDetector::ClickOutcome ClickDetector::DetectClick(const ClickEvent clickEvent, const ScreenVector& cursorDelta)
|
||||
{
|
||||
if (clickEvent == ClickEvent::Down)
|
||||
{
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (m_tryBeginTime)
|
||||
{
|
||||
const std::chrono::duration<float> diff = now - m_tryBeginTime.value();
|
||||
if (diff.count() < m_doubleClickInterval)
|
||||
{
|
||||
return ClickOutcome::Nil;
|
||||
}
|
||||
}
|
||||
|
||||
m_detectionState = DetectionState::WaitingForMove;
|
||||
m_moveAccumulator = 0.0f;
|
||||
|
||||
m_tryBeginTime = now;
|
||||
}
|
||||
else if (clickEvent == ClickEvent::Up)
|
||||
{
|
||||
const auto clickOutcome = [detectionState = m_detectionState] {
|
||||
if (detectionState == DetectionState::WaitingForMove)
|
||||
{
|
||||
return ClickOutcome::Click;
|
||||
}
|
||||
if (detectionState == DetectionState::Moved)
|
||||
{
|
||||
return ClickOutcome::Release;
|
||||
}
|
||||
return ClickOutcome::Nil;
|
||||
}();
|
||||
|
||||
m_detectionState = DetectionState::Nil;
|
||||
return clickOutcome;
|
||||
}
|
||||
|
||||
if (m_detectionState == DetectionState::WaitingForMove)
|
||||
{
|
||||
// only allow the action to begin if the mouse has been moved a small amount
|
||||
m_moveAccumulator += ScreenVectorLength(cursorDelta);
|
||||
if (m_moveAccumulator > m_deadZone)
|
||||
{
|
||||
m_detectionState = DetectionState::Moved;
|
||||
return ClickOutcome::Move;
|
||||
}
|
||||
}
|
||||
|
||||
return ClickOutcome::Nil;
|
||||
}
|
||||
} // namespace AzFramework
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzFramework/Viewport/ClickDetector.h>
|
||||
#include <AzFramework/Viewport/ScreenGeometry.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
ClickDetector::ClickOutcome ClickDetector::DetectClick(const ClickEvent clickEvent, const ScreenVector& cursorDelta)
|
||||
{
|
||||
const auto previousDetectionState = m_detectionState;
|
||||
if (previousDetectionState == DetectionState::WaitingForMove)
|
||||
{
|
||||
// only allow the action to begin if the mouse has been moved a small amount
|
||||
m_moveAccumulator += ScreenVectorLength(cursorDelta);
|
||||
if (m_moveAccumulator > m_deadZone)
|
||||
{
|
||||
m_detectionState = DetectionState::Moved;
|
||||
}
|
||||
}
|
||||
|
||||
if (clickEvent == ClickEvent::Down)
|
||||
{
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (m_tryBeginTime)
|
||||
{
|
||||
const std::chrono::duration<float> diff = now - m_tryBeginTime.value();
|
||||
if (diff.count() < m_doubleClickInterval)
|
||||
{
|
||||
return ClickOutcome::Nil;
|
||||
}
|
||||
}
|
||||
|
||||
m_detectionState = DetectionState::WaitingForMove;
|
||||
m_moveAccumulator = 0.0f;
|
||||
|
||||
m_tryBeginTime = now;
|
||||
}
|
||||
else if (clickEvent == ClickEvent::Up)
|
||||
{
|
||||
const auto clickOutcome = [detectionState = m_detectionState] {
|
||||
if (detectionState == DetectionState::WaitingForMove)
|
||||
{
|
||||
return ClickOutcome::Click;
|
||||
}
|
||||
if (detectionState == DetectionState::Moved)
|
||||
{
|
||||
return ClickOutcome::Release;
|
||||
}
|
||||
return ClickOutcome::Nil;
|
||||
}();
|
||||
|
||||
m_detectionState = DetectionState::Nil;
|
||||
return clickOutcome;
|
||||
}
|
||||
|
||||
if (previousDetectionState == DetectionState::WaitingForMove && m_detectionState == DetectionState::Moved)
|
||||
{
|
||||
return ClickOutcome::Move;
|
||||
}
|
||||
|
||||
return ClickOutcome::Nil;
|
||||
}
|
||||
} // namespace AzFramework
|
||||
|
||||
@@ -50,7 +50,11 @@ namespace AzFramework
|
||||
//! Called from any type of 'handle event' function.
|
||||
ClickOutcome DetectClick(ClickEvent clickEvent, const ScreenVector& cursorDelta);
|
||||
|
||||
//! Override the default double click interval.
|
||||
//! @note Default is 400ms - system default.
|
||||
void SetDoubleClickInterval(float doubleClickInterval);
|
||||
//! Override the dead zone before a 'move' outcome will be triggered.
|
||||
void SetDeadZone(float deadZone);
|
||||
|
||||
private:
|
||||
//! Internal state of ClickDetector based on incoming events.
|
||||
@@ -72,4 +76,9 @@ namespace AzFramework
|
||||
{
|
||||
m_doubleClickInterval = doubleClickInterval;
|
||||
}
|
||||
|
||||
inline void ClickDetector::SetDeadZone(const float deadZone)
|
||||
{
|
||||
m_deadZone = deadZone;
|
||||
}
|
||||
} // namespace AzFramework
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzFramework/Viewport/ScreenGeometry.h>
|
||||
|
||||
#include <AzCore/std/optional.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
//! Utility type to wrap a current and last cursor position.
|
||||
struct CursorState
|
||||
{
|
||||
//! Returns the delta between the current and last cursor position.
|
||||
[[nodiscard]] ScreenVector CursorDelta() const;
|
||||
//! Call this in a 'handle event' call to update the most recent cursor position.
|
||||
void SetCurrentPosition(const ScreenPoint& currentPosition);
|
||||
//! Call this in an 'update' call to copy the current cursor position to the last
|
||||
//! cursor position.
|
||||
void Update();
|
||||
|
||||
private:
|
||||
AZStd::optional<ScreenPoint> m_lastCursorPosition;
|
||||
AZStd::optional<ScreenPoint> m_currentCursorPosition;
|
||||
};
|
||||
|
||||
inline void CursorState::SetCurrentPosition(const ScreenPoint& currentPosition)
|
||||
{
|
||||
m_currentCursorPosition = currentPosition;
|
||||
}
|
||||
|
||||
inline ScreenVector CursorState::CursorDelta() const
|
||||
{
|
||||
return m_currentCursorPosition.has_value() && m_lastCursorPosition.has_value()
|
||||
? m_currentCursorPosition.value() - m_lastCursorPosition.value()
|
||||
: ScreenVector(0, 0);
|
||||
}
|
||||
|
||||
inline void CursorState::Update()
|
||||
{
|
||||
if (m_currentCursorPosition.has_value())
|
||||
{
|
||||
m_lastCursorPosition = m_currentCursorPosition;
|
||||
}
|
||||
}
|
||||
} // namespace AzFramework
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzFramework/Viewport/ScreenGeometry.h>
|
||||
|
||||
#include <AzCore/std/optional.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
//! Utility type to wrap a current and last cursor position.
|
||||
struct CursorState
|
||||
{
|
||||
//! Returns the delta between the current and last cursor position.
|
||||
[[nodiscard]] ScreenVector CursorDelta() const;
|
||||
//! Call this in a 'handle event' call to update the most recent cursor position.
|
||||
void SetCurrentPosition(const ScreenPoint& currentPosition);
|
||||
//! Call this in an 'update' call to copy the current cursor position to the last
|
||||
//! cursor position.
|
||||
void Update();
|
||||
|
||||
private:
|
||||
AZStd::optional<ScreenPoint> m_lastCursorPosition;
|
||||
AZStd::optional<ScreenPoint> m_currentCursorPosition;
|
||||
};
|
||||
|
||||
inline void CursorState::SetCurrentPosition(const ScreenPoint& currentPosition)
|
||||
{
|
||||
m_currentCursorPosition = currentPosition;
|
||||
}
|
||||
|
||||
inline ScreenVector CursorState::CursorDelta() const
|
||||
{
|
||||
return m_currentCursorPosition.has_value() && m_lastCursorPosition.has_value()
|
||||
? m_currentCursorPosition.value() - m_lastCursorPosition.value()
|
||||
: ScreenVector(0, 0);
|
||||
}
|
||||
|
||||
inline void CursorState::Update()
|
||||
{
|
||||
if (m_currentCursorPosition.has_value())
|
||||
{
|
||||
m_lastCursorPosition = m_currentCursorPosition;
|
||||
}
|
||||
}
|
||||
} // namespace AzFramework
|
||||
|
||||
@@ -123,8 +123,9 @@ namespace AzFramework
|
||||
OctreeNode* insertCheck = this;
|
||||
while (insertCheck != nullptr)
|
||||
{
|
||||
if (AZ::ShapeIntersection::Contains(insertCheck->m_bounds, boundingVolume))
|
||||
if (AZ::ShapeIntersection::Contains(insertCheck->m_bounds, boundingVolume) || !insertCheck->m_parent)
|
||||
{
|
||||
// Insert here if the entry is fully contained or if we've reached the root node
|
||||
return insertCheck->Insert(octreeScene, entry);
|
||||
}
|
||||
insertCheck = insertCheck->m_parent;
|
||||
|
||||
@@ -188,6 +188,12 @@ set(FILES
|
||||
Script/ScriptDebugMsgReflection.h
|
||||
Script/ScriptRemoteDebugging.cpp
|
||||
Script/ScriptRemoteDebugging.h
|
||||
Session/ISessionHandlingRequests.h
|
||||
Session/ISessionRequests.cpp
|
||||
Session/ISessionRequests.h
|
||||
Session/SessionConfig.cpp
|
||||
Session/SessionConfig.h
|
||||
Session/SessionNotifications.h
|
||||
StreamingInstall/StreamingInstall.h
|
||||
StreamingInstall/StreamingInstall.cpp
|
||||
StreamingInstall/StreamingInstallRequests.h
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
namespace AzNetworking
|
||||
{
|
||||
using NetworkInterfaces = AZStd::unordered_map<AZ::Name, AZStd::unique_ptr<INetworkInterface>>;
|
||||
|
||||
//! @class INetworking
|
||||
//! @brief The interface for creating and working with network interfaces.
|
||||
class INetworking
|
||||
@@ -60,5 +62,25 @@ namespace AzNetworking
|
||||
//! @param name The name of the Compressor factory to unregister, must match result of factory->GetFactoryName()
|
||||
//! @return Whether the factory was found and unregistered
|
||||
virtual bool UnregisterCompressorFactory(AZ::Name name) = 0;
|
||||
|
||||
//! Returns the raw network interfaces owned by the networking instance.
|
||||
//! @return the raw network interfaces owned by the networking instance
|
||||
virtual const NetworkInterfaces& GetNetworkInterfaces() const = 0;
|
||||
|
||||
//! Returns the number of sockets monitored by our TcpListenThread.
|
||||
//! @return the number of sockets monitored by our TcpListenThread
|
||||
virtual uint32_t GetTcpListenThreadSocketCount() const = 0;
|
||||
|
||||
//! Returns the total time spent updating our TcpListenThread.
|
||||
//! @return the total time spent updating our TcpListenThread
|
||||
virtual AZ::TimeMs GetTcpListenThreadUpdateTime() const = 0;
|
||||
|
||||
//! Returns the number of sockets monitored by our UdpReaderThread.
|
||||
//! @return the number of sockets monitored by our UdpReaderThread
|
||||
virtual uint32_t GetUdpReaderThreadSocketCount() const = 0;
|
||||
|
||||
//! Returns the total time spent updating our UdpReaderThread.
|
||||
//! @return the total time spent updating our UdpReaderThread
|
||||
virtual AZ::TimeMs GetUdpReaderThreadUpdateTime() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -149,12 +149,37 @@ namespace AzNetworking
|
||||
return m_compressorFactories.erase(name) > 0;
|
||||
}
|
||||
|
||||
const NetworkInterfaces& NetworkingSystemComponent::GetNetworkInterfaces() const
|
||||
{
|
||||
return m_networkInterfaces;
|
||||
}
|
||||
|
||||
uint32_t NetworkingSystemComponent::GetTcpListenThreadSocketCount() const
|
||||
{
|
||||
return m_listenThread->GetSocketCount();
|
||||
}
|
||||
|
||||
AZ::TimeMs NetworkingSystemComponent::GetTcpListenThreadUpdateTime() const
|
||||
{
|
||||
return m_listenThread->GetUpdateTimeMs();
|
||||
}
|
||||
|
||||
uint32_t NetworkingSystemComponent::GetUdpReaderThreadSocketCount() const
|
||||
{
|
||||
return m_readerThread->GetSocketCount();
|
||||
}
|
||||
|
||||
AZ::TimeMs NetworkingSystemComponent::GetUdpReaderThreadUpdateTime() const
|
||||
{
|
||||
return m_readerThread->GetUpdateTimeMs();
|
||||
}
|
||||
|
||||
void NetworkingSystemComponent::DumpStats([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments)
|
||||
{
|
||||
AZLOG_INFO("Total sockets monitored by TcpListenThread: %u", m_listenThread->GetSocketCount());
|
||||
AZLOG_INFO("Total time spent updating TcpListenThread: %lld", aznumeric_cast<AZ::s64>(m_listenThread->GetUpdateTimeMs()));
|
||||
AZLOG_INFO("Total sockets monitored by UdpReaderThread: %u", m_readerThread->GetSocketCount());
|
||||
AZLOG_INFO("Total time spent updating UdpReaderThread: %lld", aznumeric_cast<AZ::s64>(m_readerThread->GetUpdateTimeMs()));
|
||||
AZLOG_INFO("Total sockets monitored by TcpListenThread: %u", GetTcpListenThreadSocketCount());
|
||||
AZLOG_INFO("Total time spent updating TcpListenThread: %lld", aznumeric_cast<AZ::s64>(GetTcpListenThreadUpdateTime()));
|
||||
AZLOG_INFO("Total sockets monitored by UdpReaderThread: %u", GetUdpReaderThreadSocketCount());
|
||||
AZLOG_INFO("Total time spent updating UdpReaderThread: %lld", aznumeric_cast<AZ::s64>(GetUdpReaderThreadUpdateTime()));
|
||||
|
||||
for (auto& networkInterface : m_networkInterfaces)
|
||||
{
|
||||
|
||||
@@ -63,6 +63,11 @@ namespace AzNetworking
|
||||
void RegisterCompressorFactory(ICompressorFactory* factory) override;
|
||||
AZStd::unique_ptr<ICompressor> CreateCompressor(AZ::Name name) override;
|
||||
bool UnregisterCompressorFactory(AZ::Name name) override;
|
||||
const NetworkInterfaces& GetNetworkInterfaces() const override;
|
||||
uint32_t GetTcpListenThreadSocketCount() const override;
|
||||
AZ::TimeMs GetTcpListenThreadUpdateTime() const override;
|
||||
uint32_t GetUdpReaderThreadSocketCount() const override;
|
||||
AZ::TimeMs GetUdpReaderThreadUpdateTime() const override;
|
||||
//! @}
|
||||
|
||||
//! Console commands.
|
||||
@@ -74,7 +79,6 @@ namespace AzNetworking
|
||||
|
||||
AZ_CONSOLEFUNC(NetworkingSystemComponent, DumpStats, AZ::ConsoleFunctorFlags::Null, "Dumps stats for all instantiated network interfaces");
|
||||
|
||||
using NetworkInterfaces = AZStd::unordered_map<AZ::Name, AZStd::unique_ptr<INetworkInterface>>;
|
||||
NetworkInterfaces m_networkInterfaces;
|
||||
AZStd::unique_ptr<TcpListenThread> m_listenThread;
|
||||
AZStd::unique_ptr<UdpReaderThread> m_readerThread;
|
||||
|
||||
@@ -116,8 +116,8 @@ namespace AzNetworking
|
||||
|
||||
int32_t TcpSocket::Receive(uint8_t* outData, uint32_t size) const
|
||||
{
|
||||
AZ_Assert(size > 0, "Invalid data size for send");
|
||||
AZ_Assert(outData != nullptr, "NULL data pointer passed to send");
|
||||
AZ_Assert(size > 0, "Invalid data size for receive");
|
||||
AZ_Assert(outData != nullptr, "NULL data pointer passed to receive");
|
||||
if (!IsOpen())
|
||||
{
|
||||
return SocketOpResultErrorNotOpen;
|
||||
@@ -176,7 +176,7 @@ namespace AzNetworking
|
||||
if (::bind(aznumeric_cast<int32_t>(m_socketFd), (const sockaddr*)&hints, sizeof(hints)) != 0)
|
||||
{
|
||||
const int32_t error = GetLastNetworkError();
|
||||
AZLOG_ERROR("Failed to bind socket (%d:%s)", error, GetNetworkErrorDesc(error));
|
||||
AZLOG_ERROR("Failed to bind TCP socket to port %u (%d:%s)", uint32_t(port), error, GetNetworkErrorDesc(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,12 @@ namespace AzNetworking
|
||||
|
||||
void TcpSocketManager::ProcessEvents(AZ::TimeMs maxBlockMs, const SocketEventCallback& readCallback, const SocketEventCallback& writeCallback)
|
||||
{
|
||||
if(static_cast<int32_t>(m_maxFd) <= 0 && m_socketFds.empty())
|
||||
{
|
||||
// There are no available sockets to process
|
||||
return;
|
||||
}
|
||||
|
||||
m_readerFdSet = m_sourceFdSet;
|
||||
m_writerFdSet = m_sourceFdSet;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace AzNetworking
|
||||
const UdpReaderThread::ReceivedPackets* packets = m_readerThread.GetReceivedPackets(m_socket.get());
|
||||
if (packets == nullptr)
|
||||
{
|
||||
AZ_Assert(false, "nullptr was retrieved for the received packet buffer, check that the socket has been registered with the reader thread");
|
||||
// Socket is not yet registered with the reader thread and is likely still pending, try again later
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace AzNetworking
|
||||
if (::bind(static_cast<int32_t>(m_socketFd), (const sockaddr *)&hints, sizeof(hints)) != 0)
|
||||
{
|
||||
const int32_t error = GetLastNetworkError();
|
||||
AZLOG_ERROR("Failed to bind socket to port %u (%d:%s)", uint32_t(port), error, GetNetworkErrorDesc(error));
|
||||
AZLOG_ERROR("Failed to bind UDP socket to port %u (%d:%s)", uint32_t(port), error, GetNetworkErrorDesc(error));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,5 +65,12 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
|
||||
ly_add_googletest(
|
||||
NAME AZ::AzNetworking.Tests
|
||||
)
|
||||
|
||||
ly_add_googletest(
|
||||
NAME AZ::AzNetworking.Tests.Sandbox
|
||||
TARGET AZ::AzNetworking.Tests
|
||||
TEST_SUITE sandbox
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@
|
||||
|
||||
#define AZ_TRAIT_OS_USE_WINSOCK 0
|
||||
#define AZ_TRAIT_OS_USE_MACH 0
|
||||
#define AZ_TRAIT_USE_SOCKET_SERVER_EPOLL 1
|
||||
#define AZ_TRAIT_USE_SOCKET_SERVER_SELECT 0
|
||||
#define AZ_TRAIT_USE_SOCKET_SERVER_EPOLL 0
|
||||
#define AZ_TRAIT_USE_SOCKET_SERVER_SELECT 1
|
||||
#define AZ_TRAIT_USE_OPENSSL 1
|
||||
#define AZ_TRAIT_NEEDS_HTONLL 1
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace UnitTest
|
||||
#if AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
|
||||
TEST_F(TcpTransportTests, DISABLED_TestSingleClient)
|
||||
#else
|
||||
TEST_F(TcpTransportTests, TestSingleClient)
|
||||
TEST_F(TcpTransportTests, SUITE_sandbox_TestSingleClient)
|
||||
#endif // AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
|
||||
{
|
||||
TestTcpServer testServer;
|
||||
@@ -157,7 +157,7 @@ namespace UnitTest
|
||||
#if AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
|
||||
TEST_F(TcpTransportTests, DISABLED_TestMultipleClients)
|
||||
#else
|
||||
TEST_F(TcpTransportTests, TestMultipleClients)
|
||||
TEST_F(TcpTransportTests, SUITE_sandbox_TestMultipleClients)
|
||||
#endif // AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
|
||||
{
|
||||
constexpr uint32_t NumTestClients = 50;
|
||||
|
||||
@@ -159,6 +159,8 @@ namespace AzQtComponents
|
||||
// Timer for updating our hovered drop zone opacity
|
||||
QObject::connect(m_dropZoneHoverFadeInTimer, &QTimer::timeout, this, &FancyDocking::onDropZoneHoverFadeInUpdate);
|
||||
m_dropZoneHoverFadeInTimer->setInterval(g_FancyDockingConstants.dropZoneHoverFadeUpdateIntervalMS);
|
||||
QIcon dragIcon = QIcon(QStringLiteral(":/Cursors/Grabbing.svg"));
|
||||
m_dragCursor = QCursor(dragIcon.pixmap(16), 5, 2);
|
||||
}
|
||||
|
||||
FancyDocking::~FancyDocking()
|
||||
@@ -1884,6 +1886,8 @@ namespace AzQtComponents
|
||||
return;
|
||||
}
|
||||
|
||||
QApplication::setOverrideCursor(m_dragCursor);
|
||||
|
||||
QPoint relativePressPos = pressPos;
|
||||
|
||||
// If we are dragging a floating window, we need to grab a reference to its
|
||||
@@ -3565,6 +3569,11 @@ namespace AzQtComponents
|
||||
*/
|
||||
void FancyDocking::clearDraggingState()
|
||||
{
|
||||
if (QApplication::overrideCursor())
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
m_ghostWidget->hide();
|
||||
|
||||
// Release the mouse and keyboard from our main window since we grab them when we start dragging
|
||||
|
||||
@@ -266,6 +266,8 @@ namespace AzQtComponents
|
||||
|
||||
QString m_floatingWindowIdentifierPrefix;
|
||||
QString m_tabContainerIdentifierPrefix;
|
||||
|
||||
QCursor m_dragCursor;
|
||||
};
|
||||
|
||||
} // namespace AzQtComponents
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <QAction>
|
||||
#include <QActionEvent>
|
||||
#include <QApplication>
|
||||
#include <QHBoxLayout>
|
||||
#include <QIcon>
|
||||
#include <QLayout>
|
||||
@@ -419,6 +420,14 @@ namespace AzQtComponents
|
||||
// a mouse move. The paint handler updates the close button's visibility
|
||||
setAttribute(Qt::WA_Hover);
|
||||
AzQtComponents::Style::addClass(this, g_emptyStyleClass);
|
||||
|
||||
QIcon icon = QIcon(QStringLiteral(":/Cursors/Grab_release.svg"));
|
||||
m_hoverCursor = QCursor(icon.pixmap(16), 5, 2);
|
||||
|
||||
icon = QIcon(QStringLiteral(":/Cursors/Grabbing.svg"));
|
||||
m_dragCursor = QCursor(icon.pixmap(16), 5, 2);
|
||||
|
||||
this->setCursor(m_hoverCursor);
|
||||
}
|
||||
|
||||
void TabBar::setHandleOverflow(bool handleOverflow)
|
||||
@@ -455,6 +464,11 @@ namespace AzQtComponents
|
||||
{
|
||||
if (mouseEvent->buttons() & Qt::LeftButton)
|
||||
{
|
||||
if (!QApplication::overrideCursor() || *QApplication::overrideCursor() != m_dragCursor)
|
||||
{
|
||||
QApplication::setOverrideCursor(m_dragCursor);
|
||||
}
|
||||
|
||||
m_lastMousePress = mouseEvent->pos();
|
||||
}
|
||||
|
||||
@@ -469,6 +483,7 @@ namespace AzQtComponents
|
||||
// selected tab is moved around. The close button is not explicitly rendered for the
|
||||
// moved tab during this operation. We need to make sure not to set it visible again
|
||||
// while the tab is moving. This flag makes sure it happens.
|
||||
|
||||
m_movingTab = true;
|
||||
}
|
||||
|
||||
@@ -479,6 +494,13 @@ namespace AzQtComponents
|
||||
|
||||
void TabBar::mouseReleaseEvent(QMouseEvent* mouseEvent)
|
||||
{
|
||||
// Ensure we don't reset the cursor in the case of a dummy event being sent from DockTabWidget to trigger the animation.
|
||||
Qt::MouseButtons realButtons = QApplication::mouseButtons();
|
||||
if (QApplication::overrideCursor() && !(realButtons & Qt::LeftButton))
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
if (m_movingTab && !(mouseEvent->buttons() & Qt::LeftButton))
|
||||
{
|
||||
// When a moving tab is released, there is a short animation to put the moving tab
|
||||
@@ -632,13 +654,7 @@ namespace AzQtComponents
|
||||
{
|
||||
QPoint p = tabRect(i).topLeft();
|
||||
|
||||
int rightPadding = g_closeButtonPadding;
|
||||
if (m_overflowing == Overflowing)
|
||||
{
|
||||
rightPadding = 0;
|
||||
}
|
||||
|
||||
p.setX(p.x() + tabRect(i).width() - rightPadding - g_closeButtonWidth);
|
||||
p.setX(p.x() + tabRect(i).width() - g_closeButtonPadding - g_closeButtonWidth);
|
||||
p.setY(p.y() + 1 + (tabRect(i).height() - g_closeButtonWidth) / 2);
|
||||
tabBtn->move(p);
|
||||
}
|
||||
|
||||
@@ -203,6 +203,9 @@ namespace AzQtComponents
|
||||
bool m_movingTab = false;
|
||||
QPoint m_lastMousePress;
|
||||
|
||||
QCursor m_dragCursor;
|
||||
QCursor m_hoverCursor;
|
||||
|
||||
void resetOverflow();
|
||||
void overflowIfNeeded();
|
||||
void showCloseButtonAt(int index);
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 25.2.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#FFFFFF;}
|
||||
</style>
|
||||
<g id="Cursor-_x2F_-Grab-release">
|
||||
<g id="Group" transform="translate(3.366335, 2.000000)">
|
||||
<g id="Path">
|
||||
<g>
|
||||
<path id="path-1" d="M2.4,1v7.5H2.2C1.3,7.9,0,7.8-1.1,8.2l-0.3,0.1c-0.9,0.4-1.3,1.5-0.9,2.4l1.6,4c0.3,0.8,1.1,1.8,1.7,2.5
|
||||
l0.5,0.4c0.4,0.3,0.7,0.7,1.1,0.9l0.1,0.1L3,18.8l0.3,0.3c0.1,0.3,0.3,0.4,0.3,0.4v0.1l0,0V22h7l0.5-0.9l0.5,0.9h3.3v-2.5l0,0
|
||||
v-0.1l0.1-0.3l0.1-0.3l0.1-0.3l0.1-0.4l0.3-0.5l0.3-0.5l0.4-0.8l0.1-0.3c0.5-0.5,0.9-1.8,0.9-2.6V7.6c0-1.2-0.4-3.8-2.2-3.8
|
||||
c-1.1,0-1.3,0.5-1.6,0.8c-0.1-0.3-0.4-1.5-1.7-1.6c-1.1,0-1.6,0.5-1.7,0.9C10,3.5,9.7,2.5,8.4,2.5C7.6,2.5,7.4,2.6,7.1,3
|
||||
C6.8,2.5,6.1-2,4.6-2C3.3-2,2.4,0,2.4,1z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path id="path-1_1_" d="M2.4,1v7.5H2.2C1.3,7.9,0,7.8-1.1,8.2l-0.3,0.1c-0.9,0.4-1.3,1.5-0.9,2.4l1.6,4c0.3,0.8,1.1,1.8,1.7,2.5
|
||||
l0.5,0.4c0.4,0.3,0.7,0.7,1.1,0.9l0.1,0.1L3,18.8l0.3,0.3c0.1,0.1,0.3,0.3,0.3,0.3v0.3l0,0V22h7l0.5-0.9l0.5,0.9h3.3v-2.5l0,0
|
||||
v-0.1l0.1-0.3l0.1-0.3l0.1-0.3l0.1-0.4l0.3-0.5l0.3-0.5l0.4-0.8l0.1-0.3c0.5-0.5,0.9-1.8,0.9-2.6V7.6c0-1.2-0.4-3.8-2.2-3.8
|
||||
c-1.1,0-1.3,0.5-1.6,0.8c-0.1-0.3-0.4-1.5-1.7-1.6c-1.1,0-1.6,0.5-1.7,0.9C10,3.5,9.7,2.5,8.4,2.5C8,2.5,7.6,3,7.1,3.1
|
||||
c0,0.3,0.3-2.9-0.3-3.8C6.6-1.1,6.1-2,4.6-2C3.3-2,2.4,0,2.4,1z"/>
|
||||
</g>
|
||||
</g>
|
||||
<path id="Path_1_" class="st0" d="M7.1,6.4V5.3c0-0.5,0.4-1.5,1.3-1.5s1.2,0.9,1.2,1.6c0,2,0,0.5,0,1.3h0.8c0-2.8,0-0.4,0-0.9
|
||||
c0-0.8,0.5-1.3,1.3-1.3S13,5.1,13,5.9c0,0.5,0,0.9,0,0.9h0.8V6.4c0-0.7,0.3-1.2,1.1-1.2c0.9,0,1.2,0.7,1.3,1.7v1.3v5
|
||||
c0,0.7-0.3,1.5-0.5,2.1l-0.1,0.3l-0.4,0.8L14.8,17l-0.3,0.4l-0.3,0.4L14,18.2c-0.3,0.5-0.4,0.9-0.4,1.3v0.1v1.2h-1.2l-1.2-2.5
|
||||
l-1.3,2.5h-5v-1.2c0-0.4-0.4-0.8-0.8-1.5l-0.4-0.4l-0.4-0.4l-0.1-0.1L2.9,17l-0.3-0.3L2,16.1c-0.4-0.4-1.1-0.9-1.3-1.5l-0.3-0.4
|
||||
l-1.5-4c-0.1-0.3,0-0.7,0.1-0.8c0,0,0,0,0.1-0.1l0.3-0.1c1.1-0.4,2.2,0.1,2.9,1.1l0.1,0.1l1.1,1.7V1c0-0.7,0.7-1.3,1.3-1.3
|
||||
s1.2,0.7,1.2,1.2c0,3.6,0,5.4,0,5.5H7.1z"/>
|
||||
<polygon id="Path_2_" points="12.4,10.9 13.7,10.9 13.7,15.8 12.4,15.8 "/>
|
||||
<polygon id="Path_3_" points="9.9,10.9 11.2,10.9 11.2,15.8 9.9,15.8 "/>
|
||||
<polygon id="Path_4_" points="7.4,10.9 8.7,10.9 8.7,15.8 7.4,15.8 "/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 25.2.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill-rule:evenodd;clip-rule:evenodd;fill:#FFFFFF;}
|
||||
.st1{fill-rule:evenodd;clip-rule:evenodd;}
|
||||
</style>
|
||||
<g>
|
||||
<path class="st0" d="M5.3,4.2V2.2c0-0.6,0.2-1.1,0.6-1.6C6.3,0.1,6.9,0,7.4,0l0,0c1,0,1.7,0.5,2.4,1.1l0.2,0.2l0,0l0.2-0.2
|
||||
c0.5,0,0.8-0.2,1.1-0.2h0.2c1,0,1.7,0.5,2.4,1.1l0.2,0.2l0,0L14,2c0.3-0.2,0.5-0.3,0.8-0.3H15c1.1,0,1.9,0.5,2.5,1.1L17.7,3l0,0
|
||||
l0.2-0.2c0.5-0.2,0.8-0.3,1.1-0.3h0.2c1,0,1.7,0.5,2.4,1.1c0.6,0.6,1,1.6,1,2.5l0,0v7.5c0,1-0.5,2.5-1,3.3c0,0-2.2,3.3-2.2,4.5l0,0
|
||||
V24h-2.9l-0.6-2.2L14.7,24H6.9v-2.4c0-1.1-4.8-4.3-4.8-4.3c-1-0.6-1.6-2.1-1.6-3.2l0,0V8.4c0-1.1,0.5-2.1,1.1-2.9
|
||||
C2.6,4.6,4,4.1,5.3,4.2L5.3,4.2z"/>
|
||||
<g>
|
||||
<path d="M7.4,1C7.9,1,8.5,1.2,9,1.8l0.2,0.2l0.7,0.7L10.5,2C10.7,2,10.8,2,11,1.9c0.1,0,0.2,0,0.2,0h0.2c0.6,0,1.1,0.3,1.7,0.8
|
||||
l0.2,0.2l0.7,0.7l0.7-0.7l0.1-0.1c0,0,0.1,0,0.1-0.1c0,0,0.1,0,0.1-0.1H15c0.7,0,1.3,0.3,1.8,0.8L17,3.7l0.7,0.7l0.7-0.7
|
||||
c0.1,0,0.1,0,0.2-0.1c0.1-0.1,0.4-0.1,0.4-0.1h0.2c0.6,0,1.1,0.3,1.7,0.8c0.4,0.4,0.7,1.1,0.7,1.8v7.5c0,0.7-0.4,2.2-0.8,2.8
|
||||
c-0.7,1.1-2.4,3.7-2.4,5V23h-1.1l-0.4-1.5L16,19l-1.1,2.3L14.1,23H7.9v-1.4c0-0.4,0-1.6-5.2-5.1C2.1,16,1.5,15,1.5,14.1V8.4
|
||||
c0-0.7,0.3-1.5,0.9-2.2c0.6-0.6,1.5-1,2.4-1c0.1,0,0.2,0,0.4,0l1.1,0.1V4.2V2.2c0-0.4,0.1-0.6,0.3-0.9l0.1-0.1l0.1-0.1
|
||||
C6.8,1,7.1,1,7.4,1 M14.9,2.7L14.9,2.7L14.9,2.7 M7.4,0C6.9,0,6.3,0.1,5.9,0.6c-0.5,0.5-0.6,1-0.6,1.6v2.1c-0.2,0-0.3,0-0.5,0
|
||||
c-1.1,0-2.3,0.5-3.2,1.3C1,6.3,0.5,7.3,0.5,8.4v5.7c0,1.1,0.6,2.5,1.6,3.2c0,0,4.8,3.2,4.8,4.3V24h7.8l1.1-2.2l0.6,2.2h2.9v-2.5
|
||||
c0-1.1,2.2-4.5,2.2-4.5c0.5-0.8,1-2.4,1-3.3V6.1c0-1-0.3-1.9-1-2.5c-0.6-0.6-1.4-1.1-2.4-1.1H19c-0.3,0-0.6,0.2-1.1,0.3L17.7,3
|
||||
l-0.2-0.2c-0.6-0.6-1.4-1.1-2.5-1.1h-0.2c-0.3,0-0.5,0.2-0.8,0.3l-0.2,0.2L13.7,2c-0.6-0.6-1.4-1.1-2.4-1.1h-0.2
|
||||
c-0.3,0-0.6,0.2-1.1,0.2L9.9,1.2L9.8,1.1C9.1,0.4,8.3,0,7.4,0L7.4,0z"/>
|
||||
</g>
|
||||
<polygon class="st1" points="10.9,10.4 12.5,10.4 12.5,16.8 10.9,16.8 "/>
|
||||
<polygon class="st1" points="14,10.4 15.6,10.4 15.6,16.8 14,16.8 "/>
|
||||
<polygon class="st1" points="17.2,10.4 18.8,10.4 18.8,16.8 17.2,16.8 "/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
@@ -637,5 +637,7 @@
|
||||
</qresource>
|
||||
<qresource prefix="/Cursors">
|
||||
<file alias="Pointer.svg">img/UI20/Cursors/Pointer.svg</file>
|
||||
<file alias="Grab_release.svg">img/UI20/Cursors/Grab_release.svg</file>
|
||||
<file alias="Grabbing.svg">img/UI20/Cursors/Grabbing.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzQtComponents/Utilities/SelectionProxyModel.h>
|
||||
#include <QAbstractProxyModel>
|
||||
|
||||
namespace AzQtComponents
|
||||
{
|
||||
SelectionProxyModel::SelectionProxyModel(QItemSelectionModel* sourceSelectionModel, QAbstractProxyModel* proxyModel, QObject* parent)
|
||||
: QItemSelectionModel(proxyModel, parent)
|
||||
, m_sourceSelectionModel(sourceSelectionModel)
|
||||
{
|
||||
connect(sourceSelectionModel, &QItemSelectionModel::selectionChanged, this, &SelectionProxyModel::OnSourceSelectionChanged);
|
||||
connect(sourceSelectionModel, &QItemSelectionModel::currentChanged, this, &SelectionProxyModel::OnSourceSelectionCurrentChanged);
|
||||
connect(proxyModel, &QAbstractItemModel::rowsInserted, this, &SelectionProxyModel::OnProxyModelRowsInserted);
|
||||
connect(this, &QItemSelectionModel::selectionChanged, this, &SelectionProxyModel::OnProxySelectionChanged);
|
||||
|
||||
// Find the chain of proxy models
|
||||
QAbstractProxyModel* sourceProxyModel = proxyModel;
|
||||
while (sourceProxyModel)
|
||||
{
|
||||
m_proxyModels.push_back(sourceProxyModel);
|
||||
sourceProxyModel = qobject_cast<QAbstractProxyModel*>(sourceProxyModel->sourceModel());
|
||||
}
|
||||
|
||||
const QItemSelection currentSelection = mapFromSource(m_sourceSelectionModel->selection());
|
||||
QItemSelectionModel::select(currentSelection, QItemSelectionModel::ClearAndSelect);
|
||||
|
||||
const QModelIndex currentModelIndex = mapFromSource(m_sourceSelectionModel->currentIndex());
|
||||
QItemSelectionModel::setCurrentIndex(currentModelIndex, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
|
||||
void SelectionProxyModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
|
||||
{
|
||||
const QModelIndex sourcetIndex = mapToSource(index);
|
||||
m_sourceSelectionModel->setCurrentIndex(sourcetIndex, command);
|
||||
}
|
||||
|
||||
void SelectionProxyModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
|
||||
{
|
||||
const QModelIndex sourceIndex = mapToSource(index);
|
||||
m_sourceSelectionModel->select(sourceIndex, command);
|
||||
}
|
||||
|
||||
void SelectionProxyModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
|
||||
{
|
||||
const QItemSelection sourceSelection = mapToSource(selection);
|
||||
m_sourceSelectionModel->select(sourceSelection, command);
|
||||
}
|
||||
|
||||
void SelectionProxyModel::clear()
|
||||
{
|
||||
m_sourceSelectionModel->clear();
|
||||
}
|
||||
|
||||
void SelectionProxyModel::reset()
|
||||
{
|
||||
m_sourceSelectionModel->reset();
|
||||
}
|
||||
|
||||
void SelectionProxyModel::clearCurrentIndex()
|
||||
{
|
||||
m_sourceSelectionModel->clearCurrentIndex();
|
||||
}
|
||||
|
||||
void SelectionProxyModel::OnSourceSelectionCurrentChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
|
||||
{
|
||||
QModelIndex targetCurrent = mapFromSource(current);
|
||||
QItemSelectionModel::setCurrentIndex(targetCurrent, QItemSelectionModel::NoUpdate);
|
||||
}
|
||||
|
||||
void SelectionProxyModel::OnSourceSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
|
||||
{
|
||||
QItemSelection targetSelected = mapFromSource(selected);
|
||||
QItemSelection targetDeselected = mapFromSource(deselected);
|
||||
|
||||
QItemSelectionModel::select(targetSelected, QItemSelectionModel::Select);
|
||||
QItemSelectionModel::select(targetDeselected, QItemSelectionModel::Deselect);
|
||||
}
|
||||
|
||||
void SelectionProxyModel::OnProxySelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
|
||||
{
|
||||
const QItemSelection sourceSelected = mapToSource(selected);
|
||||
const QItemSelection sourceDeselected = mapToSource(deselected);
|
||||
|
||||
// Disconnect from the selectionChanged signal in the source model to prevent recursion. We could also block the signals
|
||||
// of the source selection model, but someone else may be connected to its signals and expect to get an update.
|
||||
disconnect(m_sourceSelectionModel, &QItemSelectionModel::selectionChanged, this, &SelectionProxyModel::OnSourceSelectionChanged);
|
||||
if (selected.empty() && deselected.empty())
|
||||
{
|
||||
// Force the signal to fire
|
||||
emit m_sourceSelectionModel->selectionChanged({}, {});
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sourceSelectionModel->select(sourceSelected, QItemSelectionModel::Select);
|
||||
m_sourceSelectionModel->select(sourceDeselected, QItemSelectionModel::Deselect);
|
||||
}
|
||||
connect(m_sourceSelectionModel, &QItemSelectionModel::selectionChanged, this, &SelectionProxyModel::OnSourceSelectionChanged);
|
||||
}
|
||||
|
||||
void SelectionProxyModel::OnProxyModelRowsInserted([[maybe_unused]] const QModelIndex& parent, [[maybe_unused]] int first, [[maybe_unused]] int last)
|
||||
{
|
||||
QModelIndex sourceIndex = m_sourceSelectionModel->currentIndex();
|
||||
QModelIndex targetIndex = mapFromSource(sourceIndex);
|
||||
if (targetIndex != currentIndex())
|
||||
{
|
||||
QItemSelectionModel::setCurrentIndex(targetIndex, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
}
|
||||
|
||||
QItemSelection sourceSelection = m_sourceSelectionModel->selection();
|
||||
QItemSelection targetSelection = mapFromSource(sourceSelection);
|
||||
if (targetSelection != selection())
|
||||
{
|
||||
QItemSelectionModel::select(targetSelection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex SelectionProxyModel::mapFromSource(const QModelIndex& sourceIndex)
|
||||
{
|
||||
QModelIndex mappedIndex = sourceIndex;
|
||||
for (QVector<QAbstractProxyModel*>::const_reverse_iterator itProxy = m_proxyModels.rbegin(); itProxy != m_proxyModels.rend(); ++itProxy)
|
||||
{
|
||||
mappedIndex = (*itProxy)->mapFromSource(mappedIndex);
|
||||
}
|
||||
return mappedIndex;
|
||||
}
|
||||
|
||||
QItemSelection SelectionProxyModel::mapFromSource(const QItemSelection& sourceSelection)
|
||||
{
|
||||
QItemSelection mappedSelection = sourceSelection;
|
||||
for (QVector<QAbstractProxyModel*>::const_reverse_iterator itProxy = m_proxyModels.rbegin(); itProxy != m_proxyModels.rend(); ++itProxy)
|
||||
{
|
||||
mappedSelection = (*itProxy)->mapSelectionFromSource(mappedSelection);
|
||||
}
|
||||
return mappedSelection;
|
||||
}
|
||||
|
||||
QModelIndex SelectionProxyModel::mapToSource(const QModelIndex& targetIndex)
|
||||
{
|
||||
QModelIndex mappedIndex = targetIndex;
|
||||
for (QVector<QAbstractProxyModel*>::const_iterator itProxy = m_proxyModels.begin(); itProxy != m_proxyModels.end(); ++itProxy)
|
||||
{
|
||||
mappedIndex = (*itProxy)->mapToSource(mappedIndex);
|
||||
}
|
||||
return mappedIndex;
|
||||
}
|
||||
|
||||
QItemSelection SelectionProxyModel::mapToSource(const QItemSelection& targetSelection)
|
||||
{
|
||||
QItemSelection mappedSelection = targetSelection;
|
||||
for (QVector<QAbstractProxyModel*>::const_iterator itProxy = m_proxyModels.begin(); itProxy != m_proxyModels.end(); ++itProxy)
|
||||
{
|
||||
mappedSelection = (*itProxy)->mapSelectionToSource(mappedSelection);
|
||||
}
|
||||
return mappedSelection;
|
||||
}
|
||||
} // namespace AzQtComponents
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <AzQtComponents/AzQtComponentsAPI.h>
|
||||
#include <QtCore/QItemSelectionModel>
|
||||
#include <QVector>
|
||||
#endif
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QAbstractProxyModel)
|
||||
|
||||
namespace AzQtComponents
|
||||
{
|
||||
//! This class is a QItemSelectionModel that syncs through proxy models and maintains
|
||||
//! selection. In Qt we can have a model being filtered/sorted by proxy models. If the
|
||||
//! selection model is connected to the original model, the view needs a new selection
|
||||
//! model that understands the filtering. This class does that conversion.
|
||||
//! @Note: this class does not support changing proxy models (anywhere in the chain).
|
||||
//! The class will have to be recreated with the new proxy model.
|
||||
class AZ_QT_COMPONENTS_API SelectionProxyModel
|
||||
: public QItemSelectionModel
|
||||
{
|
||||
Q_OBJECT // AUTOMOC
|
||||
|
||||
public:
|
||||
SelectionProxyModel(QItemSelectionModel* sourceSelectionModel, QAbstractProxyModel* proxyModel, QObject* parent = nullptr);
|
||||
|
||||
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) override;
|
||||
void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) override;
|
||||
void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) override;
|
||||
void clear() override;
|
||||
void reset() override;
|
||||
void clearCurrentIndex() override;
|
||||
|
||||
private slots:
|
||||
void OnSourceSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
||||
void OnSourceSelectionCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||
void OnProxySelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
||||
void OnProxyModelRowsInserted(const QModelIndex& parent, int first, int last);
|
||||
|
||||
private:
|
||||
QModelIndex mapFromSource(const QModelIndex& sourceIndex);
|
||||
QItemSelection mapFromSource(const QItemSelection& sourceSelection);
|
||||
|
||||
QModelIndex mapToSource(const QModelIndex& targetIndex);
|
||||
QItemSelection mapToSource(const QItemSelection& targetSelection);
|
||||
|
||||
// Contains the chain of proxy models that leads us to the real model. The outer-most proxy model
|
||||
// comes first and is followed by inner proxy models.
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
QVector<QAbstractProxyModel*> m_proxyModels;
|
||||
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
QItemSelectionModel* m_sourceSelectionModel;
|
||||
};
|
||||
} // namespace AzQtComponents
|
||||
@@ -287,6 +287,8 @@ set(FILES
|
||||
Utilities/ScreenUtilities.cpp
|
||||
Utilities/ScreenGrabber.h
|
||||
Utilities/ScopedCleanup.h
|
||||
Utilities/SelectionProxyModel.cpp
|
||||
Utilities/SelectionProxyModel.h
|
||||
Utilities/TextUtilities.cpp
|
||||
Utilities/TextUtilities.h
|
||||
)
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#define AZ_TRAIT_DISABLE_FAILED_ZERO_COLOR_CONVERSION_TEST true
|
||||
#define AZ_TRAIT_DISABLE_FAILED_FRAMEPROFILER_TEST true
|
||||
#define AZ_TRAIT_DISABLE_FAILED_FRAMEWORK_TESTS true
|
||||
#define AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS true
|
||||
#define AZ_TRAIT_DISABLE_FAILED_GRADIENT_SIGNAL_TESTS true
|
||||
#define AZ_TRAIT_DISABLE_FAILED_MULTIPLAYER_GRIDMATE_TESTS true
|
||||
#define AZ_TRAIT_DISABLE_FAILED_INPUT_TESTS true
|
||||
|
||||
@@ -52,6 +52,21 @@ namespace AzToolsFramework
|
||||
* Deletes all entities in the provided list, as well as their transform descendants.
|
||||
*/
|
||||
virtual void DeleteEntitiesAndAllDescendants(const EntityIdList& entities) = 0;
|
||||
|
||||
/**
|
||||
* Duplicate all currently-selected entities.
|
||||
*/
|
||||
virtual void DuplicateSelected() = 0;
|
||||
|
||||
/**
|
||||
* Duplicates the specified entity.
|
||||
*/
|
||||
virtual void DuplicateEntityById(AZ::EntityId entityId) = 0;
|
||||
|
||||
/**
|
||||
* Duplicates all specified entities.
|
||||
*/
|
||||
virtual void DuplicateEntities(const EntityIdList& entities) = 0;
|
||||
};
|
||||
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
+20
-2
@@ -43,7 +43,7 @@ namespace AzToolsFramework
|
||||
|
||||
void EditorEntityManager::DeleteEntityById(AZ::EntityId entityId)
|
||||
{
|
||||
DeleteEntities({entityId});
|
||||
DeleteEntities(EntityIdList{ entityId });
|
||||
}
|
||||
|
||||
void EditorEntityManager::DeleteEntities(const EntityIdList& entities)
|
||||
@@ -53,12 +53,30 @@ namespace AzToolsFramework
|
||||
|
||||
void EditorEntityManager::DeleteEntityAndAllDescendants(AZ::EntityId entityId)
|
||||
{
|
||||
DeleteEntitiesAndAllDescendants({entityId});
|
||||
DeleteEntitiesAndAllDescendants(EntityIdList{ entityId });
|
||||
}
|
||||
|
||||
void EditorEntityManager::DeleteEntitiesAndAllDescendants(const EntityIdList& entities)
|
||||
{
|
||||
m_prefabPublicInterface->DeleteEntitiesAndAllDescendantsInInstance(entities);
|
||||
}
|
||||
|
||||
void EditorEntityManager::DuplicateSelected()
|
||||
{
|
||||
EntityIdList selectedEntities;
|
||||
ToolsApplicationRequestBus::BroadcastResult(selectedEntities, &ToolsApplicationRequests::GetSelectedEntities);
|
||||
|
||||
m_prefabPublicInterface->DuplicateEntitiesInInstance(selectedEntities);
|
||||
}
|
||||
|
||||
void EditorEntityManager::DuplicateEntityById(AZ::EntityId entityId)
|
||||
{
|
||||
DuplicateEntities(EntityIdList{ entityId });
|
||||
}
|
||||
|
||||
void EditorEntityManager::DuplicateEntities(const EntityIdList& entities)
|
||||
{
|
||||
m_prefabPublicInterface->DuplicateEntitiesInInstance(entities);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ namespace AzToolsFramework
|
||||
void DeleteEntities(const EntityIdList& entities) override;
|
||||
void DeleteEntityAndAllDescendants(AZ::EntityId entityId) override;
|
||||
void DeleteEntitiesAndAllDescendants(const EntityIdList& entities) override;
|
||||
void DuplicateSelected() override;
|
||||
void DuplicateEntityById(AZ::EntityId entityId) override;
|
||||
void DuplicateEntities(const EntityIdList& entities) override;
|
||||
|
||||
private:
|
||||
Prefab::PrefabPublicInterface* m_prefabPublicInterface = nullptr;
|
||||
|
||||
+12
-1
@@ -81,9 +81,20 @@ namespace AzToolsFramework
|
||||
|
||||
m_ui->m_assetBrowserTreeViewWidget->SetName("AssetBrowserTreeView_" + name);
|
||||
|
||||
bool selectedAsset = false;
|
||||
|
||||
for (auto& assetId : selection.GetSelectedAssetIds())
|
||||
{
|
||||
m_ui->m_assetBrowserTreeViewWidget->SelectProduct(assetId);
|
||||
if (assetId.IsValid())
|
||||
{
|
||||
selectedAsset = true;
|
||||
m_ui->m_assetBrowserTreeViewWidget->SelectProduct(assetId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!selectedAsset)
|
||||
{
|
||||
m_ui->m_assetBrowserTreeViewWidget->SelectFolder(selection.GetDefaultDirectory());
|
||||
}
|
||||
|
||||
setWindowTitle(tr("Pick %1").arg(m_selection.GetTitle()));
|
||||
|
||||
@@ -93,6 +93,16 @@ namespace AzToolsFramework
|
||||
m_selectedAssetIds.push_back(selectedAssetId);
|
||||
}
|
||||
|
||||
void AssetSelectionModel::SetDefaultDirectory(AZStd::string_view defaultDirectory)
|
||||
{
|
||||
m_defaultDirectory = defaultDirectory;
|
||||
}
|
||||
|
||||
AZStd::string_view AssetSelectionModel::GetDefaultDirectory() const
|
||||
{
|
||||
return m_defaultDirectory;
|
||||
}
|
||||
|
||||
AZStd::vector<const AssetBrowserEntry*>& AssetSelectionModel::GetResults()
|
||||
{
|
||||
return m_results;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user