Hi all!
I’ve added some debug messages on my “little creature” to test FPS. I don’t know if this is normal, but when I comment the “thread.sleep” part in my main loop I get about 8200 fps which I guess is not a bad signal… But, when I toggle Thread.sleep (10ms per iteration), it goes down to an average of 105-110 fps.
This is the code of the game main loop (thanks ra4king for your good advices!!):
public abstract class Game {
...blah blah blah...
public final void run() {
//debug:
int currFPS = 0;
int avgFPS = 0;
double currTime = HiresTimer.getTime();
graphics.setDrawColor(Color.white);
while ( gameRunning ) {
deltaMsecs = HiresTimer.getTime() - lastLoopMsecs; //don't mind this.. it's used elsewhere
lastLoopMsecs = HiresTimer.getTime();
update();
do {
do {
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
render();
//debug: show fps
graphics.drawText("FPS: " + avgFPS, 10, 10);
g.dispose();
} while ( strategy.contentsRestored() );
strategy.show();
try {
//Take exactly (hopefully) 10ms per loop
Thread.sleep( (long) lastLoopMsecs + 10 - (long) HiresTimer.getTime() );
} catch (Exception e) {}
} while ( strategy.contentsLost() );
//debug:
currFPS++;
if ( HiresTimer.getTime() - currTime >= 1000 ) {
avgFPS = currFPS;
currFPS = 0;
currTime = HiresTimer.getTime();
}
}
}
Right now I’m only drawing an animated sprite that moves and jumps depending on keyboard input and showing the fps message…
To me it looks that it should be more than just 110 FPS, but maybe that’s normal… or maybe it’s just a wrong FPS calculation method???
Thanks in advance for your comments!