mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed issues caused by merge.
#bug
This commit is contained in:
@@ -7,7 +7,11 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.model.PolarTable;
|
||||
|
||||
@@ -4,15 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import seng302.client.ClientPacketParser;
|
||||
import seng302.models.Player;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.server.messages.BoatActionType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import seng302.gameServer.server.messages.BoatActionType;
|
||||
import seng302.model.Player;
|
||||
import seng302.model.Yacht;
|
||||
|
||||
/**
|
||||
* A Static class to hold information about the current state of the game (model)
|
||||
@@ -33,8 +27,6 @@ public class GameState implements Runnable {
|
||||
private static GameStages currentStage;
|
||||
private static long startTime;
|
||||
|
||||
// TODO: 26/07/17 cir27 - Super hackish fix until something more permanent can be made.
|
||||
private static ObservableList<String> observablePlayers = FXCollections.observableArrayList();
|
||||
private static Map<Player, String> playerStringMap = new HashMap<>();
|
||||
/*
|
||||
Ideally I would like to make this class an object instantiated by the server and given to
|
||||
@@ -73,20 +65,14 @@ public class GameState implements Runnable {
|
||||
return players;
|
||||
}
|
||||
|
||||
public static ObservableList<String> getObservablePlayers () {
|
||||
return observablePlayers;
|
||||
}
|
||||
|
||||
public static void addPlayer(Player player) {
|
||||
players.add(player);
|
||||
String playerText = player.getYacht().getSourceId() + " " + player.getYacht().getBoatName() + " " + player.getYacht().getCountry();
|
||||
Platform.runLater(() -> observablePlayers.add(playerText)); //Had to add this to handle javaFX window using array
|
||||
playerStringMap.put(player, playerText);
|
||||
}
|
||||
|
||||
public static void removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
observablePlayers.remove(playerStringMap.get(player));
|
||||
playerStringMap.remove(player);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package seng302.gameServer.server.messages;
|
||||
|
||||
public class BoatLocationMessage extends Message {
|
||||
|
||||
private final int MESSAGE_SIZE = 56;
|
||||
|
||||
private long messageVersionNumber;
|
||||
@@ -28,6 +29,7 @@ public class BoatLocationMessage extends Message {
|
||||
|
||||
/**
|
||||
* Describes the location, altitude and sensor data from the boat.
|
||||
*
|
||||
* @param sourceId ID of the boat
|
||||
* @param sequenceNum Sequence number of the message
|
||||
* @param latitude The boats latitude
|
||||
@@ -35,7 +37,8 @@ public class BoatLocationMessage extends Message {
|
||||
* @param heading The boats heading
|
||||
* @param boatSpeed The boats speed
|
||||
*/
|
||||
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
|
||||
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude,
|
||||
double heading, long boatSpeed) {
|
||||
messageVersionNumber = 1;
|
||||
time = System.currentTimeMillis();
|
||||
this.sourceId = sourceId;
|
||||
@@ -49,7 +52,7 @@ public class BoatLocationMessage extends Message {
|
||||
this.roll = 0;
|
||||
this.boatSpeed = boatSpeed;
|
||||
this.COG = 2;
|
||||
this.SOG = boatSpeed ;
|
||||
this.SOG = boatSpeed;
|
||||
this.apparentWindSpeed = 0;
|
||||
this.apparentWindAngle = 0;
|
||||
this.trueWindSpeed = 0;
|
||||
@@ -63,7 +66,7 @@ public class BoatLocationMessage extends Message {
|
||||
allocateBuffer();
|
||||
writeHeaderToBuffer();
|
||||
|
||||
long headingToSend = (long)((heading/360.0) * 65535.0);
|
||||
long headingToSend = (long) ((heading / 360.0) * 65535.0);
|
||||
|
||||
putByte((byte) messageVersionNumber);
|
||||
putInt(time, 6);
|
||||
@@ -94,56 +97,62 @@ public class BoatLocationMessage extends Message {
|
||||
|
||||
/**
|
||||
* Convert binary latitude or longitude to floating point number
|
||||
*
|
||||
* @param binaryPackedLatLon Binary packed lat OR lon
|
||||
* @return Floating point lat/lon
|
||||
*/
|
||||
public static double binaryPackedToLatLon(long binaryPackedLatLon){
|
||||
return (double)binaryPackedLatLon * 180.0 / 2147483648.0;
|
||||
public static double binaryPackedToLatLon(long binaryPackedLatLon) {
|
||||
return (double) binaryPackedLatLon * 180.0 / 2147483648.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert binary packed heading to floating point number
|
||||
*
|
||||
* @param binaryPackedHeading Binary packed heading
|
||||
* @return heading as a decimal
|
||||
*/
|
||||
public static double binaryPackedHeadingToDouble(long binaryPackedHeading){
|
||||
return (double)binaryPackedHeading * 360.0 / 65536.0;
|
||||
public static double binaryPackedHeadingToDouble(long binaryPackedHeading) {
|
||||
return (double) binaryPackedHeading * 360.0 / 65536.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert binary packed wind angle to floating point number
|
||||
*
|
||||
* @param binaryPackedWindAngle Binary packed wind angle
|
||||
* @return wind angle as a decimal
|
||||
*/
|
||||
public static double binaryPackedWindAngleToDouble(long binaryPackedWindAngle){
|
||||
return (double)binaryPackedWindAngle*180.0/32768.0;
|
||||
public static double binaryPackedWindAngleToDouble(long binaryPackedWindAngle) {
|
||||
return (double) binaryPackedWindAngle * 180.0 / 32768.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a latitude or longitude to a binary packed long
|
||||
*
|
||||
* @param latLon A floating point latitude/longitude
|
||||
* @return A binary packed lat/lon
|
||||
*/
|
||||
public static long latLonToBinaryPackedLong(double latLon){
|
||||
return (long)((536870912 * latLon) / 45);
|
||||
public static long latLonToBinaryPackedLong(double latLon) {
|
||||
return (long) ((536870912 * latLon) / 45);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a heading to a binary packed long
|
||||
*
|
||||
* @param heading A floating point heading
|
||||
* @return A binary packed heading
|
||||
*/
|
||||
public static long headingToBinaryPackedLong(double heading){
|
||||
return (long)((8192*heading)/45);
|
||||
public static long headingToBinaryPackedLong(double heading) {
|
||||
return (long) ((8192 * heading) / 45);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a wind angle to a binary packed long
|
||||
*
|
||||
* @param windAngle Floating point wind angle
|
||||
* @return A binary packed wind angle
|
||||
*/
|
||||
public static long windAngleToBinaryPackedLong(double windAngle){
|
||||
return (long)((8192*windAngle)/45);
|
||||
public static long windAngleToBinaryPackedLong(double windAngle) {
|
||||
return (long) ((8192 * windAngle) / 45);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
package seng302.server.simulator;
|
||||
|
||||
import seng302.server.simulator.mark.Corner;
|
||||
import seng302.server.simulator.mark.Mark;
|
||||
import seng302.server.simulator.parsers.RaceParser;
|
||||
import seng302.utilities.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import seng302.model.mark.Mark;
|
||||
import seng302.gameServer.server.simulator.parsers.RaceParser;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
public class Simulator extends Observable implements Runnable {
|
||||
|
||||
private List<Corner> course;
|
||||
private List<Boat> boats;
|
||||
private long lapse;
|
||||
private boolean isRaceStarted;
|
||||
|
||||
/**
|
||||
* Creates a simulator instance with given time lapse.
|
||||
* @param lapse time duration in millisecond.
|
||||
*/
|
||||
public Simulator(long lapse) {
|
||||
RaceParser rp = new RaceParser("/server_config/race.xml");
|
||||
course = rp.getCourse();
|
||||
boats = rp.getBoats();
|
||||
this.lapse = lapse;
|
||||
isRaceStarted = false;
|
||||
|
||||
setLegs();
|
||||
|
||||
// set start line's coordinate to boats
|
||||
Double startLat = course.get(0).getCompoundMark().getSubMark(1).getLat();
|
||||
Double startLng = course.get(0).getCompoundMark().getSubMark(1).getLng();
|
||||
for (Boat boat : boats) {
|
||||
boat.setLat(startLat);
|
||||
boat.setLng(startLng);
|
||||
boat.setLastPassedCorner(course.get(0));
|
||||
boat.setHeadingCorner(course.get(1));
|
||||
boat.setSpeed(ThreadLocalRandom.current().nextInt(40000, 60000 + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
int numOfFinishedBoats = 0;
|
||||
|
||||
while (numOfFinishedBoats < boats.size()) {
|
||||
|
||||
// if race has started, then boat should start to move.
|
||||
if (isRaceStarted) {
|
||||
for (Boat boat : boats) {
|
||||
numOfFinishedBoats += moveBoat(boat, lapse);
|
||||
}
|
||||
}
|
||||
|
||||
setChanged();
|
||||
notifyObservers(boats);
|
||||
|
||||
try {
|
||||
Thread.sleep(lapse);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("[Simulator] interrupted exception ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a boat with given time duration.
|
||||
* @param boat the boat to be moved
|
||||
* @param duration the moving duration in milliseconds
|
||||
* @return 1 if the boat has reached the final line, otherwise return 0
|
||||
*/
|
||||
private int moveBoat(Boat boat, double duration) {
|
||||
if (boat.getHeadingCorner() != null) {
|
||||
|
||||
boat.move(boat.getLastPassedCorner().getBearingToNextCorner(), duration);
|
||||
|
||||
GeoPoint boatPos = new GeoPoint(boat.getLat(), boat.getLng());
|
||||
GeoPoint lastMarkPos = boat.getLastPassedCorner().getCompoundMark().getSubMark(1);
|
||||
|
||||
double distanceFromLastMark = GeoUtility.getDistance(boatPos, lastMarkPos);
|
||||
// if a boat passes its heading mark
|
||||
while (distanceFromLastMark >= boat.getLastPassedCorner().getDistanceToNextCorner()) {
|
||||
double compensateDistance = distanceFromLastMark - boat.getLastPassedCorner().getDistanceToNextCorner();
|
||||
boat.setLastPassedCorner(boat.getHeadingCorner());
|
||||
boat.setHeadingCorner(boat.getLastPassedCorner().getNextCorner());
|
||||
|
||||
// heading corner == null means boat has reached the final mark
|
||||
if (boat.getHeadingCorner() == null) {
|
||||
boat.setFinished(true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// move compensate distance for the mark just passed
|
||||
GeoPoint pos = GeoUtility.getGeoCoordinate(
|
||||
boat.getLastPassedCorner().getCompoundMark().getSubMark(1),
|
||||
boat.getLastPassedCorner().getBearingToNextCorner(),
|
||||
compensateDistance);
|
||||
boat.setLat(pos.getLat());
|
||||
boat.setLng(pos.getLng());
|
||||
distanceFromLastMark = GeoUtility.getDistance(new GeoPoint(boat.getLat(), boat.getLng()),
|
||||
boat.getLastPassedCorner().getCompoundMark().getSubMark(1));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link all the corners in the course list so that every corner knows its next
|
||||
* corner, as well as the distance and bearing to its next corner. However,
|
||||
* the last corner's heading is null, which means it is the final line.
|
||||
*/
|
||||
private void setLegs() {
|
||||
// get the bearing from one mark to the next heading mark
|
||||
for (int i = 0; i < course.size() - 1; i++) {
|
||||
|
||||
Mark mark1 = course.get(i).getCompoundMark().getSubMark(1);
|
||||
Mark mark2 = course.get(i + 1).getCompoundMark().getSubMark(1);
|
||||
course.get(i).setDistanceToNextCorner(GeoUtility.getDistance(mark1, mark2));
|
||||
|
||||
course.get(i).setNextCorner(course.get(i + 1));
|
||||
|
||||
course.get(i).setBearingToNextCorner(
|
||||
GeoUtility.getBearing(course.get(i).getCompoundMark().getSubMark(1),
|
||||
course.get(i + 1).getCompoundMark().getSubMark(1)));
|
||||
}
|
||||
}
|
||||
|
||||
public List<Boat> getBoats(){
|
||||
return boats;
|
||||
}
|
||||
|
||||
public void setRaceStarted(boolean raceStarted) {
|
||||
isRaceStarted = raceStarted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of marks in the race
|
||||
*/
|
||||
public Set<CompoundMark> getMarks(){
|
||||
Set<CompoundMark> marks = new HashSet<>();
|
||||
|
||||
for (Corner c : course){
|
||||
marks.add(c.getCompoundMark());
|
||||
marks.add(c.getCompoundMark());
|
||||
}
|
||||
|
||||
return marks;
|
||||
}
|
||||
}
|
||||
@@ -86,4 +86,46 @@ public class CompoundMark {
|
||||
public List<Mark> getMarks () {
|
||||
return marks;
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public boolean equals(Object other) {
|
||||
// if (other == null) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (!(other instanceof Mark)){
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// Mark otherMark = (Mark) other;
|
||||
//
|
||||
// if (otherMark.getLat() != getLat() || otherMark.getLongitude() != getLongitude()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (otherMark.getCompoundMarkID() != getCompoundMarkID()){
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (otherMark.getId() != getId()){
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (!otherMark.getName().equals(name)){
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
for (Mark mark : marks) {
|
||||
hash += Double.hashCode(mark.getSourceID()) + Double.hashCode(mark.getLat())
|
||||
+ Double.hashCode(mark.getLng()) + mark.getName().hashCode();
|
||||
}
|
||||
return hash + getName().hashCode() + Integer.hashCode(getId());
|
||||
}
|
||||
}
|
||||
|
||||
+25
-27
@@ -1,28 +1,29 @@
|
||||
package seng302.models.mark;
|
||||
package seng302.model.mark;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.models.stream.XMLParser;
|
||||
import seng302.models.xml.Race;
|
||||
import seng302.models.xml.XMLGenerator;
|
||||
import seng302.server.messages.XMLMessageSubType;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import seng302.model.stream.xml.generator.Race;
|
||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.utilities.XMLGenerator;
|
||||
import seng302.utilities.XMLParser;
|
||||
|
||||
/**
|
||||
* Class to hold the order of the marks in the race.
|
||||
*/
|
||||
public class MarkOrder {
|
||||
private List<Mark> raceMarkOrder;
|
||||
private List<CompoundMark> raceMarkOrder;
|
||||
private Logger logger = LoggerFactory.getLogger(MarkOrder.class);
|
||||
|
||||
public MarkOrder(){
|
||||
@@ -33,7 +34,7 @@ public class MarkOrder {
|
||||
* @return An ordered list of marks in the race
|
||||
* OR null if the mark order could not be loaded
|
||||
*/
|
||||
public List<Mark> getMarkOrder(){
|
||||
public List<CompoundMark> getMarkOrder(){
|
||||
if (raceMarkOrder == null){
|
||||
logger.warn("Race order accessed but not instantiated");
|
||||
return null;
|
||||
@@ -48,9 +49,9 @@ public class MarkOrder {
|
||||
* @return the next mark
|
||||
* OR null if there is no next mark
|
||||
*/
|
||||
public Mark getNextMark(Mark previous){
|
||||
public CompoundMark getNextMark(CompoundMark previous){
|
||||
for (int i = 0; i < raceMarkOrder.size(); i++){
|
||||
Mark mark = raceMarkOrder.get(i);
|
||||
CompoundMark mark = raceMarkOrder.get(i);
|
||||
|
||||
if (i + 1 >= raceMarkOrder.size()){
|
||||
return null;
|
||||
@@ -60,7 +61,6 @@ public class MarkOrder {
|
||||
return raceMarkOrder.get(i+1);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -69,9 +69,7 @@ public class MarkOrder {
|
||||
* @param xml An AC35 RaceXML
|
||||
* @return An ordered list of marks in the race
|
||||
*/
|
||||
private List<Mark> loadRaceOrderFromXML(String xml){
|
||||
XMLParser xmlParser = new XMLParser();
|
||||
XMLParser.RaceXMLObject raceXMLObject;
|
||||
private List<CompoundMark> loadRaceOrderFromXML(String xml){
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db;
|
||||
@@ -84,13 +82,14 @@ public class MarkOrder {
|
||||
logger.error("Failed to read generated race XML");
|
||||
return null;
|
||||
}
|
||||
|
||||
RaceXMLData data = XMLParser.parseRace(doc);
|
||||
|
||||
xmlParser.constructXML(doc , XMLMessageSubType.RACE.getType());
|
||||
raceXMLObject = xmlParser.getRaceXML();
|
||||
|
||||
if (raceXMLObject != null){
|
||||
if (data != null){
|
||||
logger.debug("Loaded RaceXML for mark order");
|
||||
return raceXMLObject.getNonDupCompoundMarks();
|
||||
List<CompoundMark> course = new ArrayList<>(data.getCompoundMarks().values());
|
||||
course.sort(Comparator.comparingInt(CompoundMark::getId));
|
||||
return course;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -110,7 +109,6 @@ public class MarkOrder {
|
||||
logger.error("Failed to generate raceXML (for race properties)");
|
||||
return;
|
||||
}
|
||||
|
||||
raceMarkOrder = loadRaceOrderFromXML(raceXML);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import java.net.URL;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.image.Image;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.net.URL;
|
||||
import java.lang.Math;
|
||||
import seng302.model.GeoPoint;
|
||||
|
||||
/**
|
||||
* CanvasMap retrieves a map image with given geo boundary from Google Map server.
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
|
||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="11" Name="Mark4">
|
||||
<CompoundMark CompoundMarkID="5" Name="Mark4">
|
||||
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="128" />
|
||||
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="129" />
|
||||
</CompoundMark>
|
||||
|
||||
Reference in New Issue
Block a user