I’ve got a serious issue with my GameLoop. This loop varies in time with the platform and with the same hardware. This is a list of FPS achieved.
- Windows ======= 140 to 150
- Linux ======= 120 to 125
- Windows(WINE) ======= 125 to 135
And since my game loop is fixed timestep, the speed of the game is not stable. Here’s my GameLoop.
GameLoop
public final void run(){
// Initialize the resources
Map.initMap();
initResources();
// Start the timer
GTimer.startTimer();
GTimer.refresh();
long elapsedTime = 0;
// The game loop
while (running) {
// Update the game
update(elapsedTime);
if (state == GameState.GAME_PLAYING) {
Map.updateObjects(elapsedTime);
}
// Show or hide the cursor
if (Global.HIDE_CURSOR) {
setCursor(GInput.INVISIBLE_CURSOR);
} else {
setCursor(Cursor.getDefaultCursor());
}
// Repaint the game and sync
repaint();
elapsedTime = GTimer.sync();
Toolkit.getDefaultToolkit().sync();
}
}
Here are the two classes of the timer package.
https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/timer/GTimer.java
https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/timer/GFrameRateCalculator.java
How could I improve it?