Added empty data sources, to be used by VisualiserRace.

Created FrameRateTracker which can be used to track framerate.
Updated RequestToJoinEnum and JoinAcceptanceEnum to match the agreed connection API.
Added AssignPlayerBoat message, which is used internally on the client to assign the player a source ID once they have connected.
Fixed some race conditions in the MessageRouter.
Updated ConnectionAcceptor.CheckClientConnection to wait slightly longer before removing connection (there was a slight race condition before).
Race no longer has a reference to LatestMessages. LatestMessages no longer has specific messages types in it.
Created RaceState class, which contains the state that is shared between VisualiserRaceState and MockRaceState (currently only used on visualiser).
Split VisualiserRace into VisualiserRaceState and VisualiserRaceService.
Added the VisualiserRace commands (BoatLocatonCommand, RaceStatusCommand, etc...).
Slightly increased the preferred width of race.fxml table columns.
issues #27 #37 #35
#story[1095]
This commit is contained in:
fjc40
2017-08-14 00:53:05 +12:00
parent 89b0aa8b77
commit 7366aba5ec
53 changed files with 2498 additions and 1129 deletions
@@ -4,7 +4,9 @@ package visualiser.Controllers;
import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
import javafx.fxml.FXML;
import javafx.scene.chart.LineChart;
import javafx.scene.control.*;
@@ -28,6 +30,8 @@ import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller used to display a running race.
*/
@@ -37,12 +41,16 @@ public class RaceController extends Controller {
/**
* The race object which describes the currently occurring race.
*/
private VisualiserRace visualiserRace;
private VisualiserRaceEvent visualiserRace;
/**
* An additional observable list of boats. This is used by the table view, to allow it to sort boats without effecting the race's own list of boats.
* Service for sending keystrokes to server
*/
private ObservableList<VisualiserBoat> tableBoatList;
private ControllerClient controllerClient;
/**
* The canvas that draws the race.
@@ -59,15 +67,6 @@ public class RaceController extends Controller {
*/
@FXML private ArrowController arrowController;
/**
* Service for sending keystrokes to server
*/
private ControllerClient controllerClient;
/**
* The connection to the server.
*/
private ServerConnection serverConnection;
@FXML private GridPane canvasBase;
@@ -162,7 +161,7 @@ public class RaceController extends Controller {
* Initialises the frame rate functionality. This allows for toggling the frame rate, and connect the fps label to the race's fps property.
* @param visualiserRace The race to connect the fps label to.
*/
private void initialiseFps(VisualiserRace visualiserRace) {
private void initialiseFps(VisualiserRaceEvent visualiserRace) {
//On/off toggle.
initialiseFpsToggle();
@@ -192,9 +191,9 @@ public class RaceController extends Controller {
* Initialises the fps label to update when the race fps changes.
* @param visualiserRace The race to monitor the frame rate of.
*/
private void initialiseFpsLabel(VisualiserRace visualiserRace) {
private void initialiseFpsLabel(VisualiserRaceEvent visualiserRace) {
visualiserRace.fpsProperty().addListener((observable, oldValue, newValue) -> {
visualiserRace.getFrameRateProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> this.FPS.setText("FPS: " + newValue.toString()));
});
@@ -206,14 +205,15 @@ public class RaceController extends Controller {
* Initialises the information table view to listen to a given race.
* @param race Race to listen to.
*/
public void initialiseInfoTable(VisualiserRace race) {
public void initialiseInfoTable(VisualiserRaceEvent race) {
//Copy list of boats.
this.tableBoatList = FXCollections.observableArrayList(race.getBoats());
SortedList<VisualiserBoat> sortedBoats = new SortedList<>(race.getVisualiserRaceState().getBoats());
sortedBoats.comparatorProperty().bind(boatInfoTable.comparatorProperty());
//Set up table.
boatInfoTable.setItems(this.tableBoatList);
boatInfoTable.setItems(sortedBoats);
//Set up each column.
@@ -293,12 +293,12 @@ public class RaceController extends Controller {
/**
* Initialises the {@link Sparkline}, and listens to a specified {@link VisualiserRace}.
* Initialises the {@link Sparkline}, and listens to a specified {@link VisualiserRaceEvent}.
* @param race The race to listen to.
*/
private void initialiseSparkline(VisualiserRace race) {
private void initialiseSparkline(VisualiserRaceEvent race) {
//The race.getBoats() we are passing in is sorted by position in race inside the race class.
this.sparkline = new Sparkline(this.visualiserRace, this.sparklineChart);
this.sparkline = new Sparkline(this.visualiserRace.getVisualiserRaceState(), this.sparklineChart);
}
@@ -306,7 +306,7 @@ public class RaceController extends Controller {
* Initialises the {@link ResizableRaceCanvas}, provides the race to read data from.
* @param race Race to read data from.
*/
private void initialiseRaceCanvas(VisualiserRace race) {
private void initialiseRaceCanvas(VisualiserRaceEvent race) {
//Create canvas.
raceCanvas = new ResizableRaceCanvas(race);
@@ -329,18 +329,18 @@ public class RaceController extends Controller {
* Intialises the race time zone label with the race's time zone.
* @param race The race to get time zone from.
*/
private void initialiseRaceTimezoneLabel(VisualiserRace race) {
timeZone.setText(race.getRaceClock().getTimeZone());
private void initialiseRaceTimezoneLabel(VisualiserRaceEvent race) {
timeZone.setText(race.getVisualiserRaceState().getRaceClock().getTimeZone());
}
/**
* Initialises the race clock to listen to the specified race.
* @param race The race to listen to.
*/
private void initialiseRaceClock(VisualiserRace race) {
private void initialiseRaceClock(VisualiserRaceEvent race) {
//RaceClock.duration isn't necessarily being changed in the javaFX thread, so we need to runlater the update.
race.getRaceClock().durationProperty().addListener((observable, oldValue, newValue) -> {
race.getVisualiserRaceState().getRaceClock().durationProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> {
timer.setText(newValue);
});
@@ -353,13 +353,11 @@ public class RaceController extends Controller {
* Displays a specified race.
* @param visualiserRace Object modelling the race.
* @param controllerClient Socket Client that manipulates the controller.
* @param serverConnection The connection to the server.
*/
public void startRace(VisualiserRace visualiserRace, ControllerClient controllerClient, ServerConnection serverConnection) {
public void startRace(VisualiserRaceEvent visualiserRace, ControllerClient controllerClient) {
this.visualiserRace = visualiserRace;
this.controllerClient = controllerClient;
this.serverConnection = serverConnection;
initialiseRace();
@@ -375,7 +373,7 @@ public class RaceController extends Controller {
* Transition from the race view to the finish view.
* @param boats boats there are in the race.
*/
public void finishRace(ObservableList<VisualiserBoat> boats){
public void finishRace(ObservableList<VisualiserBoat> boats) {
race.setVisible(false);
parent.enterFinish(boats);
}
@@ -385,8 +383,8 @@ public class RaceController extends Controller {
* Initialises the arrow controller with data from the race to observe.
* @param race The race to observe.
*/
private void initialiseArrow(VisualiserRace race) {
arrowController.setWindProperty(race.windProperty());
private void initialiseArrow(VisualiserRaceEvent race) {
arrowController.setWindProperty(race.getVisualiserRaceState().windProperty());
}
@@ -399,7 +397,7 @@ public class RaceController extends Controller {
public void handle(long arg0) {
//Get the current race status.
RaceStatusEnum raceStatus = visualiserRace.getRaceStatusEnum();
RaceStatusEnum raceStatus = visualiserRace.getVisualiserRaceState().getRaceStatusEnum();
//If the race has finished, go to finish view.
@@ -408,7 +406,7 @@ public class RaceController extends Controller {
stop();
//Hide this, and display the finish controller.
finishRace(visualiserRace.getBoats());
finishRace(visualiserRace.getVisualiserRaceState().getBoats());
} else {
//Otherwise, render the canvas.
@@ -421,7 +419,7 @@ public class RaceController extends Controller {
}
//Return to main screen if we lose connection.
if (!serverConnection.isAlive()) {
if (!visualiserRace.getServerConnection().isAlive()) {
race.setVisible(false);
parent.enterTitle();
//TODO currently this doesn't work correctly - the title screen remains visible after clicking join game