Merge branch 'splitIntoTwoModules' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into splitIntoTwoModules
This commit is contained in:
@@ -3,6 +3,7 @@ package seng302.Controllers;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import seng302.RaceDataSource;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -16,8 +17,8 @@ public class MainController extends Controller {
|
||||
@FXML
|
||||
RaceController raceController;
|
||||
|
||||
public void beginRace(int scaleFactor, RaceDataSource raceData) {
|
||||
raceController.startRace(scaleFactor, raceData);
|
||||
public void beginRace(VisualiserInput visualiserInput) {
|
||||
raceController.startRace(visualiserInput);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import seng302.Mock.StreamedRace;
|
||||
import seng302.Model.*;
|
||||
import seng302.RaceDataSource;
|
||||
import seng302.RaceXMLReader;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
@@ -114,13 +115,13 @@ public class RaceController extends Controller {
|
||||
* Initializes and runs the race, based on the user's chosen scale factor
|
||||
* Currently uses an example racecourse
|
||||
*
|
||||
* @param scaleFactor scale value of race
|
||||
* @param visualiserInput
|
||||
*/
|
||||
public void startRace(int scaleFactor, RaceDataSource raceData) {
|
||||
StreamedRace newRace = new StreamedRace(raceData, this, scaleFactor);
|
||||
public void startRace(VisualiserInput visualiserInput) {
|
||||
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
||||
//newRace.initialiseBoats();
|
||||
|
||||
raceMap = new ResizableRaceCanvas(raceData);
|
||||
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
||||
raceMap.setMouseTransparent(true);
|
||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||
@@ -133,8 +134,8 @@ public class RaceController extends Controller {
|
||||
|
||||
//Initialize save annotation array, fps listener, and annotation listeners
|
||||
//timezone
|
||||
RaceClock raceClock = new RaceClock(raceData.getZonedDateTime());
|
||||
timeZone.setText(raceClock.getTimeZone());
|
||||
// RaceClock raceClock = new RaceClock(visualiserInput.getCourse().getZonedDateTime());
|
||||
// timeZone.setText(raceClock.getTimeZone());
|
||||
initializeFPS();
|
||||
initializeAnnotations();
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import seng302.RaceDataSource;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
@@ -53,6 +55,8 @@ public class StartController extends Controller implements Observer {
|
||||
private StreamedCourse raceData;
|
||||
private long timeLeft = 1;
|
||||
|
||||
private VisualiserInput visualiserInput;
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 15
|
||||
*/
|
||||
@@ -88,7 +92,7 @@ public class StartController extends Controller implements Observer {
|
||||
try {
|
||||
raceData = new StreamedCourse();
|
||||
raceData.addObserver(this);
|
||||
VisualiserInput visualiserInput = new VisualiserInput(raceData);
|
||||
visualiserInput = new VisualiserInput(new Socket("livedata.americascup.com", 4941), raceData);
|
||||
new Thread(visualiserInput).start();
|
||||
// StreamedCourse streamedCourse = new StreamedCourse(new BoatXMLReader("mockXML/boatXML/boatTest.xml"));
|
||||
// streamedCourse.setStreamedCourseXMLReader(new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml"));
|
||||
@@ -150,7 +154,7 @@ public class StartController extends Controller implements Observer {
|
||||
if (timeLeft <= 0) {
|
||||
updateTime("Race is starting...");
|
||||
stop();
|
||||
parent.beginRace(scaleFactor, raceData);
|
||||
parent.beginRace(visualiserInput);
|
||||
startWrapper.setVisible(false);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -80,12 +80,15 @@ public class StreamedCourseXMLReader extends XMLReader {
|
||||
private void readRace() throws ParseException {
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
||||
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
||||
|
||||
if (raceTimeTag.getNamedItem("Time") != null) dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
|
||||
|
||||
System.out.println(getTextValueOfNode(settings, "CreationTimeDate"));
|
||||
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
||||
raceType = getTextValueOfNode(settings, "RaceType");
|
||||
creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
|
||||
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
||||
|
||||
if (raceTimeTag.getNamedItem("Time") != null) raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
|
||||
else raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Start").getTextContent(), dateFormat);
|
||||
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
||||
@@ -93,6 +96,7 @@ public class StreamedCourseXMLReader extends XMLReader {
|
||||
|
||||
private void readParticipants() {
|
||||
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
|
||||
nParticipants.getChildNodes().getLength();
|
||||
for (int i = 0; i < nParticipants.getChildNodes().getLength(); i++) {
|
||||
int sourceID;
|
||||
Node yacht = nParticipants.getChildNodes().item(i);
|
||||
@@ -160,7 +164,8 @@ public class StreamedCourseXMLReader extends XMLReader {
|
||||
* @return value of "compoundMarkID" attribute
|
||||
*/
|
||||
private int getCompoundMarkID(Element element) {
|
||||
return Integer.parseInt(element.getAttribute("CompoundMarkID"));
|
||||
//return Integer.parseInt(element.getAttribute("CompoundMarkID"));
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,10 @@ import seng302.Constants;
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.*;
|
||||
import seng302.Networking.MessageDecoders.BoatLocationDecoder;
|
||||
import seng302.Networking.Utils.BoatLocationMessage;
|
||||
import seng302.RaceDataSource;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.*;
|
||||
@@ -15,12 +18,12 @@ import java.util.*;
|
||||
* Created by jjg64 on 21/04/17.
|
||||
*/
|
||||
public class StreamedRace extends Race {
|
||||
private RaceDataSource raceData;
|
||||
private VisualiserInput visualiserInput;
|
||||
private double MMPS_TO_KN = 0.001944;
|
||||
|
||||
public StreamedRace(RaceDataSource raceData, RaceController controller, int scaleFactor) {
|
||||
super(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor);
|
||||
this.raceData = raceData;
|
||||
this.scaleFactor = 1; // There will be no scaling in a live streamed race
|
||||
public StreamedRace(VisualiserInput visualiserInput, RaceController controller) {
|
||||
super(visualiserInput.getCourse(), controller, 1);
|
||||
this.visualiserInput = visualiserInput;
|
||||
}
|
||||
|
||||
public void initialiseBoats() {
|
||||
@@ -72,8 +75,16 @@ public class StreamedRace extends Race {
|
||||
* @param millisecondsElapsed time since last update
|
||||
*/
|
||||
protected void updatePosition(Boat boat, int millisecondsElapsed) {
|
||||
//TODO Grab info from network
|
||||
// setPosition(boat, coordinate);
|
||||
int sourceID = boat.getSourceID();
|
||||
BoatLocationMessage boatLocationMessage = visualiserInput.getBoatLocationMessage(sourceID);
|
||||
if(boatLocationMessage != null) {
|
||||
System.out.println(sourceID);
|
||||
double lat = boatLocationMessage.getLatitudeDouble();
|
||||
double lon = boatLocationMessage.getLongitudeDouble();
|
||||
boat.setCurrentPosition(new GPSCoordinate(lat, lon));
|
||||
boat.setHeading(boatLocationMessage.getHeadingDegrees());
|
||||
boat.setVelocity(boatLocationMessage.getBoatSpeed() * MMPS_TO_KN);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setPosition(Boat boat, GPSCoordinate coordinate) {
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Boat {
|
||||
protected long timeFinished;
|
||||
protected StringProperty position;
|
||||
protected boolean started = false;
|
||||
protected boolean dnf = false;
|
||||
private double wakeScale = 1 / 50;
|
||||
private int sourceID;
|
||||
|
||||
@@ -234,4 +235,12 @@ public class Boat {
|
||||
public int getSourceID() {
|
||||
return this.sourceID;
|
||||
}
|
||||
|
||||
public boolean isDnf() {
|
||||
return dnf;
|
||||
}
|
||||
|
||||
public void setDnf(boolean dnf) {
|
||||
this.dnf = dnf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.RaceDataSource;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
@@ -31,7 +32,7 @@ public abstract class Race implements Runnable {
|
||||
|
||||
protected int scaleFactor;
|
||||
|
||||
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
||||
protected int PRERACE_TIME = 0; //time in milliseconds to pause during pre-race
|
||||
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
||||
|
||||
/**
|
||||
@@ -69,6 +70,10 @@ public abstract class Race implements Runnable {
|
||||
this(Arrays.asList(startingBoats), legs, controller, scaleFactor);
|
||||
}
|
||||
|
||||
public void setController(RaceController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public abstract void initialiseBoats();
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,9 +51,10 @@ public class VisualiserInput implements Runnable
|
||||
private RaceStartStatus raceStartStatus;
|
||||
|
||||
public VisualiserInput(StreamedCourse course) throws IOException{
|
||||
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
||||
|
||||
//connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||
this.connectionSocket = socket;
|
||||
// this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||
|
||||
this.course = course;
|
||||
this.boatLocation = new HashMap<>();
|
||||
@@ -188,7 +189,7 @@ public class VisualiserInput implements Runnable
|
||||
lastHeartbeatTime = System.currentTimeMillis();
|
||||
//note: if the program runs for over 340 years, this will crash.
|
||||
heartbeatSeqNum = ByteConverter.bytesToLong(testDecoder.getMessage());
|
||||
System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
||||
// System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
||||
break;
|
||||
case RACESTATUS:
|
||||
System.out.println("Race Status Message");
|
||||
@@ -243,6 +244,7 @@ public class VisualiserInput implements Runnable
|
||||
//no decoder
|
||||
break;
|
||||
case BOATLOCATION:
|
||||
System.out.println("Boat Location!");
|
||||
BoatLocationMessage msg = (BoatLocationMessage) data;
|
||||
if (boatLocation.containsKey(msg.getSourceID())){
|
||||
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
|
||||
@@ -286,7 +288,8 @@ public class VisualiserInput implements Runnable
|
||||
|
||||
public static void main(String argv[]) throws Exception
|
||||
{
|
||||
VisualiserInput receiver = new VisualiserInput(new StreamedCourse());
|
||||
Socket socket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
VisualiserInput receiver = new VisualiserInput(socket, new StreamedCourse());
|
||||
receiver.run();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,4 +44,5 @@ public class BoatsXMLTest {
|
||||
StreamedBoat boat = (StreamedBoat) boatXMLReader.getBoats().get(0);
|
||||
assertEquals(boat.getSourceID(), 101);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user