Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: sky/framework/animation/simulation.dart

Issue 1001373002: Organize sky/framework/animation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/animation/scroll_curve.dart ('k') | sky/framework/animation/timer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:async';
6 import 'generator.dart';
7 import 'mechanics.dart';
8
9 class Simulation {
10 Stream<double> get onTick => _stream;
11 final System system;
12
13 FrameGenerator _generator;
14 Stream<double> _stream;
15 double _previousTime = 0.0;
16
17 Simulation(this.system, {Function terminationCondition, Function onDone}) {
18 _generator = new FrameGenerator(onDone: onDone);
19 _stream = _generator.onTick.map(_update);
20
21 if (terminationCondition != null) {
22 bool done = false;
23 _stream = _stream.takeWhile((_) {
24 if (done)
25 return false;
26 done = terminationCondition();
27 return true;
28 });
29 }
30 }
31
32 void cancel() {
33 _generator.cancel();
34 }
35
36 double _update(double timeStamp) {
37 double previousTime = _previousTime;
38 _previousTime = timeStamp;
39 if (previousTime == 0.0)
40 return timeStamp;
41 double deltaT = timeStamp - previousTime;
42 system.update(deltaT);
43 return timeStamp;
44 }
45 }
OLDNEW
« no previous file with comments | « sky/framework/animation/scroll_curve.dart ('k') | sky/framework/animation/timer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698