source: src/main/java/genius/core/PausableContinuousTimeline.java@ 256

Last change on this file since 256 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.1 KB
Line 
1package genius.core;
2
3import genius.core.timeline.ContinuousTimeline;
4
5public class PausableContinuousTimeline extends ContinuousTimeline {
6
7 private long timeAtPause;
8 private long totalPausedTime;
9
10 public PausableContinuousTimeline(int totalSecs) {
11 super(totalSecs);
12 }
13
14 /**
15 * Gets the elapsed time in seconds. Use {@link #getTime()} for a more
16 * generic version.
17 */
18 public double getElapsedSeconds() {
19 long t2;
20 if (paused) {
21 t2 = timeAtPause;
22 } else {
23 t2 = System.nanoTime();
24 }
25 return ((t2 - startTime - totalPausedTime) / 1000000000.0);
26 }
27
28 /**
29 * Gets the elapsed time in seconds. Use {@link #getTime()} for a more
30 * generic version.
31 */
32 public double getElapsedMilliSeconds() {
33 long t2;
34 if (paused) {
35 t2 = timeAtPause;
36 } else {
37 t2 = System.nanoTime();
38 }
39 return ((t2 - startTime - totalPausedTime) / 1000000.0);
40 }
41
42 public void pause() {
43 if (!paused) {
44 paused = true;
45 timeAtPause = System.nanoTime();
46 }
47 }
48
49 public void resume() {
50 if (paused) {
51 totalPausedTime += (System.nanoTime() - timeAtPause);
52 paused = false;
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.