Merge branch 'master' into story_61
Also got client-server handshake working. Multiple clients can connect and control their own boat. The client's boat has a larger black triangle drawn around it. Probably needs tidying up. Added isClientBoat boolean to VisualiserBoat. WindGenerator is now an interface, implemented by ConstantWindGenerator (useful for testing) and RandomWindGenerator. Added ConstantWindGeneratorTest. RandomWindGenerator was formerly WindGenerator. The WindGenerator is passed in to MockRace. CommandFactory throws a CommandConstructionException if it cannot create a command. MessageSerialiser and MessageDeserialiser correctly terminate on error. Readded VisualiserInput's switch statement in the main loop, pending a refactor. Removed the sleep statement from LobbyController - it was blocking javaFX thread. Lobby.fxml: moved buttons and text input into grid panes, so they don't break when you resize screen. Added some test object creation functions in several test classes (MockRaceTest.createMockRace(), BoatXMLReaderTest.createBoatDataSource(), etc...). #story[1095]
This commit is contained in:
@@ -3,15 +3,12 @@ package network.StreamRelated;
|
||||
|
||||
import network.BinaryMessageDecoder;
|
||||
import network.Exceptions.InvalidMessageException;
|
||||
import network.MessageEncoders.RaceVisionByteEncoder;
|
||||
import network.Messages.AC35Data;
|
||||
import shared.model.RunnableWithFramePeriod;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -36,9 +33,11 @@ public class MessageDeserialiser implements RunnableWithFramePeriod {
|
||||
|
||||
|
||||
/**
|
||||
* Ack numbers used in messages.
|
||||
* Determines whether or not this runnable is currently running.
|
||||
*/
|
||||
private int ackNumber = 1;
|
||||
private boolean isRunning;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -52,16 +51,6 @@ public class MessageDeserialiser implements RunnableWithFramePeriod {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Increments the ackNumber value, and returns it.
|
||||
* @return Incremented ackNumber.
|
||||
*/
|
||||
private int getNextAckNumber(){
|
||||
this.ackNumber++;
|
||||
|
||||
return this.ackNumber;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -119,34 +108,35 @@ public class MessageDeserialiser implements RunnableWithFramePeriod {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether or not this runnable is running.
|
||||
* @return True means that it is still running, false means that it has stopped.
|
||||
*/
|
||||
public boolean isRunning() {
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
isRunning = true;
|
||||
|
||||
while (!Thread.interrupted()) {
|
||||
|
||||
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 16);
|
||||
previousFrameTime = currentFrameTime;
|
||||
|
||||
|
||||
//Reads the next message.
|
||||
try {
|
||||
AC35Data message = this.getNextMessage();
|
||||
messagesRead.add(message);
|
||||
}
|
||||
catch (InvalidMessageException | IOException e) {
|
||||
catch (InvalidMessageException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "Unable to read message on thread: " + Thread.currentThread() + ".", e);
|
||||
|
||||
Logger.getGlobal().log(Level.WARNING, "Unable to read message.", e);
|
||||
|
||||
try {
|
||||
inputStream.reset();
|
||||
} catch (IOException e1) {
|
||||
Logger.getGlobal().log(Level.WARNING, "Unable to reset inputStream.", e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Logger.getGlobal().log(Level.SEVERE, "Unable to read inputStream: " + inputStream + " on thread: " + Thread.currentThread() + ".", e);
|
||||
isRunning = false;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class MessageSerialiser implements RunnableWithFramePeriod {
|
||||
|
||||
isRunning = true;
|
||||
|
||||
while (isRunning) {
|
||||
while (!Thread.interrupted()) {
|
||||
|
||||
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
@@ -104,8 +104,9 @@ public class MessageSerialiser implements RunnableWithFramePeriod {
|
||||
Logger.getGlobal().log(Level.WARNING, "Could not encode message: " + message, e);
|
||||
|
||||
} catch (IOException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "Could not write message to outputStream: " + outputStream, e);
|
||||
Logger.getGlobal().log(Level.SEVERE, "Could not write message to outputStream: " + outputStream + " on thread: " + Thread.currentThread(), e);
|
||||
isRunning = false;
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user