Merge branch 'master' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into zoomzoom
This commit is contained in:
+3
-3
@@ -41,8 +41,8 @@ public class BoatsXMLMessageCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
visualiserRace.setBoatDataSource(boatDataSource);
|
||||
|
||||
if (boatDataSource.getSequenceNumber() > visualiserRace.getBoatDataSource().getSequenceNumber()) {
|
||||
visualiserRace.setBoatDataSource(boatDataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -38,7 +38,9 @@ public class RaceXMLMessageCommand implements Command {
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
visualiserRace.setRaceDataSource(raceDataSource);
|
||||
if (raceDataSource.getSequenceNumber() > visualiserRace.getRaceDataSource().getSequenceNumber()) {
|
||||
visualiserRace.setRaceDataSource(raceDataSource);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -37,8 +37,9 @@ public class RegattaXMLMessageCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
visualiserRace.setRegattaDataSource(regattaDataSource);
|
||||
if (regattaDataSource.getSequenceNumber() > visualiserRace.getRegattaDataSource().getSequenceNumber()) {
|
||||
visualiserRace.setRegattaDataSource(regattaDataSource);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -34,17 +34,20 @@ public class XMLMessageCommandFactory {
|
||||
switch (message.getXmlMsgSubType()) {
|
||||
|
||||
case BOAT:
|
||||
BoatDataSource boatDataSource = new BoatXMLReader(message.getXmlMessage(), XMLFileType.Contents);
|
||||
BoatXMLReader boatDataSource = new BoatXMLReader(message.getXmlMessage(), XMLFileType.Contents);
|
||||
boatDataSource.setSequenceNumber(message.getSequenceNumber());
|
||||
return new BoatsXMLMessageCommand(boatDataSource, visualiserRace);
|
||||
|
||||
|
||||
case RACE:
|
||||
RaceDataSource raceDataSource = new RaceXMLReader(message.getXmlMessage(), XMLFileType.Contents);
|
||||
RaceXMLReader raceDataSource = new RaceXMLReader(message.getXmlMessage(), XMLFileType.Contents);
|
||||
raceDataSource.setSequenceNumber(message.getSequenceNumber());
|
||||
return new RaceXMLMessageCommand(raceDataSource, visualiserRace);
|
||||
|
||||
|
||||
case REGATTA:
|
||||
RegattaDataSource regattaDataSource = new RegattaXMLReader(message.getXmlMessage(), XMLFileType.Contents);
|
||||
RegattaXMLReader regattaDataSource = new RegattaXMLReader(message.getXmlMessage(), XMLFileType.Contents);
|
||||
regattaDataSource.setSequenceNumber(message.getSequenceNumber());
|
||||
return new RegattaXMLMessageCommand(regattaDataSource, visualiserRace);
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import mock.exceptions.EventConstructionException;
|
||||
import network.Messages.Enums.RequestToJoinEnum;
|
||||
import visualiser.app.App;
|
||||
import visualiser.app.MatchBrowserSingleton;
|
||||
import visualiser.network.HttpMatchBrowserHost;
|
||||
import visualiser.network.MatchBrowserInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -65,8 +66,11 @@ public class HostGameController extends Controller {
|
||||
try {
|
||||
App.game = new Event(false, currentMapIndex);
|
||||
App.gameType = currentMapIndex;
|
||||
|
||||
HttpMatchBrowserHost matchBrowserHost = new HttpMatchBrowserHost();
|
||||
new Thread(matchBrowserHost).start();
|
||||
connectSocket("localhost", 4942);
|
||||
alertMatchBrowser();
|
||||
//alertMatchBrowser();
|
||||
|
||||
} catch (EventConstructionException e) {
|
||||
Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e);
|
||||
|
||||
@@ -15,11 +15,13 @@ import javafx.scene.control.Label;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import mock.app.Event;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import network.Messages.Enums.RequestToJoinEnum;
|
||||
import shared.model.Boat;
|
||||
import visualiser.app.App;
|
||||
import visualiser.gameController.ControllerClient;
|
||||
import visualiser.layout.SeaSurface;
|
||||
@@ -28,6 +30,7 @@ import visualiser.layout.View3D;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRaceEvent;
|
||||
import visualiser.model.VisualiserRaceState;
|
||||
import visualiser.network.HttpMatchBrowserHost;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
@@ -124,61 +127,69 @@ public class InGameLobbyController extends Controller {
|
||||
|
||||
@Override
|
||||
public void onChanged(Change change) {
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
while (change.next()){
|
||||
if (change.wasAdded() || change.wasRemoved() || change.wasUpdated()){
|
||||
try{
|
||||
resetLobby();
|
||||
int count = 0;
|
||||
int row = 0;
|
||||
for (VisualiserBoat boat :visualiserRaceEvent.getVisualiserRaceState().getBoats()) {
|
||||
View3D playerBoatToSet = new View3D();
|
||||
playerBoatToSet.setItems(subjects);
|
||||
|
||||
playerContainer.add(playerBoatToSet, (count % 3) , row);
|
||||
playerContainer.setMargin(playerBoatToSet, new Insets(10, 10, 10, 10));
|
||||
|
||||
SeaSurface sea = new SeaSurface(750, 200);
|
||||
sea.setX(250);
|
||||
sea.setZ(210);
|
||||
subjects.add(sea);
|
||||
|
||||
MeshView mesh = new MeshView(importer.getImport());
|
||||
PhongMaterial boatColorMat = new PhongMaterial(boat.getColor());
|
||||
mesh.setMaterial(boatColorMat);
|
||||
Subject3D subject = new Subject3D(mesh,0);
|
||||
subjects.add(subject);
|
||||
|
||||
playerBoatToSet.setDistance(50);
|
||||
playerBoatToSet.setYaw(45);
|
||||
playerBoatToSet.setPitch(20);
|
||||
|
||||
|
||||
|
||||
AnimationTimer rotate = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
subject.setHeading(subject.getHeading().getAngle() + 0.1);
|
||||
}
|
||||
};
|
||||
rotate.start();
|
||||
|
||||
allPlayerLabels.get(count).setText(boat.getName());
|
||||
allPlayerLabels.get(count).toFront();
|
||||
count += 1;
|
||||
if (count > 2){
|
||||
row = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ConcurrentModificationException e){
|
||||
}
|
||||
}
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
while (change.next()) {
|
||||
if (change.wasAdded() || change.wasRemoved() || change.wasUpdated()) {
|
||||
populateLobby();
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void populateLobby() {
|
||||
|
||||
try{
|
||||
resetLobby();
|
||||
int count = 0;
|
||||
int row = 0;
|
||||
|
||||
ArrayList<VisualiserBoat> copy = new ArrayList<>(visualiserRaceEvent.getVisualiserRaceState().getBoats());
|
||||
|
||||
for (VisualiserBoat boat : copy) {
|
||||
View3D playerBoatToSet = new View3D();
|
||||
playerBoatToSet.setItems(subjects);
|
||||
|
||||
playerContainer.add(playerBoatToSet, (count % 3) , row);
|
||||
playerContainer.setMargin(playerBoatToSet, new Insets(10, 10, 10, 10));
|
||||
|
||||
SeaSurface sea = new SeaSurface(750, 200);
|
||||
sea.setX(250);
|
||||
sea.setZ(210);
|
||||
subjects.add(sea);
|
||||
|
||||
MeshView mesh = new MeshView(importer.getImport());
|
||||
PhongMaterial boatColorMat = new PhongMaterial(boat.getColor());
|
||||
mesh.setMaterial(boatColorMat);
|
||||
Subject3D subject = new Subject3D(mesh,0);
|
||||
subjects.add(subject);
|
||||
|
||||
playerBoatToSet.setDistance(50);
|
||||
playerBoatToSet.setYaw(45);
|
||||
playerBoatToSet.setPitch(20);
|
||||
|
||||
|
||||
|
||||
AnimationTimer rotate = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
subject.setHeading(subject.getHeading().getAngle() + 0.1);
|
||||
}
|
||||
};
|
||||
rotate.start();
|
||||
|
||||
allPlayerLabels.get(count).setText(boat.getName());
|
||||
allPlayerLabels.get(count).toFront();
|
||||
count += 1;
|
||||
if (count > 2){
|
||||
row = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ConcurrentModificationException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
private void populatePlayers(ListChangeListener.Change change){
|
||||
@@ -191,7 +202,6 @@ public class InGameLobbyController extends Controller {
|
||||
//Initialises the race clock.
|
||||
initialiseRaceClock(this.visualiserRaceEvent.getVisualiserRaceState());
|
||||
|
||||
|
||||
//Starts the race countdown timer.
|
||||
countdownTimer();
|
||||
}
|
||||
@@ -227,10 +237,9 @@ public class InGameLobbyController extends Controller {
|
||||
new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
|
||||
//Get the current race status.
|
||||
RaceStatusEnum raceStatus = visualiserRaceEvent.getVisualiserRaceState().getRaceStatusEnum();
|
||||
|
||||
|
||||
//Try catch for getting interval times
|
||||
try {
|
||||
long interval = ChronoUnit.MILLIS.between(visualiserRaceEvent.getVisualiserRaceState().getRaceClock().getCurrentTime(), visualiserRaceEvent.getVisualiserRaceState().getRaceClock().getStartingTime());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
@@ -11,8 +12,12 @@ import javafx.scene.layout.AnchorPane;
|
||||
import network.Messages.Enums.RequestToJoinEnum;
|
||||
import javafx.scene.media.AudioClip;
|
||||
import network.Messages.HostGame;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import shared.utils.JsonReader;
|
||||
import visualiser.app.MatchBrowserSingleton;
|
||||
import visualiser.model.RaceConnection;
|
||||
import visualiser.network.HttpMatchBrowserClient;
|
||||
import visualiser.network.MatchBrowserLobbyInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -41,17 +46,17 @@ public class LobbyController extends Controller {
|
||||
private AudioClip sound;
|
||||
|
||||
//the socket for match browser
|
||||
private DatagramSocket udpSocket;
|
||||
private MatchBrowserLobbyInterface matchBrowserLobbyInterface;
|
||||
private HttpMatchBrowserClient httpMatchBrowserClient;
|
||||
|
||||
|
||||
public void initialize() {
|
||||
httpMatchBrowserClient = new HttpMatchBrowserClient();
|
||||
new Thread(httpMatchBrowserClient, "Match Client").start();
|
||||
// set up the connection table
|
||||
connections = FXCollections.observableArrayList();
|
||||
customConnections = FXCollections.observableArrayList();
|
||||
//connections.add(new RaceConnection("localhost", 4942, "Local Game"));
|
||||
|
||||
lobbyTable.setItems(connections);
|
||||
lobbyTable.setItems(httpMatchBrowserClient.connections);
|
||||
gameNameColumn.setCellValueFactory(cellData -> cellData.getValue().gamenameProperty());
|
||||
hostNameColumn.setCellValueFactory(cellData -> cellData.getValue().hostnameProperty());
|
||||
statusColumn.setCellValueFactory(cellData -> cellData.getValue().statusProperty());
|
||||
@@ -68,7 +73,6 @@ public class LobbyController extends Controller {
|
||||
joinGameBtn.setDisable(true);
|
||||
spectateButton.setDisable(true);
|
||||
|
||||
this.udpSocket = MatchBrowserSingleton.getInstance().getUdpSocket();
|
||||
receiveMatchData();
|
||||
}
|
||||
|
||||
@@ -99,6 +103,7 @@ public class LobbyController extends Controller {
|
||||
* @throws IOException socket error
|
||||
*/
|
||||
public void connectSocket(RequestToJoinEnum joinType) throws IOException {
|
||||
httpMatchBrowserClient.interrupt();
|
||||
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
||||
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
||||
InGameLobbyController iglc = (InGameLobbyController)loadScene("gameLobby.fxml");
|
||||
@@ -124,7 +129,7 @@ public class LobbyController extends Controller {
|
||||
public void menuBtnPressed() throws IOException {
|
||||
sound = new AudioClip(this.getClass().getResource("/visualiser/sounds/buttonpress.wav").toExternalForm());
|
||||
sound.play();
|
||||
matchBrowserLobbyInterface.closeSocket();
|
||||
httpMatchBrowserClient.interrupt();
|
||||
loadScene("title.fxml");
|
||||
}
|
||||
|
||||
@@ -148,6 +153,7 @@ public class LobbyController extends Controller {
|
||||
}
|
||||
|
||||
public void receiveMatchData(){
|
||||
/*
|
||||
matchBrowserLobbyInterface = new MatchBrowserLobbyInterface();
|
||||
try {
|
||||
matchBrowserLobbyInterface.startReceivingHostData(new DatagramSocket(4941));
|
||||
@@ -160,17 +166,24 @@ public class LobbyController extends Controller {
|
||||
matchBrowserLobbyInterface.addObserver(o);
|
||||
} catch (SocketException e) {
|
||||
System.err.println("Socket 4941 in use");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the games received from the server
|
||||
*/
|
||||
private void addServerGames() {
|
||||
connections.clear();
|
||||
connections.addAll(customConnections);
|
||||
httpMatchBrowserClient.connections.addAll(customConnections);
|
||||
httpMatchBrowserClient.connections.addListener(new ListChangeListener<RaceConnection>() {
|
||||
@Override
|
||||
public void onChanged(Change<? extends RaceConnection> c) {
|
||||
refreshBtnPressed();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
for (HostGame game : matchBrowserLobbyInterface.getGames()) {
|
||||
connections.add(new RaceConnection(game.getIp(), 4942, "Boat Game"));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,7 @@ import visualiser.gameController.ControllerClient;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
import visualiser.layout.*;
|
||||
import visualiser.model.Sparkline;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRaceEvent;
|
||||
import visualiser.model.VisualiserRaceState;
|
||||
import visualiser.model.*;
|
||||
import visualiser.utils.GPSConverter;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -65,6 +62,8 @@ public class RaceViewController extends Controller {
|
||||
private String keyToPress;
|
||||
private View3D view3D;
|
||||
private ObservableList<Subject3D> viewSubjects;
|
||||
private ResizableRaceCanvas raceCanvas;
|
||||
private boolean mapToggle = true;
|
||||
|
||||
/**
|
||||
* Arrow pointing to next mark in third person
|
||||
@@ -78,6 +77,7 @@ public class RaceViewController extends Controller {
|
||||
// note: it says it's not used but it is! do not remove :)
|
||||
private @FXML ArrowController arrowController;
|
||||
private @FXML GridPane canvasBase;
|
||||
private @FXML GridPane canvasBase1;
|
||||
private @FXML SplitPane racePane;
|
||||
private @FXML StackPane arrowPane;
|
||||
private @FXML Label timer;
|
||||
@@ -111,6 +111,7 @@ public class RaceViewController extends Controller {
|
||||
tutorialCheck();
|
||||
initKeypressHandler();
|
||||
initialiseRaceVisuals();
|
||||
initialiseRaceCanvas();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,6 +147,9 @@ public class RaceViewController extends Controller {
|
||||
// tab key
|
||||
if (codeString.equals("TAB")){toggleTable();}
|
||||
|
||||
//map key
|
||||
if (codeString.equals("M")){bigMap();}
|
||||
|
||||
// any key pressed
|
||||
ControlKey controlKey = keyFactory.getKey(codeString);
|
||||
if(controlKey != null) {
|
||||
@@ -431,12 +435,14 @@ public class RaceViewController extends Controller {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
CompoundMark target = boat.getCurrentLeg().getEndCompoundMark();
|
||||
Bearing headingToMark = GPSCoordinate.calculateBearing(boat.getPosition(), target.getAverageGPSCoordinate());
|
||||
if (target != null) {
|
||||
Bearing headingToMark = GPSCoordinate.calculateBearing(boat.getPosition(), target.getAverageGPSCoordinate());
|
||||
|
||||
nextMarkArrow.setX(view3D.getPivot().getX());
|
||||
nextMarkArrow.setY(view3D.getPivot().getY());
|
||||
nextMarkArrow.setZ(view3D.getPivot().getZ() + 15);
|
||||
nextMarkArrow.setHeading(headingToMark.degrees());
|
||||
nextMarkArrow.setX(view3D.getPivot().getX());
|
||||
nextMarkArrow.setY(view3D.getPivot().getY());
|
||||
nextMarkArrow.setZ(view3D.getPivot().getZ() + 15);
|
||||
nextMarkArrow.setHeading(headingToMark.degrees());
|
||||
}
|
||||
}
|
||||
};
|
||||
arrowToNextMark.start();
|
||||
@@ -610,6 +616,8 @@ public class RaceViewController extends Controller {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
raceCanvas.drawRace();
|
||||
|
||||
boatInfoTable.sort();
|
||||
}
|
||||
|
||||
@@ -737,4 +745,48 @@ public class RaceViewController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the map
|
||||
*/
|
||||
private void initialiseRaceCanvas() {
|
||||
|
||||
//Create canvas.
|
||||
raceCanvas = new ResizableRaceCanvas(raceState);
|
||||
|
||||
//Set properties.
|
||||
raceCanvas.setMouseTransparent(true);
|
||||
raceCanvas.widthProperty().bind(canvasBase1.widthProperty());
|
||||
raceCanvas.heightProperty().bind(canvasBase1.heightProperty());
|
||||
|
||||
//Draw it and show it.
|
||||
raceCanvas.draw();
|
||||
raceCanvas.setVisible(true);
|
||||
|
||||
//Add to scene.
|
||||
canvasBase1.getChildren().add(0, raceCanvas);
|
||||
}
|
||||
|
||||
private void bigMap(){
|
||||
if (mapToggle){
|
||||
raceCanvas.widthProperty().bind(canvasBase.widthProperty());
|
||||
raceCanvas.heightProperty().bind(canvasBase.heightProperty());
|
||||
|
||||
raceCanvas.setFullScreen(true);
|
||||
raceCanvas.setOpacity(0.6);
|
||||
|
||||
canvasBase1.getChildren().remove(raceCanvas);
|
||||
canvasBase.getChildren().add(1, raceCanvas);
|
||||
|
||||
}else{
|
||||
raceCanvas.widthProperty().bind(canvasBase1.widthProperty());
|
||||
raceCanvas.heightProperty().bind(canvasBase1.heightProperty());
|
||||
|
||||
raceCanvas.setFullScreen(false);
|
||||
|
||||
canvasBase.getChildren().remove(raceCanvas);
|
||||
canvasBase1.getChildren().add(0, raceCanvas);
|
||||
}
|
||||
mapToggle = !mapToggle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,13 +6,11 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import network.Messages.Enums.BoatStatusEnum;
|
||||
import shared.dataInput.RaceDataSource;
|
||||
import shared.enums.RoundingType;
|
||||
import shared.model.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -44,13 +42,15 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
private VisualiserRaceState raceState;
|
||||
|
||||
|
||||
private boolean annoName = true;
|
||||
private boolean annoName = false;
|
||||
private boolean annoAbbrev = true;
|
||||
private boolean annoSpeed = true;
|
||||
private boolean annoSpeed = false;
|
||||
private boolean annoPath = true;
|
||||
private boolean annoEstTime = true;
|
||||
private boolean annoTimeSinceLastMark = true;
|
||||
private boolean annoGuideLine = false;
|
||||
private boolean annoEstTime = false;
|
||||
private boolean annoTimeSinceLastMark = false;
|
||||
private boolean annoGuideLine = true;
|
||||
|
||||
private boolean isFullScreen = false;
|
||||
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
|
||||
List<VisualiserBoat> boats = new ArrayList<>(raceState.getBoats());
|
||||
//Sort to ensure we draw boats in consistent order.
|
||||
boats.sort(Comparator.comparingInt(Boat::getSourceID));
|
||||
// boats.sort(Comparator.comparingInt(Boat::getSourceID));
|
||||
|
||||
//Current draw order:
|
||||
// track points
|
||||
@@ -302,29 +302,29 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
// text
|
||||
|
||||
//Track points.
|
||||
for (VisualiserBoat boat : boats) {
|
||||
drawTrack(boat);
|
||||
if (isFullScreen){
|
||||
for (VisualiserBoat boat : boats) {
|
||||
drawTrack(boat);
|
||||
}
|
||||
|
||||
//Text.
|
||||
for (VisualiserBoat boat : boats) {
|
||||
drawBoatText(boat);
|
||||
}
|
||||
}
|
||||
|
||||
//Wake.
|
||||
for (VisualiserBoat boat : boats) {
|
||||
//Only draw wake if they are currently racing.
|
||||
if (boat.getStatus() == BoatStatusEnum.RACING) {
|
||||
drawWake(boat);
|
||||
}
|
||||
}
|
||||
// for (VisualiserBoat boat : boats) {
|
||||
// //Only draw wake if they are currently racing.
|
||||
// if (boat.getStatus() == BoatStatusEnum.RACING) {
|
||||
// drawWake(boat);
|
||||
// }
|
||||
// }
|
||||
|
||||
//Boat.
|
||||
for (VisualiserBoat boat : boats) {
|
||||
drawBoat(boat);
|
||||
}
|
||||
|
||||
//Text.
|
||||
for (VisualiserBoat boat : boats) {
|
||||
drawBoatText(boat);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,9 +364,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
gc.fillPolygon(x, y, x.length);
|
||||
gc.restore();
|
||||
|
||||
if (boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
|
||||
drawSails(boat);
|
||||
}
|
||||
// if (boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
|
||||
// drawSails(boat);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -605,7 +605,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
|
||||
//Prepare to draw.
|
||||
gc.setLineWidth(1);
|
||||
gc.setFill(Color.AQUA);
|
||||
gc.setFill(Color.DEEPSKYBLUE);
|
||||
|
||||
|
||||
//Calculate the screen coordinates of the boundary.
|
||||
@@ -645,19 +645,23 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
//Race boundary.
|
||||
drawBoundary();
|
||||
|
||||
//Guiding Line
|
||||
if (annoGuideLine){
|
||||
//rounding lines
|
||||
if (isFullScreen){
|
||||
drawRoundingLines();
|
||||
drawRaceLine();
|
||||
}
|
||||
|
||||
//Guiding Line
|
||||
// if (annoGuideLine){
|
||||
// drawRaceLine();
|
||||
// }
|
||||
|
||||
//Boats.
|
||||
drawBoats();
|
||||
|
||||
//Marks.
|
||||
drawMarks();
|
||||
|
||||
//TEMP
|
||||
drawRoundingLines();
|
||||
|
||||
}
|
||||
|
||||
@@ -752,7 +756,8 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
gc.save();
|
||||
|
||||
gc.setLineWidth(2);
|
||||
gc.setStroke(Color.MEDIUMAQUAMARINE);
|
||||
gc.setStroke(getLineColor(legs.get(index)));
|
||||
|
||||
|
||||
gc.beginPath();
|
||||
gc.moveTo(startPath.getX(), startPath.getY());
|
||||
@@ -772,7 +777,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
gc.save();
|
||||
|
||||
gc.setLineWidth(2);
|
||||
gc.setStroke(Color.MEDIUMAQUAMARINE);
|
||||
gc.setStroke(getLineColor(legs.get(index)));
|
||||
|
||||
gc.beginPath();
|
||||
gc.moveTo(startPath.getX(), startPath.getY());
|
||||
@@ -788,6 +793,21 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
}
|
||||
}
|
||||
|
||||
private Color getLineColor(Leg leg) {
|
||||
for (VisualiserBoat boat : raceState.getBoats()) {
|
||||
if (boat.isClientBoat()) {
|
||||
if (boat.getCurrentLeg() == leg) {
|
||||
return Color.ORANGE;
|
||||
} else {
|
||||
return Color.MEDIUMAQUAMARINE;
|
||||
}
|
||||
}else{
|
||||
return Color.MEDIUMAQUAMARINE;
|
||||
}
|
||||
}
|
||||
return Color.MEDIUMAQUAMARINE;
|
||||
}
|
||||
|
||||
private void drawArrowHead(GPSCoordinate start, GPSCoordinate end){
|
||||
|
||||
GraphCoordinate lineStart = this.map.convertGPS(start);
|
||||
@@ -862,6 +882,11 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
|
||||
}
|
||||
|
||||
public boolean isFullScreen() {
|
||||
return isFullScreen;
|
||||
}
|
||||
|
||||
|
||||
public void setFullScreen(boolean fullScreen) {
|
||||
isFullScreen = fullScreen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +137,9 @@ public class VisualiserBoat extends Boat {
|
||||
//Update the nextValidTime for the next track point.
|
||||
nextValidTime = currentTimeMilli + trackPointTimeInterval;
|
||||
|
||||
if (track.size() > trackPointLimit) {
|
||||
track.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import shared.dataInput.EmptyBoatDataSource;
|
||||
import shared.dataInput.EmptyRaceDataSource;
|
||||
import shared.dataInput.EmptyRegattaDataSource;
|
||||
import visualiser.gameController.ControllerClient;
|
||||
import visualiser.network.HttpMatchBrowserHost;
|
||||
import visualiser.network.ServerConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -115,5 +116,8 @@ public class VisualiserRaceEvent {
|
||||
this.visualiserRaceServiceThread.interrupt();
|
||||
this.serverConnectionThread.interrupt();
|
||||
serverConnection.terminate();
|
||||
if (HttpMatchBrowserHost.httpMatchBrowserHost != null) {
|
||||
HttpMatchBrowserHost.httpMatchBrowserHost.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class VisualiserRaceState extends RaceState {
|
||||
super.setRaceDataSource(raceDataSource);
|
||||
|
||||
if (getBoatDataSource() != null) {
|
||||
this.generateVisualiserBoats(this.boats, getBoatDataSource().getBoats(), raceDataSource.getParticipants(), unassignedColors);
|
||||
this.generateVisualiserBoats(this.boats, getBoatDataSource().getBoats(), getRaceDataSource().getParticipants(), unassignedColors);
|
||||
}
|
||||
|
||||
initialiseLegCompletionOrder();
|
||||
@@ -109,7 +109,7 @@ public class VisualiserRaceState extends RaceState {
|
||||
super.setBoatDataSource(boatDataSource);
|
||||
|
||||
if (getRaceDataSource() != null) {
|
||||
this.generateVisualiserBoats(this.boats, boatDataSource.getBoats(), getRaceDataSource().getParticipants(), unassignedColors);
|
||||
this.generateVisualiserBoats(this.boats, getBoatDataSource().getBoats(), getRaceDataSource().getParticipants(), unassignedColors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package visualiser.network;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import shared.utils.JsonReader;
|
||||
import visualiser.model.RaceConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 19/09/2017.
|
||||
*/
|
||||
public class HttpMatchBrowserClient extends Thread {
|
||||
public ObservableList<RaceConnection> connections = FXCollections.observableArrayList();
|
||||
|
||||
/**
|
||||
* Get all the matches that have been running in the past 5 seconds.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while(!Thread.interrupted()) {
|
||||
try {
|
||||
JSONArray cons = JsonReader.readJsonFromUrlArray("http://api.umbrasheep.com/seng/get_matches/");
|
||||
connections.clear();
|
||||
|
||||
for (int i = 0; i < cons.length(); i++) {
|
||||
JSONObject con = (JSONObject) cons.get(i);
|
||||
//using "ip_address" will give their public ip
|
||||
connections.add(new RaceConnection((String) con.get("local_ip"), con.getInt("port"), "Boat Game"));
|
||||
}
|
||||
|
||||
Thread.sleep(5000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package visualiser.network;
|
||||
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Creates an Http connection that hosts a game
|
||||
*/
|
||||
public class HttpMatchBrowserHost extends Thread {
|
||||
private HttpClient httpClient;
|
||||
private List<NameValuePair> params;
|
||||
|
||||
public static HttpMatchBrowserHost httpMatchBrowserHost = null;
|
||||
|
||||
/**
|
||||
* Constructor, this sends out the creation message of the race.
|
||||
* the thread should be run as soon as possible as the race is only valid for 5 seconds
|
||||
* until it requires a heartbeat from the start function.
|
||||
* @throws IOException if the hosting url is unreachable.
|
||||
*/
|
||||
public HttpMatchBrowserHost() throws IOException {
|
||||
httpMatchBrowserHost = this;
|
||||
httpClient = HttpClients.createDefault();
|
||||
|
||||
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||
boolean matches = false;
|
||||
String ip = "";
|
||||
Pattern ipPattern = Pattern.compile("192.168.1.*");
|
||||
while(e.hasMoreElements())
|
||||
{
|
||||
if (matches){
|
||||
break;
|
||||
}
|
||||
NetworkInterface n = (NetworkInterface) e.nextElement();
|
||||
Enumeration<InetAddress> ee = n.getInetAddresses();
|
||||
while (ee.hasMoreElements())
|
||||
{
|
||||
InetAddress i = ee.nextElement();
|
||||
matches = ipPattern.matcher(i.getHostAddress()).matches();
|
||||
if (matches){
|
||||
ip = i.getHostAddress();
|
||||
//System.out.println(ip);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Request parameters and other properties.
|
||||
params = new ArrayList<>(2);
|
||||
params.add(new BasicNameValuePair("ip", ip));
|
||||
params.add(new BasicNameValuePair("port", "4942"));
|
||||
params.add(new BasicNameValuePair("magic", "Thomas and Seng"));
|
||||
|
||||
sendHttp("http://api.umbrasheep.com/seng/registermatch/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a post to a server.
|
||||
* @param domain url of to send to
|
||||
* @throws IOException if the url is unreachable.
|
||||
*/
|
||||
public void sendHttp(String domain) throws IOException {
|
||||
HttpPost httppost = new HttpPost(domain);
|
||||
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||
|
||||
//Execute and get the response.
|
||||
HttpResponse response = httpClient.execute(httppost);
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
if (entity != null) {
|
||||
InputStream instream = entity.getContent();
|
||||
try {
|
||||
// do something useful
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
} else {
|
||||
throw new IOException("No Response from Host");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* THe host starts sending out heartbeat messages every 2 seconds.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while(!Thread.interrupted()){
|
||||
try {
|
||||
sendHttp("http://api.umbrasheep.com/seng/keep_match_alive/");
|
||||
Thread.sleep(2000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,9 @@ public class MatchBrowserInterface {
|
||||
|
||||
public MatchBrowserInterface() {
|
||||
try {//132.181.16.13 is the ip of the CI as of 13/9/17
|
||||
//this.IPAddress = InetAddress.getByName("132.181.16.13"); //InetAddress.getLocalHost();
|
||||
//this.IPAddress = InetAddress.getByName("umbrasheep.com"); //InetAddress.getLocalHost();
|
||||
this.IPAddress = InetAddress.getByName("132.181.16.13"); //InetAddress.getLocalHost();
|
||||
this.IPAddress = InetAddress.getByName("191.101.233.116"); //InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user