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
@@ -103,15 +103,19 @@ public class MessageRouter implements RunnableWithFramePeriod {
AC35Data message = incomingMessages.take();
if (routeMap.containsKey(message.getType())) {
//We have a route.
routeMap.get(message.getType()).put(message);
BlockingQueue<AC35Data> queue = routeMap.get(message.getType());
if (queue != null) {
queue.put(message);
} else {
//No route. Use default.
if (defaultRoute.isPresent()) {
defaultRoute.get().put(message);
BlockingQueue<AC35Data> defaultQueue = defaultRoute.orElse(null);
if (defaultQueue != null) {
defaultQueue.put(message);
}
}
@@ -0,0 +1,39 @@
package network.Messages;
import network.Messages.Enums.JoinAcceptanceEnum;
import network.Messages.Enums.MessageType;
/**
* This is the message the client generates and sends to itself once the server has assigned a boat source ID with {@link JoinAcceptance}.
*/
public class AssignPlayerBoat extends AC35Data {
/**
* The source ID of the boat assigned to the client.
* 0 indicates they haven't been assigned a boat.
*/
private int sourceID = 0;
/**
* Constructs a AssignPlayerBoat message.
* @param sourceID The sourceID to assign to the client. 0 indicates no sourceID.
*/
public AssignPlayerBoat(int sourceID){
super(MessageType.ASSIGN_PLAYER_BOAT);
this.sourceID = sourceID;
}
/**
* Returns the source ID of the boat assigned to the client.
* @return The source ID of the boat assigned to the client.
*/
public int getSourceID() {
return sourceID;
}
}
@@ -128,7 +128,7 @@ public class BoatStatus {
}
/**
* Returns he time at which it is estimated the boat will reach the next mark. Milliseconds since unix epoch.
* Returns the time at which it is estimated the boat will reach the next mark. Milliseconds since unix epoch.
* @return Time at which boat will reach next mark.
*/
public long getEstTimeAtNextMark() {
@@ -136,7 +136,7 @@ public class BoatStatus {
}
/**
* Returns he time at which it is estimated the boat will finish the race. Milliseconds since unix epoch.
* Returns the time at which it is estimated the boat will finish the race. Milliseconds since unix epoch.
* @return Time at which boat will finish the race.
*/
public long getEstTimeAtFinish() {
@@ -11,24 +11,35 @@ public enum JoinAcceptanceEnum {
/**
* Client is allowed to join.
* Client is allowed to join and spectate.
*/
JOIN_SUCCESSFUL(1),
JOIN_SUCCESSFUL_SPECTATOR(0),
/**
* The race is full - no more participants allowed.
* Client is allowed to join and participate.
*/
RACE_PARTICIPANTS_FULL(2),
JOIN_SUCCESSFUL_PARTICIPANT(1),
/**
* The race cannot allow any more ghost participants to join.
* Client is allowed to join and play the tutorial.
*/
GHOST_PARTICIPANTS_FULL(3),
JOIN_SUCCESSFUL_TUTORIAL(2),
/**
* Client is allowed to join and participate as a ghost player.
*/
JOIN_SUCCESSFUL_GHOST(3),
/**
* Join Request was denied.
*/
JOIN_FAILURE(0x10),
/**
* The server is completely full, cannot participate or spectate.
*/
SERVER_FULL(4),
SERVER_FULL(0x11),
/**
@@ -20,17 +20,25 @@ public enum MessageType {
COURSEWIND(44),
AVGWIND(47),
BOATACTION(100),
/**
* This is used for {@link network.Messages.RequestToJoin} messages.
*/
REQUEST_TO_JOIN(55),
REQUEST_TO_JOIN(101),
/**
* This is used for {@link network.Messages.JoinAcceptance} messages.
*/
JOIN_ACCEPTANCE(56),
JOIN_ACCEPTANCE(102),
/**
* This is used for {@link network.Messages.AssignPlayerBoat} messages.
*/
ASSIGN_PLAYER_BOAT(121),
BOATACTION(100),
NOTAMESSAGE(0);
@@ -20,10 +20,15 @@ public enum RequestToJoinEnum {
*/
PARTICIPANT(1),
/**
* Client wants to play the tutorial.
*/
CONTROL_TUTORIAL(2),
/**
* Client wants to particpate as a ghost.
*/
GHOST(5),
GHOST(3),
/**
@@ -1,7 +1,6 @@
package network.Messages;
import network.Messages.Enums.XMLMessageType;
import shared.dataInput.RaceDataSource;
import java.util.*;
@@ -11,36 +10,6 @@ import java.util.*;
*/
public class LatestMessages extends Observable {
/**
* The latest RaceStatus message.
*/
private RaceStatus raceStatus;
/**
* A map of the last BoatStatus message received, for each boat.
*/
private final Map<Integer, BoatStatus> boatStatusMap = new HashMap<>();
/**
* A map of the last BoatLocation message received, for each boat.
*/
private final Map<Integer, BoatLocation> boatLocationMap = new HashMap<>();
/**
* A map of the last MarkRounding message received, for each boat.
*/
private final Map<Integer, MarkRounding> markRoundingMap = new HashMap<>();
/**
* The last AverageWind message received.
*/
private AverageWind averageWind;
/**
* The last CourseWinds message received.
*/
private CourseWinds courseWinds;
/**
* A list of messages containing a snapshot of the race.
@@ -91,138 +60,7 @@ public class LatestMessages extends Observable {
}
/**
* Gets the latest RaceStatus message received.
* @return The latest RaceStatus message received.
*/
public RaceStatus getRaceStatus() {
return raceStatus;
}
/**
* Sets the latest RaceStatus message received.
* @param raceStatus The new RaceStatus message to store.
*/
public void setRaceStatus(RaceStatus raceStatus) {
this.raceStatus = raceStatus;
}
/**
* Returns the latest BoatStatus message received for a given boat.
* @param sourceID Source ID of the boat.
* @return The latest BoatStatus message for the specified boat.
*/
public BoatStatus getBoatStatus(int sourceID) {
return boatStatusMap.get(sourceID);
}
/**
* Inserts a BoatStatus message for a given boat.
* @param boatStatus The BoatStatus message to set.
*/
public void setBoatStatus(BoatStatus boatStatus) {
boatStatusMap.put(boatStatus.getSourceID(), boatStatus);
}
/**
* Returns the latest BoatLocation message received for a given boat.
* @param sourceID Source ID of the boat.
* @return The latest BoatLocation message for the specified boat.
*/
public BoatLocation getBoatLocation(int sourceID) {
return boatLocationMap.get(sourceID);
}
/**
* Inserts a BoatLocation message for a given boat.
* @param boatLocation The BoatLocation message to set.
*/
public void setBoatLocation(BoatLocation boatLocation) {
//TODO should compare the sequence number of the new boatLocation with the existing boatLocation for this boat (if it exists), and use the newer one.
boatLocationMap.put(boatLocation.getSourceID(), boatLocation);
}
/**
* Returns the latest MarkRounding message received for a given boat.
* @param sourceID Source ID of the boat.
* @return The latest MarkRounding message for the specified boat.
*/
public MarkRounding getMarkRounding(int sourceID) {
return markRoundingMap.get(sourceID);
}
/**
* Inserts a MarkRounding message for a given boat.
* @param markRounding The MarkRounding message to set.
*/
public void setMarkRounding(MarkRounding markRounding) {
//TODO should compare the sequence number of the new markRounding with the existing boatLocation for this boat (if it exists), and use the newer one.
markRoundingMap.put(markRounding.getSourceID(), markRounding);
}
/**
* Gets the latest AverageWind message received.
* @return The latest AverageWind message received.
*/
public AverageWind getAverageWind() {
return averageWind;
}
/**
* Sets the latest AverageWind message received.
* @param averageWind The new AverageWind message to store.
*/
public void setAverageWind(AverageWind averageWind) {
this.averageWind = averageWind;
}
/**
* Gets the latest CourseWinds message received.
* @return The latest CourseWinds message received.
*/
public CourseWinds getCourseWinds() {
return courseWinds;
}
/**
* Sets the latest CourseWinds message received.
* @param courseWinds The new CourseWinds message to store.
*/
public void setCourseWinds(CourseWinds courseWinds) {
this.courseWinds = courseWinds;
}
/**
* Returns the map of boat sourceIDs to BoatLocation messages.
* @return Map between boat sourceID and BoatLocation.
*/
public Map<Integer, BoatLocation> getBoatLocationMap() {
return boatLocationMap;
}
/**
* Returns the map of boat sourceIDs to BoatStatus messages.
* @return Map between boat sourceID and BoatStatus.
*/
public Map<Integer, BoatStatus> getBoatStatusMap() {
return boatStatusMap;
}
/**
* Returns the map of boat sourceIDs to MarkRounding messages.
* @return Map between boat sourceID and MarkRounding.
*/
public Map<Integer, MarkRounding> getMarkRoundingMap() {
return markRoundingMap;
}