annotate src/com/aurellem/capture/RatchetTimer.java @ 66:0d7347b916ae

removed unnessary build dependency
author Robert McIntyre <rlm@mit.edu>
date Tue, 28 Feb 2012 11:10:14 -0600
parents 155c70b7e6de
children ddb300c5335f
rev   line source
rlm@63 1 package com.aurellem.capture;
rlm@63 2
rlm@63 3 import com.jme3.system.Timer;
rlm@63 4
rlm@63 5 /**
rlm@63 6 * RatchetTimer is the same as IsoTimer, except that it will ensure
rlm@63 7 * that the simulation does not proceed any faster than it would had
rlm@63 8 * NanoTimer been used.
rlm@63 9 *
rlm@63 10 * @author normenhansen, Robert McIntyre
rlm@63 11 */
rlm@63 12
rlm@63 13 public class RatchetTimer extends Timer{
rlm@63 14 private float framerate;
rlm@63 15 private int ticks;
rlm@63 16 private long lastTime = 0;
rlm@63 17
rlm@63 18 public RatchetTimer(float framerate) {
rlm@63 19 this.framerate = framerate;
rlm@63 20 this.ticks = 0;
rlm@63 21 }
rlm@64 22
rlm@64 23 /**
rlm@64 24 * return time in milliseconds
rlm@64 25 */
rlm@63 26 public long getTime() {
rlm@63 27 return (long) (this.ticks * (1.0f / this.framerate) * 1000f);
rlm@63 28 }
rlm@63 29
rlm@63 30 public long getResolution() {
rlm@63 31 return 1000000000L;
rlm@63 32 }
rlm@63 33
rlm@63 34 public float getFrameRate() {
rlm@63 35 return this.framerate;
rlm@63 36 }
rlm@63 37
rlm@63 38 public float getTimePerFrame() {
rlm@63 39 return (float) (1.0f / this.framerate);
rlm@63 40 }
rlm@63 41
rlm@63 42 public void update() {
rlm@63 43 long time = System.currentTimeMillis();
rlm@63 44 long difference = time - lastTime;
rlm@63 45 lastTime = time;
rlm@63 46 if (difference < (1.0f / this.framerate) * 1000.0f) {
rlm@63 47 try {
rlm@63 48 Thread.sleep(difference);
rlm@63 49 } catch (InterruptedException ex) {
rlm@63 50 }
rlm@63 51 }
rlm@63 52 this.ticks++;
rlm@63 53 }
rlm@63 54
rlm@63 55 public void reset() {
rlm@63 56 this.ticks = 0;
rlm@63 57 }
rlm@63 58 }
rlm@63 59