Skip to content

Commit e87c2da

Browse files
authored
Merge pull request o3de#17552 from aws-lumberyard-dev/daimini/fixRoundUp
DPE | Fix Spline type handling
2 parents b4be436 + 9d547d2 commit e87c2da

File tree

6 files changed

+89
-42
lines changed

6 files changed

+89
-42
lines changed

Gems/LmbrCentral/Code/Source/Shape/EditorSplineComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ namespace LmbrCentral
398398
return m_splineCommon.m_spline;
399399
}
400400

401-
void EditorSplineComponent::ChangeSplineType(const AZ::u64 splineType)
401+
void EditorSplineComponent::ChangeSplineType(const SplineType splineType)
402402
{
403403
m_splineCommon.ChangeSplineType(splineType);
404404
}

Gems/LmbrCentral/Code/Source/Shape/EditorSplineComponent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace LmbrCentral
7373

7474
// SplineComponentRequestBus overrides ...
7575
AZ::SplinePtr GetSpline() override;
76-
void ChangeSplineType(AZ::u64 splineType) override;
76+
void ChangeSplineType(SplineType splineType) override;
7777
void SetClosed(bool closed) override;
7878

7979
// SplineComponentRequestBus/VertexContainerInterface overrides ...

Gems/LmbrCentral/Code/Source/Shape/SplineComponent.cpp

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,98 @@
1515

1616
namespace LmbrCentral
1717
{
18-
using SplineComboBoxVec = AZStd::vector<AZ::Edit::EnumConstant<size_t>>;
18+
using SplineComboBoxVec = AZStd::vector<AZ::Edit::EnumConstant<SplineType>>;
1919
static SplineComboBoxVec PopulateSplineTypeList()
2020
{
2121
return SplineComboBoxVec
2222
{
23-
{ AZ::LinearSpline::RTTI_Type().GetHash(), "Linear" },
24-
{ AZ::BezierSpline::RTTI_Type().GetHash(), "Bezier" },
25-
{ AZ::CatmullRomSpline::RTTI_Type().GetHash(), "Catmull-Rom" }
23+
{ SplineType::LINEAR, "Linear" },
24+
{ SplineType::BEZIER, "Bezier" },
25+
{ SplineType::CATMULL_ROM, "Catmull-Rom" }
2626
};
2727
}
28-
29-
static AZ::SplinePtr MakeSplinePtr(AZ::u64 splineType)
28+
static bool IsMatchingType(AZ::SplinePtr spline, SplineType splineType)
3029
{
31-
if (splineType == AZ::LinearSpline::RTTI_Type().GetHash())
30+
auto splineTypeHash = spline->RTTI_GetType().GetHash();
31+
switch (splineType)
3232
{
33-
return AZStd::make_shared<AZ::LinearSpline>();
33+
case SplineType::LINEAR:
34+
{
35+
return (splineTypeHash == AZ::LinearSpline::RTTI_Type().GetHash());
36+
}
37+
break;
38+
case SplineType::BEZIER:
39+
{
40+
return (splineTypeHash == AZ::BezierSpline::RTTI_Type().GetHash());
41+
}
42+
break;
43+
case SplineType::CATMULL_ROM:
44+
{
45+
return (splineTypeHash == AZ::CatmullRomSpline::RTTI_Type().GetHash());
46+
}
47+
break;
48+
default:
49+
break;
3450
}
3551

36-
if (splineType == AZ::BezierSpline::RTTI_Type().GetHash())
37-
{
38-
return AZStd::make_shared<AZ::BezierSpline>();
39-
}
52+
return false;
53+
}
4054

41-
if (splineType == AZ::CatmullRomSpline::RTTI_Type().GetHash())
55+
static AZ::SplinePtr MakeSplinePtr(SplineType splineType)
56+
{
57+
switch (splineType)
4258
{
43-
return AZStd::make_shared<AZ::CatmullRomSpline>();
59+
case SplineType::LINEAR:
60+
{
61+
return AZStd::make_shared<AZ::LinearSpline>();
62+
}
63+
break;
64+
case SplineType::BEZIER:
65+
{
66+
return AZStd::make_shared<AZ::BezierSpline>();
67+
}
68+
break;
69+
case SplineType::CATMULL_ROM:
70+
{
71+
return AZStd::make_shared<AZ::CatmullRomSpline>();
72+
}
73+
break;
74+
default:
75+
{
76+
AZ_Assert(false, "Unhandled spline type %d in %s", splineType, __FUNCTION__);
77+
}
78+
break;
4479
}
4580

46-
AZ_Assert(false, "Unhandled spline type %d in %s", splineType, __FUNCTION__);
47-
4881
return nullptr;
4982
}
5083

51-
static AZ::SplinePtr CopySplinePtr(AZ::u64 splineType, const AZ::SplinePtr& spline)
84+
static AZ::SplinePtr CopySplinePtr(SplineType splineType, const AZ::SplinePtr& spline)
5285
{
53-
if (splineType == AZ::LinearSpline::RTTI_Type().GetHash())
54-
{
55-
return AZStd::make_shared<AZ::LinearSpline>(*spline);
56-
}
57-
58-
if (splineType == AZ::BezierSpline::RTTI_Type().GetHash())
86+
switch (splineType)
5987
{
60-
return AZStd::make_shared<AZ::BezierSpline>(*spline);
61-
}
62-
63-
if (splineType == AZ::CatmullRomSpline::RTTI_Type().GetHash())
64-
{
65-
return AZStd::make_shared<AZ::CatmullRomSpline>(*spline);
88+
case SplineType::LINEAR:
89+
{
90+
return AZStd::make_shared<AZ::LinearSpline>(*spline);
91+
}
92+
break;
93+
case SplineType::BEZIER:
94+
{
95+
return AZStd::make_shared<AZ::BezierSpline>(*spline);
96+
}
97+
break;
98+
case SplineType::CATMULL_ROM:
99+
{
100+
return AZStd::make_shared<AZ::CatmullRomSpline>(*spline);
101+
}
102+
break;
103+
default:
104+
{
105+
AZ_Assert(false, "Unhandled spline type %d in %s", splineType, __FUNCTION__);
106+
}
107+
break;
66108
}
67109

68-
AZ_Assert(false, "Unhandled spline type %d in %s", splineType, __FUNCTION__);
69-
70110
return nullptr;
71111
}
72112

@@ -101,7 +141,7 @@ namespace LmbrCentral
101141
}
102142
}
103143

