|
|
|
|
@ -30,8 +30,8 @@ public class Race implements Runnable {
|
|
|
|
|
protected List<Leg> legs;
|
|
|
|
|
protected int boatsFinished = 0;
|
|
|
|
|
protected long totalTimeElapsed;
|
|
|
|
|
protected int scaleFactor = 25;
|
|
|
|
|
protected int PRERACE_TIME = 1800; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
|
|
|
|
|
protected int scaleFactor = 20;
|
|
|
|
|
protected int PRERACE_TIME = 18000; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
|
|
|
|
|
private long startTime;
|
|
|
|
|
protected boolean countdownFinish = false;
|
|
|
|
|
protected boolean runRace = true;
|
|
|
|
|
@ -42,7 +42,6 @@ public class Race implements Runnable {
|
|
|
|
|
private static int boatOffset = 0;
|
|
|
|
|
private int finished = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initailiser for Race
|
|
|
|
|
*
|
|
|
|
|
@ -106,23 +105,17 @@ public class Race implements Runnable {
|
|
|
|
|
protected void countdownTimer() {
|
|
|
|
|
AnimationTimer timer = new AnimationTimer() {
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
//long startTime = currentTime + (PRERACE_TIME / scaleFactor);
|
|
|
|
|
//long minutes;
|
|
|
|
|
//long hours;
|
|
|
|
|
long timeLeft;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void handle(long arg0) {
|
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
|
ArrayList<BoatStatus> boatStatuses = new ArrayList<>();
|
|
|
|
|
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
|
|
|
|
//For each boat, we update its position, and generate a BoatLocationMessage.
|
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
|
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0);
|
|
|
|
|
boatStatuses.add(new BoatStatus(boat.getSourceID(),
|
|
|
|
|
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatusEnum.RACING : BoatStatusEnum.DNF, boat.getCurrentLeg().getLegNumber()));
|
|
|
|
|
}
|
|
|
|
|
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0);
|
|
|
|
|
boatStatuses.add(new BoatStatus(boat.getSourceID(), BoatStatusEnum.RACING, boat.getCurrentLeg().getLegNumber()));
|
|
|
|
|
}
|
|
|
|
|
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
|
|
|
|
|
|
|
|
|
@ -145,7 +138,6 @@ public class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
timer.start();
|
|
|
|
|
//countdownFinish = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -160,6 +152,7 @@ public class Race implements Runnable {
|
|
|
|
|
boat.setStarted(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new AnimationTimer() {
|
|
|
|
|
//Start time of loop.
|
|
|
|
|
long timeRaceStarted = System.currentTimeMillis();
|
|
|
|
|
@ -171,7 +164,7 @@ public class Race implements Runnable {
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
//Update the total elapsed time.
|
|
|
|
|
totalTimeElapsed = currentTime - timeRaceStarted;
|
|
|
|
|
ArrayList<BoatStatus> boatStatuses = new ArrayList<BoatStatus>();
|
|
|
|
|
ArrayList<BoatStatus> boatStatuses = new ArrayList<>();
|
|
|
|
|
finished = 0;
|
|
|
|
|
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
|
@ -208,19 +201,21 @@ public class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
public void initialiseBoats() {
|
|
|
|
|
Leg officialStart = legs.get(0);
|
|
|
|
|
String name = officialStart.getName();
|
|
|
|
|
Marker endMark = officialStart.getEndCompoundMark();
|
|
|
|
|
|
|
|
|
|
ArrayList<GPSCoordinate> startingPositions = getSpreadStartingPositions();
|
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
|
Boat boat = startingBoats.get(i);
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
Leg newLeg = new Leg(name, new Marker(startingPositions.get(i)), endMark, 0);
|
|
|
|
|
boat.setCurrentLeg(newLeg);
|
|
|
|
|
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
|
|
|
|
boat.setCurrentPosition(startingPositions.get(i));
|
|
|
|
|
boat.setCurrentLeg(officialStart);
|
|
|
|
|
boat.setHeading(boat.calculateHeading());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
|
|
|
|
|
*
|
|
|
|
|
@ -231,7 +226,6 @@ public class Race implements Runnable {
|
|
|
|
|
int nBoats = startingBoats.size();
|
|
|
|
|
Marker compoundMark = legs.get(0).getStartCompoundMark();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
|
|
|
|
initialCalc.setStartingGeographicPoint(compoundMark.getMark1().getLongitude(), compoundMark.getMark1().getLatitude());
|
|
|
|
|
initialCalc.setDestinationGeographicPoint(compoundMark.getMark2().getLongitude(), compoundMark.getMark2().getLatitude());
|
|
|
|
|
@ -249,6 +243,7 @@ public class Race implements Runnable {
|
|
|
|
|
Point2D position = positionCalc.getDestinationGeographicPoint();
|
|
|
|
|
positions.add(new GPSCoordinate(position.getY(), position.getX()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
positionCalc = new GeodeticCalculator();
|
|
|
|
|
positionCalc.setStartingGeographicPoint(position);
|
|
|
|
|
}
|
|
|
|
|
|