Finish screen now displays correctly on finishing.

GameState update now checks for finishing the race
Can now go back to main menu from finish screen
Labeled all threads for better debugging
Still need to implement race list ordering and finish screen ordering
This commit is contained in:
William Muir
2017-08-16 13:04:34 +12:00
parent 76a750a764
commit bf016356a6
5 changed files with 26 additions and 20 deletions
@@ -89,7 +89,7 @@ public class GameState implements Runnable {
markOrder = new MarkOrder(); //This could be instantiated at some point with a select map?
markListeners = new ArrayList<>();
new Thread(this).start(); //Run the auto updates on the game state
new Thread(this, "GameState").start(); //Run the auto updates on the game state
marks = new MarkOrder().getAllMarks();
}
@@ -184,7 +184,7 @@ public class GameState implements Runnable {
@Override
public void run() {
while (true) {
while (currentStage != GameStages.FINISHED) {
try {
Thread.sleep(1000 / STATE_UPDATES_PER_SECOND);
} catch (InterruptedException e) {
@@ -229,17 +229,24 @@ public class GameState implements Runnable {
* Called periodically in this GameState thread to update the GameState values
*/
public void update() {
Boolean raceFinished = true;
Double timeInterval = (System.currentTimeMillis() - previousUpdateTime) / 1000000.0;
previousUpdateTime = System.currentTimeMillis();
for (ServerYacht yacht : yachts.values()) {
updateVelocity(yacht);
yacht.runAutoPilot();
yacht.updateLocation(timeInterval);
if (!yacht.getFinishedRace()) {
if (yacht.getBoatStatus() != BoatStatus.FINISHED) {
checkForCollision(yacht);
checkForLegProgression(yacht);
raceFinished = false;
}
}
if (raceFinished) {
currentStage = GameStages.FINISHED;
}
}
@@ -283,7 +290,7 @@ public class GameState implements Runnable {
Double velocity = yacht.getCurrentVelocity();
Double trueWindAngle = Math.abs(windDirection - yacht.getHeading());
Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle);
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots) * 3;
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots);
// TODO: 15/08/17 remove magic numbers from these equations.
if (yacht.getSailIn()) {
if (velocity < maxBoatSpeed - 500) {
@@ -345,6 +352,7 @@ public class GameState implements Runnable {
private void checkForLegProgression(ServerYacht yacht) {
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
// System.out.println(yacht.getCurrentMarkSeqID());
Boolean hasProgressed;
if (currentMarkSeqID == 0) {
@@ -493,7 +501,6 @@ public class GameState implements Runnable {
Boolean isClockwiseCross = GeoUtility.isClockwise(mark1, mark2, prevMark.getMidPoint());
if (crossedLine == 1 && isClockwiseCross || crossedLine == 2 && !isClockwiseCross) {
yacht.setClosestCurrentMark(mark1);
yacht.setIsFinished(true);
yacht.setBoatStatus(BoatStatus.FINISHED);
return true;
}
@@ -1,5 +1,6 @@
package seng302.gameServer;
import gherkin.lexer.Fi;
import java.io.IOException;
import java.net.ServerSocket;
import java.time.LocalDateTime;
@@ -48,7 +49,7 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
GameState.addMarkPassListener(this::broadcastMessage);
terminated = false;
thread = new Thread(this);
thread = new Thread(this, "MainServer");
thread.start();
}
@@ -82,7 +83,7 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
//FINISHED
else if (GameState.getCurrentStage() == GameStages.FINISHED) {
terminate();
}
}
@@ -88,7 +88,7 @@ public class ServerToClientThread implements Runnable, Observer {
return;
}
thread = new Thread(this);
thread = new Thread(this, "ServerToClient");
thread.start();
}