boats now calculate the time since last mark
-the raceclock is passed around so that the time can be tracked -time from start to mark 1 is wrong #story[878]
This commit is contained in:
@@ -24,6 +24,7 @@ public class RaceController extends Controller {
|
|||||||
|
|
||||||
private ResizableRaceCanvas raceMap;
|
private ResizableRaceCanvas raceMap;
|
||||||
private ResizableRaceMap raceBoundaries;
|
private ResizableRaceMap raceBoundaries;
|
||||||
|
private RaceClock raceClock;
|
||||||
@FXML SplitPane race;
|
@FXML SplitPane race;
|
||||||
@FXML CheckBox showFPS;
|
@FXML CheckBox showFPS;
|
||||||
@FXML CheckBox showBoatPath;
|
@FXML CheckBox showBoatPath;
|
||||||
@@ -93,7 +94,7 @@ public class RaceController extends Controller {
|
|||||||
* @param raceClock The RaceClock to use for the race's countdown/elapsed duration + timezone.
|
* @param raceClock The RaceClock to use for the race's countdown/elapsed duration + timezone.
|
||||||
*/
|
*/
|
||||||
public void startRace(VisualiserInput visualiserInput, RaceClock raceClock) {
|
public void startRace(VisualiserInput visualiserInput, RaceClock raceClock) {
|
||||||
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
|
||||||
//newRace.initialiseBoats();
|
//newRace.initialiseBoats();
|
||||||
|
|
||||||
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
||||||
@@ -119,6 +120,11 @@ public class RaceController extends Controller {
|
|||||||
//Initialize save annotation array, fps listener, and annotation listeners
|
//Initialize save annotation array, fps listener, and annotation listeners
|
||||||
timeZone.setText(raceClock.getTimeZone());
|
timeZone.setText(raceClock.getTimeZone());
|
||||||
timer.textProperty().bind(raceClock.durationProperty());
|
timer.textProperty().bind(raceClock.durationProperty());
|
||||||
|
|
||||||
|
this.raceClock = raceClock;
|
||||||
|
raceMap.setRaceClock(raceClock);
|
||||||
|
|
||||||
|
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
||||||
initializeFPS();
|
initializeFPS();
|
||||||
initializeAnnotations();
|
initializeAnnotations();
|
||||||
|
|
||||||
@@ -213,4 +219,8 @@ public class RaceController extends Controller {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RaceClock getRaceClock() {
|
||||||
|
return raceClock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ public class StreamedRace implements Runnable {
|
|||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
Leg startLeg = new Leg(name, 0);
|
Leg startLeg = new Leg(name, 0);
|
||||||
startLeg.setEndMarker(endCompoundMark);
|
startLeg.setEndMarker(endCompoundMark);
|
||||||
boat.setCurrentLeg(startLeg);
|
System.out.println(controller.getRaceClock().getTime());
|
||||||
|
boat.setCurrentLeg(startLeg, controller.getRaceClock());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,8 +84,8 @@ public class StreamedRace implements Runnable {
|
|||||||
|
|
||||||
int legNumber = boatStatusMessage.getLegNumber();
|
int legNumber = boatStatusMessage.getLegNumber();
|
||||||
|
|
||||||
if (legNumber >= 1 && legNumber < legs.size()) {
|
if (legNumber >= 1 && legNumber < legs.size() && boat.getCurrentLeg().getLegNumber() != legNumber) {
|
||||||
boat.setCurrentLeg(legs.get(legNumber));
|
boat.setCurrentLeg(legs.get(legNumber), controller.getRaceClock());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boatStatusEnum == BoatStatusEnum.RACING) {
|
if (boatStatusEnum == BoatStatusEnum.RACING) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.geotools.referencing.GeodeticCalculator;
|
|||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ public class Boat {
|
|||||||
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
||||||
private long nextValidTime = 0;
|
private long nextValidTime = 0;
|
||||||
|
|
||||||
|
private ZonedDateTime timeSinceLastMark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boat initializer which keeps all of the information of the boat.
|
* Boat initializer which keeps all of the information of the boat.
|
||||||
*
|
*
|
||||||
@@ -181,9 +184,10 @@ public class Boat {
|
|||||||
return currentLeg;
|
return currentLeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentLeg(Leg currentLeg) {
|
public void setCurrentLeg(Leg currentLeg, RaceClock raceClock) {
|
||||||
this.currentLeg = currentLeg;
|
this.currentLeg = currentLeg;
|
||||||
this.currentLegName.setValue(currentLeg.getName());
|
this.currentLegName.setValue(currentLeg.getName());
|
||||||
|
this.setTimeSinceLastMark(raceClock.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFinished() {
|
public boolean isFinished() {
|
||||||
@@ -236,4 +240,12 @@ public class Boat {
|
|||||||
public void setDnf(boolean dnf) {
|
public void setDnf(boolean dnf) {
|
||||||
this.dnf = dnf;
|
this.dnf = dnf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime getTimeSinceLastMark() {
|
||||||
|
return timeSinceLastMark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeSinceLastMark(ZonedDateTime timeSinceLastMark) {
|
||||||
|
this.timeSinceLastMark = timeSinceLastMark;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import seng302.Mock.StreamedCourse;
|
|||||||
import seng302.RaceDataSource;
|
import seng302.RaceDataSource;
|
||||||
import seng302.RaceMap;
|
import seng302.RaceMap;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,10 +31,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
private boolean annoAbbrev = true;
|
private boolean annoAbbrev = true;
|
||||||
private boolean annoSpeed = true;
|
private boolean annoSpeed = true;
|
||||||
private boolean annoPath = true;
|
private boolean annoPath = true;
|
||||||
|
private boolean annoTimeSinceLastMark = true;
|
||||||
private List<Color> colours;
|
private List<Color> colours;
|
||||||
private final List<Marker> markers;
|
private final List<Marker> markers;
|
||||||
private final RaceDataSource raceData;
|
private final RaceDataSource raceData;
|
||||||
|
|
||||||
|
private RaceClock raceClock;
|
||||||
|
|
||||||
public ResizableRaceCanvas(RaceDataSource raceData) {
|
public ResizableRaceCanvas(RaceDataSource raceData) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -160,7 +166,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
* @param speed speed of the boat
|
* @param speed speed of the boat
|
||||||
* @param coordinate coordinate the text appears
|
* @param coordinate coordinate the text appears
|
||||||
*/
|
*/
|
||||||
private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate) {
|
private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate, ZonedDateTime timeSinceLastMark) {
|
||||||
String text = "";
|
String text = "";
|
||||||
//Check name toggle value
|
//Check name toggle value
|
||||||
if (annoName){
|
if (annoName){
|
||||||
@@ -174,6 +180,11 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
if (annoSpeed){
|
if (annoSpeed){
|
||||||
text += String.format("%.2fkn", speed);
|
text += String.format("%.2fkn", speed);
|
||||||
}
|
}
|
||||||
|
//Check time since last mark toggle value
|
||||||
|
if(annoTimeSinceLastMark){
|
||||||
|
Duration timeSince = Duration.between(timeSinceLastMark, raceClock.getTime());
|
||||||
|
text += String.format("%d", timeSince.getSeconds());
|
||||||
|
}
|
||||||
//String text = String.format("%s, %2$.2fkn", name, speed);
|
//String text = String.format("%s, %2$.2fkn", name, speed);
|
||||||
long xCoord = coordinate.getX() + 20;
|
long xCoord = coordinate.getX() + 20;
|
||||||
long yCoord = coordinate.getY();
|
long yCoord = coordinate.getY();
|
||||||
@@ -293,7 +304,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (raceAnno)
|
if (raceAnno)
|
||||||
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()), boat.getTimeSinceLastMark());
|
||||||
//TODO this needs to be fixed.
|
//TODO this needs to be fixed.
|
||||||
drawTrack(boat, colours.get(currentColour));
|
drawTrack(boat, colours.get(currentColour));
|
||||||
currentColour = (currentColour + 1) % colours.size();
|
currentColour = (currentColour + 1) % colours.size();
|
||||||
@@ -330,4 +341,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRaceClock(RaceClock raceClock) {
|
||||||
|
this.raceClock = raceClock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user