mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'develop' into issue47_disconnect_crash_rebranch
# Conflicts: # src/main/java/seng302/visualiser/GameClient.java # src/test/java/seng302/visualiser/ClientToServerTests/RegularPacketsTest.java
This commit is contained in:
@@ -21,7 +21,6 @@ import seng302.model.PolarTable;
|
|||||||
import seng302.model.ServerYacht;
|
import seng302.model.ServerYacht;
|
||||||
import seng302.model.mark.CompoundMark;
|
import seng302.model.mark.CompoundMark;
|
||||||
import seng302.utilities.GeoUtility;
|
import seng302.utilities.GeoUtility;
|
||||||
import seng302.visualiser.GameClient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class describing the overall server, which creates and collects server threads for each client
|
* A class describing the overall server, which creates and collects server threads for each client
|
||||||
@@ -48,8 +47,6 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
|
|||||||
private ServerSocket serverSocket = null;
|
private ServerSocket serverSocket = null;
|
||||||
private ArrayList<ServerToClientThread> serverToClientThreads = new ArrayList<>();
|
private ArrayList<ServerToClientThread> serverToClientThreads = new ArrayList<>();
|
||||||
|
|
||||||
private GameClient gameClient;
|
|
||||||
|
|
||||||
public MainServerThread() {
|
public MainServerThread() {
|
||||||
new GameState("localhost");
|
new GameState("localhost");
|
||||||
try {
|
try {
|
||||||
@@ -270,25 +267,17 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
|
|||||||
terminated = true;
|
terminated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pass GameClient to main server thread so it can access the properties inside.
|
|
||||||
*
|
|
||||||
* @param gameClient gameClient
|
|
||||||
*/
|
|
||||||
public void setGameClient(GameClient gameClient) {
|
|
||||||
this.gameClient = gameClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise boats to specific spaced out geopoints behind starting line.
|
* Initialise boats to specific spaced out geopoints behind starting line.
|
||||||
*/
|
*/
|
||||||
private void initialiseBoatPositions() {
|
private void initialiseBoatPositions() {
|
||||||
// Getting the start line compound marks
|
// Getting the start line compound marks
|
||||||
CompoundMark cm = gameClient.getCourseData().getCompoundMarks().get(1);
|
// if (gameClient== null) {
|
||||||
GeoPoint startMark1 = new GeoPoint(cm.getMarks().get(0).getLat(),
|
// return;
|
||||||
cm.getMarks().get(0).getLng());
|
// }
|
||||||
GeoPoint startMark2 = new GeoPoint(cm.getMarks().get(1).getLat(),
|
CompoundMark cm = GameState.getMarkOrder().getMarkOrder().get(0);
|
||||||
cm.getMarks().get(1).getLng());
|
GeoPoint startMark1 = cm.getSubMark(1);
|
||||||
|
GeoPoint startMark2 = cm.getSubMark(2);
|
||||||
|
|
||||||
// Calculating midpoint
|
// Calculating midpoint
|
||||||
Double perpendicularAngle = GeoUtility.getBearing(startMark1, startMark2);
|
Double perpendicularAngle = GeoUtility.getBearing(startMark1, startMark2);
|
||||||
|
|||||||
@@ -130,7 +130,6 @@ public class GameClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.lobbyController = lobbyController;
|
this.lobbyController = lobbyController;
|
||||||
server.setGameClient(this);
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
showConnectionError("Cannot connect to server as host");
|
showConnectionError("Cannot connect to server as host");
|
||||||
Platform.runLater(this::loadStartScreen);
|
Platform.runLater(this::loadStartScreen);
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package seng302.visualiser.ClientToServerTests;
|
package seng302.visualiser.ClientToServerTests;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import seng302.gameServer.GameStages;
|
||||||
|
import seng302.gameServer.GameState;
|
||||||
import seng302.gameServer.MainServerThread;
|
import seng302.gameServer.MainServerThread;
|
||||||
|
import seng302.gameServer.messages.BoatAction;
|
||||||
|
import seng302.model.ServerYacht;
|
||||||
import seng302.visualiser.ClientToServerThread;
|
import seng302.visualiser.ClientToServerThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,39 +22,44 @@ public class RegularPacketsTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
// new GameState("localhost");
|
new GameState("localhost");
|
||||||
// serverThread = new MainServerThread();
|
serverThread = new MainServerThread();
|
||||||
// clientThread = new ClientToServerThread("localhost", 4942);
|
clientThread = new ClientToServerThread("localhost", 4942);
|
||||||
// GameState.setCurrentStage(GameStages.RACING);
|
GameState.setCurrentStage(GameStages.RACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void packetsSentAtRegularIntervals () throws Exception {
|
public void packetsSentAtRegularIntervals() {
|
||||||
// final double TEST_DISTANCE = 10.0;
|
try {
|
||||||
// serverThread.startGame();
|
final double TEST_DISTANCE = 10.0;
|
||||||
// SleepThreadMaxDelay();
|
serverThread.startGame();
|
||||||
// ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
SleepThreadMaxDelay();
|
||||||
// double startAngle = yacht.getHeading();
|
ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
||||||
// long startTime = System.currentTimeMillis();
|
double startAngle = yacht.getHeading();
|
||||||
// clientThread.sendBoatActionMessage(BoatAction.UPWIND);
|
long startTime = System.currentTimeMillis();
|
||||||
// Thread.sleep(200);
|
clientThread.sendBoatAction(BoatAction.UPWIND); //start sending
|
||||||
// while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) {
|
Thread.sleep(200);
|
||||||
// Thread.sleep(1);
|
while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) {
|
||||||
// }
|
Thread.sleep(1);
|
||||||
// clientThread.sendBoatActionMessage(BoatAction.MAINTAIN_HEADING);
|
}
|
||||||
// long endTime = System.currentTimeMillis();
|
clientThread.sendBoatAction(BoatAction.MAINTAIN_HEADING); //stop sending
|
||||||
// SleepThreadMaxDelay();
|
long endTime = System.currentTimeMillis();
|
||||||
// //Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
|
SleepThreadMaxDelay();
|
||||||
// Assert.assertEquals(
|
//Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
|
||||||
// TEST_DISTANCE / ServerYacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
|
Assert.assertEquals(
|
||||||
// (endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
|
TEST_DISTANCE / ServerYacht.TURN_STEP
|
||||||
|
* ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
|
||||||
|
(endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Caught expected exception.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
// public void testArbitraryPacketSent() throws Exception {
|
// public void testArbitraryPacketSent() throws Exception {
|
||||||
// serverThread.startGame();
|
// serverThread.startGame();
|
||||||
// SleepThreadMaxDelay();
|
// SleepThreadMaxDelay();
|
||||||
// Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
// ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
||||||
// boolean startState = yacht.getSailIn();
|
// boolean startState = yacht.getSailIn();
|
||||||
// clientThread.sendBoatActionMessage(BoatAction.SAILS_IN);
|
// clientThread.sendBoatActionMessage(BoatAction.SAILS_IN);
|
||||||
// SleepThreadMaxDelay();
|
// SleepThreadMaxDelay();
|
||||||
@@ -61,15 +72,17 @@ public class RegularPacketsTest {
|
|||||||
* @throws Exception Thrown if thread crashes or something
|
* @throws Exception Thrown if thread crashes or something
|
||||||
*/
|
*/
|
||||||
private void SleepThreadMaxDelay() throws Exception {
|
private void SleepThreadMaxDelay() throws Exception {
|
||||||
Thread.sleep(200);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void teardown () throws Exception {
|
public void teardown() {
|
||||||
// clientThread.setSocketToClose();
|
try {
|
||||||
// serverThread.terminate();
|
clientThread.setSocketToClose();
|
||||||
// GameState.setCurrentStage(GameStages.LOBBYING);
|
serverThread.terminate();
|
||||||
// for (int i = 0; i<20; i++)
|
GameState.setCurrentStage(GameStages.LOBBYING);
|
||||||
// SleepThreadMaxDelay(); //Make sure socket is closed and toolkit remade.
|
} catch (Exception e) {
|
||||||
|
System.out.println("Caught expected exception.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user