Removed unnecessary countdownTimer from Race in visualiser module
- Run method now calls simulateRace directly #story[782]
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.Random;
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public abstract class Race implements Runnable {
|
||||
//protected Boat[] startingBoats;
|
||||
protected ObservableList<Boat> startingBoats;
|
||||
protected List<Leg> legs;
|
||||
protected RaceController controller;
|
||||
@@ -30,8 +29,6 @@ public abstract class Race implements Runnable {
|
||||
|
||||
protected int scaleFactor;
|
||||
private int lastFPS = 20;
|
||||
private int PRERACE_TIME = 0; //time in milliseconds to pause during pre-race
|
||||
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
||||
|
||||
/**
|
||||
* Initailiser for Race
|
||||
@@ -103,81 +100,7 @@ public abstract class Race implements Runnable {
|
||||
public void run() {
|
||||
setControllerListeners();
|
||||
initialiseBoats();
|
||||
if (timerEnabled) countdownTimer();
|
||||
//simulateRace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the timer
|
||||
*/
|
||||
public void disableTimer() {
|
||||
timerEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
||||
*/
|
||||
protected void countdownTimer() {
|
||||
new AnimationTimer() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
||||
long minutes;
|
||||
long currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
long hours;
|
||||
long timeLeft;
|
||||
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
timeLeft = startTime - currentTime;
|
||||
if (timeLeft <= 0 && controller != null) {
|
||||
updateTime("Race is starting...");
|
||||
stop();
|
||||
simulateRace();
|
||||
} else {
|
||||
currentTimeInSeconds = (timeLeft*scaleFactor) / 1000;
|
||||
minutes = currentTimeInSeconds / 60;
|
||||
remainingSeconds = currentTimeInSeconds % 60;
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
if (controller != null) {
|
||||
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
||||
}
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes total time elapsed and format to hour:minute:second
|
||||
*
|
||||
* @return Formatted time as string
|
||||
*/
|
||||
protected String calcTimer() {
|
||||
long minutes;
|
||||
long currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
long hours;
|
||||
|
||||
currentTimeInSeconds = (totalTimeElapsed * scaleFactor) / 1000;
|
||||
minutes = currentTimeInSeconds / 60;
|
||||
remainingSeconds = currentTimeInSeconds % 60;
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the calculated time to the timer label
|
||||
*
|
||||
* @param time The calculated time from calcTimer() method
|
||||
*/
|
||||
protected void updateTime(String time) {
|
||||
Platform.runLater(() -> {
|
||||
controller.setTimer(time);
|
||||
});
|
||||
simulateRace();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,8 +145,6 @@ public abstract class Race implements Runnable {
|
||||
boat.addTrackPoint(boat.getCurrentPosition());
|
||||
}
|
||||
}
|
||||
if (timerEnabled)
|
||||
updateTime(calcTimer());
|
||||
}
|
||||
controller.updateMap(startingBoats);
|
||||
fps++;
|
||||
|
||||
Reference in New Issue
Block a user