(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). * @return Lag factor (1.0 = 20 tps, 2.0 = 10 tps).
*/ */
public static final float getLag(final long ms, final boolean exact){ 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; final int tick = TickTask.tick;
if (tick == 0) return 1f; if (tick == 0) return 1f;
@ -249,12 +252,16 @@ public class TickTask implements Runnable {
if (exact){ if (exact){
// Attempt to count in the current tick. // Attempt to count in the current tick.
final long passed = System.currentTimeMillis() - timeLast; final long time = System.currentTimeMillis();
if (passed > 50){ if (time > timeLast){
// Only count in in the case of "overtime". final long passed = time - timeLast;
covered += 50; if (passed > 50){
sum += passed; // Only count in in the case of "overtime".
covered += 50;
sum += passed;
}
} }
} }
return (float) sum / (float) covered; return (float) sum / (float) covered;