diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-03-20 13:42:53 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-03-25 14:23:28 +0000 |
commit | 1929b3e48c0a327e7a741275d6d4847b72ddf704 (patch) | |
tree | 703782cb36b3979929b0d440550bfe337bb925a7 /src | |
parent | b18d39153453e6e2cab9e6c75bd2991aa25d0397 (diff) |
Add a function to build list of unique channel names and types
This will be needed to construct the data layout for blend trees.
Change-Id: I0b11076f5ecd55cfad094d864f3f8270841fc62a
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/animation/backend/animationutils.cpp | 31 | ||||
-rw-r--r-- | src/animation/backend/animationutils_p.h | 15 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index 8b2ba6821..d79b412fd 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -335,6 +335,37 @@ QVector<MappingData> buildPropertyMappings(Handler *handler, return mappingDataVec; } +QVector<ChannelNameAndType> buildRequiredChannelsAndTypes(Handler *handler, + const ChannelMapper *mapper) +{ + ChannelMappingManager *mappingManager = handler->channelMappingManager(); + const QVector<Qt3DCore::QNodeId> mappingIds = mapper->mappingIds(); + + // Reserve enough storage assuming each mapping is for a different channel. + // May be overkill but avoids potential for multiple allocations + QVector<ChannelNameAndType> namesAndTypes; + namesAndTypes.reserve(mappingIds.size()); + + // Iterate through the mappings and add ones not already used by an earlier mapping. + // We could add them all then sort and remove duplicates. However, our approach has the + // advantage of keeping the blend tree format more consistent with the mapping + // orderings which will have better cache locality when generating events. + for (const Qt3DCore::QNodeId mappingId : mappingIds) { + // Get the mapping object + ChannelMapping *mapping = mappingManager->lookupResource(mappingId); + Q_ASSERT(mapping); + + // Get the name and type + const ChannelNameAndType nameAndType{ mapping->channelName(), mapping->type() }; + + // Add if not already contained + if (!namesAndTypes.contains(nameAndType)) + namesAndTypes.push_back(nameAndType); + } + + return namesAndTypes; +} + QVector<Qt3DCore::QNodeId> gatherValueNodesToEvaluate(Handler *handler, Qt3DCore::QNodeId blendTreeRootId) { diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h index 705e37c34..dd600c207 100644 --- a/src/animation/backend/animationutils_p.h +++ b/src/animation/backend/animationutils_p.h @@ -102,6 +102,17 @@ struct ClipEvaluationData typedef QVector<float> ClipResults; +struct ChannelNameAndType +{ + QString name; + int type; + + bool operator==(const ChannelNameAndType &rhs) const + { + return name == rhs.name && type == rhs.type; + } +}; + template<typename Animator> AnimatorEvaluationData evaluationDataForAnimator(Animator animator, qint64 globalTime) { @@ -159,6 +170,10 @@ QVector<MappingData> buildPropertyMappings(Handler *handler, const ChannelMapper *mapper); Q_AUTOTEST_EXPORT +QVector<ChannelNameAndType> buildRequiredChannelsAndTypes(Handler *handler, + const ChannelMapper *mapper); + +Q_AUTOTEST_EXPORT double localTimeFromGlobalTime(double t_global, double t_start_global, double playbackRate, double duration, int loopCount, int ¤tLoop); |