| Index: sky/framework/animation/simulation.dart
|
| diff --git a/sky/framework/animation/simulation.dart b/sky/framework/animation/simulation.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e7904a389267f630da837e82bb4a56715f9b68df
|
| --- /dev/null
|
| +++ b/sky/framework/animation/simulation.dart
|
| @@ -0,0 +1,45 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +import 'dart:async';
|
| +import 'generator.dart';
|
| +import 'kinematics.dart';
|
| +
|
| +class Simulation {
|
| + Stream<double> get onTick => _stream;
|
| + final System system;
|
| +
|
| + FrameGenerator _generator;
|
| + Stream<double> _stream;
|
| + double _previousTime = 0.0;
|
| +
|
| + 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 cancel() {
|
| + _generator.cancel();
|
| + }
|
| +
|
| + double _update(double timeStamp) {
|
| + double previousTime = _previousTime;
|
| + _previousTime = timeStamp;
|
| + if (previousTime == 0.0)
|
| + return timeStamp;
|
| + double deltaT = timeStamp - previousTime;
|
| + system.update(deltaT);
|
| + return timeStamp;
|
| + }
|
| +}
|
|
|