Making the course limits change when a new xml packet is received..

#story[889]
This commit is contained in:
Kusal Ekanayake
2017-05-11 15:49:49 +12:00
parent 711f6f4c45
commit 4a75c062ce
4 changed files with 33 additions and 3 deletions
+3 -1
View File
@@ -62,7 +62,9 @@ public class App extends Application
}
//Change the StreamReceiver in this else block to change the default data source.
else{
sr = new StreamReceiver("localhost", 4949, "RaceStream");
// sr = new StreamReceiver("localhost", 4949, "RaceStream");
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
}
sr.start();
@@ -240,6 +240,17 @@ public class CanvasController {
}
}
}
checkForCourseChanges();
}
private void checkForCourseChanges() {
if (StreamParser.isNewXmlRecieved()){
System.out.println("New Canvas found");
gc.setFill(Color.SKYBLUE);
gc.fillRect(0,0, CANVAS_WIDTH, CANVAS_HEIGHT);
gc.restore();
addRaceBorder();
}
}
private void move(long id, RaceObject raceObject){
@@ -345,6 +356,7 @@ public class CanvasController {
* Calculates x and y location for every marker that fits it to the canvas the race will be drawn on.
*/
private void fitMarksToCanvas() {
StreamParser.isNewXmlRecieved();
findMinMaxPoint();
double minLonToMaxLon = scaleRaceExtremities();
calculateReferencePointLocation(minLonToMaxLon);
@@ -31,6 +31,7 @@ public class StreamParser extends Thread{
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>();
private String threadName;
private Thread t;
private static boolean newXmlRecieved = false;
private static boolean raceStarted = false;
private static XMLParser xmlObject;
private static boolean raceFinished = false;
@@ -122,6 +123,8 @@ public class StreamParser extends Thread{
extractDisplayMessage(packet);
break;
case XML_MESSAGE:
System.out.println("XML MESSAGE GOT");
newXmlRecieved = true;
extractXmlMessage(packet);
break;
case RACE_START_STATUS:
@@ -313,6 +316,9 @@ public class StreamParser extends Thread{
if (messageType == 7) { //7 is the boat XML
boats = xmlObject.getBoatXML().getCompetingBoats();
}
if (messageType == 6) { //6 is race info xml
newXmlRecieved = true;
}
}
/**
@@ -579,5 +585,14 @@ public class StreamParser extends Thread{
appRunning = false;
System.out.println("[CLIENT] Shutting down stream parser");
}
public static boolean isNewXmlRecieved(){
if (newXmlRecieved){
newXmlRecieved = false;
return true;
} else {
return false;
}
}
}