I am not sure that my framework code is correct, and I could not find exact examples of what I am looking for.
Essentially, I am subclassed java.awt.Component, and inside the method paint(Graphics)I call my function calculateFrameRate(), which is shown below. I do not do incremental drawing in update(). The numbers from this seem high, and I wonder if the internal double buffering of the Component class matches that the paint is called twice as much as it is displayed? I am rusty at double-buffer stuff, although this may be completely wrong.
Here is the frame rate method:
private List<Long> updateTimes = new ArrayList<Long>();
private void calculateFrameRate() {
long time = System.currentTimeMillis();
updateTimes.add(new Long(time));
float timeInSec = (time - updateTimes.get(0)) / 1000f;
currentFrameRate_ = 30f / timeInSec;
if (updateTimes.size() == 31)
updateTimes.remove(0);
}
Greetings
Hamy
source
share