RaceClock no has run(), or is runnable, as it wasn't needed.

Refactored Sparkline a bit. Now listens to our data model instead of being manually updated. Boat position labels don't work currently, though.
VisualiserRace now also tracks the order in which boats pass each leg.
This commit is contained in:
fjc40
2017-07-11 02:04:53 +12:00
parent 7d3cf6ee80
commit cab9bf9574
9 changed files with 155 additions and 133 deletions
@@ -59,6 +59,7 @@ public class Boat {
*/
private StringProperty positionInRace = new SimpleStringProperty();
/**
* The time, in milliseconds, that has elapsed during the current leg.
* TODO milliseconds
@@ -222,9 +223,12 @@ public class Boat {
* @param currentLeg The new leg of the race the boat is in.
*/
public void setCurrentLeg(Leg currentLeg) {
this.currentLeg.setValue(currentLeg);
this.setTimeElapsedInCurrentLeg(0);
this.setDistanceTravelledInLeg(0);
}
@@ -33,7 +33,7 @@ public class Constants {
* Frame periods are multiplied by this to get the amount of time a single frame represents.
* E.g., frame period = 20ms, scale = 5, frame represents 20 * 5 = 100ms, and so boats are simulated for 100ms, even though only 20ms actually occurred.
*/
public static final int RaceTimeScale = 25;
public static final int RaceTimeScale = 15;
/**
* The race pre-start time, in milliseconds. 3 minutes.
@@ -163,7 +163,6 @@ public abstract class Race implements Runnable {
//Race clock.
this.raceClock = new RaceClock(this.raceDataSource.getStartDateTime());
//this.raceClock.run();//TODO looks like we may not actually need this.
//Race status.
this.setRaceStatusEnum(RaceStatusEnum.NOT_ACTIVE);
@@ -3,10 +3,8 @@ package shared.model;
import com.github.bfsmith.geotimezone.TimeZoneLookup;
import com.github.bfsmith.geotimezone.TimeZoneResult;
import com.sun.istack.internal.Nullable;
import javafx.animation.AnimationTimer;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import shared.model.GPSCoordinate;
import visualiser.model.ResizableRaceCanvas;
import java.time.Duration;
@@ -14,7 +12,6 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
/**
@@ -24,12 +21,7 @@ import java.util.Date;
* {@link visualiser.Controllers.RaceController} and the
* {@link visualiser.Controllers.StartController}.
*/
public class RaceClock implements Runnable {
/**
* The time that we last updated the current race time at.
*/
private long lastTime;
public class RaceClock {
/**
* The time zone of the race.
@@ -72,7 +64,6 @@ public class RaceClock implements Runnable {
/**
* Format string used for current time.
* TODO probably need to fix this.
*/
private String currentTimeFormat = "'Current time:' HH:mm dd/MM/YYYY";
@@ -100,7 +91,7 @@ public class RaceClock implements Runnable {
}
//TODO could potentially remove this, and the dependency, as it doesn't appear to be needed (regatta.xml has timezone already).
/**
* Returns the ZonedDateTime corresponding to a specified GPSCoordinate.
* @param gpsCoordinate The GPSCoordinate to lookup.
@@ -113,17 +104,6 @@ public class RaceClock implements Runnable {
return LocalDateTime.now(zone).atZone(zone);
}
/**
* Starts the race clock.
*/
public void run() {
new AnimationTimer() {
@Override
public void handle(long now) {
updateTime();
}
}.start();
}
@@ -148,20 +128,6 @@ public class RaceClock implements Runnable {
return utcTime.toInstant().atZone(this.zoneId);
}
/**
* Updates time by duration elapsed since last update.
*/
private void updateTime() {
//Get duration elapsed since last update.
Duration duration = Duration.of(System.currentTimeMillis() - this.lastTime, ChronoUnit.MILLIS);
//Add this duration to the current time.
ZonedDateTime newCurrentTime = this.currentTime.plus(duration);
setCurrentTime(newCurrentTime);
}
/**
* Returns the starting time of the race.
@@ -286,8 +252,6 @@ public class RaceClock implements Runnable {
//Use it.
setCurrentTimeString(currentTimeString);
//Store the last time we updated the current time at.
this.lastTime = System.currentTimeMillis();
//Update the duration string.
updateDurationString();