Added race statuses for before the race has started. 3 min -> 1 min is warning, 1 min -> 0 min is preparatory.
-Boat locations (spread across start line) are also broad casted #story[778]
This commit is contained in:
@@ -7,6 +7,7 @@ import javafx.collections.ObservableList;
|
|||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
|
|
||||||
|
|
||||||
|
import org.joda.time.tz.UTCProvider;
|
||||||
import seng302.Constants;
|
import seng302.Constants;
|
||||||
import seng302.DataInput.RaceDataSource;
|
import seng302.DataInput.RaceDataSource;
|
||||||
import seng302.MockOutput;
|
import seng302.MockOutput;
|
||||||
@@ -31,7 +32,7 @@ public class Race implements Runnable {
|
|||||||
protected int boatsFinished = 0;
|
protected int boatsFinished = 0;
|
||||||
protected long totalTimeElapsed;
|
protected long totalTimeElapsed;
|
||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
protected int PRERACE_TIME = 12000; //time in milliseconds to pause during pre-race
|
protected int PRERACE_TIME = 180000; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
|
||||||
protected boolean countdownFinish = false;
|
protected boolean countdownFinish = false;
|
||||||
protected boolean runRace = true;
|
protected boolean runRace = true;
|
||||||
private int lastFPS = 20;
|
private int lastFPS = 20;
|
||||||
@@ -119,13 +120,33 @@ public class Race implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(long arg0) {
|
public void handle(long arg0) {
|
||||||
timeLeft = startTime - currentTime;
|
timeLeft = startTime - currentTime;
|
||||||
if (timeLeft <= 0) {
|
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<>();
|
||||||
|
//For each boat, we update it's 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());
|
||||||
|
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||||
|
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (timeLeft <= 60000/scaleFactor) {
|
||||||
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
|
||||||
|
mockOutput.parseRaceStatus(raceStatus);
|
||||||
|
}
|
||||||
|
else if (timeLeft <= 0) {
|
||||||
countdownFinish = true;
|
countdownFinish = true;
|
||||||
stop();
|
stop();
|
||||||
if (runRace) {
|
if (runRace) {
|
||||||
simulateRace();
|
simulateRace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
|
||||||
|
mockOutput.parseRaceStatus(raceStatus);
|
||||||
currentTimeInSeconds = (timeLeft * scaleFactor) / 1000;
|
currentTimeInSeconds = (timeLeft * scaleFactor) / 1000;
|
||||||
minutes = currentTimeInSeconds / 60;
|
minutes = currentTimeInSeconds / 60;
|
||||||
remainingSeconds = currentTimeInSeconds % 60;
|
remainingSeconds = currentTimeInSeconds % 60;
|
||||||
@@ -181,7 +202,7 @@ public class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||||
RaceStatus raceStatus = new RaceStatus(totalTimeElapsed, raceId, 3, 2, boatStatusMessages);
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, 2, boatStatusMessages);
|
||||||
mockOutput.parseRaceStatus(raceStatus);
|
mockOutput.parseRaceStatus(raceStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class VisualiserInput implements Runnable
|
|||||||
// System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
// System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
||||||
break;
|
break;
|
||||||
case RACESTATUS:
|
case RACESTATUS:
|
||||||
System.out.println("Race Status Message");
|
// System.out.println("Race Status Message");
|
||||||
raceStatus = ((RaceStatus) data);
|
raceStatus = ((RaceStatus) data);
|
||||||
for (BoatStatusMessage msg: raceStatus.getBoatStatusMessages()){
|
for (BoatStatusMessage msg: raceStatus.getBoatStatusMessages()){
|
||||||
boatStatus.put(msg.getSourceID(), msg);
|
boatStatus.put(msg.getSourceID(), msg);
|
||||||
@@ -244,7 +244,7 @@ public class VisualiserInput implements Runnable
|
|||||||
//no decoder
|
//no decoder
|
||||||
break;
|
break;
|
||||||
case BOATLOCATION:
|
case BOATLOCATION:
|
||||||
System.out.println("Boat Location!");
|
// System.out.println("Boat Location!");
|
||||||
BoatLocationMessage msg = (BoatLocationMessage) data;
|
BoatLocationMessage msg = (BoatLocationMessage) data;
|
||||||
if (boatLocation.containsKey(msg.getSourceID())){
|
if (boatLocation.containsKey(msg.getSourceID())){
|
||||||
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
|
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
|
||||||
|
|||||||
Reference in New Issue
Block a user