55#include " impeller/scene/animation/animation_clip.h"
66
77#include < algorithm>
8+ #include < chrono>
89#include < cmath>
910#include < memory>
1011#include < valarray>
@@ -43,7 +44,7 @@ void AnimationClip::Pause() {
4344
4445void AnimationClip::Stop () {
4546 SetPlaying (false );
46- Seek (0 );
47+ Seek (std::chrono::duration<Scalar>:: zero () );
4748}
4849
4950bool AnimationClip::GetLoop () const {
@@ -70,39 +71,46 @@ void AnimationClip::SetWeight(Scalar weight) {
7071 weight_ = weight;
7172}
7273
73- Scalar AnimationClip::GetPlaybackTime () const {
74+ std::chrono::duration< Scalar> AnimationClip::GetPlaybackTime () const {
7475 return playback_time_;
7576}
7677
77- void AnimationClip::Seek (Scalar time) {
78- playback_time_ = std::clamp (time, 0 .0f , animation_->GetEndTime ());
78+ void AnimationClip::Seek (std::chrono::duration<Scalar> time) {
79+ playback_time_ = std::clamp (time, std::chrono::duration<Scalar>::zero (),
80+ animation_->GetEndTime ());
7981}
8082
81- void AnimationClip::Advance (Scalar delta_time) {
82- if (!playing_ || delta_time <= 0 ) {
83+ void AnimationClip::Advance (std::chrono::duration< Scalar> delta_time) {
84+ if (!playing_ || delta_time <= std::chrono::duration<Scalar>:: zero () ) {
8385 return ;
8486 }
8587 delta_time *= playback_time_scale_;
8688 playback_time_ += delta_time;
8789
8890 // / Handle looping behavior.
8991
90- Scalar end_time = animation_->GetEndTime ();
91- if (end_time == 0 ) {
92- playback_time_ = 0 ;
92+ auto end_time = animation_->GetEndTime ();
93+ if (end_time == std::chrono::duration<Scalar>:: zero () ) {
94+ playback_time_ = std::chrono::duration<Scalar>:: zero () ;
9395 return ;
9496 }
95- if (!loop_ && (playback_time_ < 0 || playback_time_ > end_time)) {
97+ if (!loop_ && (playback_time_ < std::chrono::duration<Scalar>::zero () ||
98+ playback_time_ > end_time)) {
9699 // If looping is disabled, clamp to the end (or beginning, if playing in
97100 // reverse) and pause.
98101 Pause ();
99- playback_time_ = std::clamp (playback_time_, 0 .0f , end_time);
102+ playback_time_ = std::clamp (
103+ playback_time_, std::chrono::duration<Scalar>::zero (), end_time);
100104 } else if (/* loop && */ playback_time_ > end_time) {
101105 // If looping is enabled and we ran off the end, loop to the beginning.
102- playback_time_ = std::fmod (std::abs (playback_time_), end_time);
103- } else if (/* loop && */ playback_time_ < 0 ) {
106+ playback_time_ = std::chrono::duration<Scalar>(
107+ std::fmod (std::abs (playback_time_.count ()), end_time.count ()));
108+ } else if (/* loop && */ playback_time_ <
109+ std::chrono::duration<Scalar>::zero ()) {
104110 // If looping is enabled and we ran off the beginning, loop to the end.
105- playback_time_ = end_time - std::fmod (std::abs (playback_time_), end_time);
111+ playback_time_ =
112+ end_time - std::chrono::duration<Scalar>(std::fmod (
113+ std::abs (playback_time_.count ()), end_time.count ()));
106114 }
107115}
108116
0 commit comments