| Index: sky/framework/animation/generators.dart
|
| diff --git a/sky/framework/animation/generator.dart b/sky/framework/animation/generators.dart
|
| similarity index 69%
|
| rename from sky/framework/animation/generator.dart
|
| rename to sky/framework/animation/generators.dart
|
| index 7530f04a4ad3ae4af94d2219d400f9cec38cc9e5..0c5a82bc567d5378eedd8b2c8e4cd0a1942af1b6 100644
|
| --- a/sky/framework/animation/generator.dart
|
| +++ b/sky/framework/animation/generators.dart
|
| @@ -7,7 +7,12 @@ import 'dart:async';
|
| import 'dart:math' as math;
|
| import 'dart:sky' as sky;
|
|
|
| -class FrameGenerator {
|
| +abstract class Generator {
|
| + Stream<double> get onTick;
|
| + void cancel();
|
| +}
|
| +
|
| +class FrameGenerator extends Generator {
|
| Function onDone;
|
| StreamController _controller;
|
|
|
| @@ -51,7 +56,7 @@ class FrameGenerator {
|
| }
|
| }
|
|
|
| -class AnimationGenerator {
|
| +class AnimationGenerator extends Generator {
|
| Stream<double> get onTick => _stream;
|
| final double initialDelay;
|
| final double duration;
|
| @@ -107,49 +112,40 @@ class AnimationGenerator {
|
| }
|
| }
|
|
|
| -class Animation {
|
| - Stream<double> get onValueChanged => _controller.stream;
|
| -
|
| - double get value => _value;
|
| -
|
| - void set value(double value) {
|
| - stop();
|
| - _setValue(value);
|
| - }
|
| -
|
| - bool get isAnimating => _animation != null;
|
| -
|
| - StreamController _controller = new StreamController(sync: true);
|
| -
|
| - AnimationGenerator _animation;
|
| -
|
| - double _value;
|
| +class Simulation extends Generator {
|
| + Stream<double> get onTick => _stream;
|
| + final System system;
|
|
|
| - void _setValue(double value) {
|
| - _value = value;
|
| - _controller.add(_value);
|
| - }
|
| + FrameGenerator _generator;
|
| + Stream<double> _stream;
|
| + double _previousTime = 0.0;
|
|
|
| - void stop() {
|
| - if (_animation != null) {
|
| - _animation.cancel();
|
| - _animation = null;
|
| + Simulation(this.system, {Function terminationCondition, Function onDone}) {
|
| + _generator = new FrameGenerator(onDone: onDone);
|
| + _stream = _generator.onTick.map(_update);
|
| +
|
| + if (terminationCondition != null) {
|
| + bool done = false;
|
| + _stream = _stream.takeWhile((_) {
|
| + if (done)
|
| + return false;
|
| + done = terminationCondition();
|
| + return true;
|
| + });
|
| }
|
| }
|
|
|
| - void animateTo(double newValue, double duration,
|
| - { Curve curve: linear, double initialDelay: 0.0 }) {
|
| - stop();
|
| -
|
| - _animation = new AnimationGenerator(
|
| - duration: duration,
|
| - begin: _value,
|
| - end: newValue,
|
| - curve: curve,
|
| - initialDelay: initialDelay);
|
| + void cancel() {
|
| + _generator.cancel();
|
| + }
|
|
|
| - _animation.onTick.listen(_setValue, onDone: () {
|
| - _animation = null;
|
| - });
|
| + double _update(double timeStamp) {
|
| + double previousTime = _previousTime;
|
| + _previousTime = timeStamp;
|
| + if (previousTime == 0.0)
|
| + return timeStamp;
|
| + double deltaT = timeStamp - previousTime;
|
| + system.update(deltaT);
|
| + return timeStamp;
|
| }
|
| }
|
|
|