104-
void SplineCommon::ChangeSplineType(AZ::u64 splineType)
144+
void SplineCommon::ChangeSplineType(SplineType splineType)
105145
{
106146
m_splineType = splineType;
107147
OnChangeSplineType();
@@ -132,7 +172,7 @@ namespace LmbrCentral
132172
{
133173
AZ::u32 ret = AZ::Edit::PropertyRefreshLevels::None;
134174

135-
if (m_spline->RTTI_GetType().GetHash() != m_splineType)
175+
if (!IsMatchingType(m_spline, m_splineType))
136176
{
137177
m_spline = CopySplinePtr(m_splineType, m_spline);
138178
m_spline->SetCallbacks(
@@ -298,7 +338,7 @@ namespace LmbrCentral
298338
return m_splineCommon.m_spline;
299339
}
300340

301-
void SplineComponent::ChangeSplineType(AZ::u64 splineType)
341+
void SplineComponent::ChangeSplineType(SplineType splineType)
302342
{
303343
m_splineCommon.ChangeSplineType(splineType);
304344
}

Gems/LmbrCentral/Code/Source/Shape/SplineComponent.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace LmbrCentral
2727

2828
static void Reflect(AZ::ReflectContext* context);
2929

30-
void ChangeSplineType(AZ::u64 splineType);
30+
void ChangeSplineType(SplineType splineType);
3131

3232
/// Override callbacks to be used when spline changes/is modified.
3333
void SetCallbacks(
@@ -41,7 +41,7 @@ namespace LmbrCentral
4141
private:
4242
AZ::u32 OnChangeSplineType();
4343

44-
AZ::u64 m_splineType = AZ::LinearSpline::RTTI_Type().GetHash(); ///< The currently set spline type (default to Linear).
44+
SplineType m_splineType = SplineType::LINEAR; ///< The currently set spline type (default to Linear).
4545

4646
AZ::IndexFunction m_onAddVertex = nullptr;
4747
AZ::IndexFunction m_onRemoveVertex = nullptr;
@@ -69,7 +69,7 @@ namespace LmbrCentral
6969

7070
// SplineComponentRequestBus
7171
AZ::SplinePtr GetSpline() override;
72-
void ChangeSplineType(AZ::u64 splineType) override;
72+
void ChangeSplineType(SplineType splineType) override;
7373
void SetClosed(bool closed) override;
7474

7575
// SplineComponentRequestBus/VertexContainerInterface

Gems/LmbrCentral/Code/Tests/SplineComponentTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ namespace UnitTest
106106
AZ_TEST_ASSERT(linearSplinePtr->GetVertexCount() == 4);
107107

108108
// change spline type to Bezier
109-
LmbrCentral::SplineComponentRequestBus::Event(entity.GetId(), &LmbrCentral::SplineComponentRequests::ChangeSplineType, AZ::BezierSpline::RTTI_Type().GetHash());
109+
LmbrCentral::SplineComponentRequestBus::Event(entity.GetId(), &LmbrCentral::SplineComponentRequests::ChangeSplineType, LmbrCentral::SplineType::BEZIER);
110110

111111
// check data was created after change correctly
112112
AZ::ConstSplinePtr bezierSplinePtr;
@@ -164,7 +164,7 @@ namespace UnitTest
164164
}
165165

166166
// change spline type to CatmullRom
167-
LmbrCentral::SplineComponentRequestBus::Event(entity.GetId(), &LmbrCentral::SplineComponentRequests::ChangeSplineType, AZ::CatmullRomSpline::RTTI_Type().GetHash());
167+
LmbrCentral::SplineComponentRequestBus::Event(entity.GetId(), &LmbrCentral::SplineComponentRequests::ChangeSplineType, LmbrCentral::SplineType::CATMULL_ROM);
168168

169169
AZ::ConstSplinePtr catmullRomSplinePtr;
170170
LmbrCentral::SplineComponentRequestBus::EventResult(catmullRomSplinePtr, entity.GetId(), &LmbrCentral::SplineComponentRequests::GetSpline);

Gems/LmbrCentral/Code/include/LmbrCentral/Shape/SplineComponentBus.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
namespace LmbrCentral
1616
{
17+
enum class SplineType
18+
{
19+
LINEAR = 0,
20+
BEZIER,
21+
CATMULL_ROM
22+
};
23+
1724
/// Services provided by the Spline Component.
1825
class SplineComponentRequests
1926
: public AZ::VariableVertices<AZ::Vector3>
@@ -24,7 +31,7 @@ namespace LmbrCentral
2431
/// Change the type of interpolation used by the spline.
2532
/// @param splineType Refers to the RTTI Hash of the underlying Spline type
2633
/// (example: AZ::LinearSpline::RTTI_Type().GetHash()).
27-
virtual void ChangeSplineType(AZ::u64 splineType) = 0;
34+
virtual void ChangeSplineType(SplineType splineType) = 0;
2835
/// Set whether the spline should form a closed loop or not.
2936
virtual void SetClosed(bool closed) = 0;
3037

0 commit comments

Comments
 (0)