Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero committed Jan 2, 2023
1 parent fe64e42 commit 60d5719
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 34 deletions.
10 changes: 5 additions & 5 deletions impeller/scene/animation/animation_clip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void AnimationClip::SetLoop(bool looping) {
loop_ = looping;
}

Scalar AnimationClip::GetPlaybackSpeed() const {
return playback_speed_;
Scalar AnimationClip::GetPlaybackTimeScale() const {
return playback_time_scale_;
}

void AnimationClip::SetPlaybackSpeed(Scalar playback_speed) {
playback_speed_ = playback_speed;
void AnimationClip::SetPlaybackTimeScale(Scalar playback_speed) {
playback_time_scale_ = playback_speed;
}

Scalar AnimationClip::GetWeight() const {
Expand All @@ -82,7 +82,7 @@ void AnimationClip::Advance(Scalar delta_time) {
if (!playing_ || delta_time <= 0) {
return;
}
delta_time *= playback_speed_;
delta_time *= playback_time_scale_;
playback_time_ += delta_time;

/// Handle looping behavior.
Expand Down
6 changes: 3 additions & 3 deletions impeller/scene/animation/animation_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class AnimationClip final {

void SetLoop(bool looping);

Scalar GetPlaybackSpeed() const;
Scalar GetPlaybackTimeScale() const;

/// @brief Sets the animation playback speed. Negative values make the clip
/// play in reverse.
void SetPlaybackSpeed(Scalar playback_speed);
void SetPlaybackTimeScale(Scalar playback_speed);

Scalar GetWeight() const;

Expand Down Expand Up @@ -74,7 +74,7 @@ class AnimationClip final {
std::vector<ChannelBinding> bindings_;

Scalar playback_time_ = 0;
Scalar playback_speed_ = 1; // Seconds multiplier, can be negative.
Scalar playback_time_scale_ = 1; // Seconds multiplier, can be negative.
Scalar weight_ = 1;
bool playing_ = false;
bool loop_ = false;
Expand Down
8 changes: 4 additions & 4 deletions impeller/scene/animation/animation_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ AnimationClip& AnimationPlayer::AddAnimation(
// Record all of the unique default transforms that this AnimationClip
// will mutate.
for (const auto& binding : clip.bindings_) {
default_target_transforms_.insert(DefaultTransform{
.node = binding.node, .transform = binding.node->GetLocalTransform()});
default_target_transforms_.insert(
{binding.node, binding.node->GetLocalTransform()});
}

clips_.push_back(std::move(clip));
Expand All @@ -52,8 +52,8 @@ void AnimationPlayer::Update() {
}

void AnimationPlayer::Reset() {
for (auto& default_transform : default_target_transforms_) {
default_transform.node->SetLocalTransform(default_transform.transform);
for (auto& [node, transform] : default_target_transforms_) {
node->SetLocalTransform(transform);
}
}

Expand Down
23 changes: 1 addition & 22 deletions impeller/scene/animation/animation_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,7 @@ class AnimationPlayer final {
void Reset();

private:
struct DefaultTransform {
Node* node;
Matrix transform;

struct Hash {
std::size_t operator()(const DefaultTransform& o) const {
return fml::HashCombine(o.node);
}
};

struct Equal {
bool operator()(const DefaultTransform& lhs,
const DefaultTransform& rhs) const {
return lhs.node == rhs.node;
}
};
};

std::unordered_set<DefaultTransform,
DefaultTransform::Hash,
DefaultTransform::Equal>
default_target_transforms_;
std::unordered_map<Node*, Matrix> default_target_transforms_;

std::vector<AnimationClip> clips_;

Expand Down

0 comments on commit 60d5719

Please sign in to comment.