Mercurial > jmeCapture
view src/com/aurellem/capture/IsoTimer.java @ 68:302d5e9ad120
adjust format
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 19 Jul 2012 12:28:55 -0500 |
parents | f5e52169f056 |
children | ddb300c5335f |
line wrap: on
line source
1 package com.aurellem.capture;3 import com.jme3.system.Timer;5 /**6 * A standard JME3 application that extends SimpleApplication or7 * Application tries as hard as it can to keep in sync with8 * user-time. If a ball is rolling at 1 game-mile per game-hour in the9 * game, and you wait for one user-hour as measured by the clock on10 * your wall, then the ball should have traveled exactly one11 * game-mile. In order to keep sync with the real world, the game12 * throttles its physics engine and graphics display. If the13 * computations involved in running the game are too intense, then the14 * game will first skip frames, then sacrifice physics accuracy. If15 * there are particularly demanding computations, then you may only16 * get 1 fps, and the ball may tunnel through the floor or obstacles17 * due to inaccurate physics simulation, but after the end of one18 * user-hour, that ball will have traveled one game-mile.19 *20 * When we're recording video or audio, we don't care if the game-time21 * syncs with user-time, but instead whether the time in the recorded22 * video (video-time) syncs with user-time. To continue the analogy,23 * if we recorded the ball rolling at 1 game-mile per game-hour and24 * watched the video later, we would want to see 30 fps video of the25 * ball rolling at 1 video-mile per user-hour. It doesn't matter how26 * much user-time it took to simulate that hour of game-time to make27 * the high-quality recording. If an Application uses this IsoTimer28 * instead of the normal one, we can be sure that every call to29 * simpleUpdate, for example, corresponds to exactly (1 / fps) seconds30 * of game-time. This lets us record perfect video and audio even on31 * a slow computer.32 *33 * @author Robert McIntyre34 *35 */37 public class IsoTimer extends Timer {39 private long framerate;40 private int ticks;42 public IsoTimer(float framerate){43 this.framerate = (long) framerate;44 this.ticks = 0;45 }47 public long getTime() {48 return this.ticks;49 }51 public long getResolution() {52 return (long) framerate;53 }55 public float getFrameRate() {56 return this.framerate;57 }59 public float getTimePerFrame() {60 return (float) (1.0f / this.framerate);61 }63 public void update() {this.ticks++;}65 public void reset() {this.ticks = 0;}67 }