layout: Simplify logic in layout/animation.rs

Self-review is helpful it seems.
This commit is contained in:
Emilio Cobos Álvarez 2016-06-26 12:41:09 -07:00
parent f54583884e
commit 46eec45886
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -26,36 +26,25 @@ pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
pipeline_id: PipelineId) { pipeline_id: PipelineId) {
let mut new_running_animations = vec![]; let mut new_running_animations = vec![];
while let Ok(animation) = new_animations_receiver.try_recv() { while let Ok(animation) = new_animations_receiver.try_recv() {
let should_push = match animation { let mut should_push = true;
Animation::Transition(..) => true, if let Animation::Keyframes(ref node, ref name, ref state) = animation {
Animation::Keyframes(ref node, ref name, ref state) => { // If the animation was already present in the list for the
// If the animation was already present in the list for the // node, just update its state, else push the new animation to
// node, just update its state, else push the new animation to // run.
// run. if let Some(ref mut animations) = running_animations.get_mut(node) {
if let Some(ref mut animations) = running_animations.get_mut(node) { // TODO: This being linear is probably not optimal.
// TODO: This being linear is probably not optimal. for mut anim in animations.iter_mut() {
// Also, we should move this logic somehow. if let Animation::Keyframes(_, ref anim_name, ref mut anim_state) = *anim {
match animations.iter_mut().find(|anim| match **anim { if *name == *anim_name {
Animation::Keyframes(_, ref anim_name, _) => *name == *anim_name,
Animation::Transition(..) => false,
}) {
Some(mut anim) => {
debug!("update_animation_state: Found other animation {}", name); debug!("update_animation_state: Found other animation {}", name);
match *anim { anim_state.update_from_other(&state);
Animation::Keyframes(_, _, ref mut anim_state) => { should_push = false;
anim_state.update_from_other(&state); break;
false
}
_ => unreachable!(),
}
} }
None => true,
} }
} else {
true
} }
} }
}; }
if should_push { if should_push {
new_running_animations.push(animation); new_running_animations.push(animation);
@ -70,6 +59,10 @@ pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
let now = time::precise_time_s(); let now = time::precise_time_s();
// Expire old running animations. // Expire old running animations.
//
// TODO: Do not expunge Keyframes animations, since we need that state if
// the animation gets re-triggered. Probably worth splitting in two
// different maps, or at least using a linked list?
let mut keys_to_remove = vec![]; let mut keys_to_remove = vec![];
for (key, running_animations) in running_animations.iter_mut() { for (key, running_animations) in running_animations.iter_mut() {
let mut animations_still_running = vec![]; let mut animations_still_running = vec![];