From 04ce6f6103e7a42d124b4ca512b696962cb98f36 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Tue, 2 May 2017 14:18:40 +1200 Subject: [PATCH 1/3] Removed white behind fps counter --- src/main/java/seng302/App.java | 4 ++-- src/main/java/seng302/controllers/CanvasController.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index bd4de5ef..c86ef5d1 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -34,8 +34,8 @@ public class App extends Application sr = new StreamReceiver("localhost", 8085, "RaceStream"); } else{ - sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"RaceStream"); -// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); +// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"RaceStream"); + sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); // sr = new StreamReceiver("localhost", 8085, "RaceStream"); } diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 94721e39..b3406cb0 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -209,6 +209,8 @@ public class CanvasController { private void drawFps(int fps){ if (raceViewController.isDisplayFps()){ gc.clearRect(5,5,50,20); + gc.setFill(Color.SKYBLUE); + gc.fillRect(4,4,51,21); gc.setFill(Color.BLACK); gc.setFont(new Font(14)); gc.setLineWidth(3); From 3af15b2b95a82e7480d46910099b7e1d535b4493 Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Tue, 2 May 2017 18:02:44 +1200 Subject: [PATCH 2/3] Updated wind direction on race view controller so it responds to the stream. #story[818] --- .../controllers/RaceViewController.java | 21 +++++++++++++++---- .../seng302/models/parsers/StreamParser.java | 12 +++++++++++ .../java/seng302/server/ServerThread.java | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index 8468376d..6112be11 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -69,11 +69,11 @@ public class RaceViewController extends Thread{ includedCanvasController.initializeCanvas(); initializeTimer(); initializeSettings(); - + initialiseWindDirection(); //set wind direction!!!!!!! can't find another place to put my code --haoming - double windDirection = new ConfigParser("/config/config.xml").getWindDirection(); - windDirectionText.setText(String.format("%.1f°", windDirection)); - windArrowText.setRotate(windDirection); +// double windDirection = new ConfigParser("/config/config.xml").getWindDirection(); +// windDirectionText.setText(String.format("%.1f°", windDirection)); +// windArrowText.setRotate(windDirection); includedCanvasController.timer.start(); } @@ -145,6 +145,19 @@ public class RaceViewController extends Thread{ timerTimeline.playFromStart(); } + private void initialiseWindDirection() { + Timeline windDirTimeline = new Timeline(); + windDirTimeline.setCycleCount(Timeline.INDEFINITE); + windDirTimeline.getKeyFrames().add( + new KeyFrame(Duration.seconds(1), + event -> { + windDirectionText.setText(String.format("%.1f°", StreamParser.getWindDirection())); + windArrowText.setRotate(StreamParser.getWindDirection()); + }) + ); + windDirTimeline.playFromStart(); + } + /** * Generates time line for each boat, and stores time time into timelineInfos hash map */ diff --git a/src/main/java/seng302/models/parsers/StreamParser.java b/src/main/java/seng302/models/parsers/StreamParser.java index e2efd773..ff520e8a 100644 --- a/src/main/java/seng302/models/parsers/StreamParser.java +++ b/src/main/java/seng302/models/parsers/StreamParser.java @@ -39,6 +39,7 @@ public class StreamParser extends Thread{ private static boolean streamStatus = false; private static long timeSinceStart = -1; private static List boats = new ArrayList<>(); + private static double windDirection = 0; /** * Used to initialise the thread name and stream parser object so a thread can be executed @@ -194,6 +195,8 @@ public class StreamParser extends Thread{ timeSinceStart = timeTillStart; } long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20)); + double windDirFactor = 0x4000 / 90; //0x4000 is 90 degrees, 0x8000 is 180 degrees, etc... + windDirection = windDir / windDirFactor; long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22)); int noBoats = payload[22]; int raceType = payload[23]; @@ -487,5 +490,14 @@ public class StreamParser extends Thread{ public static XMLParser getXmlObject() { return xmlObject; } + + /** + * returns the wind direction in degrees + * + * @return a double wind direction value + */ + public static double getWindDirection() { + return windDirection; + } } diff --git a/src/main/java/seng302/server/ServerThread.java b/src/main/java/seng302/server/ServerThread.java index e4e5a84a..804ee5f5 100644 --- a/src/main/java/seng302/server/ServerThread.java +++ b/src/main/java/seng302/server/ServerThread.java @@ -265,7 +265,7 @@ public class ServerThread implements Runnable, Observer { for (Boat b : ((Simulator) o).getBoats()){ try { Message m = new BoatLocationMessage(b.getSourceID(), 1, b.getLat(), - b.getLng(), b.getHeadingCorner().getBearingToNextCorner(), + b.getLng(), b.getLastPassedCorner().getBearingToNextCorner(), ((long) b.getSpeed())); server.send(m); } catch (IOException e) { From 8233b75e0597b546c3edf2fe503ac2d108d4ceec Mon Sep 17 00:00:00 2001 From: Zhi You Tan Date: Tue, 2 May 2017 18:52:31 +1200 Subject: [PATCH 3/3] Fixed the start screen team list after merging. Team list shows boats competing in event again. #story[572] --- src/main/java/seng302/controllers/Controller.java | 11 +++++------ .../java/seng302/models/parsers/StreamParser.java | 11 +++++++---- src/main/java/seng302/models/parsers/XMLParser.java | 9 +++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/seng302/controllers/Controller.java b/src/main/java/seng302/controllers/Controller.java index 2baa46c4..26f75d52 100644 --- a/src/main/java/seng302/controllers/Controller.java +++ b/src/main/java/seng302/controllers/Controller.java @@ -15,7 +15,6 @@ import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; -import seng302.models.Boat; import seng302.models.parsers.StreamParser; import seng302.models.parsers.XMLParser; @@ -124,18 +123,18 @@ public class Controller implements Initializable { } private void updateTeamList() { - ObservableList data = FXCollections.observableArrayList(); + ObservableList data = FXCollections.observableArrayList(); teamList.setItems(data); boatNameCol.setCellValueFactory( - new PropertyValueFactory("boatName") + new PropertyValueFactory("BoatName") ); shortNameCol.setCellValueFactory( - new PropertyValueFactory("shortName") + new PropertyValueFactory("ShortName") ); countryCol.setCellValueFactory( - new PropertyValueFactory("country") + new PropertyValueFactory("Country") ); - for (Boat boat : StreamParser.getBoats()) { + for (XMLParser.BoatXMLObject.Boat boat : StreamParser.getBoats()) { data.add(boat); } } diff --git a/src/main/java/seng302/models/parsers/StreamParser.java b/src/main/java/seng302/models/parsers/StreamParser.java index ff520e8a..b0eed3aa 100644 --- a/src/main/java/seng302/models/parsers/StreamParser.java +++ b/src/main/java/seng302/models/parsers/StreamParser.java @@ -5,7 +5,6 @@ import javafx.geometry.Point3D; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import seng302.models.Boat; import seng302.models.parsers.packets.BoatPositionPacket; import seng302.models.parsers.packets.StreamPacket; @@ -38,7 +37,7 @@ public class StreamParser extends Thread{ private static boolean raceFinished = false; private static boolean streamStatus = false; private static long timeSinceStart = -1; - private static List boats = new ArrayList<>(); + private static List boats = new ArrayList<>(); private static double windDirection = 0; /** @@ -202,7 +201,8 @@ public class StreamParser extends Thread{ int raceType = payload[23]; ArrayList boatStatuses = new ArrayList<>(); for (int i = 0; i < noBoats; i++){ - String boatStatus = "SourceID: " + bytesToLong(Arrays.copyOfRange(payload,24 + (i * 20),28+ (i * 20))); + Long boatStatusSourceID = bytesToLong(Arrays.copyOfRange(payload,24 + (i * 20),28+ (i * 20))); + String boatStatus = "SourceID: " + boatStatusSourceID; boatStatus += "\nBoat Status: " + (int)payload[28 + (i * 20)]; boatStatus += "\nLegNumber: " + (int)payload[29 + (i * 20)]; boatStatus += "\nPenaltiesAwarded: " + (int)payload[29 + (i * 20)]; @@ -258,6 +258,9 @@ public class StreamParser extends Thread{ } xmlObject.constructXML(doc, messageType); + if (messageType == 7) { //7 is the boat XML + boats = xmlObject.getBoatXML().getCompetingBoats(); + } } /** @@ -477,7 +480,7 @@ public class StreamParser extends Thread{ * * @return list of boats */ - public static List getBoats() { + public static List getBoats() { return boats; } diff --git a/src/main/java/seng302/models/parsers/XMLParser.java b/src/main/java/seng302/models/parsers/XMLParser.java index a50cbcbc..43016500 100644 --- a/src/main/java/seng302/models/parsers/XMLParser.java +++ b/src/main/java/seng302/models/parsers/XMLParser.java @@ -6,6 +6,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.ArrayList; +import java.util.List; /** * Class to create an XML object from the XML Packet Messages. @@ -393,6 +394,8 @@ public class XMLParser { //Boats ArrayList boats; + //Competing boats + List competingBoats = new ArrayList<>(); /** * Constructor for a BoatXMLObject. @@ -427,6 +430,9 @@ public class XMLParser { if (currentBoat.getNodeName().equals("Boat")) { Boat boat = new Boat(currentBoat); this.boats.add(boat); + if (boat.getBoatType().equals("Yacht")) { + competingBoats.add(boat); + } } //System.out.println(this.getBoats()); } @@ -442,6 +448,9 @@ public class XMLParser { public Double getCourseZoneSize() { return courseZoneSize; } public ArrayList getZoneLimits() { return zoneLimits; } public ArrayList getBoats() { return boats; } + public List getCompetingBoats() { + return competingBoats; + } public class Boat {