Browse Source

Animation: added Player::resume().

pull/297/head
Vladimír Vondruš 8 years ago
parent
commit
1234bc8c48
  1. 3
      doc/changelog.dox
  2. 8
      src/Magnum/Animation/Player.h
  3. 5
      src/Magnum/Animation/Player.hpp
  4. 39
      src/Magnum/Animation/Test/PlayerTest.cpp

3
doc/changelog.dox

@ -48,6 +48,9 @@ See also:
@ref Animation::unpack(), @ref Animation::unpackEase() and @ref Animation::unpack(), @ref Animation::unpackEase() and
@ref Animation::unpackEaseClamped() utilities for combining interpolators @ref Animation::unpackEaseClamped() utilities for combining interpolators
with easing functions and/or unpackers with easing functions and/or unpackers
- @ref Animation::Player::resume() that acts the same as
@ref Animation::Player::play() "play()" except it doesn't restart the
animation from the start if it is already playing
@subsubsection changelog-latest-new-math Math library @subsubsection changelog-latest-new-math Math library

8
src/Magnum/Animation/Player.h

@ -637,6 +637,14 @@ template<class T, class K
*/ */
Player<T, K>& play(T startTime); Player<T, K>& play(T startTime);
/**
* @brief Resume
*
* Behaves similarly to @ref play(), but doesn't restart the animation
* from the beginning when @ref state() is already @ref State::Playing.
*/
Player<T, K>& resume(T startTime);
/** /**
* @brief Pause * @brief Pause
* *

5
src/Magnum/Animation/Player.hpp

@ -118,6 +118,11 @@ template<class T, class K> Player<T, K>& Player<T, K>::play(T startTime) {
return *this; return *this;
} }
template<class T, class K> Player<T, K>& Player<T, K>::resume(T startTime) {
if(_state == State::Playing) return *this;
return play(startTime);
}
template<class T, class K> Player<T, K>& Player<T, K>::pause(T pauseTime) { template<class T, class K> Player<T, K>& Player<T, K>::pause(T pauseTime) {
/* Avoid breaking the pause state when not playing */ /* Avoid breaking the pause state when not playing */
if(_state != State::Playing) return *this; if(_state != State::Playing) return *this;

39
src/Magnum/Animation/Test/PlayerTest.cpp

@ -48,6 +48,7 @@ struct PlayerTest: TestSuite::Tester {
void advanceNotRunning(); void advanceNotRunning();
void advancePlaying(); void advancePlaying();
void advanceRestart(); void advanceRestart();
void advanceResume();
void advanceStop(); void advanceStop();
void advancePauseResume(); void advancePauseResume();
void advancePauseStop(); void advancePauseStop();
@ -129,6 +130,7 @@ PlayerTest::PlayerTest() {
&PlayerTest::advanceNotRunning, &PlayerTest::advanceNotRunning,
&PlayerTest::advancePlaying, &PlayerTest::advancePlaying,
&PlayerTest::advanceRestart, &PlayerTest::advanceRestart,
&PlayerTest::advanceResume,
&PlayerTest::advanceStop, &PlayerTest::advanceStop,
&PlayerTest::advancePauseResume, &PlayerTest::advancePauseResume,
&PlayerTest::advancePauseStop, &PlayerTest::advancePauseStop,
@ -430,6 +432,43 @@ void PlayerTest::advanceRestart() {
CORRADE_COMPARE(value, 2.5f); CORRADE_COMPARE(value, 2.5f);
} }
void PlayerTest::advanceResume() {
/* A variant of advanceRestart() that doesn't restart */
Float value = -1.0f;
Player<Float> player;
player.add(Track, value)
.resume(2.0f);
CORRADE_COMPARE(player.state(), State::Playing);
CORRADE_COMPARE(player.elapsed(0.0f), std::make_pair(0, 0.0f));
CORRADE_COMPARE(value, -1.0f);
/* Still before starting time, nothing is done */
player.advance(1.75f);
CORRADE_COMPARE(player.state(), State::Playing);
CORRADE_COMPARE(player.elapsed(1.75f), std::make_pair(0, 0.0f));
CORRADE_COMPARE(value, -1.0f);
/* 1.75 secs in */
player.advance(3.75f);
CORRADE_COMPARE(player.state(), State::Playing);
CORRADE_COMPARE(player.elapsed(3.75f), std::make_pair(0, 1.75f));
CORRADE_COMPARE(value, 4.0f);
/* Calling resume() will not restart from the beginning */
value = -1.0f;
player.resume(4.0f);
CORRADE_COMPARE(player.state(), State::Playing);
CORRADE_COMPARE(player.elapsed(4.0f), std::make_pair(0, 2.0f));
CORRADE_COMPARE(value, -1.0f);
player.advance(4.5f);
CORRADE_COMPARE(player.state(), State::Playing);
CORRADE_COMPARE(player.elapsed(4.5f), std::make_pair(0, 2.5f));
CORRADE_COMPARE(value, 3.5f);
}
void PlayerTest::advanceStop() { void PlayerTest::advanceStop() {
Float value = -1.0f; Float value = -1.0f;
Player<Float> player; Player<Float> player;

Loading…
Cancel
Save