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:
@@ -1,18 +1,15 @@
|
||||
package visualiser.gameController;
|
||||
|
||||
import mock.exceptions.CommandConstructionException;
|
||||
import mock.model.MockRace;
|
||||
import mock.model.commandFactory.Command;
|
||||
import mock.model.commandFactory.CommandFactory;
|
||||
import mock.model.commandFactory.CompositeCommand;
|
||||
import network.BinaryMessageDecoder;
|
||||
import network.Exceptions.InvalidMessageException;
|
||||
import network.MessageDecoders.BoatActionDecoder;
|
||||
import network.Messages.AC35Data;
|
||||
import network.Messages.BoatAction;
|
||||
import network.Messages.Enums.MessageType;
|
||||
import shared.model.RunnableWithFramePeriod;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -20,7 +17,7 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* Service for dispatching key press data to race from client
|
||||
*/
|
||||
public class ControllerServer implements Runnable {
|
||||
public class ControllerServer implements RunnableWithFramePeriod {
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,6 +30,11 @@ public class ControllerServer implements Runnable {
|
||||
* Collection of commands from client for race to execute.
|
||||
*/
|
||||
private CompositeCommand compositeCommand;
|
||||
|
||||
/**
|
||||
* The context for each command.
|
||||
*/
|
||||
private MockRace raceState;
|
||||
|
||||
/**
|
||||
* This is the source ID associated with the client.
|
||||
@@ -46,15 +48,18 @@ public class ControllerServer implements Runnable {
|
||||
* @param compositeCommand Commands for the race to execute.
|
||||
* @param inputQueue The queue of messages to read from.
|
||||
* @param clientSourceID The source ID of the client's boat.
|
||||
* @param raceState The context for each command.
|
||||
*/
|
||||
public ControllerServer(CompositeCommand compositeCommand, BlockingQueue<AC35Data> inputQueue, int clientSourceID) {
|
||||
public ControllerServer(CompositeCommand compositeCommand, BlockingQueue<AC35Data> inputQueue, int clientSourceID, MockRace raceState) {
|
||||
this.compositeCommand = compositeCommand;
|
||||
this.inputQueue = inputQueue;
|
||||
this.clientSourceID = clientSourceID;
|
||||
this.raceState = raceState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Wait for controller key input from client and loop.
|
||||
*/
|
||||
@@ -70,10 +75,17 @@ public class ControllerServer implements Runnable {
|
||||
|
||||
BoatAction boatAction = (BoatAction) message;
|
||||
|
||||
|
||||
boatAction.setSourceID(clientSourceID);
|
||||
|
||||
Command command = CommandFactory.createCommand(boatAction);
|
||||
compositeCommand.addCommand(command);
|
||||
try {
|
||||
Command command = CommandFactory.createCommand(raceState, boatAction);
|
||||
compositeCommand.addCommand(command);
|
||||
|
||||
} catch (CommandConstructionException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "ControllerServer could not create a Command for BoatAction: " + boatAction + ".", e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +93,7 @@ public class ControllerServer implements Runnable {
|
||||
Logger.getGlobal().log(Level.WARNING, "ControllerServer Interrupted while waiting for message on incoming message queue.", e);
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user