-
Notifications
You must be signed in to change notification settings - Fork 55
Description
When the new architecture was implemented, its intentionally naive querying model introduced quite a bit of latency within animations. This latency makes it so that even running the simple circle example on instant does not result in the circle being instantly drawn.
To fix this, someone needs to find the bottleneck that is slowing down animations when the speed is set to instant. As mentioned, this is likely a result of the querying taking a while. A possible fix may be to just somehow skip a query when the speed is set to instant and immediately update the turtle to the end state of the animation.
Animations are created with code like this:
Lines 116 to 137 in 2e3f549
| pub fn forward(&mut self, distance: Distance) { | |
| if distance == 0. { | |
| return; | |
| } | |
| let TurtleState {position: start, speed, heading, pen, ..} = self.fetch_turtle(); | |
| let x = distance * heading.cos(); | |
| let y = distance * heading.sin(); | |
| let end = math::add(start, [x, y]); | |
| let speed = speed.to_absolute(); // px per second | |
| // We take the absolute value because the time is always positive, even if distance is negative | |
| let total_millis = (distance / speed * 1000.).abs(); | |
| let animation = MoveAnimation { | |
| path: Path {start, end, pen}, | |
| timer: Instant::now(), | |
| total_millis, | |
| }; | |
| self.play_animation(animation); | |
| } |
fetch_turtle() will perform a query, but so will play_animation() at least once. It is probably better to just update the turtle immediately instead of running an animation if we know that the speed is instant.
If you would like to work on this, let me know in the comments and I can provide you with more details and instructions.