mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge remote-tracking branch 'origin/develop' into issue#5_fix_pre-race_boats_on_leaderboard
This commit is contained in:
@@ -62,7 +62,8 @@ 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("livedata.americascup.com", 4941, "RaceStream");
|
||||
}
|
||||
|
||||
sr.start();
|
||||
|
||||
@@ -25,7 +25,7 @@ public class RaceController {
|
||||
String teamsConfigFile = "/config/teams.xml";
|
||||
|
||||
try {
|
||||
race = createRace(raceConfigFile, teamsConfigFile);
|
||||
race = createRace(raceConfigFile, teamsConfigFile); //These config files arent actually used
|
||||
} catch (Exception e) {
|
||||
System.out.println("There was an error creating the race.");
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ package seng302.controllers;
|
||||
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
@@ -50,6 +51,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
@FXML
|
||||
private Button selectAnnotationBtn;
|
||||
@FXML
|
||||
private ComboBox boatSelectionComboBox;
|
||||
@FXML
|
||||
private CanvasController includedCanvasController;
|
||||
|
||||
private ArrayList<Yacht> startingBoats = new ArrayList<>();
|
||||
@@ -57,26 +60,27 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
private Timeline timerTimeline;
|
||||
private Race race;
|
||||
private Stage stage;
|
||||
|
||||
private ImportantAnnotationsState importantAnnotations;
|
||||
private Yacht selectedBoat;
|
||||
|
||||
public void initialize() {
|
||||
// Load a default important annotation state
|
||||
importantAnnotations = new ImportantAnnotationsState();
|
||||
|
||||
//Initialise race controller
|
||||
RaceController raceController = new RaceController();
|
||||
raceController.initializeRace();
|
||||
race = raceController.getRace();
|
||||
|
||||
for (Yacht boat : race.getBoats()) {
|
||||
startingBoats.add(boat);
|
||||
}
|
||||
startingBoats = new ArrayList<>(Arrays.asList(race.getBoats()));
|
||||
|
||||
includedCanvasController.setup(this);
|
||||
includedCanvasController.initializeCanvas();
|
||||
initializeTimer();
|
||||
initializeSettings();
|
||||
initialiseWindDirection();
|
||||
initialisePositionVBox();
|
||||
initializeUpdateTimer();
|
||||
initialiseFPSCheckBox();
|
||||
initialiseAnnotationSlider();
|
||||
initialiseBoatSelectionComboBox();
|
||||
includedCanvasController.timer.start();
|
||||
|
||||
selectAnnotationBtn.setOnAction(event -> {
|
||||
@@ -86,7 +90,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
|
||||
/**
|
||||
* The important annotations have been changed, update this view
|
||||
*
|
||||
* @param importantAnnotationsState The current state of the selected annotations
|
||||
*/
|
||||
public void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState) {
|
||||
@@ -110,7 +113,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
// Load FXML and set CSS
|
||||
fxmlLoader
|
||||
.setLocation(getClass().getResource("/views/importantAnnotationSelectView.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 469, 270);
|
||||
Scene scene = new Scene(fxmlLoader.load(), 469, 248);
|
||||
scene.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||
stage.initStyle(StageStyle.UNDECORATED);
|
||||
|
||||
@@ -124,18 +127,14 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeSettings() {
|
||||
|
||||
private void initialiseFPSCheckBox() {
|
||||
displayFps = true;
|
||||
|
||||
toggleFps.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
|
||||
Boolean newValue) {
|
||||
displayFps = !displayFps;
|
||||
toggleFps.selectedProperty().addListener(
|
||||
(observable, oldValue, newValue) -> displayFps = !displayFps);
|
||||
}
|
||||
});
|
||||
|
||||
//SLIDER STUFF BELOW
|
||||
private void initialiseAnnotationSlider() {
|
||||
annotationSlider.setLabelFormatter(new StringConverter<Double>() {
|
||||
@Override
|
||||
public String toString(Double n) {
|
||||
@@ -143,12 +142,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
return "None";
|
||||
}
|
||||
if (n == 1) {
|
||||
return "Low";
|
||||
}
|
||||
if (n == 2) {
|
||||
return "Important";
|
||||
}
|
||||
if (n == 3) {
|
||||
if (n == 2) {
|
||||
return "All";
|
||||
}
|
||||
|
||||
@@ -160,15 +156,13 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
switch (s) {
|
||||
case "None":
|
||||
return 0d;
|
||||
case "Low":
|
||||
return 1d;
|
||||
case "Important":
|
||||
return 2d;
|
||||
return 1d;
|
||||
case "All":
|
||||
return 3d;
|
||||
return 2d;
|
||||
|
||||
default:
|
||||
return 3d;
|
||||
return 2d;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -176,22 +170,27 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
annotationSlider.valueProperty().addListener((obs, oldval, newVal) ->
|
||||
setAnnotations((int) annotationSlider.getValue()));
|
||||
|
||||
annotationSlider.setValue(3);
|
||||
annotationSlider.setValue(2);
|
||||
}
|
||||
|
||||
private void initializeTimer() {
|
||||
|
||||
/**
|
||||
* Initalises a timer which updates elements of the RaceView such as wind direction, boat
|
||||
* orderings etc.. which are dependent on the info from the stream parser constantly.
|
||||
* Updates of each of these attributes are called ONCE EACH SECOND
|
||||
*/
|
||||
private void initializeUpdateTimer() {
|
||||
timerTimeline = new Timeline();
|
||||
timerTimeline.setCycleCount(Timeline.INDEFINITE);
|
||||
// Run timer update every second
|
||||
timerTimeline.getKeyFrames().add(
|
||||
new KeyFrame(Duration.seconds(1),
|
||||
event -> {
|
||||
if (StreamParser.isRaceFinished()) {
|
||||
timerLabel.setFill(Color.RED);
|
||||
timerLabel.setText("Race Finished!");
|
||||
} else {
|
||||
timerLabel.setText(currentTimer());
|
||||
}
|
||||
updateRaceTime();
|
||||
updateWindDirection();
|
||||
updateOrder();
|
||||
updateBoatSelectionComboBox();
|
||||
|
||||
})
|
||||
);
|
||||
|
||||
@@ -199,54 +198,45 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
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();
|
||||
}
|
||||
|
||||
private void initialisePositionVBox() {
|
||||
|
||||
Timeline posVBoxTimeline = new Timeline();
|
||||
posVBoxTimeline.setCycleCount(Timeline.INDEFINITE);
|
||||
posVBoxTimeline.getKeyFrames().add(
|
||||
new KeyFrame(Duration.seconds(1),
|
||||
event -> {
|
||||
showOrder();
|
||||
})
|
||||
);
|
||||
posVBoxTimeline.playFromStart();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the list of boats in the order they finished the race
|
||||
* Updates the wind direction arrow and text as from info from the StreamParser
|
||||
*/
|
||||
private void loadRaceResultView() {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/views/FinishView.fxml"));
|
||||
loader.setController(new RaceResultController(race));
|
||||
private void updateWindDirection() {
|
||||
windDirectionText.setText(String.format("%.1f°", StreamParser.getWindDirection()));
|
||||
windArrowText.setRotate(StreamParser.getWindDirection());
|
||||
}
|
||||
|
||||
try {
|
||||
contentAnchorPane.getChildren().removeAll();
|
||||
contentAnchorPane.getChildren().clear();
|
||||
contentAnchorPane.getChildren().addAll((Pane) loader.load());
|
||||
|
||||
} catch (javafx.fxml.LoadException e) {
|
||||
System.err.println(e.getCause());
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
/**
|
||||
* Updates the clock for the race
|
||||
*/
|
||||
private void updateRaceTime() {
|
||||
if (StreamParser.isRaceFinished()) {
|
||||
timerLabel.setFill(Color.RED);
|
||||
timerLabel.setText("Race Finished!");
|
||||
} else {
|
||||
timerLabel.setText(getTimeSinceStartOfRace());
|
||||
}
|
||||
}
|
||||
|
||||
private void showOrder() {
|
||||
|
||||
/**
|
||||
* Grabs the boats currently in the race as from the StreamParser and sets them to be selectable
|
||||
* in the boat selection combo box
|
||||
*/
|
||||
private void updateBoatSelectionComboBox() {
|
||||
ObservableList<Yacht> observableBoats = FXCollections
|
||||
.observableArrayList(StreamParser.getBoatsPos().values());
|
||||
boatSelectionComboBox.setItems(observableBoats);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the order of the boats as from the StreamParser and sets them in the boat order
|
||||
* section
|
||||
*/
|
||||
private void updateOrder() {
|
||||
positionVbox.getChildren().clear();
|
||||
positionVbox.getChildren().removeAll();
|
||||
positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||
@@ -279,6 +269,44 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialised the combo box with any boats currently in the race and adds the required listener
|
||||
* for the combobox to take action upon selection
|
||||
*/
|
||||
private void initialiseBoatSelectionComboBox() {
|
||||
updateBoatSelectionComboBox();
|
||||
boatSelectionComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||
//This listener is fired whenever the combo box changes. This means when the values are updated
|
||||
//We dont want to set the selected value if the values are updated but nothing clicked (null)
|
||||
if (newValue != null && newValue != selectedBoat) {
|
||||
Yacht thisYacht = (Yacht) newValue;
|
||||
setSelectedBoat(thisYacht);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display the list of boats in the order they finished the race
|
||||
*/
|
||||
private void loadRaceResultView() {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/views/FinishView.fxml"));
|
||||
loader.setController(new RaceResultController(race));
|
||||
|
||||
try {
|
||||
contentAnchorPane.getChildren().removeAll();
|
||||
contentAnchorPane.getChildren().clear();
|
||||
contentAnchorPane.getChildren().addAll((Pane) loader.load());
|
||||
|
||||
} catch (javafx.fxml.LoadException e) {
|
||||
System.err.println(e.getCause());
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert seconds to a string of the format mm:ss
|
||||
*
|
||||
@@ -292,7 +320,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
return String.format("%02d:%02d", time / 60, time % 60);
|
||||
}
|
||||
|
||||
private String currentTimer() {
|
||||
private String getTimeSinceStartOfRace() {
|
||||
String timerString = "0:00";
|
||||
if (StreamParser.getTimeSinceStart() > 0) {
|
||||
String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60);
|
||||
@@ -312,13 +340,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
return timerString;
|
||||
}
|
||||
|
||||
public void stopTimer() {
|
||||
timerTimeline.stop();
|
||||
}
|
||||
|
||||
public void startTimer() {
|
||||
timerTimeline.play();
|
||||
}
|
||||
|
||||
public boolean isDisplayFps() {
|
||||
return displayFps;
|
||||
@@ -328,13 +349,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
return race;
|
||||
}
|
||||
|
||||
public ArrayList<Yacht> getStartingBoats() {
|
||||
return startingBoats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the important annotations for a specific BoatGroup
|
||||
*
|
||||
* @param bg The boat group to set the annotations for
|
||||
*/
|
||||
private void setBoatGroupImportantAnnotations(BoatGroup bg) {
|
||||
@@ -391,22 +408,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Low Annotations
|
||||
case 1:
|
||||
for (RaceObject ro : includedCanvasController.getRaceObjects()) {
|
||||
if (ro instanceof BoatGroup) {
|
||||
BoatGroup bg = (BoatGroup) ro;
|
||||
bg.setTeamNameObjectVisible(true);
|
||||
bg.setVelocityObjectVisible(false);
|
||||
bg.setEstTimeToNextMarkObjectVisible(false);
|
||||
bg.setLegTimeObjectVisible(false);
|
||||
bg.setLineGroupVisible(false);
|
||||
bg.setWakeVisible(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Important Annotations
|
||||
case 2:
|
||||
case 1:
|
||||
for (RaceObject ro : includedCanvasController.getRaceObjects()) {
|
||||
if (ro instanceof BoatGroup) {
|
||||
BoatGroup bg = (BoatGroup) ro;
|
||||
@@ -415,7 +418,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
break;
|
||||
// All Annotations
|
||||
case 3:
|
||||
case 2:
|
||||
for (RaceObject ro : includedCanvasController.getRaceObjects()) {
|
||||
if (ro instanceof BoatGroup) {
|
||||
BoatGroup bg = (BoatGroup) ro;
|
||||
@@ -431,6 +434,28 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets all the annotations of the selected boat to be visible and all others to be hidden
|
||||
*
|
||||
* @param yacht The yacht for which we want to view all annotations
|
||||
*/
|
||||
private void setSelectedBoat(Yacht yacht) {
|
||||
for (RaceObject ro : includedCanvasController.getRaceObjects()) {
|
||||
if (ro instanceof BoatGroup) {
|
||||
BoatGroup bg = (BoatGroup) ro;
|
||||
//We need to iterate over all race groups to get the matching boat group belonging to this boat if we
|
||||
//are to toggle its annotations, there is no other backwards knowledge of a yacht to its boatgroup.
|
||||
if (bg.getBoat().getHullID().equals(yacht.getHullID())) {
|
||||
bg.setIsSelected(true);
|
||||
selectedBoat = yacht;
|
||||
} else {
|
||||
bg.setIsSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setStage(Stage stage) {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Line;
|
||||
@@ -49,6 +50,7 @@ public class BoatGroup extends RaceObject {
|
||||
private Text estTimeToNextMarkObject;
|
||||
private Text legTimeObject;
|
||||
private Wake wake;
|
||||
private boolean isSelected = true; //Boats annotations are visible by default at the start
|
||||
//Handles boat moving when connecting to a stream
|
||||
private boolean setToInitialLocation = false;
|
||||
private boolean destinationSet;
|
||||
@@ -95,8 +97,16 @@ public class BoatGroup extends RaceObject {
|
||||
private void initChildren(Color color, double... points) {
|
||||
boatPoly = new Polygon(points);
|
||||
boatPoly.setFill(color);
|
||||
boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE));
|
||||
boatPoly.setOnMouseExited(event -> boatPoly.setFill(color));
|
||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||
boatPoly.setCache(true);
|
||||
boatPoly.setCacheHint(CacheHint.SPEED);
|
||||
|
||||
|
||||
teamNameObject = new Text(boat.getShortName());
|
||||
teamNameObject.setCache(true);
|
||||
teamNameObject.setCacheHint(CacheHint.SPEED);
|
||||
velocityObject = new Text(String.valueOf(boat.getVelocity()));
|
||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||
String timeToNextMark = format
|
||||
@@ -109,6 +119,8 @@ public class BoatGroup extends RaceObject {
|
||||
} else {
|
||||
legTimeObject = new Text("Last mark: -");
|
||||
}
|
||||
velocityObject.setCache(true);
|
||||
velocityObject.setCacheHint(CacheHint.SPEED);
|
||||
|
||||
teamNameObject.setX(TEAMNAME_X_OFFSET);
|
||||
teamNameObject.setY(TEAMNAME_Y_OFFSET);
|
||||
@@ -210,8 +222,6 @@ public class BoatGroup extends RaceObject {
|
||||
* on.
|
||||
*/
|
||||
public void updatePosition(long timeInterval) {
|
||||
//Calculate the movement of the boat.
|
||||
if (isMaximized) {
|
||||
double dx = pixelVelocityX * timeInterval;
|
||||
double dy = pixelVelocityY * timeInterval;
|
||||
double rotation = rotationalVelocity * timeInterval;
|
||||
@@ -228,7 +238,7 @@ public class BoatGroup extends RaceObject {
|
||||
boatPoly.getLayoutY()
|
||||
);
|
||||
l.getStrokeDashArray().setAll(3d, 7d);
|
||||
l.setStroke(boatPoly.getFill());
|
||||
l.setStroke(boat.getColour());
|
||||
lineGroup.getChildren().add(l);
|
||||
}
|
||||
if (destinationSet) { //Only begin drawing after the first destination is set
|
||||
@@ -237,7 +247,6 @@ public class BoatGroup extends RaceObject {
|
||||
}
|
||||
wake.updatePosition(timeInterval);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the destination of the boat and the headng it should have once it reaches
|
||||
@@ -253,32 +262,21 @@ public class BoatGroup extends RaceObject {
|
||||
if (setToInitialLocation) {
|
||||
destinationSet = true;
|
||||
boat.setVelocity(groundSpeed);
|
||||
if (currentRotation < 0) {
|
||||
currentRotation = 360 - currentRotation;
|
||||
}
|
||||
double dx = newXValue - boatPoly.getLayoutX();
|
||||
double dy = newYValue - boatPoly.getLayoutY();
|
||||
//Check movement is reasonable. Assumes a 1000 * 1000 canvas
|
||||
if (Math.abs(dx) > 50 || Math.abs(dy) > 50) {
|
||||
dx = 0;
|
||||
dy = 0;
|
||||
moveTo(newXValue, newYValue);
|
||||
}
|
||||
|
||||
|
||||
pixelVelocityX = dx / expectedUpdateInterval;
|
||||
pixelVelocityY = dy / expectedUpdateInterval;
|
||||
rotationalGoal = rotation;
|
||||
calculateRotationalVelocity();
|
||||
|
||||
if (wakeGenerationDelay > 0) {
|
||||
wake.rotate(rotationalGoal);
|
||||
rotateTo(rotationalGoal); //Need to test with this removed.
|
||||
if (Math.abs(rotationalVelocity) > 0.075) {
|
||||
rotationalVelocity = 0;
|
||||
wakeGenerationDelay--;
|
||||
} else {
|
||||
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal,
|
||||
boat.getVelocity());
|
||||
rotateTo(rotationalGoal);
|
||||
wake.rotate(rotationalGoal);
|
||||
}
|
||||
wake.setRotationalVelocity(rotationalVelocity, boat.getVelocity());
|
||||
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
|
||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||
// estimate time to next mark
|
||||
@@ -300,27 +298,6 @@ public class BoatGroup extends RaceObject {
|
||||
}
|
||||
}
|
||||
//If minimized generate lines every 5 calls to set destination.
|
||||
if (!isMaximized) {
|
||||
setToInitialLocation = false;
|
||||
wakeGenerationDelay = 2;
|
||||
if (setCallCount-- == 0) {
|
||||
setCallCount = 5;
|
||||
if (lastPoint != null) {
|
||||
Line l = new Line(
|
||||
lastPoint.getX(),
|
||||
lastPoint.getY(),
|
||||
newXValue,
|
||||
newYValue
|
||||
);
|
||||
l.getStrokeDashArray().setAll(3d, 7d);
|
||||
l.setStroke(boatPoly.getFill());
|
||||
lineStorage.add(l);
|
||||
}
|
||||
if (destinationSet) { //Only begin drawing after the first destination is set
|
||||
lastPoint = new Point2D(newXValue, newYValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDestination(double newXValue, double newYValue, double groundSpeed,
|
||||
@@ -349,6 +326,10 @@ public class BoatGroup extends RaceObject {
|
||||
wake.rotate(rotationalGoal);
|
||||
}
|
||||
|
||||
public void paintBoat(Color color) {
|
||||
boatPoly.setFill(color);
|
||||
}
|
||||
|
||||
public void setTeamNameObjectVisible(Boolean visible) {
|
||||
teamNameObject.setVisible(visible);
|
||||
}
|
||||
@@ -377,6 +358,24 @@ public class BoatGroup extends RaceObject {
|
||||
return boat;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function sets the boats isSelected property AS WELL as actually acting upon the value of
|
||||
* that selection. (Painting or not painting annotations)
|
||||
*
|
||||
* @param isSelected A Boolean indicating whether or not the boat is selected
|
||||
*/
|
||||
public void setIsSelected(Boolean isSelected) {
|
||||
this.isSelected = isSelected;
|
||||
setTeamNameObjectVisible(isSelected);
|
||||
setVelocityObjectVisible(isSelected);
|
||||
setLineGroupVisible(isSelected);
|
||||
setWakeVisible(isSelected);
|
||||
setEstTimeToNextMarkObjectVisible(isSelected);
|
||||
setLegTimeObjectVisible(isSelected);
|
||||
// TODO: 17/05/17 wmu16 - this should iterate over some list of annotations which we should make to easily make extensible
|
||||
// paintBoat((isSelected) ? Color.WHITE : boat.getColour());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this BoatGroup contains at least one of the given IDs.
|
||||
*
|
||||
@@ -435,4 +434,9 @@ public class BoatGroup extends RaceObject {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return boat.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Arc;
|
||||
import javafx.scene.shape.ArcType;
|
||||
import javafx.scene.shape.StrokeLineCap;
|
||||
import javafx.scene.transform.Rotate;
|
||||
|
||||
/**
|
||||
* By default wake is a group containing 5 arcs. Each arc starts from the same point. Each arc is larger and more
|
||||
* transparent than the last. On calling updatePositions() arcs rotate at velocities given by setRotationalVelocity().
|
||||
* The larger and more transparent an arc is the longer the delay before it rotates at the latest velocity. It is
|
||||
* assumed that rotationalVelocities() are set regularly as wakes do not stop rotating and an array of velocities needs
|
||||
* to be populated for the class to work as expected.
|
||||
* A group containing objects used to represent wakes onscreen. Contains functionality for their animation.
|
||||
*/
|
||||
class Wake extends Group {
|
||||
|
||||
private int numWakes = 5;
|
||||
private double[] velocities = new double[13];
|
||||
//The number of wakes
|
||||
private int numWakes = 8;
|
||||
//The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less.
|
||||
private final double MAX_DIFF = 75;
|
||||
//Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation.
|
||||
private final int UNIFICATION_SPEED = 750;
|
||||
|
||||
|
||||
private Arc[] arcs = new Arc[numWakes];
|
||||
private double[] rotationalVelocities = new double[numWakes];
|
||||
private double[] rotations = new double[numWakes];
|
||||
private int[] velocityIndices = new int[numWakes];
|
||||
private double sum = 0;
|
||||
private static double max;
|
||||
private double baseRad;
|
||||
|
||||
/**
|
||||
* Create a wake at the given location.
|
||||
*
|
||||
* @param startingX x location where the tip of wake arcs will be.
|
||||
* @param startingY y location where the tip of wake arcs will be.
|
||||
*/
|
||||
@@ -34,74 +38,77 @@ class Wake extends Group {
|
||||
Arc arc;
|
||||
for (int i = 0; i < numWakes; i++) {
|
||||
//Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg.
|
||||
arc = new Arc(0,0,0,0,-110,40);
|
||||
//Opacity increases from 0.5 -> 0 evenly over the 5 wake arcs.
|
||||
arc.setFill(new Color(0.18, 0.7, 1.0, 1.0 + -0.175 * i));
|
||||
arc.setType(ArcType.ROUND);
|
||||
arc = new Arc(0, 0, 0, 0, -110, 40);
|
||||
arc.setCache(true);
|
||||
arc.setCacheHint(CacheHint.SPEED);
|
||||
arc.setType(ArcType.OPEN);
|
||||
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
|
||||
arc.setStrokeWidth(3.0);
|
||||
arc.setStrokeLineCap(StrokeLineCap.ROUND);
|
||||
arc.setFill(new Color(0.0, 0.0, 0.0, 0.0));
|
||||
baseRad = (20 / numWakes);
|
||||
arcs[i] = arc;
|
||||
}
|
||||
super.getChildren().addAll(arcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rotationalVelocity of each arc. Each arc is 3 velocities behind the next smallest arc. The smallest uses
|
||||
* the latest given velocity.
|
||||
* Sets the rotationalVelocity of each arc.
|
||||
*
|
||||
* @param rotationalVelocity The rotationalVelocity the wake should move at.
|
||||
* @param rotationGoal Where the wake will rotate to if the wake is calculated to be on a straight section. This is
|
||||
* used to prevent desynchronisation with the Boat polygon.
|
||||
* @param velocity The real world velocity of the boat in m/s.
|
||||
*/
|
||||
void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocity) {
|
||||
sum -= Math.abs(velocities[(velocityIndices[0] + 10) % 13]);
|
||||
sum += Math.abs(rotationalVelocity);
|
||||
max = Math.max(max, rotationalVelocity);
|
||||
if (sum < (max / 3))
|
||||
rotate (rotationGoal); //In relatively straight segments the wake snaps to match the boats current position.
|
||||
//This stops the wake from eventually becoming out of sync with the boat.
|
||||
//This accounts for rogue rotations that are greater than what would be realistic. Value is kinda rough.
|
||||
//Basically just for our internal mock.
|
||||
if (Math.abs(rotationalVelocity) > 0.05) {
|
||||
rotationalVelocity = 0;
|
||||
rotate(rotationGoal);
|
||||
}
|
||||
//Update the index of the array of recent velocities that each wake uses. Each wake is 3 velocities behind the
|
||||
//next smallest wake.
|
||||
velocityIndices[0] = (13 + (velocityIndices[0] - 1) % 13) % 13;
|
||||
velocities[velocityIndices[0]] = rotationalVelocity;
|
||||
for (int i = 1; i < numWakes; i++)
|
||||
velocityIndices[i] = (velocityIndices[0] + 3 * i) % 13;
|
||||
void setRotationalVelocity(double rotationalVelocity, double velocity) {
|
||||
rotationalVelocities[0] = rotationalVelocity;
|
||||
for (int i = 1; i < numWakes; i++) {
|
||||
double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]);
|
||||
double shortestDistance = Math.atan2(
|
||||
Math.sin(wakeSeparationRad),
|
||||
Math.cos(wakeSeparationRad)
|
||||
);
|
||||
double distDeg = Math.toDegrees(shortestDistance);
|
||||
|
||||
//Scale wakes based on velocity.
|
||||
double baseRad = 20;
|
||||
double rad;
|
||||
for (Arc arc :arcs) {
|
||||
rad = baseRad + velocity;
|
||||
if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) {
|
||||
rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||
|
||||
} else {
|
||||
if (distDeg < (MAX_DIFF / numWakes))
|
||||
rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||
else
|
||||
rotationalVelocities[i] = rotationalVelocities[i - 1];
|
||||
}
|
||||
}
|
||||
|
||||
double rad = baseRad + velocity;
|
||||
for (Arc arc : arcs) {
|
||||
arc.setRadiusX(rad);
|
||||
arc.setRadiusY(rad);
|
||||
baseRad += 5 + (velocity / 2);
|
||||
rad += (20 / numWakes) + (velocity / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Arcs rotate based on the distance they would have travelled over the supplied time interval.
|
||||
*
|
||||
* @param timeInterval the time interval, in microseconds, that the wake should move.
|
||||
*/
|
||||
void updatePosition (long timeInterval) {
|
||||
void updatePosition(long timeInterval) {
|
||||
for (int i = 0; i < numWakes; i++) {
|
||||
rotations[i] = rotations[i] + velocities[velocityIndices[i]] * timeInterval;
|
||||
rotations[i] = rotations[i] + rotationalVelocities[i] * timeInterval;
|
||||
arcs[i].getTransforms().setAll(new Rotate(rotations[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate all wakes to the given rotation.
|
||||
*
|
||||
* @param rotation the from north angle in degrees to rotate to.
|
||||
*/
|
||||
void rotate (double rotation) {
|
||||
void rotate(double rotation) {
|
||||
for (int i = 0; i < arcs.length; i++) {
|
||||
rotations[i] = rotation;
|
||||
rotationalVelocities[i] = 0;
|
||||
arcs[i].getTransforms().setAll(new Rotate(rotation));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -174,4 +174,9 @@ public class Yacht {
|
||||
public void setMarkRoundingTime(Long markRoundingTime) {
|
||||
this.markRoundingTime = markRoundingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return boatName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package seng302.models.mark;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
/**
|
||||
@@ -24,7 +25,6 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
* and parsed in by turning the byte arrays into useful data. There are two public static hashmaps
|
||||
* that are threadsafe so the visualiser can always access the latest speed and position available
|
||||
* Created by kre39 on 23/04/17.
|
||||
*
|
||||
*/
|
||||
public class StreamParser extends Thread{
|
||||
|
||||
@@ -37,8 +37,8 @@ public class StreamParser extends Thread{
|
||||
private static boolean raceFinished = false;
|
||||
private static boolean streamStatus = false;
|
||||
private static long timeSinceStart = -1;
|
||||
private static Map<Integer, Yacht> boats = new HashMap<>();
|
||||
private static Map<Long, Yacht> boatsPos = new TreeMap<>();
|
||||
private static Map<Integer, Yacht> boats = new ConcurrentHashMap<>();
|
||||
private static Map<Long, Yacht> boatsPos = new ConcurrentSkipListMap<>();
|
||||
private static double windDirection = 0;
|
||||
private static Long currentTimeLong;
|
||||
private static String currentTimeString;
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package seng302.server.messages;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
public class BoatLocationMessage extends Message {
|
||||
private final int MESSAGE_SIZE = 56;
|
||||
@@ -44,7 +41,7 @@ public class BoatLocationMessage extends Message {
|
||||
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
|
||||
boatSpeed /= 10;
|
||||
messageVersionNumber = 1;
|
||||
time = System.currentTimeMillis() / 1000L;
|
||||
time = System.currentTimeMillis();
|
||||
this.sourceId = sourceId;
|
||||
this.sequenceNum = sequenceNum;
|
||||
this.deviceType = DeviceType.RACING_YACHT;
|
||||
|
||||
@@ -128,6 +128,24 @@ Table
|
||||
-fx-border-style: none;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Combo Box
|
||||
*/
|
||||
|
||||
.combo-box-base {
|
||||
-fx-background-color: #119796;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.combo-box-popup .list-view .list-cell:hover {
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.combo-box .cell:selected {
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
/**
|
||||
Remove scroll bars
|
||||
*/
|
||||
|
||||
@@ -56,9 +56,11 @@
|
||||
</Text>
|
||||
</children>
|
||||
</Pane>
|
||||
<Slider fx:id="annotationSlider" blockIncrement="1.0" layoutX="38.0" layoutY="527.0" majorTickUnit="1.0" max="3.0" minorTickCount="0" prefHeight="51.0" prefWidth="170.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" styleClass="ui-slider" />
|
||||
<Slider fx:id="annotationSlider" blockIncrement="1.0" layoutX="38.0" layoutY="527.0" majorTickUnit="1.0" max="2.0" minorTickCount="0" prefHeight="51.0" prefWidth="170.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" styleClass="ui-slider" />
|
||||
<Label layoutX="10.0" layoutY="499.0" text="Annotations" textFill="WHITE" />
|
||||
<Button fx:id="selectAnnotationBtn" layoutX="35.0" layoutY="578.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="170.0" styleClass="blue-ui-btn" text="Select Annotations" textFill="WHITE" />
|
||||
<Text fill="WHITE" layoutX="11.0" layoutY="649.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Selection" />
|
||||
<ComboBox fx:id="boatSelectionComboBox" layoutX="37.0" layoutY="664.0" prefHeight="25.0" prefWidth="170.0" promptText="Select Boat" styleClass="combo-box-base" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane fx:id="contentAnchorPane" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: skyblue;" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP">
|
||||
|
||||
Reference in New Issue
Block a user