Merge remote-tracking branch 'origin/splitIntoTwoModules' into splitIntoTwoModules

main
Connor Taylor-Brown 9 years ago
commit 9bab3d3359

@ -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 * 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){ public synchronized void parseBoatLocation(int sourceID, double lat, double lon, double heading, double speed){
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(sourceID, lat, lon, boatLocationSequenceNumber, heading);
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(sourceID, lat, lon, boatLocationSequenceNumber, heading, speed);
//iterates the sequence number //iterates the sequence number
boatLocationSequenceNumber++; boatLocationSequenceNumber++;

@ -43,7 +43,7 @@ public class Event {
System.out.println("Sending Boat"); System.out.println("Sending Boat");
sendBoatData(); sendBoatData();
Race newRace = new Race(raceDataSource, 3, mockOutput); Race newRace = new Race(raceDataSource, 15, mockOutput);
new Thread((newRace)).start(); new Thread((newRace)).start();
} }

@ -32,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 = 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 countdownFinish = false;
protected boolean runRace = true; protected boolean runRace = true;
private int lastFPS = 20; private int lastFPS = 20;
@ -112,46 +112,40 @@ public class Race implements Runnable {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
long startTime = currentTime + (PRERACE_TIME / scaleFactor); long startTime = currentTime + (PRERACE_TIME / scaleFactor);
long minutes; long minutes;
long currentTimeInSeconds;
long remainingSeconds;
long hours; long hours;
long timeLeft; long timeLeft;
@Override @Override
public void handle(long arg0) { public void handle(long arg0) {
timeLeft = startTime - currentTime; timeLeft = startTime - currentTime;
System.out.println(timeLeft);
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<>(); ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<>();
//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++) {
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size()); Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
if (boat != null) { 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(), boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber())); boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
} }
} }
boatOffset = (boatOffset + 1) % (startingBoats.size()); boatOffset = (boatOffset + 1) % (startingBoats.size());
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
if (timeLeft <= 60000/scaleFactor) {
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages); RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
mockOutput.parseRaceStatus(raceStatus); mockOutput.parseRaceStatus(raceStatus);
} }
else if (timeLeft <= 0) { else if (timeLeft <= 0) {
countdownFinish = true; countdownFinish = true;
stop();
if (runRace) { if (runRace) {
simulateRace(); simulateRace();
} }
} else { System.out.println("Stopping");
stop();
}
else {
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages); RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
mockOutput.parseRaceStatus(raceStatus); mockOutput.parseRaceStatus(raceStatus);
currentTimeInSeconds = (timeLeft * scaleFactor) / 1000;
minutes = currentTimeInSeconds / 60;
remainingSeconds = currentTimeInSeconds % 60;
hours = minutes / 60;
minutes = minutes % 60;
} }
currentTime = System.currentTimeMillis(); currentTime = System.currentTimeMillis();
} }
@ -194,7 +188,7 @@ public class Race implements Runnable {
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS)); updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
checkPosition(boat, totalTimeElapsed); 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(), boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber())); boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
} else { } else {
@ -208,8 +202,6 @@ public class Race implements Runnable {
} }
}.start(); }.start();
} }
public void initialiseBoats() { public void initialiseBoats() {
Leg officialStart = legs.get(0); Leg officialStart = legs.get(0);
String name = officialStart.getName(); String name = officialStart.getName();

@ -150,7 +150,7 @@ public class BoatLocationMessage extends AC35Data
this.rudderAngle = rudderAngle; 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); super(MessageType.BOATLOCATION);
this.messageVersionNumber = (byte) 1; this.messageVersionNumber = (byte) 1;
@ -164,7 +164,7 @@ public class BoatLocationMessage extends AC35Data
this.heading = convertHeadingDoubleToInt(heading); this.heading = convertHeadingDoubleToInt(heading);
this.pitch = 0; this.pitch = 0;
this.roll = 0; this.roll = 0;
this.boatSpeed = 0; this.boatSpeed = convertBoatSpeedDoubleToInt(boatSpeed);
this.boatCOG = 0; this.boatCOG = 0;
this.boatSOG = 0; this.boatSOG = 0;
this.apparentWindSpeed = 0; this.apparentWindSpeed = 0;

Loading…
Cancel
Save