Merge branch 'develop' into 1276_Next_Mark_Indicator

This commit is contained in:
alistairjmcintyre
2017-09-28 02:06:18 +13:00
19 changed files with 457 additions and 407 deletions
@@ -1,5 +1,6 @@
package seng302.visualiser;
import javafx.application.Platform;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,7 +14,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
@@ -45,6 +51,8 @@ import seng302.visualiser.controllers.ViewManager;
*/
public class ClientToServerThread implements Runnable {
private boolean isStarted = false;
/**
* Functional interface for receiving packets from client socket.
*/
@@ -120,6 +128,8 @@ public class ClientToServerThread implements Runnable {
* variable is false.
*/
public void run() {
isStarted = true;
int sync1;
int sync2;
// TODO: 14/07/17 wmu16 - Work out how to fix this while loop
@@ -170,8 +180,10 @@ public class ClientToServerThread implements Runnable {
notifyDisconnectListeners("Connection to server was terminated");
closeSocket();
ViewManager.getInstance().goToStartView();
ViewManager.getInstance().showErrorSnackBar("Server rejected connection.");
Platform.runLater(() -> {
ViewManager.getInstance().showErrorSnackBar("Server rejected connection.");
ViewManager.getInstance().goToStartView();
});
}
public void sendCustomizationRequest(CustomizeRequestType reqType, byte[] payload) {
@@ -197,12 +209,6 @@ public class ClientToServerThread implements Runnable {
if (connectionErrorListener != null){
connectionErrorListener.notifyConnectionError(message);
}
try {
this.socket.close();
} catch (IOException e) {
logger.error("Couldn't close socket");
}
}
/**
@@ -393,9 +399,9 @@ public class ClientToServerThread implements Runnable {
}
if (currentByte == -1) {
notifyDisconnectListeners("Cannot read from server.");
closeSocket();
logger.warn("InputStream reach end of stream", 1);
handleConnectionError("Could not connect to server. Server is no longer available.");
closeSocket();
}
return currentByte;
}
@@ -438,4 +444,8 @@ public class ClientToServerThread implements Runnable {
).getBuffer()
);
}
public boolean hasStarted() {
return isStarted;
}
}
@@ -119,7 +119,7 @@ public class GameClient {
getServerThread().setConnectionErrorListener((eMessage) -> {
ViewManager.getInstance().showErrorSnackBar(eMessage);
destroyClientToServerThread();
//destroyClientToServerThread();
});
this.lobbyController = ViewManager.getInstance().goToLobby(true);
@@ -147,18 +147,45 @@ public class GameClient {
server = new MainServerThread();
while (!server.hasStarted()){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
try {
startClientToServerThread(ipAddress, 4942);
} catch (IOException e) {
showConnectionError("Cannot connect to server as host");
}
// Wait for C2S thread
while (!socketThread.hasStarted()){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
socketThread.sendXML(race, serverName, numLegs, maxPlayers, tokensEnabled);
while (regattaData == null){
int triesLeft = 15;
while (regattaData == null && triesLeft > 0){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
triesLeft--;
}
if (triesLeft <= 0){
showConnectionError("Could not launch server");
return null;
}
this.lobbyController = ViewManager.getInstance().goToLobby(false);
@@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import javafx.animation.RotateTransition;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.property.ReadOnlyBooleanProperty;
@@ -43,6 +44,7 @@ import javafx.scene.shape.Polyline;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import seng302.model.ClientYacht;
import seng302.model.RaceState;
import seng302.model.mark.CompoundMark;
@@ -140,6 +142,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private Timer blinkingTimer = new Timer();
private ImageView iconToDisplay;
private Double lastWindDirection;
public void initialize() {
contentStackPane.setVisible(false);
Image loadingImage = new Image("PP.png");
@@ -188,6 +192,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
chatHistory.decreaseOpacity();
}
});
lastWindDirection = 0d;
}
public void showFinishDialog(ArrayList<ClientYacht> finishedBoats) {
@@ -435,7 +441,13 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
*/
private void updateWindDirection(double direction) {
windDirectionLabel.setText(String.format("%.1f°", direction));
windImageView.setRotate(direction);
RotateTransition rt = new RotateTransition(Duration.millis(300), windImageView);
rt.setByAngle(direction - lastWindDirection);
rt.setCycleCount(3);
rt.setAutoReverse(true);
rt.play();
lastWindDirection = direction;
// windImageView.setRotate(direction);
}
/**
@@ -119,6 +119,12 @@ public class ServerCreationController implements Initializable {
.runAsHost("localhost", 4941, serverName.getText(), (int) maxPlayersSlider
.getValue(), mapMaker.getCurrentRacePath(), (int) legsSlider.getValue(), pickupsCheckBox.isSelected());
if (serverDescription == null){
ViewManager.getInstance().getGameClient().getServerThread().closeSocket();
ViewManager.getInstance().getGameClient().stopGame();
return;
}
ViewManager.getInstance().setProperty("serverName", serverDescription.getName());
ViewManager.getInstance().setProperty("mapName", serverDescription.getMapName());
}
@@ -12,7 +12,8 @@ public enum BoatMeshType {
0.997, null, false, 1.0, 1.4, 2.0),
PIRATE_SHIP("pirateship_hull.stl", "pirateship_mast.stl", -0.5415, "pirateship_mainsail.stl",
-0.5415, "pirateship_frontsail.stl", true, 1.2, 1.6, 1.2),
DUCKY("ducky_hull.stl", "ducky_mast.stl", -2.18539, "ducky_sail.stl", -2.18539, "ducky_eyes.stl", false, 1.2, 1.1, 1.4);
DUCKY("ducky_hull.stl", "ducky_mast.stl", -2.18539, "ducky_sail.stl", -2.18539, "ducky_eyes.stl", false, 1.2, 1.1, 1.4),
PARROT("parrot_hull.stl", null, 0, "parrot_sail.stl", 0, "parrot_features.stl", true, 1, 1, 1);
final String hullFile, mastFile, sailFile, jibFile;
final double mastOffset, sailOffset;
@@ -20,7 +21,7 @@ public enum BoatMeshType {
public final double accelerationMultiplier;
public final double turnStep;
final boolean fixedSail;
final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CATAMARAN, PIRATE_SHIP, DUCKY};
final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CATAMARAN, PIRATE_SHIP, DUCKY, PARROT};
BoatMeshType(String hullFile, String mastFile, double mastOffset, String sailFile,
double sailOffset, String jibFile, boolean fixedSail, double maxSpeedMultiplier, double accelerationMultiplier, double turnStep) {
@@ -35,6 +35,8 @@ public class BoatObject extends Group {
private Color colour = Color.BLACK;
private Boolean isSelected = false;
private Rotate rotation = new Rotate(0, new Point3D(0,0,1));
// private Rotate tilt = new Rotate(0, new Point3D(0, 1, 0));
private double previousRotation = 0;
// This stuff only matters to the players boat object.
private Group markIndicator;
@@ -119,6 +121,14 @@ public class BoatObject extends Group {
private void rotateTo(double heading, boolean sailsIn, double windDir) {
rotationProperty.set(heading);
rotation.setAngle(heading);
// if (heading == previousRotation) {
// tilt.setAngle(0);
// } else if (heading < previousRotation) {
// tilt.setAngle(-10);
// } else {
// tilt.setAngle(10);
// }
// previousRotation = heading;
wake.getTransforms().setAll(new Rotate(heading, new Point3D(0,0,1)));
if (sailsIn) {
boatAssets.showSail();
@@ -117,17 +117,25 @@ public class ModelFactory {
Group boatAssets = new Group();
MeshView hull = importSTL(boatType.hullFile);
hull.setMaterial(new PhongMaterial(primaryColour));
MeshView mast = importSTL(boatType.mastFile);
mast.setMaterial(new PhongMaterial(primaryColour));
MeshView sail = importSTL(boatType.sailFile);
sail.setMaterial(new PhongMaterial(Color.WHITE));
sail.setMaterial(
new PhongMaterial(boatType == BoatMeshType.PARROT ? Color.BLACK : Color.WHITE)
);
boatAssets.getChildren().addAll(hull, sail);
if (boatType.mastFile != null) {
MeshView mast = importSTL(boatType.mastFile);
mast.setMaterial(new PhongMaterial(primaryColour));
boatAssets.getChildren().add(mast);
}
if (boatType.jibFile != null) {
MeshView jib = importSTL(boatType.jibFile);
sail.setMaterial(new PhongMaterial(Color.WHITE));
boatAssets.getChildren().addAll(hull, mast, sail, jib);
} else {
boatAssets.getChildren().addAll(hull, mast, sail);
sail.setMaterial(
new PhongMaterial(boatType == BoatMeshType.PARROT ? Color.DARKGRAY : Color.WHITE)
);
boatAssets.getChildren().add(jib);
}
return boatAssets;