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
@@ -0,0 +1,119 @@
package visualiser.model;
import javafx.beans.property.IntegerProperty;
import mock.model.commandFactory.CompositeCommand;
import network.Messages.Enums.RequestToJoinEnum;
import shared.dataInput.EmptyBoatDataSource;
import shared.dataInput.EmptyRaceDataSource;
import shared.dataInput.EmptyRegattaDataSource;
import visualiser.gameController.ControllerClient;
import visualiser.network.ServerConnection;
import java.io.IOException;
import java.net.Socket;
/**
* This class holds a race, and a client's connection to it
*/
public class VisualiserRaceEvent {
/**
* Our connection to the server.
*/
private ServerConnection serverConnection;
/**
* The thread serverConnection is running on.
*/
private Thread serverConnectionThread;
/**
* The race object which describes the currently occurring race.
*/
private VisualiserRaceState visualiserRaceState;
/**
* The service for updating the {@link #visualiserRaceState}.
*/
private VisualiserRaceService visualiserRaceService;
/**
* The thread {@link #visualiserRaceService} is running on.
*/
private Thread visualiserRaceServiceThread;
/**
* Creates a visualiser race event, with a given socket and request type.
* @param socket The socket to connect to.
* @param requestType The type of {@link network.Messages.RequestToJoin} to make.
* @throws IOException Thrown if there is a problem with the socket.
*/
public VisualiserRaceEvent(Socket socket, RequestToJoinEnum requestType) throws IOException {
this.visualiserRaceState = new VisualiserRaceState(new EmptyRaceDataSource(), new EmptyRegattaDataSource(), new EmptyBoatDataSource());
CompositeCommand raceCommands = new CompositeCommand();
this.visualiserRaceService = new VisualiserRaceService(raceCommands, visualiserRaceState);
this.visualiserRaceServiceThread = new Thread(visualiserRaceService, "VisualiserRaceEvent()->VisualiserRaceService thread " + visualiserRaceService);
this.visualiserRaceServiceThread.start();
this.serverConnection = new ServerConnection(socket, visualiserRaceState, raceCommands, requestType);
this.serverConnectionThread = new Thread(serverConnection, "StartController.enterLobby()->serverConnection thread " + serverConnection);
this.serverConnectionThread.start();
}
/**
* Returns the state of the race.
* @return The state of the race.
*/
public VisualiserRaceState getVisualiserRaceState() {
return visualiserRaceState;
}
/**
* Returns the controller client, which writes BoatAction messages to the outgoing queue.
* @return The ControllerClient.
*/
public ControllerClient getControllerClient() {
return serverConnection.getControllerClient();
}
/**
* Returns the connection to server.
* @return Connection to server.
*/
public ServerConnection getServerConnection() {
return serverConnection;
}
/**
* Returns the framerate property of the race.
* @return Framerate property of race.
*/
public IntegerProperty getFrameRateProperty() {
return visualiserRaceService.getFrameRateProperty();
}
/**
* Terminates the server connection and race service.
*/
public void terminate() {
this.serverConnectionThread.interrupt();
this.visualiserRaceServiceThread.interrupt();
}
}