Merge branch 'master' into wind_(story53)
This commit is contained in:
@@ -85,22 +85,15 @@ public class Event {
|
||||
|
||||
//Read XML files.
|
||||
try {
|
||||
this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90);
|
||||
//this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90);
|
||||
this.raceXML = XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8);
|
||||
this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8));
|
||||
|
||||
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
|
||||
this.regattaXML = XMLReader.readXMLFileToString(regattaXMLFile, StandardCharsets.UTF_8);
|
||||
|
||||
} catch (XMLReaderException e) {
|
||||
throw new EventConstructionException("Could not read XML files.", e);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidRaceDataException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.xmlFileType = XMLFileType.Contents;
|
||||
@@ -177,13 +170,6 @@ public class Event {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends the initial race data and then begins race simulation.
|
||||
*/
|
||||
public void start() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends out each xml string, via the mock output
|
||||
@@ -196,4 +182,29 @@ public class Event {
|
||||
|
||||
connectionAcceptor.setBoatsXml(boatXML);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO remove this after demo on 18th august!
|
||||
/**
|
||||
* Sets the xml description of the race to show the race was created now, and starts in 4 minutes
|
||||
* @param raceXML The race.xml contents.
|
||||
* @return String containing edited xml
|
||||
*/
|
||||
public static String setRaceXMLAtCurrentTimeToNow(String raceXML) {
|
||||
|
||||
//The start time is current time + 4 minutes. prestart is 3 minutes, and we add another minute.
|
||||
long millisecondsToAdd = Constants.RacePreStartTime + (1 * 60 * 1000);
|
||||
long secondsToAdd = millisecondsToAdd / 1000;
|
||||
//Scale the time using our time scalar.
|
||||
secondsToAdd = secondsToAdd / Constants.RaceTimeScale;
|
||||
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
ZonedDateTime creationTime = ZonedDateTime.now();
|
||||
raceXML = raceXML.replace("RACE_CREATION_TIME", dateFormat.format(creationTime));
|
||||
raceXML = raceXML.replace("RACE_START_TIME", dateFormat.format(creationTime.plusSeconds(secondsToAdd)));
|
||||
|
||||
|
||||
return raceXML;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -101,8 +101,6 @@ public class MockOutput implements RunnableWithFramePeriod {
|
||||
Logger.getGlobal().log(Level.WARNING, "MockOutput.run() interrupted while putting message in queue.", e);
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -92,11 +92,8 @@ public class HeartBeatService implements RunnableWithFramePeriod {
|
||||
|
||||
while (!Thread.interrupted()) {
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
try {
|
||||
waitForFramePeriod(lastHeartbeatTime, currentFrameTime, heartbeatPeriod);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
waitForFramePeriod(lastHeartbeatTime, currentFrameTime, heartbeatPeriod);
|
||||
|
||||
lastHeartbeatTime = currentFrameTime;
|
||||
|
||||
try {
|
||||
|
||||
@@ -50,17 +50,9 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
|
||||
public void run() {
|
||||
race.initialiseBoats();
|
||||
|
||||
try {
|
||||
countdown();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
countdown();
|
||||
|
||||
try {
|
||||
raceLoop();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
raceLoop();
|
||||
}
|
||||
|
||||
public void boolFalse(){
|
||||
@@ -71,7 +63,7 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
|
||||
/**
|
||||
* Countdown timer until race starts.
|
||||
*/
|
||||
private void countdown() throws Exception {
|
||||
private void countdown() {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
|
||||
@@ -110,7 +102,7 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
|
||||
/**
|
||||
* Timer that runs for the duration of the race, until all boats finish.
|
||||
*/
|
||||
private void raceLoop() throws Exception {
|
||||
private void raceLoop() {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
|
||||
@@ -199,4 +191,4 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
|
||||
// else if(e.getBearing().degrees() > 270) System.out.println("Port");
|
||||
// else System.out.println("Behind");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +93,7 @@ public class MessageSerialiser implements RunnableWithFramePeriod {
|
||||
|
||||
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
try {
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 16);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 16);
|
||||
previousFrameTime = currentFrameTime;
|
||||
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ public class CompoundMark extends XMLCompoundMark{
|
||||
|
||||
/**
|
||||
* Used to find how far apart the marks that make up this gate are
|
||||
* If this compound mark is only one point return base length of 250m
|
||||
* If this compound mark is only one point return base length of 400m
|
||||
* @return the acceptable distance to round a mark
|
||||
*/
|
||||
public double getRoundingDistance(){
|
||||
@@ -187,7 +187,7 @@ public class CompoundMark extends XMLCompoundMark{
|
||||
}
|
||||
|
||||
//finds the mark furthest west and east
|
||||
if(this.getMark1Position().getLatitude() > this.getMark2Position().getLatitude()){
|
||||
if(this.getMark1Position().getLongitude() > this.getMark2Position().getLongitude()){
|
||||
westMostMark = this.mark1;
|
||||
eastMostMark = this.mark2;
|
||||
}else{
|
||||
@@ -196,7 +196,7 @@ public class CompoundMark extends XMLCompoundMark{
|
||||
}
|
||||
|
||||
//finds the mark furthest north and south
|
||||
if(this.getMark1Position().getLongitude() > this.getMark2Position().getLongitude()){
|
||||
if(this.getMark1Position().getLatitude() > this.getMark2Position().getLatitude()){
|
||||
northMostMark = this.mark1;
|
||||
southMostMark = this.mark2;
|
||||
}else{
|
||||
|
||||
@@ -20,8 +20,7 @@ public interface RunnableWithFramePeriod extends Runnable {
|
||||
* @param currentFrameTime The timestamp of the current frame.
|
||||
* @param minimumFramePeriod The minimum period the frame must be.
|
||||
*/
|
||||
default void waitForFramePeriod(long previousFrameTime, long currentFrameTime, long minimumFramePeriod) throws Exception {
|
||||
|
||||
default void waitForFramePeriod(long previousFrameTime, long currentFrameTime, long minimumFramePeriod) {
|
||||
|
||||
//This is the time elapsed, in milliseconds, since the last server "frame".
|
||||
long framePeriod = currentFrameTime - previousFrameTime;
|
||||
@@ -39,10 +38,10 @@ public interface RunnableWithFramePeriod extends Runnable {
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
//If we get interrupted, exit the function.
|
||||
/*Logger.getGlobal().log(Level.SEVERE, "RunnableWithFramePeriod.waitForFramePeriod().sleep(framePeriod) was interrupted on thread: " + Thread.currentThread(), e);
|
||||
//Logger.getGlobal().log(Level.WARNING, "RunnableWithFramePeriod.waitForFramePeriod().sleep(framePeriod) was interrupted on thread: " + Thread.currentThread(), e);
|
||||
//Re-set the interrupt flag.
|
||||
Thread.currentThread().interrupt();
|
||||
return;*/
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -136,12 +136,8 @@ public class ArrowController {
|
||||
* @param bearing The bearing to use to rotate arrow.
|
||||
*/
|
||||
private void updateWindBearing(Bearing bearing) {
|
||||
|
||||
//We need to display wind-from, so add 180 degrees.
|
||||
Bearing fromBearing = Bearing.fromDegrees(bearing.degrees() + 180d);
|
||||
|
||||
//Rotate the wind arrow.
|
||||
arrowStackPane.setRotate(fromBearing.degrees());
|
||||
arrowStackPane.setRotate(bearing.degrees());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ public class HostController extends Controller {
|
||||
public void hostGamePressed() throws IOException{
|
||||
try {
|
||||
this.game = new Event(false);
|
||||
game.start();
|
||||
connectSocket("localhost", 4942);
|
||||
} catch (EventConstructionException e) {
|
||||
Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e);
|
||||
|
||||
@@ -3,7 +3,6 @@ package visualiser.model;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.LinearGradient;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.transform.Rotate;
|
||||
@@ -13,7 +12,6 @@ import shared.enums.RoundingType;
|
||||
import shared.model.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -735,6 +733,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
|
||||
gc.save();
|
||||
|
||||
gc.setLineWidth(2);
|
||||
gc.setStroke(Color.MEDIUMAQUAMARINE);
|
||||
|
||||
gc.beginPath();
|
||||
gc.moveTo(startPath.getX(), startPath.getY());
|
||||
gc.lineTo(endPath.getX(), endPath.getY());
|
||||
|
||||
@@ -68,13 +68,7 @@ public class VisualiserRaceService implements RunnableWithFramePeriod {
|
||||
while (!Thread.interrupted()) {
|
||||
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 16);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 16);
|
||||
previousFrameTime = currentFrameTime;
|
||||
|
||||
|
||||
|
||||
@@ -330,11 +330,8 @@ public class ServerConnection implements RunnableWithFramePeriod {
|
||||
while (!Thread.interrupted()) {
|
||||
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
try {
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 100);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 100);
|
||||
|
||||
previousFrameTime = currentFrameTime;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user