Refactored Race, MockRace, and VisualiserRace to use RaceClock instead of keeping their own timers.
Moved FPS tracking to Race class, so both VisualiserRace and MockRace can monitor their FPS. LatestMessages is now observable. It notifies observers when an XMLMessage is received. Boat now has StringProperty for name and country/abbreviation. Moved the MockRace timescale value to Constants.RaceTimeScale. This is passed in to MockRace on construction. Tidied up StartController. Copied the visualiser's resources into the resources folder. Refactored RaceClock. Added comments. Tidied code a bit. Moved to shared.model. Started work on RaceController.
This commit is contained in:
@@ -10,45 +10,84 @@ import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import visualiser.model.RaceClock;
|
||||
import visualiser.app.VisualiserInput;
|
||||
import shared.model.RaceClock;
|
||||
import visualiser.model.Sparkline;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRace;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
* Controller used to display a running race.
|
||||
*/
|
||||
public class RaceController extends Controller {
|
||||
|
||||
/**
|
||||
* The object used to read packets from the connected server.
|
||||
*/
|
||||
private VisualiserInput visualiserInput;
|
||||
|
||||
/**
|
||||
* The race object which describes the currently occurring race.
|
||||
*/
|
||||
private VisualiserRace visualiserRace;
|
||||
|
||||
private ResizableRaceCanvas raceMap;
|
||||
private ResizableRaceMap raceBoundaries;
|
||||
|
||||
private RaceClock raceClock;
|
||||
/**
|
||||
* The sparkline graph.
|
||||
*/
|
||||
private Sparkline sparkline;
|
||||
|
||||
private int legNum;
|
||||
|
||||
@FXML GridPane canvasBase;
|
||||
@FXML Pane arrow;
|
||||
@FXML SplitPane race;
|
||||
@FXML StackPane arrowPane;
|
||||
@FXML Label timer;
|
||||
@FXML Label FPS;
|
||||
@FXML Label timeZone;
|
||||
@FXML CheckBox showFPS;
|
||||
@FXML TableView<Boat> boatInfoTable;
|
||||
@FXML TableColumn<Boat, String> boatPlacingColumn;
|
||||
@FXML TableColumn<Boat, String> boatTeamColumn;
|
||||
@FXML TableColumn<Boat, String> boatMarkColumn;
|
||||
@FXML TableColumn<Boat, String> boatSpeedColumn;
|
||||
@FXML LineChart<Number, Number> sparklineChart;
|
||||
@FXML AnchorPane annotationPane;
|
||||
@FXML private GridPane canvasBase;
|
||||
@FXML private Pane arrow;
|
||||
@FXML private SplitPane race;
|
||||
@FXML private StackPane arrowPane;
|
||||
@FXML private Label timer;
|
||||
@FXML private Label FPS;
|
||||
@FXML private Label timeZone;
|
||||
@FXML private CheckBox showFPS;
|
||||
@FXML private TableView<VisualiserBoat> boatInfoTable;
|
||||
@FXML private TableColumn<VisualiserBoat, String> boatPlacingColumn;
|
||||
@FXML private TableColumn<VisualiserBoat, String> boatTeamColumn;
|
||||
@FXML private TableColumn<VisualiserBoat, String> boatMarkColumn;
|
||||
@FXML private TableColumn<VisualiserBoat, String> boatSpeedColumn;
|
||||
@FXML private LineChart<Number, Number> sparklineChart;
|
||||
@FXML private AnchorPane annotationPane;
|
||||
|
||||
|
||||
/**
|
||||
* Ctor.
|
||||
*/
|
||||
public RaceController() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
initialiseFpsToggle();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialises a listener for the fps toggle.
|
||||
*/
|
||||
private void initialiseFpsToggle() {
|
||||
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (showFPS.isSelected()) {
|
||||
FPS.setVisible(true);
|
||||
|
||||
} else {
|
||||
FPS.setVisible(false);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the ResizableRaceCanvas (raceMap) with most recent data
|
||||
@@ -79,17 +118,7 @@ public class RaceController extends Controller {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
//listener for fps
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (showFPS.isSelected()) {
|
||||
FPS.setVisible(true);
|
||||
} else {
|
||||
FPS.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and sets initial display for Sparkline for race positions.
|
||||
@@ -107,14 +136,16 @@ public class RaceController extends Controller {
|
||||
sparkline.updateSparkline(boatsInRace);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes and runs the race, based on the user's chosen scale factor
|
||||
* Currently uses an example racecourse
|
||||
*
|
||||
* @param visualiserInput input from network
|
||||
* @param raceClock The RaceClock to use for the race's countdown/elapsed duration + timezone.
|
||||
* Displays a specified race.
|
||||
* @param visualiserInput Object used to read packets from server.
|
||||
* @param visualiserRace Object modelling the race.
|
||||
*/
|
||||
public void startRace(VisualiserInput visualiserInput, RaceClock raceClock) {
|
||||
public void startRace(VisualiserInput visualiserInput, VisualiserRace visualiserRace) {
|
||||
|
||||
this.visualiserInput = visualiserInput;
|
||||
this.visualiserRace = visualiserRace;
|
||||
|
||||
legNum = visualiserInput.getCourse().getLegs().size()-1;
|
||||
|
||||
@@ -154,17 +185,7 @@ public class RaceController extends Controller {
|
||||
raceMap.setRaceClock(raceClock);
|
||||
|
||||
//TODO move this list of colors somewhere more sensible.
|
||||
List<Color> colours = new ArrayList<>(Arrays.asList(
|
||||
Color.BLUEVIOLET,
|
||||
Color.BLACK,
|
||||
Color.RED,
|
||||
Color.ORANGE,
|
||||
Color.DARKOLIVEGREEN,
|
||||
Color.LIMEGREEN,
|
||||
Color.PURPLE,
|
||||
Color.DARKGRAY,
|
||||
Color.YELLOW
|
||||
));
|
||||
|
||||
StreamedRace newRace = new StreamedRace(visualiserInput, colours, this);
|
||||
|
||||
initializeFPS();
|
||||
|
||||
Reference in New Issue
Block a user