diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-06-19 17:08:15 +0300 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-07-03 09:35:34 +0300 |
commit | e13ab913d2fe4d1b8d687713693b5a8bb5856e7c (patch) | |
tree | 5494484b4230bf95526af6f11303fe4bf2eaa6a2 /src | |
parent | 4faf224295b1a86081bbb90c323fa6295f8d4e73 (diff) |
Simplify the 2 methods that gets the animation arity
Change the return type of the 2 methods below to only return the arity
(num animation channels). It is enough to check if the arity is
> 0 to know that the data type is animatable. This makes the methods
usage much cleaner.
GetDatatypeAnimatableAndArity()
GetVariantAnimatableAndArity()
You much also pull the commit with the same name in the qt3dstudio repo
for the Editor to compile after this is pulled.
Change-Id: I3e80d49aa6ddf893be43a359ddaf583f50df9180
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/dm/systems/Qt3DSDMAnimation.h | 50 | ||||
-rw-r--r-- | src/dm/systems/SlideSystem.cpp | 12 | ||||
-rw-r--r-- | src/dm/systems/StudioAnimationSystem.cpp | 49 |
3 files changed, 54 insertions, 57 deletions
diff --git a/src/dm/systems/Qt3DSDMAnimation.h b/src/dm/systems/Qt3DSDMAnimation.h index 457b042..9009efb 100644 --- a/src/dm/systems/Qt3DSDMAnimation.h +++ b/src/dm/systems/Qt3DSDMAnimation.h @@ -494,67 +494,67 @@ inline EAnimationType GetKeyframeType(const TKeyframe &inKeyframe) return inKeyframe.getType(); } -struct SAnimatableArityVisitor +struct SAnimArityVisitor { - std::tuple<bool, size_t> operator()(bool) const + size_t operator()(bool) const { - return std::tuple<bool, size_t>(true, 1); + return 1; } - std::tuple<bool, size_t> operator()(long) const + size_t operator()(long) const { - return std::tuple<bool, size_t>(true, 1); + return 1; } - std::tuple<bool, size_t> operator()(float) const + size_t operator()(float) const { - return std::tuple<bool, size_t>(true, 1); + return 1; } - std::tuple<bool, size_t> operator()(const SFloat2 &) const + size_t operator()(const SFloat2 &) const { - return std::tuple<bool, size_t>(true, 2); + return 2; } - std::tuple<bool, size_t> operator()(const SFloat3 &) const + size_t operator()(const SFloat3 &) const { - return std::tuple<bool, size_t>(true, 3); + return 3; } - std::tuple<bool, size_t> operator()(const SFloat4 &) const + size_t operator()(const SFloat4 &) const { - return std::tuple<bool, size_t>(true, 4); + return 4; } template <typename TDataType> - std::tuple<bool, size_t> operator()(const TDataType &) const + size_t operator()(const TDataType &) const { - return std::tuple<bool, size_t>(false, 0); + return 0; } - std::tuple<bool, size_t> operator()() + size_t operator()() { QT3DS_ASSERT(false); - return std::tuple<bool, size_t>(false, 0); + return 0; } }; -inline std::tuple<bool, size_t> GetVariantAnimatableAndArity(const SValue &inValue) +inline size_t GetVariantAnimatableArity(const SValue &inValue) { - return inValue.visit<std::tuple<bool, size_t>>(SAnimatableArityVisitor()); + return inValue.visit<size_t>(SAnimArityVisitor()); } -inline std::tuple<bool, size_t> GetDatatypeAnimatableAndArity(DataModelDataType::Value inDataType) +inline size_t GetDatatypeAnimatableArity(DataModelDataType::Value inDataType) { switch (inDataType) { case DataModelDataType::Long: case DataModelDataType::Float: - return std::make_tuple(true, 1); + return 1; case DataModelDataType::Float2: - return std::make_tuple(true, 2); + return 2; case DataModelDataType::Float3: - return std::make_tuple(true, 3); + return 3; case DataModelDataType::Float4: - return std::make_tuple(true, 4); + return 4; default: - return std::make_tuple(false, 0); + return 0; } } diff --git a/src/dm/systems/SlideSystem.cpp b/src/dm/systems/SlideSystem.cpp index d6d8893..7105a04 100644 --- a/src/dm/systems/SlideSystem.cpp +++ b/src/dm/systems/SlideSystem.cpp @@ -110,12 +110,12 @@ void CopyAnimationIfExist(Qt3DSDMSlideHandle inMaster, Qt3DSDMSlideHandle inTarg TInstancePropertyPair inPropertyPair, TPropertySystemPtr inPropertySystem, TAnimationCorePtr inAnimationCore) { - DataModelDataType::Value thePropertyType = inPropertySystem->GetDataType(inPropertyPair.second); - std::tuple<bool, size_t> theArity = GetDatatypeAnimatableAndArity(thePropertyType); - if (std::get<0>(theArity)) - do_times(std::get<1>(theArity), std::bind(CopySpecificAnimation, inMaster, inTarget, - inPropertyPair, inAnimationCore, - std::placeholders::_1)); + DataModelDataType::Value propertyType = inPropertySystem->GetDataType(inPropertyPair.second); + size_t arity = GetDatatypeAnimatableArity(propertyType); + if (arity) { + do_times(arity, std::bind(CopySpecificAnimation, inMaster, inTarget, inPropertyPair, + inAnimationCore, std::placeholders::_1)); + } } void SetEntryValueIfNotReferenced(const TSlideEntry &inEntry, diff --git a/src/dm/systems/StudioAnimationSystem.cpp b/src/dm/systems/StudioAnimationSystem.cpp index 2b78888..be33bb1 100644 --- a/src/dm/systems/StudioAnimationSystem.cpp +++ b/src/dm/systems/StudioAnimationSystem.cpp @@ -128,20 +128,17 @@ bool CStudioAnimationSystem::GetAnimatedInstancePropertyValue(Qt3DSDMSlideHandle { bool retval = false; - tuple<bool, size_t> arity = GetVariantAnimatableAndArity(outValue); - if (get<0>(arity)) { + size_t arity = GetVariantAnimatableArity(outValue); + if (arity) { for (size_t index = 0; index < m_AnimationFloatPairs.size(); ++index) retval |= ApplyIfAnimationMatches(m_AnimationFloatPairs.at(index), inSlide, inInstance, inProperty, m_AnimationCore, outValue); } if (!retval) { - bool animatable; - size_t numChannels; bool animated = false; - - std::tie(animatable, numChannels) = GetVariantAnimatableAndArity(outValue); - if (animatable) { + size_t numChannels = GetVariantAnimatableArity(outValue); + if (numChannels > 0) { TGraphSlidePair theGraphSlidePair = m_SlideGraphCore->GetAssociatedGraph(inInstance); float theSeconds = m_SlideCore->GetSlideTime( m_SlideGraphCore->GetGraphActiveSlide(theGraphSlidePair.first)); @@ -275,12 +272,12 @@ void DoKeyframeProperty(Qt3DSDMSlideHandle inSlide, Qt3DSDMInstanceHandle inInst TAnimationFloatPairList &inAnimationFloatPairs, float inEaseIn, float inEaseOut) { - tuple<bool, size_t> arity = GetVariantAnimatableAndArity(inValue); + size_t arity = GetVariantAnimatableArity(inValue); TAnimationHandleList thePresentAnimations; GetPresentAnimations(inSlide, inInstance, inProperty, std::cref(inAnimationFloatPairs), inAnimationCore, thePresentAnimations); if (thePresentAnimations.empty()) - do_times(get<1>(arity), std::bind(CreateAnimationAndAdd, inSlide, inInstance, inProperty, + do_times(arity, std::bind(CreateAnimationAndAdd, inSlide, inInstance, inProperty, std::placeholders::_1, inAnimationCore, std::ref(thePresentAnimations))); if (!inDoDiffValue @@ -347,8 +344,8 @@ bool CStudioAnimationSystem::SetAnimatedInstancePropertyValue(Qt3DSDMSlideHandle Qt3DSDMPropertyHandle inProperty, const SValue &inValue) { - tuple<bool, size_t> arity = GetVariantAnimatableAndArity(inValue); - if (get<0>(arity)) { + size_t arity = GetVariantAnimatableArity(inValue); + if (arity > 0) { if (m_AutoKeyframe && IsPropertyAnimated(inInstance, inProperty)) // prerequisite for // autoset-keyframes is // that the property is @@ -405,8 +402,8 @@ Qt3DSDMSlideHandle CStudioAnimationSystem::GetApplicableGraphAndSlide( Qt3DSDMInstanceHandle inInstance, Qt3DSDMPropertyHandle inProperty, const SValue &inValue) { Qt3DSDMSlideHandle theApplicableSlide; - tuple<bool, size_t> arity = GetVariantAnimatableAndArity(inValue); - if (get<0>(arity)) + size_t arity = GetVariantAnimatableArity(inValue); + if (arity > 0) theApplicableSlide = m_SlideSystem->GetApplicableSlide(inInstance, inProperty); return theApplicableSlide; } @@ -443,9 +440,9 @@ void CStudioAnimationSystem::Animate(Qt3DSDMInstanceHandle inInstance, if (theApplicableSlide.Valid()) { // Check if previously we have set animation & keyframes DataModelDataType::Value theDataType = m_PropertySystem->GetDataType(inProperty); - std::tuple<bool, size_t> theArity = GetDatatypeAnimatableAndArity(theDataType); + size_t theArity = GetDatatypeAnimatableArity(theDataType); bool theFound = false; - for (size_t i = 0; i < std::get<1>(theArity); ++i) { + for (size_t i = 0; i < theArity; ++i) { TAnimationKeyframesPairList::iterator theAnimationKeyframeIter = m_DeletedAnimationData.begin(); for (; theAnimationKeyframeIter < m_DeletedAnimationData.end(); @@ -482,8 +479,8 @@ void CStudioAnimationSystem::Deanimate(Qt3DSDMInstanceHandle inInstance, Qt3DSDMPropertyHandle inProperty) { DataModelDataType::Value theDataType = m_PropertySystem->GetDataType(inProperty); - std::tuple<bool, size_t> theArity = GetDatatypeAnimatableAndArity(theDataType); - for (size_t i = 0; i < std::get<1>(theArity); ++i) { + size_t theArity = GetDatatypeAnimatableArity(theDataType); + for (size_t i = 0; i < theArity; ++i) { Qt3DSDMAnimationHandle theAnimationHandle = GetControllingAnimation(inInstance, inProperty, i); @@ -524,8 +521,8 @@ void CStudioAnimationSystem::SetOrCreateKeyframe(Qt3DSDMInstanceHandle inInstanc { qt3dsdm::DataModelDataType::Value thePropertyType = m_PropertySystem->GetDataType(inProperty); Qt3DSDMSlideHandle theApplicableSlide; - std::tuple<bool, size_t> arity = GetDatatypeAnimatableAndArity(thePropertyType); - if (std::get<0>(arity)) { + size_t arity = GetDatatypeAnimatableArity(thePropertyType); + if (arity) { theApplicableSlide = m_SlideSystem->GetApplicableSlide(inInstance, inProperty); if (theApplicableSlide.Valid()) { @@ -533,7 +530,7 @@ void CStudioAnimationSystem::SetOrCreateKeyframe(Qt3DSDMInstanceHandle inInstanc GetPresentAnimations(theApplicableSlide, inInstance, inProperty, std::cref(m_AnimationFloatPairs), m_AnimationCore, thePresentAnimations); - size_t numIterations = std::min(inNumInfos, get<1>(arity)); + size_t numIterations = std::min(inNumInfos, arity); if (thePresentAnimations.empty()) { for (size_t idx = 0, end = numIterations; idx < end; ++idx) { CreateAnimationAndAdd(theApplicableSlide, inInstance, inProperty, idx, @@ -579,9 +576,9 @@ Qt3DSDMAnimationHandle CStudioAnimationSystem::GetControllingAnimation( bool CStudioAnimationSystem::IsPropertyAnimatable(Qt3DSDMInstanceHandle inInstance, Qt3DSDMPropertyHandle inProperty) const { - DataModelDataType::Value theDataType = m_PropertySystem->GetDataType(inProperty); - std::tuple<bool, size_t> theArity = GetDatatypeAnimatableAndArity(theDataType); - if (std::get<0>(theArity)) + DataModelDataType::Value dataType = m_PropertySystem->GetDataType(inProperty); + size_t arity = GetDatatypeAnimatableArity(dataType); + if (arity) return m_SlideGraphCore->GetAssociatedGraph(inInstance).first.Valid(); return false; } @@ -589,9 +586,9 @@ bool CStudioAnimationSystem::IsPropertyAnimatable(Qt3DSDMInstanceHandle inInstan bool CStudioAnimationSystem::IsPropertyAnimated(Qt3DSDMInstanceHandle inInstance, Qt3DSDMPropertyHandle inProperty) const { - DataModelDataType::Value theDataType = m_PropertySystem->GetDataType(inProperty); - std::tuple<bool, size_t> theArity = GetDatatypeAnimatableAndArity(theDataType); - for (size_t i = 0; i < std::get<1>(theArity); ++i) { + DataModelDataType::Value dataType = m_PropertySystem->GetDataType(inProperty); + size_t arity = GetDatatypeAnimatableArity(dataType); + for (size_t i = 0; i < arity; ++i) { if (GetControllingAnimation(inInstance, inProperty, i).Valid()) return true; } |