Merge remote-tracking branch 'origin/1124_broadcast_mark_rounding_message' into 1124_broadcast_mark_rounding_message

# Conflicts:
#	src/main/java/seng302/gameServer/GameState.java
This commit is contained in:
Calum
2017-08-15 15:13:40 +12:00
13 changed files with 375 additions and 290 deletions
+16 -18
View File
@@ -4,9 +4,9 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import seng302.gameServer.server.messages.BoatAction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import seng302.gameServer.server.messages.BoatAction;
import seng302.gameServer.server.messages.MarkRoundingMessage; import seng302.gameServer.server.messages.MarkRoundingMessage;
import seng302.gameServer.server.messages.MarkType; import seng302.gameServer.server.messages.MarkType;
import seng302.gameServer.server.messages.Message; import seng302.gameServer.server.messages.Message;
@@ -14,7 +14,7 @@ import seng302.gameServer.server.messages.RoundingBoatStatus;
import seng302.model.GeoPoint; import seng302.model.GeoPoint;
import seng302.model.Player; import seng302.model.Player;
import seng302.model.PolarTable; import seng302.model.PolarTable;
import seng302.model.Yacht; import seng302.model.ServerYacht;
import seng302.model.mark.CompoundMark; import seng302.model.mark.CompoundMark;
import seng302.model.mark.Mark; import seng302.model.mark.Mark;
import seng302.model.mark.MarkOrder; import seng302.model.mark.MarkOrder;
@@ -44,7 +44,7 @@ public class GameState implements Runnable {
private static String hostIpAddress; private static String hostIpAddress;
private static List<Player> players; private static List<Player> players;
private static Map<Integer, Yacht> yachts; private static Map<Integer, ServerYacht> yachts;
private static Boolean isRaceStarted; private static Boolean isRaceStarted;
private static GameStages currentStage; private static GameStages currentStage;
private static MarkOrder markOrder; private static MarkOrder markOrder;
@@ -102,7 +102,7 @@ public class GameState implements Runnable {
playerStringMap.remove(player); playerStringMap.remove(player);
} }
public static void addYacht(Integer sourceId, Yacht yacht) { public static void addYacht(Integer sourceId, ServerYacht yacht) {
yachts.put(sourceId, yacht); yachts.put(sourceId, yacht);
} }
@@ -146,7 +146,7 @@ public class GameState implements Runnable {
return GeoUtility.mmsToKnots(windSpeed); // TODO: 26/07/17 cir27 - remove magic numbers return GeoUtility.mmsToKnots(windSpeed); // TODO: 26/07/17 cir27 - remove magic numbers
} }
public static Map<Integer, Yacht> getYachts() { public static Map<Integer, ServerYacht> getYachts() {
return yachts; return yachts;
} }
@@ -185,7 +185,7 @@ public class GameState implements Runnable {
} }
public static void updateBoat(Integer sourceId, BoatAction actionType) { public static void updateBoat(Integer sourceId, BoatAction actionType) {
Yacht playerYacht = yachts.get(sourceId); ServerYacht playerYacht = yachts.get(sourceId);
switch (actionType) { switch (actionType) {
case VMG: case VMG:
playerYacht.turnToVMG(); playerYacht.turnToVMG();
@@ -215,7 +215,7 @@ public class GameState implements Runnable {
public void update() { public void update() {
Double timeInterval = (System.currentTimeMillis() - previousUpdateTime) / 1000000.0; Double timeInterval = (System.currentTimeMillis() - previousUpdateTime) / 1000000.0;
previousUpdateTime = System.currentTimeMillis(); previousUpdateTime = System.currentTimeMillis();
for (Yacht yacht : yachts.values()) { for (ServerYacht yacht : yachts.values()) {
updateVelocity(yacht); updateVelocity(yacht);
yacht.runAutoPilot(); yacht.runAutoPilot();
yacht.updateLocation(timeInterval); yacht.updateLocation(timeInterval);
@@ -226,13 +226,11 @@ public class GameState implements Runnable {
} }
private void updateVelocity(Yacht yacht) { private void updateVelocity(ServerYacht yacht) {
Double velocity = yacht.getCurrentVelocity(); Double velocity = yacht.getCurrentVelocity();
Double trueWindAngle = Math.abs(windDirection - yacht.getHeading()); Double trueWindAngle = Math.abs(windDirection - yacht.getHeading());
Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle); Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle);
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots); Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots);
yacht.setCurrentMaxVelocity(maxBoatSpeed);
System.out.println(maxBoatSpeed);
// TODO: 15/08/17 remove magic numbers from these equations. // TODO: 15/08/17 remove magic numbers from these equations.
if (yacht.getSailIn()) { if (yacht.getSailIn()) {
if (velocity < maxBoatSpeed - 500) { if (velocity < maxBoatSpeed - 500) {
@@ -262,7 +260,7 @@ public class GameState implements Runnable {
* @throws IndexOutOfBoundsException If the next mark is null (ie the last mark in the race) * @throws IndexOutOfBoundsException If the next mark is null (ie the last mark in the race)
* Check first using {@link seng302.model.mark.MarkOrder#isLastMark(Integer)} * Check first using {@link seng302.model.mark.MarkOrder#isLastMark(Integer)}
*/ */
private Double calcDistanceToCurrentMark(Yacht yacht) throws IndexOutOfBoundsException { private Double calcDistanceToCurrentMark(ServerYacht yacht) throws IndexOutOfBoundsException {
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID(); Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID); CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
GeoPoint location = yacht.getLocation(); GeoPoint location = yacht.getLocation();
@@ -291,7 +289,7 @@ public class GameState implements Runnable {
* in-race Gate 3 - Passing any in-race Mark 4 - Passing the finish line * in-race Gate 3 - Passing any in-race Mark 4 - Passing the finish line
* @param yacht the current yacht to check for progression * @param yacht the current yacht to check for progression
*/ */
private void checkForLegProgression(Yacht yacht) { private void checkForLegProgression(ServerYacht yacht) {
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID(); Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID); CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
@@ -323,7 +321,7 @@ public class GameState implements Runnable {
* *
* @param yacht The current yacht to check for * @param yacht The current yacht to check for
*/ */
private Boolean checkStartLineCrossing(Yacht yacht) { private Boolean checkStartLineCrossing(ServerYacht yacht) {
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID(); Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID); CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
GeoPoint lastLocation = yacht.getLastLocation(); GeoPoint lastLocation = yacht.getLastLocation();
@@ -353,7 +351,7 @@ public class GameState implements Runnable {
* *
* @param yacht The current yacht to check for * @param yacht The current yacht to check for
*/ */
private Boolean checkMarkRounding(Yacht yacht) { private Boolean checkMarkRounding(ServerYacht yacht) {
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID(); Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID); CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
GeoPoint lastLocation = yacht.getLastLocation(); GeoPoint lastLocation = yacht.getLastLocation();
@@ -382,7 +380,7 @@ public class GameState implements Runnable {
* *
* @param yacht The current yacht to check for * @param yacht The current yacht to check for
*/ */
private Boolean checkGateRounding(Yacht yacht) { private Boolean checkGateRounding(ServerYacht yacht) {
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID(); Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID); CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
GeoPoint lastLocation = yacht.getLastLocation(); GeoPoint lastLocation = yacht.getLastLocation();
@@ -425,7 +423,7 @@ public class GameState implements Runnable {
* *
* @param yacht The current yacht to check for * @param yacht The current yacht to check for
*/ */
private Boolean checkFinishLineCrossing(Yacht yacht) { private Boolean checkFinishLineCrossing(ServerYacht yacht) {
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID(); Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID); CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
GeoPoint lastLocation = yacht.getLastLocation(); GeoPoint lastLocation = yacht.getLastLocation();
@@ -449,7 +447,7 @@ public class GameState implements Runnable {
return false; return false;
} }
private void sendMarkRoundingMessage(Yacht yacht) { private void sendMarkRoundingMessage(ServerYacht yacht) {
Integer sourceID = yacht.getSourceId(); Integer sourceID = yacht.getSourceId();
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID(); Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID); CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
@@ -467,7 +465,7 @@ public class GameState implements Runnable {
} }
private void logMarkRounding(Yacht yacht) { private void logMarkRounding(ServerYacht yacht) {
Mark roundingMark = yacht.getClosestCurrentMark(); Mark roundingMark = yacht.getClosestCurrentMark();
logger.debug( logger.debug(
@@ -19,6 +19,7 @@ import java.util.zip.CRC32;
import java.util.zip.Checksum; import java.util.zip.Checksum;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import seng302.gameServer.server.messages.BoatAction;
import seng302.gameServer.server.messages.BoatLocationMessage; import seng302.gameServer.server.messages.BoatLocationMessage;
import seng302.gameServer.server.messages.BoatStatus; import seng302.gameServer.server.messages.BoatStatus;
import seng302.gameServer.server.messages.BoatSubMessage; import seng302.gameServer.server.messages.BoatSubMessage;
@@ -32,13 +33,12 @@ import seng302.gameServer.server.messages.RegistrationResponseStatus;
import seng302.gameServer.server.messages.XMLMessage; import seng302.gameServer.server.messages.XMLMessage;
import seng302.gameServer.server.messages.XMLMessageSubType; import seng302.gameServer.server.messages.XMLMessageSubType;
import seng302.model.Player; import seng302.model.Player;
import seng302.model.Yacht; import seng302.model.ServerYacht;
import seng302.model.stream.packets.PacketType; import seng302.model.stream.packets.PacketType;
import seng302.model.stream.packets.StreamPacket; import seng302.model.stream.packets.StreamPacket;
import seng302.model.stream.xml.generator.Race; import seng302.model.stream.xml.generator.Race;
import seng302.model.stream.xml.generator.Regatta; import seng302.model.stream.xml.generator.Regatta;
import seng302.utilities.XMLGenerator; import seng302.utilities.XMLGenerator;
import seng302.gameServer.server.messages.BoatAction;
/** /**
* A class describing a single connection to a Client for the purposes of sending and receiving on * A class describing a single connection to a Client for the purposes of sending and receiving on
@@ -115,8 +115,7 @@ public class ServerToClientThread implements Runnable, Observer {
all = ln.lines().collect(Collectors.toList()); all = ln.lines().collect(Collectors.toList());
lName = all.get(ThreadLocalRandom.current().nextInt(0, all.size())); lName = all.get(ThreadLocalRandom.current().nextInt(0, all.size()));
ServerYacht yacht = new ServerYacht(
Yacht yacht = new Yacht(
"Yacht", sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ" "Yacht", sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ"
); );
@@ -221,7 +220,7 @@ public class ServerToClientThread implements Runnable, Observer {
xml = new XMLGenerator(); xml = new XMLGenerator();
Race race = new Race(); Race race = new Race();
for (Yacht yacht : GameState.getYachts().values()) { for (ServerYacht yacht : GameState.getYachts().values()) {
race.addBoat(yacht); race.addBoat(yacht);
} }
@@ -299,8 +298,8 @@ public class ServerToClientThread implements Runnable, Observer {
public void sendBoatLocationPackets() { public void sendBoatLocationPackets() {
ArrayList<Yacht> yachts = new ArrayList<>(GameState.getYachts().values()); ArrayList<ServerYacht> yachts = new ArrayList<>(GameState.getYachts().values());
for (Yacht yacht : yachts) { for (ServerYacht yacht : yachts) {
BoatLocationMessage boatLocationMessage = BoatLocationMessage boatLocationMessage =
new BoatLocationMessage( new BoatLocationMessage(
yacht.getSourceId(), yacht.getSourceId(),
@@ -326,7 +325,7 @@ public class ServerToClientThread implements Runnable, Observer {
RaceStatus raceStatus; RaceStatus raceStatus;
for (Player player : GameState.getPlayers()) { for (Player player : GameState.getPlayers()) {
Yacht y = player.getYacht(); ServerYacht y = player.getYacht();
if (GameState.getCurrentStage() == GameStages.PRE_RACE) { if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
boatStatus = BoatStatus.PRESTART; boatStatus = BoatStatus.PRESTART;
@@ -0,0 +1,258 @@
package seng302.model;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.beans.property.ReadOnlyLongProperty;
import javafx.beans.property.ReadOnlyLongWrapper;
import javafx.scene.paint.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import seng302.model.mark.CompoundMark;
/**
* Yacht class for the racing boat. <p> Class created to store more variables (eg. boat statuses)
* compared to the XMLParser boat class, also done outside Boat class because some old variables are
* not used anymore.
*/
public class ClientYacht extends Observable {
@FunctionalInterface
public interface YachtLocationListener {
void notifyLocation(ClientYacht clientYacht, double lat, double lon, double heading,
double velocity);
}
private Logger logger = LoggerFactory.getLogger(ClientYacht.class);
//BOTH AFAIK
private String boatType;
private Integer sourceId;
private String hullID; //matches HullNum in the XML spec.
private String shortName;
private String boatName;
private String country;
private Long estimateTimeAtFinish;
private Integer currentMarkSeqID = 0;
private Long markRoundTime;
private Long timeTillNext;
private Double heading;
private Integer legNumber = 0;
private GeoPoint location;
private Integer boatStatus;
private Double currentVelocity;
//CLIENT SIDE
private List<YachtLocationListener> locationListeners = new ArrayList<>();
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
private CompoundMark lastMarkRounded;
private Integer positionInt = 0;
private Color colour;
public ClientYacht(String boatType, Integer sourceId, String hullID, String shortName,
String boatName, String country) {
this.boatType = boatType;
this.sourceId = sourceId;
this.hullID = hullID;
this.shortName = shortName;
this.boatName = boatName;
this.country = country;
this.location = new GeoPoint(57.670341, 11.826856);
this.heading = 120.0; //In degrees
this.currentVelocity = 0d;
}
/**
* Add ServerToClientThread as the observer, this observer pattern mainly server for the boat
* rounding package.
*/
@Override
public void addObserver(Observer o) {
super.addObserver(o);
}
public String getBoatType() {
return boatType;
}
public Integer getSourceId() {
//@TODO Remove and merge with Creating Game Loop
if (sourceId == null) {
return 0;
}
return sourceId;
}
public String getHullID() {
if (hullID == null) {
return "";
}
return hullID;
}
public String getShortName() {
return shortName;
}
public String getBoatName() {
return boatName;
}
public String getCountry() {
if (country == null) {
return "";
}
return country;
}
public Integer getBoatStatus() {
return boatStatus;
}
public void setBoatStatus(Integer boatStatus) {
this.boatStatus = boatStatus;
}
public Integer getLegNumber() {
return legNumber;
}
public void setLegNumber(Integer legNumber) {
this.legNumber = legNumber;
}
public void setEstimateTimeTillNextMark(Long estimateTimeTillNextMark) {
timeTillNext = estimateTimeTillNextMark;
}
public String getEstimateTimeAtFinish() {
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return format.format(estimateTimeAtFinish);
}
public void setEstimateTimeAtFinish(Long estimateTimeAtFinish) {
this.estimateTimeAtFinish = estimateTimeAtFinish;
}
public Integer getPositionInteger() {
return positionInt;
}
public void setPositionInteger(Integer position) {
this.positionInt = position;
}
public void updateVelocityProperty(double velocity) {
this.velocityProperty.set(velocity);
}
public void setMarkRoundingTime(Long markRoundingTime) {
this.markRoundTime = markRoundingTime;
}
public ReadOnlyDoubleProperty getVelocityProperty() {
return velocityProperty.getReadOnlyProperty();
}
public ReadOnlyLongProperty timeTillNextProperty() {
return timeTillNextProperty.getReadOnlyProperty();
}
public Long getTimeTillNext() {
return timeTillNext;
}
public Long getMarkRoundTime() {
return markRoundTime;
}
public CompoundMark getLastMarkRounded() {
return lastMarkRounded;
}
public void setLastMarkRounded(CompoundMark lastMarkRounded) {
this.lastMarkRounded = lastMarkRounded;
}
public GeoPoint getLocation() {
return location;
}
/**
* Sets the current location of the boat in lat and long whilst preserving the last location
*
* @param lat Latitude
* @param lng Longitude
*/
public void setLocation(Double lat, Double lng) {
location.setLat(lat);
location.setLng(lng);
}
public Double getHeading() {
return heading;
}
public void setHeading(Double heading) {
this.heading = heading;
}
@Override
public String toString() {
return boatName;
}
public void updateTimeSinceLastMarkProperty(long timeSinceLastMark) {
this.timeSinceLastMarkProperty.set(timeSinceLastMark);
}
public ReadOnlyLongProperty timeSinceLastMarkProperty() {
return timeSinceLastMarkProperty.getReadOnlyProperty();
}
public void setTimeTillNext(Long timeTillNext) {
this.timeTillNext = timeTillNext;
}
public Color getColour() {
return colour;
}
public void setColour(Color colour) {
this.colour = colour;
}
// public Double getCurrentVelocity() {
// return currentVelocity;
// }
//
// public void setCurrentVelocity(Double currentVelocity) {
// this.currentVelocity = currentVelocity;
// }
public void updateLocation(double lat, double lng, double heading, double velocity) {
setLocation(lat, lng);
this.heading = heading;
// this.currentVelocity = velocity;
updateVelocityProperty(velocity);
for (YachtLocationListener yll : locationListeners) {
yll.notifyLocation(this, lat, lng, heading, velocity);
}
}
public void addLocationListener(YachtLocationListener listener) {
locationListeners.add(listener);
}
}
+3 -3
View File
@@ -9,11 +9,11 @@ import java.net.Socket;
public class Player { public class Player {
private Socket socket; private Socket socket;
private Yacht yacht; private ServerYacht yacht;
private Integer lastMarkPassed; private Integer lastMarkPassed;
public Player(Socket socket, Yacht yacht) { public Player(Socket socket, ServerYacht yacht) {
this.socket = socket; this.socket = socket;
this.yacht = yacht; this.yacht = yacht;
} }
@@ -30,7 +30,7 @@ public class Player {
this.lastMarkPassed = lastMarkPassed; this.lastMarkPassed = lastMarkPassed;
} }
public Yacht getYacht() { public ServerYacht getYacht() {
return yacht; return yacht;
} }
@@ -1,21 +1,11 @@
package seng302.model; package seng302.model;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.beans.property.ReadOnlyLongProperty;
import javafx.beans.property.ReadOnlyLongWrapper;
import javafx.scene.paint.Color;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.model.mark.CompoundMark;
import seng302.model.mark.Mark; import seng302.model.mark.Mark;
import seng302.utilities.GeoUtility; import seng302.utilities.GeoUtility;
@@ -24,18 +14,12 @@ import seng302.utilities.GeoUtility;
* compared to the XMLParser boat class, also done outside Boat class because some old variables are * compared to the XMLParser boat class, also done outside Boat class because some old variables are
* not used anymore. * not used anymore.
*/ */
public class Yacht extends Observable { public class ServerYacht extends Observable {
@FunctionalInterface private Logger logger = LoggerFactory.getLogger(ClientYacht.class);
public interface YachtLocationListener {
void notifyLocation(Yacht yacht, double lat, double lon, double heading, double velocity); public static final Double TURN_STEP = 5.0;
}
private Logger logger = LoggerFactory.getLogger(Yacht.class);
//BOTH AFAIK
private String boatType; private String boatType;
private Integer sourceId; private Integer sourceId;
private String hullID; //matches HullNum in the XML spec. private String hullID; //matches HullNum in the XML spec.
@@ -43,43 +27,24 @@ public class Yacht extends Observable {
private String boatName; private String boatName;
private String country; private String country;
private Long estimateTimeAtFinish;
private Integer currentMarkSeqID = 0;
private Long markRoundTime;
private Double distanceToCurrentMark;
private Long timeTillNext;
private Double heading;
private Integer legNumber = 0;
//SERVER SIDE
public static final Double TURN_STEP = 5.0; //This should be in some utils class somewhere 2bh. Public for tests sake.
private Double lastHeading; private Double lastHeading;
private Boolean sailIn; private Boolean sailIn;
private Double heading;
private GeoPoint location; private GeoPoint location;
private Integer boatStatus;
private Double currentVelocity; private Double currentVelocity;
private Double currentMaxVelocity;
private Boolean isAuto; private Boolean isAuto;
private Double autoHeading; private Double autoHeading;
//MARK ROUNDING INFO private Integer currentMarkSeqID = 0;
private GeoPoint lastLocation; //For purposes of mark rounding calculations private GeoPoint lastLocation;
private Boolean hasEnteredRoundingZone; //The distance that the boat must be from the mark to round private Boolean hasEnteredRoundingZone;
private Mark closestCurrentMark; private Mark closestCurrentMark;
private Boolean hasPassedLine; private Boolean hasPassedLine;
private Boolean hasPassedThroughGate; private Boolean hasPassedThroughGate;
private Boolean finishedRace; private Boolean finishedRace;
//CLIENT SIDE
private List<YachtLocationListener> locationListeners = new ArrayList<>();
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
private CompoundMark lastMarkRounded;
private Integer positionInt = 0;
private Color colour;
public Yacht(String boatType, Integer sourceId, String hullID, String shortName, public ServerYacht(String boatType, Integer sourceId, String hullID, String shortName,
String boatName, String country) { String boatName, String country) {
this.boatType = boatType; this.boatType = boatType;
this.sourceId = sourceId; this.sourceId = sourceId;
@@ -103,6 +68,7 @@ public class Yacht extends Observable {
/** /**
* Changes the boats current currentVelocity by a set amount, positive or negative * Changes the boats current currentVelocity by a set amount, positive or negative
*
* @param velocityChange The ammount to change the currentVelocity by, in mms-1 * @param velocityChange The ammount to change the currentVelocity by, in mms-1
*/ */
public void changeVelocity(Double velocityChange) { public void changeVelocity(Double velocityChange) {
@@ -128,7 +94,6 @@ public class Yacht extends Observable {
super.addObserver(o); super.addObserver(o);
} }
/** /**
* Adjusts the heading of the boat by a given amount, while recording the boats last heading. * Adjusts the heading of the boat by a given amount, while recording the boats last heading.
* *
@@ -291,10 +256,6 @@ public class Yacht extends Observable {
return normalizedHeading; return normalizedHeading;
} }
public String getBoatType() {
return boatType;
}
public Integer getSourceId() { public Integer getSourceId() {
//@TODO Remove and merge with Creating Game Loop //@TODO Remove and merge with Creating Game Loop
if (sourceId == null) { if (sourceId == null) {
@@ -303,6 +264,7 @@ public class Yacht extends Observable {
return sourceId; return sourceId;
} }
// TODO: 15/08/17 This method is implicitly called from the XML generator for boats DO NOT DELETE
public String getHullID() { public String getHullID() {
if (hullID == null) { if (hullID == null) {
return ""; return "";
@@ -310,6 +272,7 @@ public class Yacht extends Observable {
return hullID; return hullID;
} }
// TODO: 15/08/17 This method is implicitly called from the XML generator for boats DO NOT DELETE
public String getShortName() { public String getShortName() {
return shortName; return shortName;
} }
@@ -325,102 +288,11 @@ public class Yacht extends Observable {
return country; return country;
} }
public Integer getBoatStatus() {
return boatStatus;
}
public void setBoatStatus(Integer boatStatus) {
this.boatStatus = boatStatus;
}
public Integer getLegNumber() {
return legNumber;
}
public void setLegNumber(Integer legNumber) {
// if (colour != null && position != "-" && legNumber != this.legNumber) {
// RaceViewController.updateYachtPositionSparkline(this, legNumber);
// }
this.legNumber = legNumber;
}
public void setEstimateTimeTillNextMark(Long estimateTimeTillNextMark) {
timeTillNext = estimateTimeTillNextMark;
}
public String getEstimateTimeAtFinish() {
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return format.format(estimateTimeAtFinish);
}
public void setEstimateTimeAtFinish(Long estimateTimeAtFinish) {
this.estimateTimeAtFinish = estimateTimeAtFinish;
}
public Integer getPositionInteger() {
return positionInt;
}
public void setPositionInteger(Integer position) {
this.positionInt = position;
}
public void updateVelocityProperty(double velocity) {
this.velocityProperty.set(velocity);
}
public void setMarkRoundingTime(Long markRoundingTime) {
this.markRoundTime = markRoundingTime;
}
public ReadOnlyDoubleProperty getVelocityProperty() {
return velocityProperty.getReadOnlyProperty();
}
public double getVelocityMMS() {
return currentVelocity;
}
public ReadOnlyLongProperty timeTillNextProperty() {
return timeTillNextProperty.getReadOnlyProperty();
}
public Double getVelocityKnots() {
return currentVelocity / 1000 * 1.943844492; // TODO: 26/07/17 cir27 - remove magic number
}
public Long getTimeTillNext() {
return timeTillNext;
}
public Long getMarkRoundTime() {
return markRoundTime;
}
public CompoundMark getLastMarkRounded() {
return lastMarkRounded;
}
public void setLastMarkRounded(CompoundMark lastMarkRounded) {
this.lastMarkRounded = lastMarkRounded;
}
public GeoPoint getLocation() { public GeoPoint getLocation() {
return location; return location;
} }
/**
* Sets the current location of the boat in lat and long whilst preserving the last location
*
* @param lat Latitude
* @param lng Longitude
*/
public void setLocation(Double lat, Double lng) {
lastLocation.setLat(location.getLat());
lastLocation.setLng(location.getLng());
location.setLat(lat);
location.setLng(lng);
}
public Double getHeading() { public Double getHeading() {
return heading; return heading;
@@ -439,26 +311,6 @@ public class Yacht extends Observable {
return boatName; return boatName;
} }
public void updateTimeSinceLastMarkProperty(long timeSinceLastMark) {
this.timeSinceLastMarkProperty.set(timeSinceLastMark);
}
public ReadOnlyLongProperty timeSinceLastMarkProperty() {
return timeSinceLastMarkProperty.getReadOnlyProperty();
}
public void setTimeTillNext(Long timeTillNext) {
this.timeTillNext = timeTillNext;
}
public Color getColour() {
return colour;
}
public void setColour(Color colour) {
this.colour = colour;
}
public void setIsFinished(Boolean isFinished) { public void setIsFinished(Boolean isFinished) {
finishedRace = isFinished; finishedRace = isFinished;
@@ -519,30 +371,4 @@ public class Yacht extends Observable {
public Boolean hasPassedLine() { public Boolean hasPassedLine() {
return hasPassedLine; return hasPassedLine;
} }
public Double getDistanceToCurrentMark() {
return distanceToCurrentMark;
}
public Double getCurrentMaxVelocity() {
return currentMaxVelocity;
}
public void setCurrentMaxVelocity(Double currentMaxVelocity) {
this.currentMaxVelocity = currentMaxVelocity;
}
public void updateLocation(double lat, double lng, double heading, double velocity) {
setLocation(lat, lng);
this.heading = heading;
this.currentVelocity = velocity;
updateVelocityProperty(velocity);
for (YachtLocationListener yll : locationListeners) {
yll.notifyLocation(this, lat, lng, heading, velocity);
}
}
public void addLocationListener(YachtLocationListener listener) {
locationListeners.add(listener);
}
} }
@@ -4,13 +4,14 @@ import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import seng302.model.Yacht; import seng302.model.ServerYacht;
/** /**
* A Race object that can be parsed into XML * A Race object that can be parsed into XML
*/ */
public class Race { public class Race {
private List<Yacht> yachts;
private List<ServerYacht> yachts;
private LocalDateTime startTime; private LocalDateTime startTime;
public Race(){ public Race(){
@@ -22,7 +23,7 @@ public class Race {
* Add a boat to the race * Add a boat to the race
* @param yacht The boat to add * @param yacht The boat to add
*/ */
public void addBoat(Yacht yacht){ public void addBoat(ServerYacht yacht) {
yachts.add(yacht); yachts.add(yacht);
} }
@@ -30,7 +31,7 @@ public class Race {
* Get a list of boats in the race * Get a list of boats in the race
* @return A List of boats * @return A List of boats
*/ */
public List<Yacht> getBoats(){ public List<ServerYacht> getBoats() {
return Collections.unmodifiableList(yachts); return Collections.unmodifiableList(yachts);
} }
@@ -8,8 +8,8 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import seng302.model.ClientYacht;
import seng302.model.Limit; import seng302.model.Limit;
import seng302.model.Yacht;
import seng302.model.mark.CompoundMark; import seng302.model.mark.CompoundMark;
import seng302.model.mark.Corner; import seng302.model.mark.Corner;
import seng302.model.mark.Mark; import seng302.model.mark.Mark;
@@ -125,8 +125,8 @@ public class XMLParser {
* @param doc XML Document Object * @param doc XML Document Object
* @return Mapping of sourceIds to Boats. * @return Mapping of sourceIds to Boats.
*/ */
public static Map<Integer, Yacht> parseBoats(Document doc){ public static Map<Integer, ClientYacht> parseBoats(Document doc) {
Map<Integer, Yacht> competingBoats = new HashMap<>(); Map<Integer, ClientYacht> competingBoats = new HashMap<>();
Element docEle = doc.getDocumentElement(); Element docEle = doc.getDocumentElement();
@@ -135,7 +135,8 @@ public class XMLParser {
Node currentBoat = boatsList.item(i); Node currentBoat = boatsList.item(i);
if (currentBoat.getNodeName().equals("Boat")) { if (currentBoat.getNodeName().equals("Boat")) {
// Boat boat = new Boat(currentBoat); // Boat boat = new Boat(currentBoat);
Yacht yacht = new Yacht(XMLParser.getNodeAttributeString(currentBoat, "Type"), ClientYacht yacht = new ClientYacht(
XMLParser.getNodeAttributeString(currentBoat, "Type"),
XMLParser.getNodeAttributeInt(currentBoat, "SourceID"), XMLParser.getNodeAttributeInt(currentBoat, "SourceID"),
XMLParser.getNodeAttributeString(currentBoat, "HullNum"), XMLParser.getNodeAttributeString(currentBoat, "HullNum"),
XMLParser.getNodeAttributeString(currentBoat, "ShortName"), XMLParser.getNodeAttributeString(currentBoat, "ShortName"),
@@ -14,8 +14,8 @@ import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import seng302.gameServer.MainServerThread; import seng302.gameServer.MainServerThread;
import seng302.gameServer.server.messages.BoatAction; import seng302.gameServer.server.messages.BoatAction;
import seng302.model.ClientYacht;
import seng302.model.RaceState; import seng302.model.RaceState;
import seng302.model.Yacht;
import seng302.model.stream.packets.StreamPacket; import seng302.model.stream.packets.StreamPacket;
import seng302.model.stream.parser.MarkRoundingData; import seng302.model.stream.parser.MarkRoundingData;
import seng302.model.stream.parser.PositionUpdateData; import seng302.model.stream.parser.PositionUpdateData;
@@ -41,7 +41,7 @@ public class GameClient {
private RaceViewController raceView; private RaceViewController raceView;
private Map<Integer, Yacht> allBoatsMap; private Map<Integer, ClientYacht> allBoatsMap;
private RegattaXMLData regattaData; private RegattaXMLData regattaData;
private RaceXMLData courseData; private RaceXMLData courseData;
private RaceState raceState = new RaceState(); private RaceState raceState = new RaceState();
@@ -151,7 +151,7 @@ public class GameClient {
holderPane.getScene().setOnKeyPressed(this::keyPressed); holderPane.getScene().setOnKeyPressed(this::keyPressed);
holderPane.getScene().setOnKeyReleased(this::keyReleased); holderPane.getScene().setOnKeyReleased(this::keyReleased);
raceView = fxmlLoader.getController(); raceView = fxmlLoader.getController();
Yacht player = allBoatsMap.get(socketThread.getClientId()); ClientYacht player = allBoatsMap.get(socketThread.getClientId());
raceView.loadRace(allBoatsMap, courseData, raceState, player); raceView.loadRace(allBoatsMap, courseData, raceState, player);
} }
@@ -224,8 +224,8 @@ public class GameClient {
private void updatePosition(PositionUpdateData positionData) { private void updatePosition(PositionUpdateData positionData) {
if (positionData.getType() == DeviceType.YACHT_TYPE) { if (positionData.getType() == DeviceType.YACHT_TYPE) {
if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) { if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) {
Yacht yacht = allBoatsMap.get(positionData.getDeviceId()); ClientYacht clientYacht = allBoatsMap.get(positionData.getDeviceId());
yacht.updateLocation(positionData.getLat(), clientYacht.updateLocation(positionData.getLat(),
positionData.getLon(), positionData.getHeading(), positionData.getLon(), positionData.getHeading(),
positionData.getGroundSpeed()); positionData.getGroundSpeed());
} }
@@ -242,11 +242,11 @@ public class GameClient {
*/ */
private void updateMarkRounding(MarkRoundingData roundingData) { private void updateMarkRounding(MarkRoundingData roundingData) {
if (allXMLReceived()) { if (allXMLReceived()) {
Yacht yacht = allBoatsMap.get(roundingData.getBoatId()); ClientYacht clientYacht = allBoatsMap.get(roundingData.getBoatId());
yacht.setMarkRoundingTime(roundingData.getTimeStamp()); clientYacht.setMarkRoundingTime(roundingData.getTimeStamp());
yacht.updateTimeSinceLastMarkProperty( clientYacht.updateTimeSinceLastMarkProperty(
raceState.getRaceTime() - roundingData.getTimeStamp()); raceState.getRaceTime() - roundingData.getTimeStamp());
yacht.setLastMarkRounded( clientYacht.setLastMarkRounded(
courseData.getCompoundMarks().get( courseData.getCompoundMarks().get(
roundingData.getMarkId() roundingData.getMarkId()
) )
@@ -258,20 +258,20 @@ public class GameClient {
if (allXMLReceived()) { if (allXMLReceived()) {
raceState.updateState(data); raceState.updateState(data);
for (long[] boatData : data.getBoatData()) { for (long[] boatData : data.getBoatData()) {
Yacht yacht = allBoatsMap.get((int) boatData[0]); ClientYacht clientYacht = allBoatsMap.get((int) boatData[0]);
yacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]); clientYacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]);
yacht.setEstimateTimeAtFinish(boatData[2]); clientYacht.setEstimateTimeAtFinish(boatData[2]);
int legNumber = (int) boatData[3]; int legNumber = (int) boatData[3];
yacht.setLegNumber(legNumber); clientYacht.setLegNumber(legNumber);
yacht.setBoatStatus((int) boatData[4]); clientYacht.setBoatStatus((int) boatData[4]);
if (legNumber != yacht.getLegNumber()) { if (legNumber != clientYacht.getLegNumber()) {
int placing = 1; int placing = 1;
for (Yacht otherYacht : allBoatsMap.values()) { for (ClientYacht otherClientYacht : allBoatsMap.values()) {
if (otherYacht.getSourceId() != boatData[0] && if (otherClientYacht.getSourceId() != boatData[0] &&
yacht.getLegNumber() <= otherYacht.getLegNumber()) clientYacht.getLegNumber() <= otherClientYacht.getLegNumber())
placing++; placing++;
} }
yacht.setPositionInteger(placing); clientYacht.setPositionInteger(placing);
} }
} }
} }
+15 -15
View File
@@ -19,10 +19,10 @@ import javafx.scene.paint.Color;
import javafx.scene.paint.Paint; import javafx.scene.paint.Paint;
import javafx.scene.shape.Polygon; import javafx.scene.shape.Polygon;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import seng302.model.ClientYacht;
import seng302.model.Colors; import seng302.model.Colors;
import seng302.model.GeoPoint; import seng302.model.GeoPoint;
import seng302.model.Limit; import seng302.model.Limit;
import seng302.model.Yacht;
import seng302.model.mark.CompoundMark; import seng302.model.mark.CompoundMark;
import seng302.model.mark.Corner; import seng302.model.mark.Corner;
import seng302.model.mark.Mark; import seng302.model.mark.Mark;
@@ -61,8 +61,8 @@ public class GameView extends Pane {
private List<Limit> borderPoints; private List<Limit> borderPoints;
private Map<Mark, Marker> markerObjects; private Map<Mark, Marker> markerObjects;
private Map<Yacht, BoatObject> boatObjects = new HashMap<>(); private Map<ClientYacht, BoatObject> boatObjects = new HashMap<>();
private Map<Yacht, AnnotationBox> annotations = new HashMap<>(); private Map<ClientYacht, AnnotationBox> annotations = new HashMap<>();
private ObservableList<Node> gameObjects; private ObservableList<Node> gameObjects;
private Group annotationsGroup = new Group(); private Group annotationsGroup = new Group();
private Group wakesGroup = new Group(); private Group wakesGroup = new Group();
@@ -318,23 +318,23 @@ public class GameView extends Pane {
/** /**
* Draws all the boats. * Draws all the boats.
* @param yachts The yachts to set in the race * @param clientYachts The yachts to set in the race
*/ */
public void setBoats(List<Yacht> yachts) { public void setBoats(List<ClientYacht> clientYachts) {
BoatObject newBoat; BoatObject newBoat;
final List<Group> wakes = new ArrayList<>(); final List<Group> wakes = new ArrayList<>();
for (Yacht yacht : yachts) { for (ClientYacht clientYacht : clientYachts) {
Paint colour = Colors.getColor(); Paint colour = Colors.getColor();
newBoat = new BoatObject(); newBoat = new BoatObject();
newBoat.setFill(colour); newBoat.setFill(colour);
boatObjects.put(yacht, newBoat); boatObjects.put(clientYacht, newBoat);
createAndBindAnnotationBox(yacht, colour); createAndBindAnnotationBox(clientYacht, colour);
// wakesGroup.getChildren().add(newBoat.getWake()); // wakesGroup.getChildren().add(newBoat.getWake());
wakes.add(newBoat.getWake()); wakes.add(newBoat.getWake());
boatObjectGroup.getChildren().add(newBoat); boatObjectGroup.getChildren().add(newBoat);
trails.getChildren().add(newBoat.getTrail()); trails.getChildren().add(newBoat.getTrail());
// TODO: 1/08/17 Make this less vile to look at. // TODO: 1/08/17 Make this less vile to look at.
yacht.addLocationListener((boat, lat, lon, heading, velocity) ->{ clientYacht.addLocationListener((boat, lat, lon, heading, velocity) -> {
BoatObject bo = boatObjects.get(boat); BoatObject bo = boatObjects.get(boat);
Point2D p2d = findScaledXY(lat, lon); Point2D p2d = findScaledXY(lat, lon);
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity); bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity);
@@ -358,11 +358,11 @@ public class GameView extends Pane {
}); });
} }
private void createAndBindAnnotationBox (Yacht yacht, Paint colour) { private void createAndBindAnnotationBox(ClientYacht clientYacht, Paint colour) {
AnnotationBox newAnnotation = new AnnotationBox(); AnnotationBox newAnnotation = new AnnotationBox();
newAnnotation.setFill(colour); newAnnotation.setFill(colour);
newAnnotation.addAnnotation( newAnnotation.addAnnotation(
"name", "Player: " + yacht.getShortName() "name", "Player: " + clientYacht.getShortName()
); );
// newAnnotation.addAnnotation( // newAnnotation.addAnnotation(
// "velocity", // "velocity",
@@ -385,7 +385,7 @@ public class GameView extends Pane {
// return format.format(time); // return format.format(time);
// } // }
// ); // );
annotations.put(yacht, newAnnotation); annotations.put(clientYacht, newAnnotation);
} }
private void drawFps(Double fps){ private void drawFps(Double fps){
@@ -562,9 +562,9 @@ public class GameView extends Pane {
fpsDisplay.setVisible(visibility); fpsDisplay.setVisible(visibility);
} }
public void selectBoat (Yacht selectedYacht) { public void selectBoat(ClientYacht selectedClientYacht) {
boatObjects.forEach((boat, group) -> boatObjects.forEach((boat, group) ->
group.setIsSelected(boat == selectedYacht) group.setIsSelected(boat == selectedClientYacht)
); );
} }
@@ -576,7 +576,7 @@ public class GameView extends Pane {
timer.start(); timer.start();
} }
public void setBoatAsPlayer (Yacht playerYacht) { public void setBoatAsPlayer(ClientYacht playerYacht) {
boatObjects.get(playerYacht).setAsPlayer(); boatObjects.get(playerYacht).setAsPlayer();
annotations.get(playerYacht).addAnnotation( annotations.get(playerYacht).addAnnotation(
"velocity", "velocity",
@@ -17,24 +17,24 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import seng302.model.Yacht; import seng302.model.ClientYacht;
public class FinishScreenViewController implements Initializable { public class FinishScreenViewController implements Initializable {
@FXML @FXML
private GridPane finishScreenGridPane; private GridPane finishScreenGridPane;
@FXML @FXML
private TableView<Yacht> finishOrderTable; private TableView<ClientYacht> finishOrderTable;
@FXML @FXML
private TableColumn<Yacht, String> posCol; private TableColumn<ClientYacht, String> posCol;
@FXML @FXML
private TableColumn<Yacht, String> boatNameCol; private TableColumn<ClientYacht, String> boatNameCol;
@FXML @FXML
private TableColumn<Yacht, String> shortNameCol; private TableColumn<ClientYacht, String> shortNameCol;
@FXML @FXML
private TableColumn<Yacht, String> countryCol; private TableColumn<ClientYacht, String> countryCol;
ObservableList<Yacht> data = FXCollections.observableArrayList(); ObservableList<ClientYacht> data = FXCollections.observableArrayList();
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
@@ -61,9 +61,9 @@ public class FinishScreenViewController implements Initializable {
finishOrderTable.refresh(); finishOrderTable.refresh();
} }
public void setFinishers (List<Yacht> participants) { public void setFinishers(List<ClientYacht> participants) {
List<Yacht> sorted = new ArrayList<>(participants); List<ClientYacht> sorted = new ArrayList<>(participants);
sorted.sort(Comparator.comparingInt(Yacht::getPositionInteger)); sorted.sort(Comparator.comparingInt(ClientYacht::getPositionInteger));
finishOrderTable.getItems().setAll(sorted); finishOrderTable.getItems().setAll(sorted);
} }
@@ -34,8 +34,8 @@ import javafx.scene.text.Text;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.StageStyle; import javafx.stage.StageStyle;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import seng302.model.ClientYacht;
import seng302.model.RaceState; import seng302.model.RaceState;
import seng302.model.Yacht;
import seng302.model.mark.CompoundMark; import seng302.model.mark.CompoundMark;
import seng302.model.mark.Mark; import seng302.model.mark.Mark;
import seng302.model.stream.xml.parser.RaceXMLData; import seng302.model.stream.xml.parser.RaceXMLData;
@@ -70,10 +70,10 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
@FXML @FXML
private Button selectAnnotationBtn; private Button selectAnnotationBtn;
@FXML @FXML
private ComboBox<Yacht> yachtSelectionComboBox; private ComboBox<ClientYacht> yachtSelectionComboBox;
//Race Data //Race Data
private Map<Integer, Yacht> participants; private Map<Integer, ClientYacht> participants;
private Map<Integer, CompoundMark> markers; private Map<Integer, CompoundMark> markers;
private RaceXMLData courseData; private RaceXMLData courseData;
private GameView gameView; private GameView gameView;
@@ -101,7 +101,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
} }
public void loadRace ( public void loadRace (
Map<Integer, Yacht> participants, RaceXMLData raceData, RaceState raceState, Yacht player Map<Integer, ClientYacht> participants, RaceXMLData raceData, RaceState raceState,
ClientYacht player
) { ) {
this.participants = participants; this.participants = participants;
this.courseData = raceData; this.courseData = raceData;
@@ -214,7 +215,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
// TODO: 2/08/17 there is about 0 chance of this working. Once we are keeping track of boat positions it can be fixed. // TODO: 2/08/17 there is about 0 chance of this working. Once we are keeping track of boat positions it can be fixed.
// Collect the racing yachts that aren't already in the chart // Collect the racing yachts that aren't already in the chart
sparkLineData.clear(); sparkLineData.clear();
List<Yacht> sparkLineCandidates = new ArrayList<>(participants.values()); List<ClientYacht> sparkLineCandidates = new ArrayList<>(participants.values());
// Create a new data series for new yachts // Create a new data series for new yachts
sparkLineCandidates sparkLineCandidates
.stream() .stream()
@@ -260,15 +261,15 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
/** /**
* Updates the yachts sparkline of the desired yacht and using the new leg number * Updates the yachts sparkline of the desired yacht and using the new leg number
* @param yacht The yacht to be updated on the sparkline * @param clientYacht The yacht to be updated on the sparkline
* @param legNumber the leg number that the position will be assigned to * @param legNumber the leg number that the position will be assigned to
*/ */
void updateYachtPositionSparkline(Yacht yacht, Integer legNumber){ void updateYachtPositionSparkline(ClientYacht clientYacht, Integer legNumber) {
for (XYChart.Series<String, Double> positionData : sparkLineData) { for (XYChart.Series<String, Double> positionData : sparkLineData) {
positionData.getData().add( positionData.getData().add(
new Data<>( new Data<>(
Integer.toString(legNumber), Integer.toString(legNumber),
1.0 + participants.size() - yacht.getPositionInteger() 1.0 + participants.size() - clientYacht.getPositionInteger()
) )
); );
} }
@@ -376,21 +377,21 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
// positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString()); // positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
// list of racing yacht id // list of racing yacht id
List<Yacht> sorted = new ArrayList<>(participants.values()); List<ClientYacht> sorted = new ArrayList<>(participants.values());
sorted.sort(Comparator.comparingInt(Yacht::getPositionInteger)); sorted.sort(Comparator.comparingInt(ClientYacht::getPositionInteger));
List<Text> vboxEntries = new ArrayList<>(); List<Text> vboxEntries = new ArrayList<>();
for (Yacht yacht : sorted) { for (ClientYacht clientYacht : sorted) {
// System.out.println("yacht == null " + String.valueOf(yacht == null)); // System.out.println("yacht == null " + String.valueOf(yacht == null));
if (yacht.getBoatStatus() == 3) { // 3 is finish status if (clientYacht.getBoatStatus() == 3) { // 3 is finish status
Text textToAdd = new Text(yacht.getPositionInteger() + ". " + Text textToAdd = new Text(clientYacht.getPositionInteger() + ". " +
yacht.getShortName() + " (Finished)"); clientYacht.getShortName() + " (Finished)");
textToAdd.setFill(Paint.valueOf("#d3d3d3")); textToAdd.setFill(Paint.valueOf("#d3d3d3"));
vboxEntries.add(textToAdd); vboxEntries.add(textToAdd);
} else { } else {
Text textToAdd = new Text(yacht.getPositionInteger() + ". " + Text textToAdd = new Text(clientYacht.getPositionInteger() + ". " +
yacht.getShortName() + " "); clientYacht.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3")); textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle(""); textToAdd.setStyle("");
vboxEntries.add(textToAdd); vboxEntries.add(textToAdd);
@@ -575,9 +576,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
/** /**
* Sets all the annotations of the selected yacht to be visible and all others to be hidden * Sets all the annotations of the selected yacht to be visible and all others to be hidden
* *
* @param yacht The yacht for which we want to view all annotations * @param clientYacht The yacht for which we want to view all annotations
*/ */
private void setSelectedBoat(Yacht yacht) { private void setSelectedBoat(ClientYacht clientYacht) {
// for (BoatObject bg : gameViewController.getBoatGroups()) { // for (BoatObject bg : gameViewController.getBoatGroups()) {
// //We need to iterate over all race groups to get the matching yacht group belonging to this yacht if we // //We need to iterate over all race groups to get the matching yacht group belonging to this yacht if we
// //are to toggle its annotations, there is no other backwards knowledge of a yacht to its yachtgroup. // //are to toggle its annotations, there is no other backwards knowledge of a yacht to its yachtgroup.
+3 -3
View File
@@ -8,12 +8,12 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.model.PolarTable; import seng302.model.PolarTable;
import seng302.model.Yacht; import seng302.model.ServerYacht;
public class YachtTest { public class YachtTest {
private static Yacht y1; private static ServerYacht y1;
//Yacht y2; //Yacht y2;
private static Double windDirection = 180d; private static Double windDirection = 180d;
private static Double windSpeed = 20d; private static Double windSpeed = 20d;
@@ -21,7 +21,7 @@ public class YachtTest {
@BeforeClass @BeforeClass
public static void setUp() { public static void setUp() {
y1 = new Yacht("Yacht", 101, "Y1", "Y1", "Yacht 1", "C1"); y1 = new ServerYacht("Yacht", 101, "Y1", "Y1", "Yacht 1", "C1");
gs = new GameState("localhost"); gs = new GameState("localhost");
} }
@@ -9,7 +9,7 @@ import seng302.gameServer.GameStages;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.gameServer.MainServerThread; import seng302.gameServer.MainServerThread;
import seng302.gameServer.server.messages.BoatAction; import seng302.gameServer.server.messages.BoatAction;
import seng302.model.Yacht; import seng302.model.ServerYacht;
import seng302.visualiser.ClientToServerThread; import seng302.visualiser.ClientToServerThread;
/** /**
@@ -33,7 +33,7 @@ public class RegularPacketsTest {
final double TEST_DISTANCE = 10.0; final double TEST_DISTANCE = 10.0;
serverThread.startGame(); serverThread.startGame();
SleepThreadMaxDelay(); SleepThreadMaxDelay();
Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0); ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
double startAngle = yacht.getHeading(); double startAngle = yacht.getHeading();
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
clientThread.sendBoatAction(BoatAction.UPWIND); clientThread.sendBoatAction(BoatAction.UPWIND);
@@ -45,7 +45,8 @@ public class RegularPacketsTest {
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
SleepThreadMaxDelay(); SleepThreadMaxDelay();
//Allowed to be two loops of delay due to loop delay and processing delay at client + server ends. //Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
Assert.assertEquals(TEST_DISTANCE / Yacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS, Assert.assertEquals(
TEST_DISTANCE / ServerYacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
(endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS); (endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
} }