Wrapped race in an event which sends out starting xml files

#story[778]
This commit is contained in:
Erika Savell
2017-04-21 13:10:30 +12:00
parent 231a1824d1
commit 97c5c9662b
9 changed files with 220 additions and 427 deletions
+3 -5
View File
@@ -4,8 +4,7 @@ package seng302;
import javafx.application.Application;
import javafx.stage.Stage;
import org.xml.sax.SAXException;
import seng302.Model.ConstantVelocityRace;
import seng302.Model.Race;
import seng302.Model.Event;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
@@ -25,9 +24,8 @@ public class App extends Application {
public void start(Stage primaryStage) {
try {
RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
Race newRace = new Race(raceData, 15);
System.out.println(newRace.getStartingBoats());
new Thread((newRace)).start();
Event raceEvent = new Event(raceData);
raceEvent.start();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
@@ -0,0 +1,23 @@
package seng302.Data;
import seng302.Model.Boat;
import seng302.Model.Marker;
import java.time.OffsetDateTime;
import java.util.List;
/**
* Created by esa46 on 21/04/17.
*/
public class RaceData {
private String raceID;
private String raceType;
private OffsetDateTime creationTimeDate;
private OffsetDateTime raceStartTime;
private List<Boat> participants;
// private List<Marker>
}
@@ -29,12 +29,6 @@ public class BoatInRace extends Boat {
private StringProperty position;
private double heading;
private Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
private long nextValidTime = 0;
private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
private static float trackPointTimeInterval = 5000; // every 1 seconds
private final int TRACK_POINT_LIMIT = 10;
private boolean trackVisible = true;
/**
@@ -269,44 +263,4 @@ public class BoatInRace extends Boat {
this.position.set(position);
}
/**
* Returns the boat's sampled track between start of race and current time.
* @return queue of track points
* @see seng302.Model.TrackPoint
*/
public Queue<TrackPoint> getTrack() {
return track;
}
/**
* Returns whether track is visible
* @return true if visible
*/
public boolean isTrackVisible() {
return trackVisible;
}
/**
* Sets track visibility.
* @param trackVisible visible if true.
*/
public void setTrackVisible(boolean trackVisible) {
this.trackVisible = trackVisible;
}
/**
* Get base track point time interval
* @return base track point time interval
*/
public static float getBaseTrackPointTimeInterval() {
return BASE_TRACK_POINT_TIME_INTERVAL;
}
/**
* Set track point time interval
* @param value track point time interval value
*/
public static void setTrackPointTimeInterval(float value) {
trackPointTimeInterval = value;
}
}
@@ -1,23 +0,0 @@
package seng302.Model;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
import seng302.GPSCoordinate;
import seng302.RaceDataSource;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
/**
* Created by cbt24 on 6/03/17.
*
*/
public class ConstantVelocityRace{
}
@@ -0,0 +1,42 @@
package seng302.Model;
import seng302.Data.RaceData;
import seng302.Model.Race;
import seng302.RaceDataSource;
/**
* Created by esa46 on 21/04/17.
*/
public class Event {
RaceDataSource raceData;
public Event(RaceDataSource raceData) {
this.raceData = raceData;
}
public void start() {
sendRegattaData();
sendRaceData();
sendBoatData();
Race newRace = new Race(raceData, 15);
new Thread((newRace)).start();
}
public void sendRegattaData() {
}
public void sendRaceData() {
RaceData raceData = new RaceData();
}
public void sendBoatData() {
}
}
@@ -55,10 +55,6 @@ public class Race implements Runnable {
}
}
public Race(BoatInRace[] startingBoats, List<Leg> legs, int scaleFactor) {
this(Arrays.asList(startingBoats), legs, scaleFactor);
}
public Race(RaceDataSource raceData, int scaleFactor) {
this(raceData.getBoats(), raceData.getLegs(), scaleFactor);
}
@@ -150,9 +146,7 @@ public class Race implements Runnable {
}
}
}
}
}.start();
}
@@ -171,15 +165,11 @@ public class Race implements Runnable {
}
}
public void initialiseBoats() {
Leg officialStart = legs.get(0);
String name = officialStart.getName();
Marker endMarker = officialStart.getEndMarker();
BoatInRace.setTrackPointTimeInterval(BoatInRace.getBaseTrackPointTimeInterval() / scaleFactor);
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
for (int i = 0; i < startingBoats.size(); i++) {
BoatInRace boat = startingBoats.get(i);
@@ -321,7 +311,6 @@ public class Race implements Runnable {
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
}
/**
* Returns the boats that have started the race.
*
@@ -1,50 +0,0 @@
package seng302.Model;
import seng302.GPSCoordinate;
/**
* Created by cbt24 on 7/04/17.
*/
public class TrackPoint {
private GPSCoordinate coordinate;
private long timeAdded;
private long expiry;
private double minAlpha;
/**
* Creates a new track point with fixed GPS coordinates and time, to reach minimum opacity on expiry.
* @param coordinate position of point on physical race map
* @param timeAdded system clock at time of addition
* @param expiry time to minimum opacity after added
*/
public TrackPoint(GPSCoordinate coordinate, long timeAdded, long expiry) {
this.coordinate = coordinate;
this.timeAdded = timeAdded;
this.expiry = expiry;
this.minAlpha = 0.1;
}
/**
* Gets the position of the point on physical race map.
* @return GPS coordinate of point
*/
public GPSCoordinate getCoordinate() {
return coordinate;
}
/**
* Gets opacity of point scaled by age in proportion to expiry, between 1 and minimum opacity inclusive.
* @return greater of minimum opacity and scaled opacity
*/
public double getAlpha() {
return Double.max(minAlpha,1.0 - (double)(System.currentTimeMillis() - timeAdded) / expiry);
}
/**
* Gets time point was added to track.
* @return system clock at time of addition
*/
public long getTimeAdded() {
return timeAdded;
}
}