Normand Briere
2018-07-07 09ddd38fd4a8a7100c834a5e976f4796fae53541
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package mocap.player;
 
import java.util.logging.Level;
import java.util.logging.Logger;
 
import mocap.JMocap;
import mocap.figure.FigureManager;
 
/**
 * Drives the figures managed by the FigureManager by calling the update
 * method.
 * 
 * @author Michael Kipp
 */
public class AnimClock extends Thread {
 
    private FigureManager _figureManager;
    private int _frames = 0;
    private float _fps = 100; // used for fps computation
    private long _t0 = System.currentTimeMillis();
 
    public AnimClock(FigureManager fm) {
        _figureManager = fm;
    }
 
    @Override
    public void run() {
        while (true) {
            _frames++;
 
            // TODO: make this dependent on time *****
            if (_frames >= 200) {
                long t = System.currentTimeMillis();
                _fps = _frames / ((t - _t0) / 1000f);
                _frames = 0;
                _t0 = t;
            }
            _figureManager.update(_fps);
            try {
                sleep(5);
            } catch (InterruptedException ex) {
                Logger.getLogger(JMocap.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}