mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'wake_remake' into Story30b_correcting_boat_movement
# Conflicts: # src/main/java/seng302/controllers/CanvasController.java # src/main/java/seng302/models/BoatGroup.java # src/main/java/seng302/models/parsers/StreamParser.java
This commit is contained in:
@@ -32,10 +32,10 @@ public class StreamParser extends Thread{
|
||||
private String threadName;
|
||||
private Thread t;
|
||||
private static boolean raceStarted = false;
|
||||
|
||||
|
||||
|
||||
|
||||
private static boolean raceFinished = false;
|
||||
private static boolean streamStatus = false;
|
||||
private static long timeSinceStart = -1;
|
||||
private static List<Boat> boats = new ArrayList<>();
|
||||
|
||||
public StreamParser(String threadName){
|
||||
this.threadName = threadName;
|
||||
@@ -48,6 +48,7 @@ public class StreamParser extends Thread{
|
||||
public void run(){
|
||||
try {
|
||||
System.out.println("START OF STREAM");
|
||||
streamStatus = true;
|
||||
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
|
||||
Thread.sleep(1);
|
||||
}
|
||||
@@ -158,16 +159,21 @@ public class StreamParser extends Thread{
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
|
||||
if (timeTillStart > 0 && timeTillStart % 10 == 0) {
|
||||
timeSinceStart = timeTillStart;
|
||||
System.out.println("Time till start: " + timeTillStart + " Seconds");
|
||||
} else {
|
||||
if (raceStatus == 4 || raceStatus == 8){
|
||||
raceFinished = true;
|
||||
raceStarted = false;
|
||||
System.out.println("RACE HAS FINISHED");
|
||||
} else if (!raceStarted){
|
||||
raceStarted = true;
|
||||
raceFinished = false;
|
||||
System.out.println("RACE HAS STARTED");
|
||||
}
|
||||
if (timeTillStart % 10 == 0){
|
||||
//System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
||||
System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
||||
timeSinceStart = timeTillStart;
|
||||
}
|
||||
}
|
||||
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
||||
@@ -184,7 +190,6 @@ public class StreamParser extends Thread{
|
||||
boatStatus += "\nEstTimeAtNextMark: " + extractTimeStamp(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20)), 6);
|
||||
boatStatus += "\nEstTimeAtFinish: " + extractTimeStamp(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)), 6);
|
||||
boatStatuses.add(boatStatus);
|
||||
// System.out.println("boatStatus = " + boatStatus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,19 +233,25 @@ public class StreamParser extends Thread{
|
||||
//Converts XML message to string to be parsed
|
||||
int currentChar;
|
||||
while (payloadStream.available() > 0 && (currentChar = payloadStream.read()) != 0) {
|
||||
xmlMessage += (char)currentChar;
|
||||
xmlMessage += (char)currentChar;
|
||||
}
|
||||
|
||||
// Parse boat xml from server
|
||||
if (xmlMessageSubType == 7) {
|
||||
BoatsParser boatsParser = new BoatsParser(xmlMessage);
|
||||
boats = boatsParser.getBoats();
|
||||
}
|
||||
|
||||
//Create XML document Object
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = null;
|
||||
try {
|
||||
db = dbf.newDocumentBuilder();
|
||||
Document doc = db.parse(new InputSource(new StringReader(xmlMessage)));
|
||||
// TODO: 25/04/17 ajm412: Check that the object matches expected structure and return Document object.
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
// DocumentBuilder db = null;
|
||||
// try {
|
||||
// db = dbf.newDocumentBuilder();
|
||||
// Document doc = db.parse(new InputSource(new StringReader(xmlMessage)));
|
||||
// // TODO: 25/04/17 ajm412: Check that the object matches expected structure and return Document object.
|
||||
// } catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -417,5 +428,50 @@ public class StreamParser extends Thread{
|
||||
}
|
||||
return partialLong;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns false if race not started, true otherwise
|
||||
*
|
||||
* @return race started status
|
||||
*/
|
||||
public static boolean isRaceStarted() {
|
||||
return raceStarted;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns false if stream not connected, true otherwise
|
||||
*
|
||||
* @return stream started status
|
||||
*/
|
||||
public static boolean isStreamStatus() {
|
||||
return streamStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns race timer
|
||||
*
|
||||
* @return race timer in long
|
||||
*/
|
||||
public static long getTimeSinceStart() {
|
||||
return timeSinceStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* return false if race not finished, true otherwise
|
||||
*
|
||||
* @return race finished status
|
||||
*/
|
||||
public static boolean isRaceFinished() {
|
||||
return raceFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* return list of boats from the server
|
||||
*
|
||||
* @return list of boats
|
||||
*/
|
||||
public static List<Boat> getBoats() {
|
||||
return boats;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user