Merge branch 'cbt-multi-controller' into css
# Conflicts: # racevisionGame/src/main/java/mock/app/App.java # racevisionGame/src/main/java/visualiser/Controllers/ConnectionController.java # racevisionGame/src/main/java/visualiser/app/App.java # racevisionGame/src/main/java/visualiser/model/RaceConnection.java # racevisionGame/src/main/resources/visualiser/scenes/connect.fxml
This commit is contained in:
Generated
+3
@@ -0,0 +1,3 @@
|
|||||||
|
<component name="CopyrightManager">
|
||||||
|
<settings default="" />
|
||||||
|
</component>
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
<transformer
|
<transformer
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
<manifestEntries>
|
<manifestEntries>
|
||||||
<Main-Class>mock.app.App</Main-Class>
|
<Main-Class>visualiser.app.App</Main-Class>
|
||||||
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
|
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
|
||||||
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
|
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
|
||||||
</manifestEntries>
|
</manifestEntries>
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
package mock.app;
|
|
||||||
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import mock.dataInput.PolarParser;
|
|
||||||
import mock.model.Polars;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import shared.dataInput.XMLReader;
|
|
||||||
import shared.enums.XMLFileType;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import javax.xml.transform.TransformerException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class App extends Application implements Runnable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entry point for running the programme
|
|
||||||
*
|
|
||||||
* @param args for starting the programme
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) {
|
|
||||||
try {
|
|
||||||
Polars boatPolars = PolarParser.parse("mock/polars/acc_polars.csv");
|
|
||||||
|
|
||||||
String regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
|
||||||
String raceXML = XMLReader.readXMLFileToString("mock/mockXML/raceTest.xml", StandardCharsets.UTF_8);
|
|
||||||
String boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatTest.xml", StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
Event raceEvent = new Event(raceXML, regattaXML, boatXML, XMLFileType.Contents, boatPolars);
|
|
||||||
raceEvent.start();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
//Catch all exceptions, print, and exit.
|
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
launch();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,211 @@
|
|||||||
|
package mock.app;
|
||||||
|
|
||||||
|
import network.Messages.Enums.XMLMessageType;
|
||||||
|
import network.Messages.LatestMessages;
|
||||||
|
import network.Messages.XMLMessage;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection acceptor for multiple clients
|
||||||
|
*/
|
||||||
|
public class ConnectionAcceptor implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Port to expose server on.
|
||||||
|
*/
|
||||||
|
private int serverPort = 4942;
|
||||||
|
/**
|
||||||
|
* Socket used to listen for clients on.
|
||||||
|
*/
|
||||||
|
private ServerSocket serverSocket;
|
||||||
|
//mock outputs
|
||||||
|
private ArrayBlockingQueue<MockOutput> mockOutputList = new ArrayBlockingQueue<>(16, true);
|
||||||
|
//latest messages
|
||||||
|
private LatestMessages latestMessages;
|
||||||
|
//Acknowledgement number for packets
|
||||||
|
private int ackNumber = 0;
|
||||||
|
//race xml sequence number
|
||||||
|
private short raceXMLSequenceNumber;
|
||||||
|
//boat xml sequence number
|
||||||
|
private short boatXMLSequenceNumber;
|
||||||
|
//regatta xml sequence number
|
||||||
|
private short regattaXMLSequenceNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection Acceptor Constructor
|
||||||
|
* @param latestMessages Latest messages to be sent
|
||||||
|
* @throws IOException if a server socket cannot be instantiated.
|
||||||
|
*/
|
||||||
|
public ConnectionAcceptor(LatestMessages latestMessages) throws IOException {
|
||||||
|
|
||||||
|
this.latestMessages =latestMessages;
|
||||||
|
this.serverSocket = new ServerSocket(serverPort);
|
||||||
|
CheckClientConnection checkClientConnection = new CheckClientConnection(mockOutputList);
|
||||||
|
new Thread(checkClientConnection).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() throws UnknownHostException {
|
||||||
|
return InetAddress.getLocalHost().getHostAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getServerPort() {
|
||||||
|
return serverPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the Acceptor
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while(true){//should be connections not filled up
|
||||||
|
try {
|
||||||
|
System.out.println("Waiting for a connection...");//TEMP DEBUG REMOVE
|
||||||
|
Socket mockSocket = serverSocket.accept();
|
||||||
|
DataOutputStream outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
||||||
|
MockOutput mockOutput = new MockOutput(latestMessages, outToVisualiser);
|
||||||
|
new Thread(mockOutput).start();
|
||||||
|
mockOutputList.add(mockOutput);
|
||||||
|
System.out.println(String.format("%d number of Visualisers Connected.", mockOutputList.size()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nested class to remove disconnected clients
|
||||||
|
*/
|
||||||
|
class CheckClientConnection implements Runnable{
|
||||||
|
|
||||||
|
private ArrayBlockingQueue<MockOutput> mocks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param mocks Mocks "connected"
|
||||||
|
*/
|
||||||
|
public CheckClientConnection(ArrayBlockingQueue<MockOutput> mocks){
|
||||||
|
this.mocks = mocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the remover.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
double timeSinceLastHeartBeat = System.currentTimeMillis();
|
||||||
|
while(true) {
|
||||||
|
//System.out.println(mocks.size());//used to see current amount of visualisers connected.
|
||||||
|
ArrayBlockingQueue<MockOutput> m = new ArrayBlockingQueue(16, true, mocks);
|
||||||
|
for (MockOutput mo : m) {
|
||||||
|
try {
|
||||||
|
mo.sendHeartBeat();
|
||||||
|
} catch (IOException e) {
|
||||||
|
mocks.remove(mo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Race XML to send.
|
||||||
|
* @param raceXml XML to send to the Client.
|
||||||
|
*/
|
||||||
|
public void setRaceXml(String raceXml) {
|
||||||
|
//Create the message.
|
||||||
|
XMLMessage message = this.createXMLMessage(raceXml, XMLMessageType.RACE);
|
||||||
|
|
||||||
|
//Place it in LatestMessages.
|
||||||
|
this.latestMessages.setRaceXMLMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Regatta XMl to send.
|
||||||
|
* @param regattaXml XML to send to Client.
|
||||||
|
*/
|
||||||
|
public void setRegattaXml(String regattaXml) {
|
||||||
|
//Create the message.
|
||||||
|
XMLMessage message = this.createXMLMessage(regattaXml, XMLMessageType.REGATTA);
|
||||||
|
|
||||||
|
//Place it in LatestMessages.
|
||||||
|
this.latestMessages.setRegattaXMLMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Boats XML to send.
|
||||||
|
* @param boatsXml XMl to send to the Client.
|
||||||
|
*/
|
||||||
|
public void setBoatsXml(String boatsXml) {
|
||||||
|
//Create the message.
|
||||||
|
XMLMessage message = this.createXMLMessage(boatsXml, XMLMessageType.BOAT);
|
||||||
|
|
||||||
|
//Place it in LatestMessages.
|
||||||
|
this.latestMessages.setBoatXMLMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an XMLMessage of a specified subtype using the xml contents string.
|
||||||
|
* @param xmlString The contents of the xml file.
|
||||||
|
* @param messageType The subtype of xml message (race, regatta, boat).
|
||||||
|
* @return The created XMLMessage object.
|
||||||
|
*/
|
||||||
|
private XMLMessage createXMLMessage(String xmlString, XMLMessageType messageType) {
|
||||||
|
|
||||||
|
//Get the correct sequence number to use, and increment it.
|
||||||
|
short sequenceNumber = 0;
|
||||||
|
if (messageType == XMLMessageType.RACE) {
|
||||||
|
sequenceNumber = this.raceXMLSequenceNumber;
|
||||||
|
this.raceXMLSequenceNumber++;
|
||||||
|
|
||||||
|
} else if (messageType == XMLMessageType.BOAT) {
|
||||||
|
sequenceNumber = this.boatXMLSequenceNumber;
|
||||||
|
this.boatXMLSequenceNumber++;
|
||||||
|
|
||||||
|
} else if (messageType == XMLMessageType.REGATTA) {
|
||||||
|
sequenceNumber = this.regattaXMLSequenceNumber;
|
||||||
|
this.regattaXMLSequenceNumber++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create the message.
|
||||||
|
XMLMessage message = new XMLMessage(
|
||||||
|
XMLMessage.currentVersionNumber,
|
||||||
|
getNextAckNumber(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
messageType,
|
||||||
|
sequenceNumber,
|
||||||
|
xmlString);
|
||||||
|
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the ackNumber value, and returns it.
|
||||||
|
* @return Incremented ackNumber.
|
||||||
|
*/
|
||||||
|
private int getNextAckNumber(){
|
||||||
|
this.ackNumber++;
|
||||||
|
|
||||||
|
return this.ackNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package mock.app;
|
package mock.app;
|
||||||
|
|
||||||
|
import mock.dataInput.PolarParser;
|
||||||
import mock.model.MockRace;
|
import mock.model.MockRace;
|
||||||
import mock.model.Polars;
|
import mock.model.Polars;
|
||||||
import network.Messages.LatestMessages;
|
import network.Messages.LatestMessages;
|
||||||
@@ -11,7 +12,10 @@ import shared.exceptions.InvalidRegattaDataException;
|
|||||||
import shared.exceptions.XMLReaderException;
|
import shared.exceptions.XMLReaderException;
|
||||||
import shared.model.Constants;
|
import shared.model.Constants;
|
||||||
|
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@@ -20,6 +24,7 @@ import java.time.format.DateTimeFormatter;
|
|||||||
* A Race Event, this holds all of the race's information as well as handling the connection to its clients.
|
* A Race Event, this holds all of the race's information as well as handling the connection to its clients.
|
||||||
*/
|
*/
|
||||||
public class Event {
|
public class Event {
|
||||||
|
private static Event theEvent = new Event();
|
||||||
|
|
||||||
private String raceXML;
|
private String raceXML;
|
||||||
private String regattaXML;
|
private String regattaXML;
|
||||||
@@ -29,40 +34,45 @@ public class Event {
|
|||||||
|
|
||||||
private Polars boatPolars;
|
private Polars boatPolars;
|
||||||
|
|
||||||
private MockOutput mockOutput;
|
private ConnectionAcceptor mockOutput;
|
||||||
private LatestMessages latestMessages;
|
private LatestMessages latestMessages;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an event, using various XML files.
|
* Constructs an event, using various XML files.
|
||||||
* @param raceXML The race.xml file.
|
|
||||||
* @param regattaXML The regatta.xml file.
|
|
||||||
* @param boatXML The boat.xml file.
|
|
||||||
* @param type How to read the file - e.g., load as resource.
|
|
||||||
* @param boatPolars polars that the boat uses
|
|
||||||
*/
|
*/
|
||||||
public Event(String raceXML, String regattaXML, String boatXML, XMLFileType type, Polars boatPolars) {
|
private Event() {
|
||||||
|
|
||||||
this.raceXML = getRaceXMLAtCurrentTime(raceXML);
|
|
||||||
this.boatXML = boatXML;
|
|
||||||
this.regattaXML = regattaXML;
|
|
||||||
|
|
||||||
this.xmlFileType = type;
|
|
||||||
|
|
||||||
this.boatPolars = boatPolars;
|
|
||||||
|
|
||||||
this.latestMessages = new LatestMessages();
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.mockOutput = new MockOutput(this.latestMessages);
|
this.raceXML = getRaceXMLAtCurrentTime(XMLReader.readXMLFileToString("mock/mockXML/raceTest.xml", StandardCharsets.UTF_8));
|
||||||
new Thread(mockOutput).start();
|
this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatTest.xml", StandardCharsets.UTF_8);
|
||||||
|
this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
||||||
|
this.xmlFileType = XMLFileType.Contents;
|
||||||
|
|
||||||
} catch (IOException e) {
|
this.boatPolars = PolarParser.parse("mock/polars/acc_polars.csv");
|
||||||
|
|
||||||
|
this.latestMessages = new LatestMessages();
|
||||||
|
this.mockOutput = new ConnectionAcceptor(latestMessages);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (XMLReaderException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (TransformerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Event getEvent() {
|
||||||
|
return theEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() throws UnknownHostException {
|
||||||
|
return mockOutput.getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return mockOutput.getServerPort();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the initial race data and then begins race simulation.
|
* Sends the initial race data and then begins race simulation.
|
||||||
* @throws InvalidRaceDataException Thrown if the race xml file cannot be parsed.
|
* @throws InvalidRaceDataException Thrown if the race xml file cannot be parsed.
|
||||||
@@ -71,6 +81,7 @@ public class Event {
|
|||||||
* @throws InvalidRegattaDataException Thrown if the regatta xml file cannot be parsed.
|
* @throws InvalidRegattaDataException Thrown if the regatta xml file cannot be parsed.
|
||||||
*/
|
*/
|
||||||
public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException {
|
public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException {
|
||||||
|
new Thread(mockOutput).start();
|
||||||
|
|
||||||
sendXMLs();
|
sendXMLs();
|
||||||
|
|
||||||
@@ -120,5 +131,4 @@ public class Event {
|
|||||||
return raceXML;
|
return raceXML;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,18 +29,6 @@ public class MockOutput implements Runnable
|
|||||||
*/
|
*/
|
||||||
private double heartbeatPeriod = 5.0;
|
private double heartbeatPeriod = 5.0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Port to expose server on.
|
|
||||||
*/
|
|
||||||
private int serverPort = 4942;
|
|
||||||
/**
|
|
||||||
* Socket used to listen for clients on.
|
|
||||||
*/
|
|
||||||
private ServerSocket serverSocket;
|
|
||||||
/**
|
|
||||||
* Socket used to communicate with a client.
|
|
||||||
*/
|
|
||||||
private Socket mockSocket;
|
|
||||||
/**
|
/**
|
||||||
* Output stream which wraps around mockSocket outstream.
|
* Output stream which wraps around mockSocket outstream.
|
||||||
*/
|
*/
|
||||||
@@ -60,22 +48,6 @@ public class MockOutput implements Runnable
|
|||||||
*/
|
*/
|
||||||
private int ackNumber = 1;
|
private int ackNumber = 1;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sequence number for race xml messages.
|
|
||||||
*/
|
|
||||||
private short raceXMLSequenceNumber = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sequence number for boat xml messages.
|
|
||||||
*/
|
|
||||||
private short boatXMLSequenceNumber = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sequence number for regatta xml messages.
|
|
||||||
*/
|
|
||||||
private short regattaXMLSequenceNumber = 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sequence number for heartbeat messages.
|
* Sequence number for heartbeat messages.
|
||||||
*/
|
*/
|
||||||
@@ -86,13 +58,14 @@ public class MockOutput implements Runnable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor.
|
* Ctor.
|
||||||
* @param latestMessages The collection of messages to send to connected clients.
|
*
|
||||||
* @throws IOException if server socket cannot be opened.
|
* @throws IOException if server socket cannot be opened.
|
||||||
*/
|
*/
|
||||||
public MockOutput(LatestMessages latestMessages) throws IOException {
|
public MockOutput(LatestMessages latestMessages, DataOutputStream outToVisualiser) throws IOException {
|
||||||
|
|
||||||
|
this.outToVisualiser = outToVisualiser;
|
||||||
|
|
||||||
this.lastHeartbeatTime = System.currentTimeMillis();
|
this.lastHeartbeatTime = System.currentTimeMillis();
|
||||||
this.serverSocket = new ServerSocket(serverPort);
|
|
||||||
|
|
||||||
this.latestMessages = latestMessages;
|
this.latestMessages = latestMessages;
|
||||||
|
|
||||||
@@ -155,44 +128,6 @@ public class MockOutput implements Runnable
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an XMLMessage of a specified subtype using the xml contents string.
|
|
||||||
* @param xmlString The contents of the xml file.
|
|
||||||
* @param messageType The subtype of xml message (race, regatta, boat).
|
|
||||||
* @return The created XMLMessage object.
|
|
||||||
*/
|
|
||||||
private XMLMessage createXMLMessage(String xmlString, XMLMessageType messageType) {
|
|
||||||
|
|
||||||
//Get the correct sequence number to use, and increment it.
|
|
||||||
short sequenceNumber = 0;
|
|
||||||
if (messageType == XMLMessageType.RACE) {
|
|
||||||
sequenceNumber = this.raceXMLSequenceNumber;
|
|
||||||
this.raceXMLSequenceNumber++;
|
|
||||||
|
|
||||||
} else if (messageType == XMLMessageType.BOAT) {
|
|
||||||
sequenceNumber = this.boatXMLSequenceNumber;
|
|
||||||
this.boatXMLSequenceNumber++;
|
|
||||||
|
|
||||||
} else if (messageType == XMLMessageType.REGATTA) {
|
|
||||||
sequenceNumber = this.regattaXMLSequenceNumber;
|
|
||||||
this.regattaXMLSequenceNumber++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create the message.
|
|
||||||
XMLMessage message = new XMLMessage(
|
|
||||||
XMLMessage.currentVersionNumber,
|
|
||||||
getNextAckNumber(),
|
|
||||||
System.currentTimeMillis(),
|
|
||||||
messageType,
|
|
||||||
sequenceNumber,
|
|
||||||
xmlString );
|
|
||||||
|
|
||||||
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes/serialises a XMLMessage message, and returns it.
|
* Encodes/serialises a XMLMessage message, and returns it.
|
||||||
* @param xmlMessage The XMLMessage message to serialise.
|
* @param xmlMessage The XMLMessage message to serialise.
|
||||||
@@ -266,6 +201,17 @@ public class MockOutput implements Runnable
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a heartbeat
|
||||||
|
* @throws IOException if the socket is no longer open at both ends the heartbeat returns an error.
|
||||||
|
*/
|
||||||
|
public void sendHeartBeat() throws IOException {
|
||||||
|
//Sends a heartbeat every so often.
|
||||||
|
if (timeSinceHeartbeat() >= heartbeatPeriod) {
|
||||||
|
outToVisualiser.write(parseHeartbeat(createHeartbeatMessage()));
|
||||||
|
lastHeartbeatTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sending loop of the Server
|
* Sending loop of the Server
|
||||||
@@ -274,11 +220,6 @@ public class MockOutput implements Runnable
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
while (!stop){
|
while (!stop){
|
||||||
//Wait for a client to connect.
|
|
||||||
System.out.println("Waiting for a connection...");//TEMP DEBUG REMOVE
|
|
||||||
mockSocket = serverSocket.accept();
|
|
||||||
|
|
||||||
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
|
||||||
|
|
||||||
//Wait until all of the xml files have been set.
|
//Wait until all of the xml files have been set.
|
||||||
if (!this.latestMessages.hasAllXMLMessages()) {
|
if (!this.latestMessages.hasAllXMLMessages()) {
|
||||||
@@ -307,12 +248,6 @@ public class MockOutput implements Runnable
|
|||||||
long minimumFramePeriod = 16;
|
long minimumFramePeriod = 16;
|
||||||
if (framePeriod >= minimumFramePeriod) {
|
if (framePeriod >= minimumFramePeriod) {
|
||||||
|
|
||||||
//Sends a heartbeat every so often.
|
|
||||||
if (timeSinceHeartbeat() >= heartbeatPeriod) {
|
|
||||||
outToVisualiser.write(parseHeartbeat(createHeartbeatMessage()));
|
|
||||||
lastHeartbeatTime = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Send XML messages.
|
//Send XML messages.
|
||||||
if (!sentXMLs) {
|
if (!sentXMLs) {
|
||||||
//Serialise them.
|
//Serialise them.
|
||||||
@@ -385,47 +320,4 @@ public class MockOutput implements Runnable
|
|||||||
stop = true;
|
stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Race XML to send.
|
|
||||||
* @param raceXml XML to send to the Client.
|
|
||||||
*/
|
|
||||||
public void setRaceXml(String raceXml) {
|
|
||||||
//Create the message.
|
|
||||||
XMLMessage message = this.createXMLMessage(raceXml, XMLMessageType.RACE);
|
|
||||||
|
|
||||||
//Place it in LatestMessages.
|
|
||||||
this.latestMessages.setRaceXMLMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Regatta XMl to send.
|
|
||||||
* @param regattaXml XML to send to Client.
|
|
||||||
*/
|
|
||||||
public void setRegattaXml(String regattaXml) {
|
|
||||||
//Create the message.
|
|
||||||
XMLMessage message = this.createXMLMessage(regattaXml, XMLMessageType.REGATTA);
|
|
||||||
|
|
||||||
//Place it in LatestMessages.
|
|
||||||
this.latestMessages.setRegattaXMLMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Boats XML to send.
|
|
||||||
* @param boatsXml XMl to send to the Client.
|
|
||||||
*/
|
|
||||||
public void setBoatsXml(String boatsXml) {
|
|
||||||
//Create the message.
|
|
||||||
XMLMessage message = this.createXMLMessage(boatsXml, XMLMessageType.BOAT);
|
|
||||||
|
|
||||||
//Place it in LatestMessages.
|
|
||||||
this.latestMessages.setBoatXMLMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String argv[]) throws Exception
|
|
||||||
{
|
|
||||||
MockOutput client = new MockOutput(new LatestMessages());
|
|
||||||
client.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,8 +289,7 @@ public class LatestMessages extends Observable {
|
|||||||
* @return True if race, boat, and regatta have an xml message, false otherwise.
|
* @return True if race, boat, and regatta have an xml message, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasAllXMLMessages() {
|
public boolean hasAllXMLMessages() {
|
||||||
|
if (this.regattaXMLMessage == null || this.boatXMLMessage == null || this.raceXMLMessage == null) {
|
||||||
if ((this.regattaXMLMessage == null) || (this.boatXMLMessage == null) || (this.raceXMLMessage == null)) {
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,12 +5,18 @@ import javafx.collections.ObservableList;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import mock.app.Event;
|
||||||
|
import shared.exceptions.InvalidBoatDataException;
|
||||||
|
import shared.exceptions.InvalidRaceDataException;
|
||||||
|
import shared.exceptions.InvalidRegattaDataException;
|
||||||
|
import shared.exceptions.XMLReaderException;
|
||||||
import visualiser.model.RaceConnection;
|
import visualiser.model.RaceConnection;
|
||||||
|
|
||||||
import javax.xml.soap.Text;
|
import javax.xml.soap.Text;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,8 +85,6 @@ public class ConnectionController extends Controller {
|
|||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
// TODO - replace with config file
|
// TODO - replace with config file
|
||||||
connections = FXCollections.observableArrayList();
|
connections = FXCollections.observableArrayList();
|
||||||
connections.add(new RaceConnection("livedata.americascup.com", 4941, null));
|
|
||||||
connections.add(new RaceConnection("localhost", 4942, null));
|
|
||||||
|
|
||||||
connectionTable.setItems(connections);
|
connectionTable.setItems(connections);
|
||||||
hostnameColumn.setCellValueFactory(cellData -> cellData.getValue().hostnameProperty());
|
hostnameColumn.setCellValueFactory(cellData -> cellData.getValue().hostnameProperty());
|
||||||
@@ -113,6 +117,7 @@ public class ConnectionController extends Controller {
|
|||||||
try{
|
try{
|
||||||
RaceConnection connection = connectionTable.getSelectionModel().getSelectedItem();
|
RaceConnection connection = connectionTable.getSelectionModel().getSelectedItem();
|
||||||
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
||||||
|
socket.setKeepAlive(true);
|
||||||
connectionWrapper.setVisible(false);
|
connectionWrapper.setVisible(false);
|
||||||
parent.enterLobby(socket);
|
parent.enterLobby(socket);
|
||||||
} catch (IOException e) { /* Never reached */ }
|
} catch (IOException e) { /* Never reached */ }
|
||||||
@@ -130,6 +135,29 @@ public class ConnectionController extends Controller {
|
|||||||
}catch(NumberFormatException e){
|
}catch(NumberFormatException e){
|
||||||
System.err.println("Port number entered is not a number");
|
System.err.println("Port number entered is not a number");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up a new host
|
||||||
|
*/
|
||||||
|
public void addLocal() {
|
||||||
|
try {
|
||||||
|
Event game = Event.getEvent();
|
||||||
|
urlField.textProperty().set(game.getAddress());
|
||||||
|
portField.textProperty().set(Integer.toString(game.getPort()));
|
||||||
|
|
||||||
|
game.start();
|
||||||
|
addConnection();
|
||||||
|
} catch (InvalidRaceDataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (XMLReaderException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvalidBoatDataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvalidRegattaDataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import javafx.animation.AnimationTimer;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.chart.LineChart;
|
import javafx.scene.chart.LineChart;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
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;
|
||||||
@@ -16,8 +19,11 @@ import javafx.util.Callback;
|
|||||||
import network.Messages.Enums.RaceStatusEnum;
|
import network.Messages.Enums.RaceStatusEnum;
|
||||||
import shared.model.Leg;
|
import shared.model.Leg;
|
||||||
import visualiser.app.VisualiserInput;
|
import visualiser.app.VisualiserInput;
|
||||||
|
import visualiser.gameController.Keys.ControlKey;
|
||||||
|
import visualiser.gameController.Keys.KeyFactory;
|
||||||
import visualiser.model.*;
|
import visualiser.model.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -79,6 +85,14 @@ public class RaceController extends Controller {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
// Initialise keyboard handler
|
||||||
|
race.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||||
|
String codeString = event.getCode().toString();
|
||||||
|
ControlKey controlKey = KeyFactory.getKey(codeString);
|
||||||
|
if(controlKey != null) {
|
||||||
|
System.out.println(controlKey.toString() + " is Pressed.");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -278,8 +292,6 @@ public class RaceController extends Controller {
|
|||||||
|
|
||||||
//Add to scene.
|
//Add to scene.
|
||||||
canvasBase.getChildren().add(0, raceCanvas);
|
canvasBase.getChildren().add(0, raceCanvas);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -345,7 +357,6 @@ public class RaceController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timer which monitors the race.
|
* Timer which monitors the race.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
|
||||||
import static network.Utils.ByteConverter.bytesToShort;
|
import static network.Utils.ByteConverter.bytesToShort;
|
||||||
|
|
||||||
@@ -372,6 +373,4 @@ public class VisualiserInput implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package visualiser.gameController;
|
||||||
|
|
||||||
|
import javafx.animation.AnimationTimer;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import visualiser.gameController.Keys.ControlKey;
|
||||||
|
import visualiser.gameController.Keys.KeyFactory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static javafx.application.Application.launch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for checking what keys are currently being used
|
||||||
|
*/
|
||||||
|
public class InputChecker {
|
||||||
|
private HashMap<String, Boolean> currentlyActiveKeys = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller loop that detects key presses that runs parallel to the main scene.
|
||||||
|
* @param scene Scene the controller is to run in parallel with.
|
||||||
|
*/
|
||||||
|
public void runWithScene(Scene scene){
|
||||||
|
scene.setOnKeyPressed(event -> {
|
||||||
|
String codeString = event.getCode().toString();
|
||||||
|
if (!currentlyActiveKeys.containsKey(codeString)) {
|
||||||
|
ControlKey controlKey = KeyFactory.getKey(codeString);
|
||||||
|
if (controlKey != null) {
|
||||||
|
controlKey.onAction();
|
||||||
|
System.out.println(controlKey.toString() + " is Pressed.");
|
||||||
|
}
|
||||||
|
currentlyActiveKeys.put(codeString, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
scene.setOnKeyReleased(event -> {
|
||||||
|
String codeString = event.getCode().toString();
|
||||||
|
ControlKey controlKey = KeyFactory.getKey(codeString);
|
||||||
|
if (controlKey != null) {
|
||||||
|
controlKey.onRelease();
|
||||||
|
System.out.println(controlKey.toString() + " is Released.");
|
||||||
|
}
|
||||||
|
currentlyActiveKeys.remove(event.getCode().toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
new AnimationTimer() {
|
||||||
|
@Override
|
||||||
|
public void handle(long now) {
|
||||||
|
for (String key: currentlyActiveKeys.keySet()){
|
||||||
|
ControlKey controlKey = KeyFactory.getKey(key);
|
||||||
|
if (controlKey != null){
|
||||||
|
controlKey.onHold();
|
||||||
|
System.out.println(controlKey.toString() + " is Held.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for (String key : InputKeys.stringKeysMap.keySet()){
|
||||||
|
// if (removeActiveKey(key)) {
|
||||||
|
// System.out.println(key);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes a key from the active dictionary
|
||||||
|
* @param codeString string of the key press to remove
|
||||||
|
* @return whether or not the key has been removed or not.
|
||||||
|
*/
|
||||||
|
private boolean removeActiveKey(String codeString) {
|
||||||
|
Boolean isActive = currentlyActiveKeys.get(codeString);
|
||||||
|
|
||||||
|
if (isActive != null && isActive) {
|
||||||
|
currentlyActiveKeys.put(codeString, false);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key for the controller, part of the abstract factory KeyFactory
|
||||||
|
*/
|
||||||
|
public abstract class ControlKey {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private KeyCode keyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Control
|
||||||
|
* @param name name of the key
|
||||||
|
* @param keyCode key code for the key
|
||||||
|
*/
|
||||||
|
public ControlKey(String name, KeyCode keyCode){
|
||||||
|
this.name = name;
|
||||||
|
this.keyCode = keyCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To String method
|
||||||
|
* @return returns the name of the key
|
||||||
|
*/
|
||||||
|
public String toString(){
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What this key should do when the command is issued for it to do its job.
|
||||||
|
*/
|
||||||
|
public abstract void onAction();//may want to make it take in a visualiser and stuff in the future.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What to do when the key is held
|
||||||
|
*/
|
||||||
|
public abstract void onHold();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What to do when the key is released.
|
||||||
|
*/
|
||||||
|
public abstract void onRelease();
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key to send downwind packet to server
|
||||||
|
*/
|
||||||
|
public class DownWindKey extends ControlKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Control
|
||||||
|
*
|
||||||
|
* @param name name of the key
|
||||||
|
* @param keyCode key code for the key
|
||||||
|
*/
|
||||||
|
public DownWindKey(String name, KeyCode keyCode) {
|
||||||
|
super(name, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating Keys, these could be predefined in the future.
|
||||||
|
*/
|
||||||
|
public class KeyFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Control Key incharge of a key press
|
||||||
|
* @param key key pressed (String value of KeyCode)
|
||||||
|
* @return the Control Key behaviour of the key pressed.
|
||||||
|
*/
|
||||||
|
public static ControlKey getKey(String key){
|
||||||
|
switch(key){
|
||||||
|
case "Z":
|
||||||
|
return new ZoomInKey("Z", KeyCode.Z);
|
||||||
|
case "X":
|
||||||
|
return new ZoomOutKey("X", KeyCode.X);
|
||||||
|
case "SPACE":
|
||||||
|
return new VMGKey("SPACE", KeyCode.SPACE);
|
||||||
|
case "SHIFT":
|
||||||
|
return new SailsToggleKey("SHIFT", KeyCode.SHIFT);
|
||||||
|
case "ENTER":
|
||||||
|
return new TackGybeKey("ENTER", KeyCode.ENTER);
|
||||||
|
case "PAGE_UP":
|
||||||
|
return new UpWindKey("PAGE_UP", KeyCode.PAGE_UP);
|
||||||
|
case "PAGE_DOWN":
|
||||||
|
return new DownWindKey("PAGE_DOWN", KeyCode.PAGE_DOWN);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key to toggle the sails
|
||||||
|
*/
|
||||||
|
public class SailsToggleKey extends ControlKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Control
|
||||||
|
*
|
||||||
|
* @param name name of the key
|
||||||
|
* @param keyCode key code for the key
|
||||||
|
*/
|
||||||
|
public SailsToggleKey(String name, KeyCode keyCode) {
|
||||||
|
super(name, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* key to toggle between tacking and gybing
|
||||||
|
*/
|
||||||
|
public class TackGybeKey extends ControlKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Control
|
||||||
|
*
|
||||||
|
* @param name name of the key
|
||||||
|
* @param keyCode key code for the key
|
||||||
|
*/
|
||||||
|
public TackGybeKey(String name, KeyCode keyCode) {
|
||||||
|
super(name, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key to go upwind
|
||||||
|
*/
|
||||||
|
public class UpWindKey extends ControlKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Control
|
||||||
|
*
|
||||||
|
* @param name name of the key
|
||||||
|
* @param keyCode key code for the key
|
||||||
|
*/
|
||||||
|
public UpWindKey(String name, KeyCode keyCode) {
|
||||||
|
super(name, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key to trigger auto VMG
|
||||||
|
*/
|
||||||
|
public class VMGKey extends ControlKey{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Control
|
||||||
|
*
|
||||||
|
* @param name name of the key
|
||||||
|
* @param keyCode key code for the key
|
||||||
|
*/
|
||||||
|
public VMGKey(String name, KeyCode keyCode) {
|
||||||
|
super(name, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* key to zoom into the game
|
||||||
|
*/
|
||||||
|
public class ZoomInKey extends ControlKey {
|
||||||
|
|
||||||
|
public ZoomInKey(String name, KeyCode keyCode) {
|
||||||
|
super(name, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key to zoom out of the game.
|
||||||
|
*/
|
||||||
|
public class ZoomOutKey extends ControlKey{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Control
|
||||||
|
*
|
||||||
|
* @param name name of the key
|
||||||
|
* @param keyCode key code for the key
|
||||||
|
*/
|
||||||
|
public ZoomOutKey(String name, KeyCode keyCode) {
|
||||||
|
super(name, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,12 @@ public class RaceConnection {
|
|||||||
private final StringProperty gamename;
|
private final StringProperty gamename;
|
||||||
|
|
||||||
public RaceConnection(String hostname, int port, String gamename) {
|
public RaceConnection(String hostname, int port, String gamename) {
|
||||||
|
/**
|
||||||
|
* Constructor for remote host connections.
|
||||||
|
* @param hostname URL for remote host
|
||||||
|
* @param port port for game feed
|
||||||
|
*/
|
||||||
|
public RaceConnection(String hostname, int port) {
|
||||||
this.hostname = new SimpleStringProperty(hostname);
|
this.hostname = new SimpleStringProperty(hostname);
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.status = new SimpleStringProperty("");
|
this.status = new SimpleStringProperty("");
|
||||||
@@ -35,6 +41,10 @@ public class RaceConnection {
|
|||||||
try (Socket s = new Socket()){
|
try (Socket s = new Socket()){
|
||||||
s.connect(i, 750);//TODO this should be at least a second or two, once moved to its own thread
|
s.connect(i, 750);//TODO this should be at least a second or two, once moved to its own thread
|
||||||
status.set("Ready");
|
status.set("Ready");
|
||||||
|
s.shutdownInput();
|
||||||
|
s.shutdownOutput();
|
||||||
|
s.close();
|
||||||
|
//System.out.println(String.valueOf(s.isClosed()));
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import java.lang.*?>
|
|
||||||
<?import javafx.scene.text.*?>
|
|
||||||
<?import javafx.geometry.*?>
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
|
||||||
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
|
|
||||||
<children>
|
<children>
|
||||||
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package visualiser.gameController;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.WindowEvent;
|
||||||
|
import visualiser.gameController.InputChecker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start to manually test the game controller
|
||||||
|
*/
|
||||||
|
public class GameControllerManualTest extends Application {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws Exception {
|
||||||
|
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(WindowEvent event) {
|
||||||
|
Platform.exit();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
GridPane root = new GridPane();
|
||||||
|
Scene scene = new Scene(root, 1200, 800);
|
||||||
|
|
||||||
|
InputChecker inputChecker = new InputChecker();
|
||||||
|
inputChecker.runWithScene(scene);
|
||||||
|
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.setTitle("RaceVision - Team 7 - Input Tester Manual Test");
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user