Well, Display.sync(…) doesnt work on my system, neither does sync2() or sync3(), but i have now come up with a solution that lets me have a tick based game at any frame rate. It uses this class shown below:
eg. in mainloop:
int t = TickTimerInstnce.getNumIntervalsPassed();
for(int i=0; i<t; i++)
updateWorldOneTick();
import org.lwjgl.Sys;
/*
*a class to help tick based animation with variable frame rate
*/
public class TickTimer{
//length of each interval, or tick
private float interval;
//amount through interval at last check
private float amount;
//time at last check, in millis
private float lastCheck;
//the timer has been started
private boolean started;
public TickTimer(float interval){
this.interval = interval;
}
/**
*starts the timer going, should be called before using the timer
*/
public void start(){
lastCheck = FPSCounter.getTime();
started = true;
}
public boolean isStarted(){
return started;
}
/**
*returns the number of intervals that have passed since
*this method was last called, or since start() was called
*/
public int getNumIntervalsPassed() throws IllegalStateException{
//started already?
if(!started)
throw new IllegalStateException("Timer must be started.");
//
float now = (Sys.getTime()*1000f) / (float)Sys.getTimerResolution();
float delta = now - lastCheck;
lastCheck = now;
//
float newAmount = amount+delta;
int intervalCount = 0;
//
while(newAmount >= interval){
newAmount -= interval;
intervalCount++;
}
amount = newAmount;
return intervalCount;
}
}