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]
main
hba56 9 years ago
parent 7990ac9d2e
commit 9eb4e3daea

@ -24,6 +24,7 @@ public class RaceController extends Controller {
private ResizableRaceCanvas raceMap;
private ResizableRaceMap raceBoundaries;
private RaceClock raceClock;
@FXML SplitPane race;
@FXML CheckBox showFPS;
@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.
*/
public void startRace(VisualiserInput visualiserInput, RaceClock raceClock) {
StreamedRace newRace = new StreamedRace(visualiserInput, this);
//newRace.initialiseBoats();
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
@ -119,6 +120,11 @@ public class RaceController extends Controller {
//Initialize save annotation array, fps listener, and annotation listeners
timeZone.setText(raceClock.getTimeZone());
timer.textProperty().bind(raceClock.durationProperty());
this.raceClock = raceClock;
raceMap.setRaceClock(raceClock);
StreamedRace newRace = new StreamedRace(visualiserInput, this);
initializeFPS();
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) {
Leg startLeg = new Leg(name, 0);
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();
if (legNumber >= 1 && legNumber < legs.size()) {
boat.setCurrentLeg(legs.get(legNumber));
if (legNumber >= 1 && legNumber < legs.size() && boat.getCurrentLeg().getLegNumber() != legNumber) {
boat.setCurrentLeg(legs.get(legNumber), controller.getRaceClock());
}
if (boatStatusEnum == BoatStatusEnum.RACING) {

@ -6,6 +6,7 @@ import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate;
import java.awt.geom.Point2D;
import java.time.ZonedDateTime;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@ -31,6 +32,8 @@ public class Boat {
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
private long nextValidTime = 0;
private ZonedDateTime timeSinceLastMark;
/**
* Boat initializer which keeps all of the information of the boat.
*
@ -181,9 +184,10 @@ public class Boat {
return currentLeg;
}
public void setCurrentLeg(Leg currentLeg) {
public void setCurrentLeg(Leg currentLeg, RaceClock raceClock) {
this.currentLeg = currentLeg;
this.currentLegName.setValue(currentLeg.getName());
this.setTimeSinceLastMark(raceClock.getTime());
}
public boolean isFinished() {
@ -236,4 +240,12 @@ public class Boat {
public void setDnf(boolean 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.RaceMap;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -28,10 +31,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
private boolean annoAbbrev = true;
private boolean annoSpeed = true;
private boolean annoPath = true;
private boolean annoTimeSinceLastMark = true;
private List<Color> colours;
private final List<Marker> markers;
private final RaceDataSource raceData;
private RaceClock raceClock;
public ResizableRaceCanvas(RaceDataSource raceData) {
super();
@ -160,7 +166,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
* @param speed speed of the boat
* @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 = "";
//Check name toggle value
if (annoName){
@ -174,6 +180,11 @@ public class ResizableRaceCanvas extends ResizableCanvas {
if (annoSpeed){
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);
long xCoord = coordinate.getX() + 20;
long yCoord = coordinate.getY();
@ -293,7 +304,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
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.
drawTrack(boat, colours.get(currentColour));
currentColour = (currentColour + 1) % colours.size();
@ -330,4 +341,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
));
}
public void setRaceClock(RaceClock raceClock) {
this.raceClock = raceClock;
}
}
Loading…
Cancel
Save