Created FrameRateTracker which can be used to track framerate. Updated RequestToJoinEnum and JoinAcceptanceEnum to match the agreed connection API. Added AssignPlayerBoat message, which is used internally on the client to assign the player a source ID once they have connected. Fixed some race conditions in the MessageRouter. Updated ConnectionAcceptor.CheckClientConnection to wait slightly longer before removing connection (there was a slight race condition before). Race no longer has a reference to LatestMessages. LatestMessages no longer has specific messages types in it. Created RaceState class, which contains the state that is shared between VisualiserRaceState and MockRaceState (currently only used on visualiser). Split VisualiserRace into VisualiserRaceState and VisualiserRaceService. Added the VisualiserRace commands (BoatLocatonCommand, RaceStatusCommand, etc...). Slightly increased the preferred width of race.fxml table columns. issues #27 #37 #35 #story[1095]
80 lines
2.4 KiB
Java
80 lines
2.4 KiB
Java
package visualiser.model;
|
|
|
|
import mock.exceptions.CommandConstructionException;
|
|
import mock.model.commandFactory.Command;
|
|
import mock.model.commandFactory.CompositeCommand;
|
|
import network.Messages.*;
|
|
import shared.model.RunnableWithFramePeriod;
|
|
import visualiser.Commands.VisualiserRaceCommands.VisualiserRaceCommandFactory;
|
|
|
|
import java.util.concurrent.BlockingQueue;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
* The controller for race related messages, coming from the server to the client.
|
|
*/
|
|
public class VisualiserRaceController implements RunnableWithFramePeriod {
|
|
|
|
|
|
/**
|
|
* Incoming messages from server.
|
|
*/
|
|
private BlockingQueue<AC35Data> incomingMessages;
|
|
|
|
|
|
/**
|
|
* Commands are placed in here, and executed by visualiserRace.
|
|
*/
|
|
private CompositeCommand compositeRaceCommand;
|
|
|
|
|
|
/**
|
|
* The context that created commands operate on.
|
|
*/
|
|
private VisualiserRaceState visualiserRace;
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Constructs a visualiserInput to convert an incoming stream of messages into commands.
|
|
* @param incomingMessages The incoming queue of messages.
|
|
* @param visualiserRace The context to for commands to operate on.
|
|
* @param compositeRaceCommand The composite command to place command in.
|
|
*/
|
|
public VisualiserRaceController(BlockingQueue<AC35Data> incomingMessages, VisualiserRaceState visualiserRace, CompositeCommand compositeRaceCommand) {
|
|
this.incomingMessages = incomingMessages;
|
|
this.compositeRaceCommand = compositeRaceCommand;
|
|
this.visualiserRace = visualiserRace;
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
public void run() {
|
|
|
|
while (!Thread.interrupted()) {
|
|
|
|
try {
|
|
AC35Data message = incomingMessages.take();
|
|
|
|
Command command = VisualiserRaceCommandFactory.create(message, visualiserRace);
|
|
compositeRaceCommand.addCommand(command);
|
|
|
|
} catch (CommandConstructionException e) {
|
|
Logger.getGlobal().log(Level.WARNING, "VisualiserRaceController could not create a command for incoming message.");
|
|
|
|
} catch (InterruptedException e) {
|
|
Logger.getGlobal().log(Level.SEVERE, "VisualiserRaceController was interrupted on thread: " + Thread.currentThread() + " while waiting for messages.");
|
|
Thread.currentThread().interrupt();
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|