Refactored Race, MockRace, and VisualiserRace to use RaceClock instead of keeping their own timers.
Moved FPS tracking to Race class, so both VisualiserRace and MockRace can monitor their FPS. LatestMessages is now observable. It notifies observers when an XMLMessage is received. Boat now has StringProperty for name and country/abbreviation. Moved the MockRace timescale value to Constants.RaceTimeScale. This is passed in to MockRace on construction. Tidied up StartController. Copied the visualiser's resources into the resources folder. Refactored RaceClock. Added comments. Tidied code a bit. Moved to shared.model. Started work on RaceController.
This commit is contained in:
@@ -15,9 +15,7 @@ import shared.dataInput.BoatDataSource;
|
||||
import shared.dataInput.RaceDataSource;
|
||||
import shared.dataInput.RegattaDataSource;
|
||||
import shared.model.*;
|
||||
import visualiser.Controllers.FinishController;
|
||||
import visualiser.Controllers.RaceController;
|
||||
import visualiser.app.VisualiserInput;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -41,10 +39,6 @@ public class VisualiserRace extends Race {
|
||||
*/
|
||||
private ObservableList<Mark> boatMarkers;
|
||||
|
||||
//TODO remove these controller references once refactored
|
||||
private RaceController controller;
|
||||
protected FinishController finishController;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -52,10 +46,10 @@ public class VisualiserRace extends Race {
|
||||
* @param boatDataSource Data source for boat related data (yachts and marker boats).
|
||||
* @param raceDataSource Data source for race related data (participating boats, legs, etc...).
|
||||
* @param regattaDataSource Data source for race related data (course name, location, timezone, etc...).
|
||||
* @param colors A collection of colors used to assign a color to each boat.
|
||||
* @param latestMessages The LatestMessages to send events to.
|
||||
* @param colors A collection of colors used to assign a color to each boat.
|
||||
*/
|
||||
public VisualiserRace(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, List<Color> colors, LatestMessages latestMessages, RaceController controller) {
|
||||
public VisualiserRace(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages, List<Color> colors) {
|
||||
|
||||
super(boatDataSource, raceDataSource, regattaDataSource, latestMessages);
|
||||
|
||||
@@ -64,9 +58,6 @@ public class VisualiserRace extends Race {
|
||||
|
||||
this.boatMarkers = FXCollections.observableArrayList(boatDataSource.getMarkerBoats().values());
|
||||
|
||||
|
||||
this.controller = controller;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +139,7 @@ public class VisualiserRace extends Race {
|
||||
for (VisualiserBoat boat : boats) {
|
||||
|
||||
boat.setCurrentLeg(startingLeg);
|
||||
boat.setTimeSinceLastMark(controller.getRaceClock().getTime());
|
||||
boat.setTimeSinceLastMark(this.raceClock.getCurrentTime());
|
||||
|
||||
}
|
||||
|
||||
@@ -209,7 +200,7 @@ public class VisualiserRace extends Race {
|
||||
if (legNumber >= 1 && legNumber < legs.size()) {
|
||||
if (boat.getCurrentLeg() != legs.get(legNumber)) {
|
||||
boat.setCurrentLeg(legs.get(legNumber));
|
||||
boat.setTimeSinceLastMark(controller.getRaceClock().getTime());
|
||||
boat.setTimeSinceLastMark(this.raceClock.getCurrentTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,54 +270,41 @@ public class VisualiserRace extends Race {
|
||||
//Wind speed.
|
||||
this.windSpeed = raceStatus.getWindSpeedKnots();
|
||||
|
||||
//Current race time.
|
||||
this.raceClock.setUTCTime(raceStatus.getCurrentTime());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setController(RaceController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runnable for the thread.
|
||||
*/
|
||||
public void run() {
|
||||
setControllerListeners();
|
||||
Platform.runLater(() -> controller.createSparkLine(boats));
|
||||
initialiseBoats();
|
||||
startRaceStream();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the calculated fps to the fps label
|
||||
*
|
||||
* @param fps The new calculated fps value
|
||||
*/
|
||||
private void updateFPS(int fps) {
|
||||
Platform.runLater(() -> controller.setFrames("FPS: " + fps));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts the Race Simulation, playing the race start to finish with the timescale.
|
||||
* This prints the boats participating, the order that the events occur in time order, and the respective information of the events.
|
||||
* Starts the race.
|
||||
* This updates the race based on {@link #latestMessages}.
|
||||
*/
|
||||
private void startRaceStream() {
|
||||
|
||||
System.setProperty("javafx.animation.fullspeed", "true");
|
||||
|
||||
|
||||
|
||||
new AnimationTimer() {
|
||||
|
||||
final long timeRaceStarted = System.currentTimeMillis(); //start time of loop
|
||||
//final long timeRaceStarted = System.currentTimeMillis(); //start time of loop
|
||||
int fps = 0; //init fps value
|
||||
long timeCurrent = System.currentTimeMillis(); //current time
|
||||
//long timeCurrent = System.currentTimeMillis(); //current time
|
||||
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
|
||||
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
||||
//totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
||||
|
||||
|
||||
|
||||
@@ -343,22 +321,11 @@ public class VisualiserRace extends Race {
|
||||
updateRaceStatus(latestMessages.getRaceStatus());
|
||||
|
||||
|
||||
//TODO tidy this circular dependency up
|
||||
if (getRaceStatusEnum() == RaceStatusEnum.FINISHED) {
|
||||
controller.finishRace(boats);
|
||||
stop();
|
||||
}
|
||||
|
||||
controller.updateMap(boats, boatMarkers);
|
||||
|
||||
fps++;
|
||||
|
||||
if ((System.currentTimeMillis() - timeCurrent) > 1000) {
|
||||
updateFPS(fps);
|
||||
lastFPS = fps;
|
||||
fps = 0;
|
||||
timeCurrent = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
@@ -400,12 +367,7 @@ public class VisualiserRace extends Race {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update call for the controller.
|
||||
*/
|
||||
private void setControllerListeners() {
|
||||
if (controller != null) controller.setInfoTable(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the boats participating in the race.
|
||||
|
||||
Reference in New Issue
Block a user