Merge remote-tracking branch 'origin/sprint4_master' into story36_boundary_fix_attempt_2
# Conflicts: # mock/src/main/java/seng302/Model/Race.java Resolved. Also reverted the change to the prestart and preparatory time, as they had gotten flipped around (prestart is > 3min to start, preparatory is < 1 min to start).
This commit is contained in:
@@ -50,8 +50,8 @@ public abstract class XMLReader {
|
||||
|
||||
/**
|
||||
* Alternate constructor
|
||||
* @param xmlFile
|
||||
* @param isWholeFile
|
||||
* @param xmlFile File to be read
|
||||
* @param isWholeFile boolean value whether entire file is being passed
|
||||
*/
|
||||
public XMLReader(String xmlFile, Boolean isWholeFile) {
|
||||
|
||||
@@ -91,9 +91,9 @@ public abstract class XMLReader {
|
||||
|
||||
/**
|
||||
* Get the contents of the XML FILe.
|
||||
* @param document
|
||||
* @return
|
||||
* @throws TransformerException
|
||||
* @param document holds all xml information
|
||||
* @return String representation of document
|
||||
* @throws TransformerException when document is malformed, and cannot be turned into a string
|
||||
*/
|
||||
public static String getContents(Document document) throws TransformerException {
|
||||
DOMSource source = new DOMSource(document);
|
||||
|
||||
@@ -108,10 +108,11 @@ public class MockOutput implements Runnable
|
||||
* @param lon longitude of boat
|
||||
* @param heading heading of boat
|
||||
* @param speed speed of boat
|
||||
* @param time historical time of race
|
||||
*/
|
||||
public synchronized void parseBoatLocation(int sourceID, double lat, double lon, double heading, double speed){
|
||||
public synchronized void parseBoatLocation(int sourceID, double lat, double lon, double heading, double speed, long time){
|
||||
|
||||
BoatLocation boatLocation = new BoatLocation(sourceID, lat, lon, boatLocationSequenceNumber, heading, speed);
|
||||
BoatLocation boatLocation = new BoatLocation(sourceID, lat, lon, boatLocationSequenceNumber, heading, speed, time);
|
||||
//iterates the sequence number
|
||||
boatLocationSequenceNumber++;
|
||||
|
||||
|
||||
@@ -81,6 +81,8 @@ public class Boat {
|
||||
*/
|
||||
private long timeSinceTackChange = 0;
|
||||
|
||||
private long estimatedTime = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a boat object with a given sourceID, name, country/team abbreviation, and polars table.
|
||||
@@ -442,4 +444,11 @@ public class Boat {
|
||||
return distanceTravelledMeters;
|
||||
}
|
||||
|
||||
public long getEstimatedTime() {
|
||||
return estimatedTime;
|
||||
}
|
||||
|
||||
public void setEstimatedTime(long estimatedTime) {
|
||||
this.estimatedTime = estimatedTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Math.cos;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a yacht race.
|
||||
@@ -181,7 +183,7 @@ public class Race implements Runnable {
|
||||
*/
|
||||
private void parseIndividualMark(Mark mark) {
|
||||
|
||||
this.mockOutput.parseBoatLocation(mark.getSourceID(), mark.getPosition().getLatitude(), mark.getPosition().getLongitude(),0,0);
|
||||
this.mockOutput.parseBoatLocation(mark.getSourceID(), mark.getPosition().getLatitude(), mark.getPosition().getLongitude(),0,0, totalTimeElapsed+startTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -210,7 +212,8 @@ public class Race implements Runnable {
|
||||
boat.getCurrentPosition().getLatitude(),
|
||||
boat.getCurrentPosition().getLongitude(),
|
||||
boat.getBearing().degrees(),
|
||||
boat.getCurrentSpeed()
|
||||
boat.getCurrentSpeed(),
|
||||
startTime + totalTimeElapsed
|
||||
);
|
||||
|
||||
}
|
||||
@@ -261,7 +264,7 @@ public class Race implements Runnable {
|
||||
//Add each boat status to the status list.
|
||||
for (Boat boat : boats) {
|
||||
|
||||
BoatStatus boatStatus = new BoatStatus(boat.getSourceID(), boat.getStatus(), boat.getCurrentLeg().getLegNumber());
|
||||
BoatStatus boatStatus = new BoatStatus(boat.getSourceID(), boat.getStatus(), boat.getCurrentLeg().getLegNumber(), boat.getEstimatedTime());
|
||||
|
||||
boatStatuses.add(boatStatus);
|
||||
}
|
||||
@@ -379,26 +382,29 @@ public class Race implements Runnable {
|
||||
|
||||
} else {
|
||||
//Otherwise, the race is over!
|
||||
System.out.println("test");
|
||||
raceFinished.start();
|
||||
setRaceStatusEnum(RaceStatusEnum.FINISHED);
|
||||
this.stop();
|
||||
}
|
||||
|
||||
// Change wind direction
|
||||
changeWindDir();
|
||||
if (getNumberOfActiveBoats() != 0) {
|
||||
// Change wind direction
|
||||
changeWindDir();
|
||||
|
||||
//Parse the boat locations.
|
||||
parseBoatLocations();
|
||||
//Parse the boat locations.
|
||||
parseBoatLocations();
|
||||
|
||||
//Parse the marks.
|
||||
parseMarks();
|
||||
//Parse the marks.
|
||||
parseMarks();
|
||||
|
||||
//Parse the race status.
|
||||
parseRaceStatus();
|
||||
//Parse the race status.
|
||||
parseRaceStatus();
|
||||
|
||||
|
||||
//Update the last frame time.
|
||||
this.lastFrameTime = currentTime;
|
||||
//Update the last frame time.
|
||||
this.lastFrameTime = currentTime;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -409,7 +415,7 @@ public class Race implements Runnable {
|
||||
int iters = 0;
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, startTime, 0, 2300, 2, null);
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, startTime, 0, 2300, 2, new ArrayList<>());
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
if (iters > 500){
|
||||
mockOutput.stop();
|
||||
@@ -625,10 +631,11 @@ public class Race implements Runnable {
|
||||
if (!willStayInsideCourse) {
|
||||
boat.setVMG(newVMG);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.updateEstimatedTime(boat);
|
||||
|
||||
|
||||
//Check the boats position (update leg and stuff).
|
||||
this.checkPosition(boat, totalTimeElapsed);
|
||||
@@ -757,7 +764,6 @@ public class Race implements Runnable {
|
||||
boat.setTimeFinished(timeElapsed);
|
||||
boat.setCurrentSpeed(0);
|
||||
boat.setStatus(BoatStatusEnum.FINISHED);
|
||||
|
||||
} else if (doNotFinish()) {
|
||||
//Boat has pulled out of race.
|
||||
boat.setTimeFinished(timeElapsed);
|
||||
@@ -909,4 +915,16 @@ public class Race implements Runnable {
|
||||
protected int getWind(){
|
||||
return windDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the boat's estimated time to next mark if positive
|
||||
* @param boat to estimate time given its velocity
|
||||
*/
|
||||
private void updateEstimatedTime(Boat boat) {
|
||||
double velocityToMark = boat.getCurrentSpeed() * cos(boat.getBearing().radians() - boat.calculateBearingToNextMarker().radians()) / Constants.KnotsToMMPerSecond;
|
||||
if (velocityToMark > 0) {
|
||||
long timeFromNow = (long)(1000*boat.calculateDistanceToNextMarker()/velocityToMark);
|
||||
boat.setEstimatedTime(startTime + totalTimeElapsed + timeFromNow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class RaceTest{
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
testRace.countdownTimer.handle(1);
|
||||
verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble());
|
||||
verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong());
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user