Browse Source

Trade: make AnimationData::release() consistent with MeshData.

pull/371/head
Vladimír Vondruš 7 years ago
parent
commit
b71e50b023
  1. 5
      src/Magnum/Trade/AnimationData.cpp
  2. 9
      src/Magnum/Trade/AnimationData.h
  3. 23
      src/Magnum/Trade/Test/AnimationDataTest.cpp

5
src/Magnum/Trade/AnimationData.cpp

@ -100,6 +100,11 @@ const Animation::TrackViewStorage<Float>& AnimationData::mutableTrack(UnsignedIn
return reinterpret_cast<const Animation::TrackViewStorage<Float>&>(_tracks[id]._view); return reinterpret_cast<const Animation::TrackViewStorage<Float>&>(_tracks[id]._view);
} }
Containers::Array<char> AnimationData::release() {
_tracks = nullptr;
return std::move(_data);
}
template<class V, class R> auto animationInterpolatorFor(Animation::Interpolation interpolation) -> R(*)(const V&, const V&, Float) { template<class V, class R> auto animationInterpolatorFor(Animation::Interpolation interpolation) -> R(*)(const V&, const V&, Float) {
return Animation::interpolatorFor<V, R>(interpolation); return Animation::interpolatorFor<V, R>(interpolation);
} }

9
src/Magnum/Trade/AnimationData.h

@ -522,12 +522,13 @@ class MAGNUM_TRADE_EXPORT AnimationData {
* @brief Release data storage * @brief Release data storage
* *
* Releases the ownership of the data array and resets internal state * Releases the ownership of the data array and resets internal state
* to default. Note that the returned array has a custom no-op deleter * to default. The animation then behaves like it's empty. Note that
* when the data are not owned by the animation, and while the returned * the returned array has a custom no-op deleter when the data are not
* array type is mutable, the actual memory might be not. * owned by the animation, and while the returned array type is
* mutable, the actual memory might be not.
* @see @ref data(), @ref dataFlags() * @see @ref data(), @ref dataFlags()
*/ */
Containers::Array<char> release() { return std::move(_data); } Containers::Array<char> release();
/** /**
* @brief Importer-specific state * @brief Importer-specific state

23
src/Magnum/Trade/Test/AnimationDataTest.cpp

@ -55,6 +55,8 @@ struct AnimationDataTest: TestSuite::Tester {
void trackWrongType(); void trackWrongType();
void trackWrongResultType(); void trackWrongResultType();
void release();
void debugAnimationTrackType(); void debugAnimationTrackType();
void debugAnimationTrackTargetType(); void debugAnimationTrackTargetType();
}; };
@ -91,6 +93,8 @@ AnimationDataTest::AnimationDataTest() {
&AnimationDataTest::trackWrongType, &AnimationDataTest::trackWrongType,
&AnimationDataTest::trackWrongResultType, &AnimationDataTest::trackWrongResultType,
&AnimationDataTest::release,
&AnimationDataTest::debugAnimationTrackType, &AnimationDataTest::debugAnimationTrackType,
&AnimationDataTest::debugAnimationTrackTargetType}); &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"); CORRADE_COMPARE(out.str(), "Trade::AnimationData::track(): improper result type requested for Trade::AnimationTrackType::Vector3\n");
} }
void AnimationDataTest::release() {
const std::pair<Float, bool> keyframes[] {
{1.0f, true},
{5.0f, false}
};
AnimationData data{{}, keyframes, Containers::Array<AnimationTrackData>{Containers::InPlaceInit, {
{AnimationTrackType::Bool,
AnimationTrackTargetType(129), 0,
Animation::TrackView<const Float, const bool>{keyframes, Animation::Interpolation::Constant}},
}}};
CORRADE_COMPARE(data.trackCount(), 1);
Containers::Array<char> released = data.release();
CORRADE_COMPARE(data.data(), nullptr);
CORRADE_COMPARE(data.trackCount(), 0);
CORRADE_COMPARE(static_cast<const void*>(released.data()), keyframes);
}
void AnimationDataTest::debugAnimationTrackType() { void AnimationDataTest::debugAnimationTrackType() {
std::ostringstream out; std::ostringstream out;

Loading…
Cancel
Save