comparison src/com/aurellem/capture/IsoTimer.java @ 54:6484a820e27d

wrote main documentation.
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Dec 2011 19:15:43 -0600
parents edaa7e7806e4
children afc437f637bd
comparison
equal deleted inserted replaced
53:3dc1f15e1e13 54:6484a820e27d
1 package com.aurellem.capture; 1 package com.aurellem.capture;
2 2
3 import com.jme3.system.Timer; 3 import com.jme3.system.Timer;
4
5 /**
6 * A standard JME3 application that extends SimpleApplication or
7 * Application tries as hard as it can to keep in sync with
8 * user-time. If a ball is rolling at 1 game-mile per game-hour in the
9 * game, and you wait for one user-hour as measured by the clock on
10 * your wall, then the ball should have traveled exactly one
11 * game-mile. In order to keep sync with the real world, the game
12 * throttles its physics engine and graphics display. If the
13 * computations involved in running the game are too intense, then the
14 * game will first skip frames, then sacrifice physics accuracy. If
15 * there are particularly demanding computations, then you may only get
16 * 1 fps, and the ball may tunnel through the floor or obstacles due
17 * to inaccurate physics simulation, but after the end of one
18 * 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-time
21 * syncs with user-time, but instead whether the time in the recorded
22 * 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 and
24 * watched the video later, we would want to see 30 fps video of the
25 * ball rolling at 1 video-mile per user-hour. It doesn't matter how
26 * much user-time it took to simulate that hour of game-time to make
27 * the high-quality recording. If an Application uses this IsoTimer
28 * instead of the normal one, we can be sure that every call to
29 * simpleUpdate, for example, corresponds to exactly (1 / fps) seconds
30 * of game-time. This let's us record perfect video and audio even on
31 * a slow computer.
32 *
33 * @author Robert McIntyre
34 *
35 */
4 36
5 public class IsoTimer extends Timer { 37 public class IsoTimer extends Timer {
6 38
7 private float framerate; 39 private float framerate;
8 private int ticks; 40 private int ticks;
9 41
10 public IsoTimer(float framerate){ 42 public IsoTimer(float framerate){
11 this.framerate = framerate; 43 this.framerate = framerate;
12 this.ticks = 0;} 44 this.ticks = 0;
45 }
13 46
14 public long getTime() { 47 public long getTime() {
15 return (long) (this.ticks / this.framerate);} 48 return (long) (this.ticks / this.framerate);
49 }
16 50
17 public long getResolution() { 51 public long getResolution() {
18 return 1000000000L;} 52 return 1000000000L;
53 }
19 54
20 public float getFrameRate() { 55 public float getFrameRate() {
21 return this.framerate;} 56 return this.framerate;
57 }
22 58
23 public float getTimePerFrame() { 59 public float getTimePerFrame() {
24 return (float) (1.0f / this.framerate);} 60 return (float) (1.0f / this.framerate);
61 }
25 62
26 public void update() {this.ticks++;} 63 public void update() {this.ticks++;}
27 64
28 public void reset() {this.ticks = 0;} 65 public void reset() {this.ticks = 0;}
29 66