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