Now reads course wind direction from the live stream, so the wind arrow now changes when the wind changes. #story[882]
This commit is contained in:
@@ -17,6 +17,7 @@ public class RaceStatus extends AC35Data {
|
|||||||
private int windSpeed;
|
private int windSpeed;
|
||||||
private int raceType;
|
private int raceType;
|
||||||
private ArrayList<BoatStatus> boatStatuses;
|
private ArrayList<BoatStatus> boatStatuses;
|
||||||
|
private static final double windDirectionScalar = 360.0 / 32768.0; // 0x8000 / 360
|
||||||
|
|
||||||
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, ArrayList<BoatStatus> boatStatuses){
|
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, ArrayList<BoatStatus> boatStatuses){
|
||||||
super(MessageType.RACESTATUS);
|
super(MessageType.RACESTATUS);
|
||||||
@@ -121,4 +122,8 @@ public class RaceStatus extends AC35Data {
|
|||||||
public boolean isPrestart() {
|
public boolean isPrestart() {
|
||||||
return raceStatus == 10;
|
return raceStatus == 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getScaledWindDirection() {
|
||||||
|
return (double) windDirection * windDirectionScalar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class StreamedCourse extends Observable implements RaceDataSource {
|
|||||||
StreamedCourseXMLReader streamedCourseXMLReader = null;
|
StreamedCourseXMLReader streamedCourseXMLReader = null;
|
||||||
BoatXMLReader boatXMLReader = null;
|
BoatXMLReader boatXMLReader = null;
|
||||||
RegattaXMLReader regattaXMLReader = null;
|
RegattaXMLReader regattaXMLReader = null;
|
||||||
|
private double windDirection = 0;
|
||||||
|
|
||||||
public StreamedCourse() {}
|
public StreamedCourse() {}
|
||||||
|
|
||||||
@@ -54,6 +55,14 @@ public class StreamedCourse extends Observable implements RaceDataSource {
|
|||||||
notifyObservers();
|
notifyObservers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWindDirection(double windDirection) {
|
||||||
|
this.windDirection = windDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWindDirection() {
|
||||||
|
return windDirection;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasReadRegatta() { return regattaXMLReader != null; }
|
public boolean hasReadRegatta() { return regattaXMLReader != null; }
|
||||||
|
|
||||||
public boolean hasReadBoats() { return boatXMLReader != null; }
|
public boolean hasReadBoats() { return boatXMLReader != null; }
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import javafx.scene.paint.Paint;
|
|||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
import seng302.*;
|
import seng302.*;
|
||||||
import seng302.Controllers.RaceController;
|
import seng302.Controllers.RaceController;
|
||||||
|
import seng302.Mock.StreamedCourse;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -29,6 +30,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
private List<Color> colours;
|
private List<Color> colours;
|
||||||
private List<Marker> markers;
|
private List<Marker> markers;
|
||||||
double[] xpoints = {}, ypoints = {};
|
double[] xpoints = {}, ypoints = {};
|
||||||
|
RaceDataSource raceData;
|
||||||
|
|
||||||
public ResizableRaceCanvas(RaceDataSource raceData) {
|
public ResizableRaceCanvas(RaceDataSource raceData) {
|
||||||
super();
|
super();
|
||||||
@@ -42,6 +44,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
|
|
||||||
this.markers = raceData.getMarkers();
|
this.markers = raceData.getMarkers();
|
||||||
makeColours();
|
makeColours();
|
||||||
|
this.raceData = raceData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +136,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
* @param angle Angle that the arrow is to be facing in degrees 0 degrees = North (Up).
|
* @param angle Angle that the arrow is to be facing in degrees 0 degrees = North (Up).
|
||||||
* @see GraphCoordinate
|
* @see GraphCoordinate
|
||||||
*/
|
*/
|
||||||
private void displayArrow(GraphCoordinate coordinate, int angle) {
|
private void displayArrow(GraphCoordinate coordinate, double angle) {
|
||||||
gc.save();
|
gc.save();
|
||||||
rotate(angle, coordinate.getX(), coordinate.getY());
|
rotate(angle, coordinate.getX(), coordinate.getY());
|
||||||
gc.setFill(Color.BLACK);
|
gc.setFill(Color.BLACK);
|
||||||
@@ -236,7 +239,11 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
drawMarkers();
|
drawMarkers();
|
||||||
|
|
||||||
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
||||||
displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150);
|
if (raceData instanceof StreamedCourse) {
|
||||||
|
displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), ((StreamedCourse) raceData).getWindDirection());
|
||||||
|
} else {
|
||||||
|
displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -363,4 +370,4 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -157,6 +157,13 @@ public class VisualiserInput implements Runnable {
|
|||||||
return markRoundingMap;
|
return markRoundingMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the wind direction for the current course.
|
||||||
|
*/
|
||||||
|
private void setCourseWindDirection(double direction) {
|
||||||
|
this.course.setWindDirection(direction);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads and returns the next message as an array of bytes from the socket. Use getNextMessage() to get the actual message object instead.
|
* Reads and returns the next message as an array of bytes from the socket. Use getNextMessage() to get the actual message object instead.
|
||||||
* @return Encoded binary message bytes.
|
* @return Encoded binary message bytes.
|
||||||
@@ -286,6 +293,7 @@ public class VisualiserInput implements Runnable {
|
|||||||
for (BoatStatus boatStatus: this.raceStatus.getBoatStatuses()) {
|
for (BoatStatus boatStatus: this.raceStatus.getBoatStatuses()) {
|
||||||
this.boatStatusMap.put(boatStatus.getSourceID(), boatStatus);
|
this.boatStatusMap.put(boatStatus.getSourceID(), boatStatus);
|
||||||
}
|
}
|
||||||
|
setCourseWindDirection(raceStatus.getScaledWindDirection() + 180);
|
||||||
}
|
}
|
||||||
//DisplayTextMessage.
|
//DisplayTextMessage.
|
||||||
/*else if (message instanceof DisplayTextMessage) {
|
/*else if (message instanceof DisplayTextMessage) {
|
||||||
|
|||||||
Reference in New Issue
Block a user