Minor cleaning in yacht class

tags: #story[1124]
This commit is contained in:
William Muir
2017-08-03 13:53:30 +12:00
parent 1c0d869894
commit db078538ff
3 changed files with 3 additions and 124 deletions
@@ -165,7 +165,7 @@ public class GameState implements Runnable {
// printBoatStatus(playerYacht); // printBoatStatus(playerYacht);
} }
public static void update() { public void update() {
Long timeInterval = System.currentTimeMillis() - previousUpdateTime; Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
previousUpdateTime = System.currentTimeMillis(); previousUpdateTime = System.currentTimeMillis();
for (Yacht yacht : yachts.values()) { for (Yacht yacht : yachts.values()) {
+2 -95
View File
@@ -28,11 +28,6 @@ public class Yacht {
void notifyLocation(Yacht yacht, double lat, double lon, double heading, double velocity); void notifyLocation(Yacht yacht, double lat, double lon, double heading, double velocity);
} }
@FunctionalInterface
public interface YachtPositionListener {
void notifyPosition(int position);
}
//BOTH AFAIK //BOTH AFAIK
private String boatType; private String boatType;
private Integer sourceId; private Integer sourceId;
@@ -44,6 +39,7 @@ public class Yacht {
private Long estimateTimeAtFinish; private Long estimateTimeAtFinish;
private Long timeTillNext; private Long timeTillNext;
private Long markRoundTime; private Long markRoundTime;
private CompoundMark nextMark;
private Double heading; private Double heading;
private Double lat; private Double lat;
private Double lon; private Double lon;
@@ -62,60 +58,10 @@ public class Yacht {
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper(); private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper(); private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper(); private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
// private ReadOnlyDoubleWrapper headingProperty = new ReadOnlyDoubleWrapper();
// private ReadOnlyDoubleWrapper latitudeProperty = new ReadOnlyDoubleWrapper();
// private ReadOnlyDoubleWrapper longitudeProperty = new ReadOnlyDoubleWrapper();
private CompoundMark lastMarkRounded; private CompoundMark lastMarkRounded;
private CompoundMark nextMark;
private Integer positionInt = 0; private Integer positionInt = 0;
private Color colour; private Color colour;
/**
* @param location latlon location of the boat stored in a geopoint
* @param heading heading of the boat in degrees from 0 to 365 with 0 being north
*/
public Yacht(GeoPoint location, Double heading) {
this.location = location;
this.heading = heading;
this.velocity = 0.0;
this.sailIn = false;
}
/**
* Used in EventTest and RaceTest.
* @param boatName boatName
* @param shortName shortName
* @param location location
* @param heading heading
*/
public Yacht(String boatName, String shortName, GeoPoint location, Double heading) {
this.boatName = boatName;
this.shortName = shortName;
this.location = location;
this.heading = heading;
this.velocity = 0.0;
this.sailIn = false;
}
/**
* Used in BoatGroupTest.
*
* @param boatName The name of the team sailing the boat
* @param boatVelocity The speed of the boat in meters/second
* @param shortName A shorter version of the teams name
* @param id The id for the yacht
*/
public Yacht(String boatName, double boatVelocity, String shortName, int id) {
this.boatName = boatName;
this.velocity = boatVelocity;
this.shortName = shortName;
this.sourceId = id;
this.sailIn = false;
}
public Yacht(String boatType, Integer sourceId, String hullID, String shortName, public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
String boatName, String country) { String boatName, String country) {
this.boatType = boatType; this.boatType = boatType;
@@ -162,17 +108,7 @@ public class Yacht {
} }
} }
} }
// if (sailIn) {
// Double secondsElapsed = timeInterval / 1000000.0;
// Double windSpeedKnots = GameState.getWindSpeedKnots();
// Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
// Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
// velocity = boatSpeedInKnots / 1.943844492 * 1000; // TODO: 26/07/17 cir27 - Remove magic number
// Double metersCovered = velocity * secondsElapsed;
// location = getGeoCoordinate(location, heading, metersCovered);
// } else {
// velocity = 0d;
// }
Double metersCovered = velocity * secondsElapsed; Double metersCovered = velocity * secondsElapsed;
location = getGeoCoordinate(location, heading, metersCovered); location = getGeoCoordinate(location, heading, metersCovered);
} }
@@ -180,7 +116,6 @@ public class Yacht {
public void adjustHeading(Double amount) { public void adjustHeading(Double amount) {
Double newVal = heading + amount; Double newVal = heading + amount;
lastHeading = heading; lastHeading = heading;
// TODO: 24/07/17 wmu16 - '%' in java does remainder, we need modulo. All this must be changed here, this is why we have neg values!
heading = (double) Math.floorMod(newVal.longValue(), 360L); heading = (double) Math.floorMod(newVal.longValue(), 360L);
} }
@@ -457,30 +392,6 @@ public class Yacht {
this.velocity = velocity; this.velocity = velocity;
} }
// public void updateLatitudeProperty (Double lat) {
// latitudeProperty.set(lat);
// }
//
// public void updateLongitudeProperty (double lon) {
// longitudeProperty.set(lon);
// }
//
// public void updateHeadingProperty (double heading) {
// headingProperty.set(heading);
// }
//
// public ReadOnlyDoubleProperty latitudeProperty () {
// return latitudeProperty.getReadOnlyProperty();
// }
//
// public ReadOnlyDoubleProperty longitudeProperty () {
// return longitudeProperty.getReadOnlyProperty();
// }
//
// public ReadOnlyDoubleProperty headingProperty () {
// return headingProperty;
// }
public void updateLocation (double lat, double lon, double heading, double velocity) { public void updateLocation (double lat, double lon, double heading, double velocity) {
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
@@ -495,8 +406,4 @@ public class Yacht {
public void addLocationListener (YachtLocationListener listener) { public void addLocationListener (YachtLocationListener listener) {
locationListeners.add(listener); locationListeners.add(listener);
} }
public void addPositionListener (YachtPositionListener listener) {
}
} }
@@ -1,28 +0,0 @@
package seng302.models;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import seng302.model.PolarTable;
import seng302.model.Yacht;
import seng302.model.GeoPoint;
public class YachtTest {
Double windDir;
Double windSpd;
List<Yacht> yachts = new ArrayList<>();
@Before
public void setUp() {
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
windDir = 90d;
windSpd = 10d;
yachts.add(new Yacht("Yacht 1", "Y1", new GeoPoint(-30.0, 20.0), 160.0));
yachts.add(new Yacht("Yacht 2", "Y2", new GeoPoint(-40.0, -20.0), 100.0));
yachts.add(new Yacht("Yacht 3", "Y3", new GeoPoint(-35.0, -15.5), 20.0));
}
}