Merge remote-tracking branch 'origin/sprint4_master' into Story877
# Conflicts: # mock/src/main/java/seng302/DataInput/BoatXMLReader.java # mock/src/main/java/seng302/DataInput/XMLReader.java # mock/src/main/java/seng302/Model/Boat.java # mock/src/main/java/seng302/Model/CompoundMark.java # mock/src/main/java/seng302/Model/Leg.java # mock/src/main/java/seng302/Model/Mark.java # mock/src/main/java/seng302/Model/Marker.java # mock/src/main/java/seng302/Model/Race.java # mock/src/test/java/seng302/Model/LegTest.java # visualiser/src/main/java/seng302/Controllers/RaceController.java # visualiser/src/main/java/seng302/Mock/StreamedRace.java # visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java # visualiser/src/main/resources/scenes/race.fxml
This commit is contained in:
@@ -5,6 +5,7 @@ import seng302.Networking.Messages.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static seng302.Networking.Utils.ByteConverter.*;
|
||||
|
||||
@@ -32,7 +33,7 @@ public class RaceVisionByteEncoder {
|
||||
*/
|
||||
public static byte[] raceStatus(RaceStatus raceStatus){
|
||||
|
||||
ArrayList<BoatStatus> boatStatuses = raceStatus.getBoatStatuses();
|
||||
List<BoatStatus> boatStatuses = raceStatus.getBoatStatuses();
|
||||
|
||||
ByteBuffer raceStatusMessage = ByteBuffer.allocate(24 + 20* boatStatuses.size());
|
||||
//Version Number 1 bytes
|
||||
|
||||
@@ -251,7 +251,7 @@ public class BoatLocation extends AC35Data {
|
||||
* @param angle Angle to convert. double.
|
||||
* @return short representation of heading.
|
||||
*/
|
||||
public static short convertTrueWindAngleShortToDouble(double angle) {
|
||||
public static short convertTrueWindAngleDoubleToShort(double angle) {
|
||||
|
||||
short angleShort = (short) ((angle / 180.0) * 32768.0);
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ public class BoatStatus {
|
||||
this.sourceID = sourceID;
|
||||
this.boatStatus = boatStatusEnum.getValue();
|
||||
this.legNumber = ByteConverter.intToBytes(legNum)[0];
|
||||
numPenaltiesAwarded = 0;
|
||||
numPenaltiesServed = 0;
|
||||
estTimeAtFinish = 0;
|
||||
estTimeAtNextMark = 0;
|
||||
this.numPenaltiesAwarded = 0;
|
||||
this.numPenaltiesServed = 0;
|
||||
this.estTimeAtFinish = 0;
|
||||
this.estTimeAtNextMark = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package seng302.Networking.Messages.Enums;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Enumeration that encapsulates the various statuses a race can have. See AC35 streaming spec, 4.2.
|
||||
*/
|
||||
public enum RaceStatusEnum {
|
||||
|
||||
NOT_ACTIVE(0),
|
||||
|
||||
/**
|
||||
* Between 3:00 and 1:00 minutes before start.
|
||||
*/
|
||||
WARNING(1),
|
||||
|
||||
/**
|
||||
* Less than 1:00 minutes before start.
|
||||
*/
|
||||
PREPARATORY(2),
|
||||
STARTED(3),
|
||||
|
||||
/**
|
||||
* Obsolete.
|
||||
*/
|
||||
FINISHED(4),
|
||||
|
||||
/**
|
||||
* Obsolete.
|
||||
*/
|
||||
RETIRED(5),
|
||||
ABANDONED(6),
|
||||
POSTPONED(7),
|
||||
TERMINATED(8),
|
||||
RACE_START_TIME_NOT_SET(9),
|
||||
|
||||
/**
|
||||
* More than 3:00 minutes until start.
|
||||
*/
|
||||
PRESTART(10),
|
||||
|
||||
/**
|
||||
* Used to indicate that a given byte value is invalid.
|
||||
*/
|
||||
NOT_A_STATUS(-1);
|
||||
|
||||
|
||||
/**
|
||||
* Primitive value of the enum.
|
||||
*/
|
||||
private byte value;
|
||||
|
||||
|
||||
/**
|
||||
* Ctor. Creates a RaceStatusEnum from a given primitive integer value, cast to a byte.
|
||||
* @param value Integer, which is cast to byte, to construct from.
|
||||
*/
|
||||
private RaceStatusEnum(int value) {
|
||||
this.value = (byte) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive value of the enum.
|
||||
* @return Primitive value of the enum.
|
||||
*/
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores a mapping between Byte values and RaceStatusEnum values.
|
||||
*/
|
||||
private static final Map<Byte, RaceStatusEnum> byteToStatusMap = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Static initialization block. Initializes the byteToStatusMap.
|
||||
*/
|
||||
static {
|
||||
for (RaceStatusEnum type : RaceStatusEnum.values()) {
|
||||
RaceStatusEnum.byteToStatusMap.put(type.value, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the enumeration value which corresponds to a given byte value.
|
||||
* @param raceStatusByte Byte value to convert to a RaceStatusEnum value.
|
||||
* @return The RaceStatusEnum value which corresponds to the given byte value.
|
||||
*/
|
||||
public static RaceStatusEnum fromByte(byte raceStatusByte) {
|
||||
//Gets the corresponding MessageType from the map.
|
||||
RaceStatusEnum type = RaceStatusEnum.byteToStatusMap.get(raceStatusByte);
|
||||
|
||||
if (type == null) {
|
||||
//If the byte value wasn't found, return the NOT_A_STATUS RaceStatusEnum.
|
||||
return RaceStatusEnum.NOT_A_STATUS;
|
||||
} else {
|
||||
//Otherwise, return the RaceStatusEnum.
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package seng302.Networking.Messages.Enums;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Enumeration that encapsulates the various types of races. See AC35 streaming spec, 4.2.
|
||||
*/
|
||||
public enum RaceTypeEnum {
|
||||
|
||||
|
||||
/**
|
||||
* A race between two boats.
|
||||
*/
|
||||
MATCH_RACE(1),
|
||||
|
||||
/**
|
||||
* A race between a fleet of boats.
|
||||
*/
|
||||
FLEET_RACE(2),
|
||||
|
||||
/**
|
||||
* Used to indicate that a given byte value is invalid.
|
||||
*/
|
||||
NOT_A_STATUS(-1);
|
||||
|
||||
|
||||
/**
|
||||
* Primitive value of the enum.
|
||||
*/
|
||||
private byte value;
|
||||
|
||||
|
||||
/**
|
||||
* Ctor. Creates a RaceTypeEnum from a given primitive integer value, cast to a byte.
|
||||
* @param value Integer, which is cast to byte, to construct from.
|
||||
*/
|
||||
private RaceTypeEnum(int value) {
|
||||
this.value = (byte) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive value of the enum.
|
||||
* @return Primitive value of the enum.
|
||||
*/
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores a mapping between Byte values and RaceStatusEnum values.
|
||||
*/
|
||||
private static final Map<Byte, RaceTypeEnum> byteToStatusMap = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Static initialization block. Initializes the byteToStatusMap.
|
||||
*/
|
||||
static {
|
||||
for (RaceTypeEnum type : RaceTypeEnum.values()) {
|
||||
RaceTypeEnum.byteToStatusMap.put(type.value, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the enumeration value which corresponds to a given byte value.
|
||||
* @param raceTypeEnum Byte value to convert to a RaceTypeEnum value.
|
||||
* @return The RaceTypeEnum value which corresponds to the given byte value.
|
||||
*/
|
||||
public static RaceTypeEnum fromByte(byte raceTypeEnum) {
|
||||
//Gets the corresponding MessageType from the map.
|
||||
RaceTypeEnum type = RaceTypeEnum.byteToStatusMap.get(raceTypeEnum);
|
||||
|
||||
if (type == null) {
|
||||
//If the byte value wasn't found, return the NOT_A_STATUS RaceTypeEnum.
|
||||
return RaceTypeEnum.NOT_A_STATUS;
|
||||
} else {
|
||||
//Otherwise, return the RaceTypeEnum.
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package seng302.Networking.Messages;
|
||||
import seng302.Networking.Messages.Enums.MessageType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
@@ -16,10 +17,10 @@ public class RaceStatus extends AC35Data {
|
||||
private int windDirection;
|
||||
private int windSpeed;
|
||||
private int raceType;
|
||||
private ArrayList<BoatStatus> boatStatuses;
|
||||
private List<BoatStatus> boatStatuses;
|
||||
private static final double windDirectionScalar = 360.0 / 32768.0; // 0x8000 / 360
|
||||
|
||||
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, ArrayList<BoatStatus> boatStatuses){
|
||||
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, List<BoatStatus> boatStatuses){
|
||||
super(MessageType.RACESTATUS);
|
||||
this.currentTime = currentTime;
|
||||
this.raceID = raceID;
|
||||
@@ -74,7 +75,7 @@ public class RaceStatus extends AC35Data {
|
||||
return raceType;
|
||||
}
|
||||
|
||||
public ArrayList<BoatStatus> getBoatStatuses()
|
||||
public List<BoatStatus> getBoatStatuses()
|
||||
{
|
||||
return boatStatuses;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user