comparison src/com/aurellem/capture/RatchetTimer.java @ 69:ddb300c5335f

fixed RatchetTimer time reporting.
author Robert McIntyre <rlm@mit.edu>
date Wed, 29 May 2013 17:15:41 -0400
parents 155c70b7e6de
children
comparison
equal deleted inserted replaced
68:302d5e9ad120 69:ddb300c5335f
9 * 9 *
10 * @author normenhansen, Robert McIntyre 10 * @author normenhansen, Robert McIntyre
11 */ 11 */
12 12
13 public class RatchetTimer extends Timer{ 13 public class RatchetTimer extends Timer{
14 private float framerate; 14 private long framerate;
15 private int ticks; 15 private int ticks;
16 private long lastTime = 0; 16 private long lastTime = 0;
17 17
18 public RatchetTimer(float framerate) { 18 public RatchetTimer(float framerate) {
19 this.framerate = framerate; 19 this.framerate = (long) framerate;
20 this.ticks = 0; 20 this.ticks = 0;
21 } 21 }
22 22
23 /** 23 /**
24 * return time in milliseconds 24 * return time in milliseconds
25 */ 25 */
26 public long getTime() { 26 public long getTime() {
27 return (long) (this.ticks * (1.0f / this.framerate) * 1000f); 27 return ticks;
28 } 28 }
29 29
30 public long getResolution() { 30 public long getResolution() {
31 return 1000000000L; 31 return framerate;
32 } 32 }
33 33
34 public float getFrameRate() { 34 public float getFrameRate() {
35 return this.framerate; 35 return framerate;
36 } 36 }
37 37
38 public float getTimePerFrame() { 38 public float getTimePerFrame() {
39 return (float) (1.0f / this.framerate); 39 return (float) (1.0f / framerate);
40 } 40 }
41 41
42 public void update() { 42 public void update() {
43 long time = System.currentTimeMillis(); 43 long time = System.currentTimeMillis();
44 long difference = time - lastTime; 44 long difference = time - lastTime;