Fixed race scaling
- Races were completed far too quickly because a set SLEEPTIME was used as the time elapsed, instead of the actual break time #story[16]
This commit is contained in:
@@ -34,7 +34,8 @@ public class ConstantVelocityRace extends Race {
|
||||
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
|
||||
|
||||
//distanceTravelled = velocity (nm p hr) * time taken to update loop
|
||||
double distanceTravelled = boat.getScaledVelocity() * millisecondsElapsed / 3600000;
|
||||
double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000;
|
||||
|
||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||
|
||||
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.Model;
|
||||
|
||||
import com.oracle.xmlns.internal.webservices.jaxws_databinding.SoapBindingUse;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
@@ -96,7 +97,6 @@ public class Leg {
|
||||
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
||||
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
||||
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ public abstract class Race implements Runnable {
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
|
||||
private int lastFPS = 20;
|
||||
|
||||
|
||||
protected int scaleFactor;
|
||||
|
||||
@@ -72,7 +74,6 @@ public abstract class Race implements Runnable {
|
||||
|
||||
|
||||
protected void initialiseBoats() {
|
||||
System.out.println("boat initialisation");
|
||||
|
||||
// Leg startLeg = legs.get(0);
|
||||
// Leg copyLeg = startLeg.createCopy();
|
||||
@@ -106,21 +107,6 @@ public abstract class Race implements Runnable {
|
||||
timerEnabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the state in waiting for the race starts.
|
||||
*/
|
||||
private void preRace() {
|
||||
//show the boats participating.
|
||||
System.out.println("Boats Participating:");
|
||||
System.out.println("====================");
|
||||
for (int i = 0; i < startingBoats.size(); i++) {
|
||||
if (startingBoats.get(i) != null) {
|
||||
System.out.println(i + 1 + ". " + startingBoats.get(i).toString() + ", Speed: "
|
||||
+ Math.round(startingBoats.get(i).getVelocity()) + "kn");
|
||||
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
||||
@@ -228,7 +214,7 @@ public abstract class Race implements Runnable {
|
||||
|
||||
for (BoatInRace boat : startingBoats) {
|
||||
if (boat != null && !boat.isFinished()) {
|
||||
updatePosition(boat, SLEEP_TIME);
|
||||
updatePosition(boat, Math.round(1000/lastFPS));
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
}
|
||||
}
|
||||
@@ -245,19 +231,13 @@ public abstract class Race implements Runnable {
|
||||
fps++;
|
||||
if ((System.currentTimeMillis()-timeCurrent) > 1000){
|
||||
updateFPS(fps);
|
||||
lastFPS = fps;
|
||||
fps = 0;
|
||||
timeCurrent = System.currentTimeMillis();
|
||||
}
|
||||
;
|
||||
/*fps++;
|
||||
try {
|
||||
timeLoopEnded = System.currentTimeMillis();
|
||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}*/
|
||||
};
|
||||
//System.out.println("Avg fps:" + fps/(totalTimeElapsed/1000));
|
||||
|
||||
}
|
||||
|
||||
}.start();
|
||||
}
|
||||
|
||||
@@ -279,6 +259,8 @@ public abstract class Race implements Runnable {
|
||||
boatsFinished++;
|
||||
boat.setFinished(true);
|
||||
boat.setCurrentLeg(new Leg("DNF",-1));
|
||||
boat.setVelocity(0);
|
||||
boat.setScaledVelocity(0);
|
||||
} else {
|
||||
//Calculate how much the boat overshot the marker by
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||
|
||||
@@ -169,7 +169,6 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
*/
|
||||
private void displayText(String name, double speed, GraphCoordinate coordinate){
|
||||
String text = String.format("%s, %2$.2fkn", name, speed);
|
||||
//System.out.println(text.length()*7);
|
||||
long xCoord = coordinate.getX()+20;
|
||||
long yCoord = coordinate.getY();
|
||||
if (xCoord+(text.length()*7) >= getWidth()){
|
||||
@@ -207,7 +206,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
double height = getHeight();
|
||||
|
||||
gc.clearRect(0, 0, width, height);
|
||||
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
|
||||
|
||||
if (map == null) {
|
||||
return;//TODO this should return a exception in the future
|
||||
}
|
||||
@@ -250,7 +249,6 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
*/
|
||||
public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) {
|
||||
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
|
||||
//System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
|
||||
displayPoint(graphCoordinate, colour);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ public class RaceXMLReader extends XMLReader{
|
||||
String name = getTextValueOfNode((Element) nBoats.item(i), "name");
|
||||
String abbrev = getTextValueOfNode((Element) nBoats.item(i), "abbr");
|
||||
double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed"));
|
||||
//System.out.println(String.format("%s, %s, %s",name, abbrev, velo));
|
||||
BoatInRace boat = new BoatInRace(name, velo, colors[i], abbrev);
|
||||
boat.setCurrentPosition(startPt1);
|
||||
if (legs.size() > 0){
|
||||
@@ -70,7 +69,6 @@ public class RaceXMLReader extends XMLReader{
|
||||
Marker startMarker = getMarker(start);
|
||||
NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish");
|
||||
Marker finishMarker = getMarker(finish);
|
||||
//System.out.println(String.format("%s, %s, %s, %s",label, startCoord, finishCoord, i));
|
||||
legs.add(new Leg(label, startMarker, finishMarker, i));
|
||||
}
|
||||
}
|
||||
@@ -107,11 +105,6 @@ public class RaceXMLReader extends XMLReader{
|
||||
minLongitude = boundary.get(i).getLongitude();
|
||||
}
|
||||
}
|
||||
/*System.out.println(nBounds.getLength());
|
||||
System.out.println(maxLatitude);
|
||||
System.out.println(minLatitude);
|
||||
System.out.println(maxLongitude);
|
||||
System.out.println(minLongitude);*/
|
||||
|
||||
double difference = 0;//this will hold the largest difference so we can make the map square.
|
||||
double latitudeDiff = Math.abs(Math.abs(boundary.get(maxLatitudeIndex).getLatitude()) - Math.abs(boundary.get(minLatitudeIndex).getLatitude()));
|
||||
|
||||
@@ -2,31 +2,31 @@
|
||||
<boats>
|
||||
<boat>
|
||||
<name>ORACLE TEAM USA</name>
|
||||
<speed>30</speed>
|
||||
<speed>20</speed>
|
||||
<abbr>USA</abbr>
|
||||
<colour>BLUEVIOLET</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Land Rover BAR</name>
|
||||
<speed>50</speed>
|
||||
<speed>30</speed>
|
||||
<abbr>GBR</abbr>
|
||||
<colour>BLACK</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>SoftBank Team Japan</name>
|
||||
<speed>40</speed>
|
||||
<speed>25</speed>
|
||||
<abbr>JPN</abbr>
|
||||
<colour>RED</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Groupama Team France</name>
|
||||
<speed>35</speed>
|
||||
<speed>20</speed>
|
||||
<abbr>FRA</abbr>
|
||||
<colour>ORANGE</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Artemis Racing</name>
|
||||
<speed>44</speed>
|
||||
<speed>29</speed>
|
||||
<abbr>SWE</abbr>
|
||||
<colour>DARKOLIVEGREEN</colour>
|
||||
</boat>
|
||||
|
||||
@@ -115,43 +115,43 @@ public class BoatInRaceTest {
|
||||
assertFalse(testBoat.isFinished());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getWakeAtProperHeading() throws Exception {
|
||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
|
||||
// Construct leg of 0 degrees
|
||||
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate endPoint = new GPSCoordinate(50, 0);
|
||||
Leg leg0deg = new Leg("Start", startPoint, endPoint, 0);
|
||||
boat.setCurrentLeg(leg0deg);
|
||||
boat.setCurrentPosition(new GPSCoordinate(0,0));
|
||||
|
||||
assertEquals(0, boat.calculateHeading(), 1e-8);
|
||||
|
||||
// Construct leg from wake - heading should be 180 degrees
|
||||
Leg leg180deg = new Leg("Start", startPoint, boat.getWake(), 0);
|
||||
boat.setCurrentLeg(leg180deg);
|
||||
|
||||
assertEquals(180, boat.calculateHeading(), 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWakeProportionalToVelocity() throws Exception {
|
||||
BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
|
||||
// Construct leg of 0 degrees at 0 N
|
||||
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate endPoint = new GPSCoordinate(50, 0);
|
||||
Leg leg0deg = new Leg("Start", startPoint, endPoint, 0);
|
||||
boat.setCurrentLeg(leg0deg);
|
||||
boat.setCurrentPosition(new GPSCoordinate(0,0));
|
||||
|
||||
// Get latitude of endpoint of wake at 10 kn (longitude is 0)
|
||||
double endpointAt10Kn = boat.getWake().getLatitude();
|
||||
|
||||
// Latitude of endpoint at 20 kn should be twice endpoint at 10 kn
|
||||
boat.setVelocity(20);
|
||||
assertEquals(2*endpointAt10Kn, boat.getWake().getLatitude(), 1e-8);
|
||||
}
|
||||
//
|
||||
// @Test
|
||||
// public void getWakeAtProperHeading() throws Exception {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
//
|
||||
// // Construct leg of 0 degrees
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(50, 0);
|
||||
// Leg leg0deg = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(leg0deg);
|
||||
// boat.setCurrentPosition(new GPSCoordinate(0,0));
|
||||
//
|
||||
// assertEquals(0, boat.calculateHeading(), 1e-8);
|
||||
//
|
||||
// // Construct leg from wake - heading should be 180 degrees
|
||||
// Leg leg180deg = new Leg("Start", startPoint, boat.getWake(), 0);
|
||||
// boat.setCurrentLeg(leg180deg);
|
||||
//
|
||||
// assertEquals(180, boat.calculateHeading(), 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void getWakeProportionalToVelocity() throws Exception {
|
||||
// BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
//
|
||||
// // Construct leg of 0 degrees at 0 N
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(50, 0);
|
||||
// Leg leg0deg = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(leg0deg);
|
||||
// boat.setCurrentPosition(new GPSCoordinate(0,0));
|
||||
//
|
||||
// // Get latitude of endpoint of wake at 10 kn (longitude is 0)
|
||||
// double endpointAt10Kn = boat.getWake().getLatitude();
|
||||
//
|
||||
// // Latitude of endpoint at 20 kn should be twice endpoint at 10 kn
|
||||
// boat.setVelocity(20);
|
||||
// assertEquals(2*endpointAt10Kn, boat.getWake().getLatitude(), 1e-8);
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user