mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Updated wind direction on race view controller so it responds to the stream.
#story[818]
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -39,6 +39,7 @@ public class StreamParser extends Thread{
|
||||
private static boolean streamStatus = false;
|
||||
private static long timeSinceStart = -1;
|
||||
private static List<Boat> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user