Added empty data sources, to be used by VisualiserRace.
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]
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package visualiser.model;
|
||||
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import mock.model.commandFactory.CompositeCommand;
|
||||
import shared.model.FrameRateTracker;
|
||||
import shared.model.RunnableWithFramePeriod;
|
||||
|
||||
|
||||
/**
|
||||
* Handles updating a {@link VisualiserRaceState} with incoming commands.
|
||||
*/
|
||||
public class VisualiserRaceService implements RunnableWithFramePeriod {
|
||||
|
||||
|
||||
/**
|
||||
* The race state to update.
|
||||
*/
|
||||
private VisualiserRaceState visualiserRaceState;
|
||||
|
||||
|
||||
/**
|
||||
* A composite commands to execute to update the race.
|
||||
*/
|
||||
private CompositeCommand raceCommands;
|
||||
|
||||
|
||||
/**
|
||||
* Used to track the framerate of the "simulation".
|
||||
*/
|
||||
private FrameRateTracker frameRateTracker;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a visualiser race which models a yacht race, and is modified by CompositeCommand.
|
||||
* @param raceCommands A composite commands to execute to update the race.
|
||||
* @param visualiserRaceState The race state to update.
|
||||
*/
|
||||
public VisualiserRaceService(CompositeCommand raceCommands, VisualiserRaceState visualiserRaceState) {
|
||||
this.raceCommands = raceCommands;
|
||||
this.visualiserRaceState = visualiserRaceState;
|
||||
|
||||
this.frameRateTracker = new FrameRateTracker();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the CompositeCommand executed by the race.
|
||||
* @return CompositeCommand executed by race.
|
||||
*/
|
||||
public CompositeCommand getRaceCommands() {
|
||||
return raceCommands;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
|
||||
while (!Thread.interrupted()) {
|
||||
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
|
||||
waitForFramePeriod(previousFrameTime, currentFrameTime, 16);
|
||||
|
||||
previousFrameTime = currentFrameTime;
|
||||
|
||||
|
||||
raceCommands.execute();
|
||||
|
||||
}
|
||||
|
||||
frameRateTracker.stop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the framerate property of the race.
|
||||
* @return Framerate property of race.
|
||||
*/
|
||||
public IntegerProperty getFrameRateProperty() {
|
||||
return frameRateTracker.fpsProperty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user