Merge remote-tracking branch 'origin/splitIntoTwoModules' into splitIntoTwoModules
This commit is contained in:
@@ -86,8 +86,9 @@ public class MockOutput implements Runnable
|
||||
/**
|
||||
* Used to give the mocOutput information about boat location to be made into a message and sent
|
||||
*/
|
||||
public synchronized void parseBoatLocation(int sourceID, double lat, double lon, double heading){
|
||||
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(sourceID, lat, lon, boatLocationSequenceNumber, heading);
|
||||
public synchronized void parseBoatLocation(int sourceID, double lat, double lon, double heading, double speed){
|
||||
|
||||
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(sourceID, lat, lon, boatLocationSequenceNumber, heading, speed);
|
||||
//iterates the sequence number
|
||||
boatLocationSequenceNumber++;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Event {
|
||||
System.out.println("Sending Boat");
|
||||
sendBoatData();
|
||||
|
||||
Race newRace = new Race(raceDataSource, 3, mockOutput);
|
||||
Race newRace = new Race(raceDataSource, 15, mockOutput);
|
||||
new Thread((newRace)).start();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Race implements Runnable {
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
protected int scaleFactor;
|
||||
protected int PRERACE_TIME = 180000; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
|
||||
protected int PRERACE_TIME = 180; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
|
||||
protected boolean countdownFinish = false;
|
||||
protected boolean runRace = true;
|
||||
private int lastFPS = 20;
|
||||
@@ -112,46 +112,40 @@ public class Race implements Runnable {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long startTime = currentTime + (PRERACE_TIME / scaleFactor);
|
||||
long minutes;
|
||||
long currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
long hours;
|
||||
long timeLeft;
|
||||
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
timeLeft = startTime - currentTime;
|
||||
System.out.println(timeLeft);
|
||||
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());
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0);
|
||||
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) {
|
||||
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
else if (timeLeft <= 0) {
|
||||
countdownFinish = true;
|
||||
stop();
|
||||
if (runRace) {
|
||||
simulateRace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("Stopping");
|
||||
stop();
|
||||
}
|
||||
else {
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
currentTimeInSeconds = (timeLeft * scaleFactor) / 1000;
|
||||
minutes = currentTimeInSeconds / 60;
|
||||
remainingSeconds = currentTimeInSeconds % 60;
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
}
|
||||
@@ -194,7 +188,7 @@ public class Race implements Runnable {
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
}
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading());
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getScaledVelocity());
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
} else {
|
||||
@@ -208,8 +202,6 @@ public class Race implements Runnable {
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
public void initialiseBoats() {
|
||||
Leg officialStart = legs.get(0);
|
||||
String name = officialStart.getName();
|
||||
|
||||
@@ -150,7 +150,7 @@ public class BoatLocationMessage extends AC35Data
|
||||
this.rudderAngle = rudderAngle;
|
||||
}
|
||||
|
||||
public BoatLocationMessage(int sourceID, double lat, double lon, long sequenceNumber, double heading) {
|
||||
public BoatLocationMessage(int sourceID, double lat, double lon, long sequenceNumber, double heading, double boatSpeed) {
|
||||
super(MessageType.BOATLOCATION);
|
||||
|
||||
this.messageVersionNumber = (byte) 1;
|
||||
@@ -164,7 +164,7 @@ public class BoatLocationMessage extends AC35Data
|
||||
this.heading = convertHeadingDoubleToInt(heading);
|
||||
this.pitch = 0;
|
||||
this.roll = 0;
|
||||
this.boatSpeed = 0;
|
||||
this.boatSpeed = convertBoatSpeedDoubleToInt(boatSpeed);
|
||||
this.boatCOG = 0;
|
||||
this.boatSOG = 0;
|
||||
this.apparentWindSpeed = 0;
|
||||
|
||||
Reference in New Issue
Block a user