01: /*
02: *
03: * Copyright (c) 2000-2001 Silvere Martin-Michiellot All Rights Reserved.
04: *
05: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
06: * royalty free, license to use, modify but not to redistribute this
07: * software in source and binary code form,
08: * provided that i) this copyright notice and license appear on all copies of
09: * the software; and ii) Licensee does not utilize the software in a manner
10: * which is disparaging to Silvere Martin-Michiellot.
11: *
12: * This software is provided "AS IS," without a warranty of any kind. ALL
13: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
14: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
15: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
16: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
17: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
18: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
19: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
20: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
21: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
22: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
23: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
25: *
26: * This software is not designed or intended for use in on-line control of
27: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
28: * the design, construction, operation or maintenance of any nuclear
29: * facility. Licensee represents and warrants that it will not use or
30: * redistribute the Software for such purposes.
31: *
32: * @Author: Silvere Martin-Michiellot
33: *
34: */
35:
36: package com.db.utils.timers;
37:
38: // This code is repackaged after the code from Joerg Plewe
39: // Site http://www.hardcode.de/
40: // Email plewe@hardcode.de
41:
42: import javax.media.j3d.*;
43: import javax.vecmath.*;
44: import java.util.Enumeration;
45:
46: public final class FrameRateCalculator extends Behavior {
47:
48: protected final int numberOfFrames;
49: protected final WakeupCondition w;
50:
51: protected long startTime;
52:
53: public FrameRateCalculator(int numberOfFrames) {
54:
55: this .numberOfFrames = numberOfFrames;
56: w = new WakeupOnElapsedFrames(numberOfFrames);
57:
58: }
59:
60: public FrameRateCalculator() {
61:
62: this (1000);
63:
64: }
65:
66: public void initialize() {
67:
68: setSchedulingBounds(new BoundingSphere(new Point3d(), 1000));
69: startTime = System.currentTimeMillis();
70: wakeupOn(w);
71:
72: }
73:
74: public void processStimulus(Enumeration criteria) {
75:
76: double time = (double) (System.currentTimeMillis() - startTime);
77: double frame = numberOfFrames / time;
78:
79: System.out.println("FPS : " + (1000 * frame) + "(time : "
80: + time + " ");
81: startTime = System.currentTimeMillis();
82: wakeupOn(w);
83:
84: }
85:
86: }
|