Why does my game loop speed vary on different platforms with the same hardware?
- by Sri Harsha Chilakapati
I've got a serious issue with my game loop. 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 game loop.
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();
}
}
The timer package
How could I improve it?