mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +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();
|
includedCanvasController.initializeCanvas();
|
||||||
initializeTimer();
|
initializeTimer();
|
||||||
initializeSettings();
|
initializeSettings();
|
||||||
|
initialiseWindDirection();
|
||||||
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
||||||
double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
|
// double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
|
||||||
windDirectionText.setText(String.format("%.1f°", windDirection));
|
// windDirectionText.setText(String.format("%.1f°", windDirection));
|
||||||
windArrowText.setRotate(windDirection);
|
// windArrowText.setRotate(windDirection);
|
||||||
includedCanvasController.timer.start();
|
includedCanvasController.timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +145,19 @@ public class RaceViewController extends Thread{
|
|||||||
timerTimeline.playFromStart();
|
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
|
* 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 boolean streamStatus = false;
|
||||||
private static long timeSinceStart = -1;
|
private static long timeSinceStart = -1;
|
||||||
private static List<Boat> boats = new ArrayList<>();
|
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
|
* 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;
|
timeSinceStart = timeTillStart;
|
||||||
}
|
}
|
||||||
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
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));
|
long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
|
||||||
int noBoats = payload[22];
|
int noBoats = payload[22];
|
||||||
int raceType = payload[23];
|
int raceType = payload[23];
|
||||||
@@ -487,5 +490,14 @@ public class StreamParser extends Thread{
|
|||||||
public static XMLParser getXmlObject() {
|
public static XMLParser getXmlObject() {
|
||||||
return xmlObject;
|
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()){
|
for (Boat b : ((Simulator) o).getBoats()){
|
||||||
try {
|
try {
|
||||||
Message m = new BoatLocationMessage(b.getSourceID(), 1, b.getLat(),
|
Message m = new BoatLocationMessage(b.getSourceID(), 1, b.getLat(),
|
||||||
b.getLng(), b.getHeadingCorner().getBearingToNextCorner(),
|
b.getLng(), b.getLastPassedCorner().getBearingToNextCorner(),
|
||||||
((long) b.getSpeed()));
|
((long) b.getSpeed()));
|
||||||
server.send(m);
|
server.send(m);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user