From b71e50b023d131d1a0843937c3d49847cd7d5ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 12 Nov 2019 13:10:04 +0100 Subject: [PATCH] Trade: make AnimationData::release() consistent with MeshData. --- src/Magnum/Trade/AnimationData.cpp | 5 +++++ src/Magnum/Trade/AnimationData.h | 9 ++++---- src/Magnum/Trade/Test/AnimationDataTest.cpp | 23 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Magnum/Trade/AnimationData.cpp b/src/Magnum/Trade/AnimationData.cpp index 5bfbfba50..dca88ba8d 100644 --- a/src/Magnum/Trade/AnimationData.cpp +++ b/src/Magnum/Trade/AnimationData.cpp @@ -100,6 +100,11 @@ const Animation::TrackViewStorage& AnimationData::mutableTrack(UnsignedIn return reinterpret_cast&>(_tracks[id]._view); } +Containers::Array AnimationData::release() { + _tracks = nullptr; + return std::move(_data); +} + template auto animationInterpolatorFor(Animation::Interpolation interpolation) -> R(*)(const V&, const V&, Float) { return Animation::interpolatorFor(interpolation); } diff --git a/src/Magnum/Trade/AnimationData.h b/src/Magnum/Trade/AnimationData.h index 4ca38958d..0935c4813 100644 --- a/src/Magnum/Trade/AnimationData.h +++ b/src/Magnum/Trade/AnimationData.h @@ -522,12 +522,13 @@ class MAGNUM_TRADE_EXPORT AnimationData { * @brief Release data storage * * Releases the ownership of the data array and resets internal state - * to default. Note that the returned array has a custom no-op deleter - * when the data are not owned by the animation, and while the returned - * array type is mutable, the actual memory might be not. + * to default. The animation then behaves like it's empty. Note that + * the returned array has a custom no-op deleter when the data are not + * owned by the animation, and while the returned array type is + * mutable, the actual memory might be not. * @see @ref data(), @ref dataFlags() */ - Containers::Array release() { return std::move(_data); } + Containers::Array release(); /** * @brief Importer-specific state diff --git a/src/Magnum/Trade/Test/AnimationDataTest.cpp b/src/Magnum/Trade/Test/AnimationDataTest.cpp index 5830e926d..c61228eef 100644 --- a/src/Magnum/Trade/Test/AnimationDataTest.cpp +++ b/src/Magnum/Trade/Test/AnimationDataTest.cpp @@ -55,6 +55,8 @@ struct AnimationDataTest: TestSuite::Tester { void trackWrongType(); void trackWrongResultType(); + void release(); + void debugAnimationTrackType(); void debugAnimationTrackTargetType(); }; @@ -91,6 +93,8 @@ AnimationDataTest::AnimationDataTest() { &AnimationDataTest::trackWrongType, &AnimationDataTest::trackWrongResultType, + &AnimationDataTest::release, + &AnimationDataTest::debugAnimationTrackType, &AnimationDataTest::debugAnimationTrackTargetType}); } @@ -566,6 +570,25 @@ void AnimationDataTest::trackWrongResultType() { CORRADE_COMPARE(out.str(), "Trade::AnimationData::track(): improper result type requested for Trade::AnimationTrackType::Vector3\n"); } +void AnimationDataTest::release() { + const std::pair keyframes[] { + {1.0f, true}, + {5.0f, false} + }; + + AnimationData data{{}, keyframes, Containers::Array{Containers::InPlaceInit, { + {AnimationTrackType::Bool, + AnimationTrackTargetType(129), 0, + Animation::TrackView{keyframes, Animation::Interpolation::Constant}}, + }}}; + CORRADE_COMPARE(data.trackCount(), 1); + + Containers::Array released = data.release(); + CORRADE_COMPARE(data.data(), nullptr); + CORRADE_COMPARE(data.trackCount(), 0); + CORRADE_COMPARE(static_cast(released.data()), keyframes); +} + void AnimationDataTest::debugAnimationTrackType() { std::ostringstream out;