(Hot-) fix negative indices on TickTask.getLag.

This commit is contained in:
asofold 2013-01-23 02:06:31 +01:00
parent 3ad3309e43
commit 9b75979dee

View File

@ -230,7 +230,10 @@ public class TickTask implements Runnable {
* @return Lag factor (1.0 = 20 tps, 2.0 = 10 tps).
*/
public static final float getLag(final long ms, final boolean exact){
// TODO: Account for freezing (i.e. check timeLast, might be an extra method)!
if (ms < 0){
// Account for freezing (i.e. check timeLast, might be an extra method)!
return getLag(0, exact);
}
final int tick = TickTask.tick;
if (tick == 0) return 1f;
@ -249,12 +252,16 @@ public class TickTask implements Runnable {
if (exact){
// Attempt to count in the current tick.
final long passed = System.currentTimeMillis() - timeLast;
if (passed > 50){
// Only count in in the case of "overtime".
covered += 50;
sum += passed;
final long time = System.currentTimeMillis();
if (time > timeLast){
final long passed = time - timeLast;
if (passed > 50){
// Only count in in the case of "overtime".
covered += 50;
sum += passed;
}
}
}
return (float) sum / (float) covered;