Added LatestMessages to network.Messages. This is an object that encapsulates the latest up to date set of race messages.

Race stores a reference to it. MockRace writes to it, and eventually, VisualiserRace will read from it.
Updated MockRace, MockOutput, Event to use it.

Angle now implements hashCode().
This commit is contained in:
fjc40
2017-07-06 16:02:11 +12:00
parent 3a0b81834f
commit 8e18ad62ca
9 changed files with 361 additions and 109 deletions
@@ -2,8 +2,10 @@ package mock.model;
import javafx.animation.AnimationTimer;
import mock.app.MockOutput;
import network.Messages.BoatLocation;
import network.Messages.BoatStatus;
import network.Messages.Enums.BoatStatusEnum;
import network.Messages.LatestMessages;
import network.Messages.RaceStatus;
import network.Utils.AC35UnitConverter;
import shared.dataInput.BoatDataSource;
@@ -52,12 +54,6 @@ public class MockRace extends Race {
private int dnfChance = 0;
/**
* The mockOutput to send messages to.
*/
private MockOutput mockOutput;
/**
* Used to generate random numbers when changing the wind direction.
@@ -88,13 +84,12 @@ public class MockRace extends Race {
* @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 polars The polars table to be used for boat simulation.
* @param mockOutput The mockOutput to send events to.
* @param latestMessages The LatestMessages to send events to.
*/
public MockRace(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, Polars polars, MockOutput mockOutput) {
public MockRace(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, Polars polars, LatestMessages latestMessages) {
super(boatDataSource, raceDataSource, regattaDataSource);
super(boatDataSource, raceDataSource, regattaDataSource, latestMessages);
this.mockOutput = mockOutput;
this.boats = this.generateMockBoats(boatDataSource.getBoats(), raceDataSource.getParticipants(), polars);
@@ -175,14 +170,20 @@ public class MockRace extends Race {
*/
private void parseIndividualMark(Mark mark) {
this.mockOutput.parseBoatLocation(
//Create message.
BoatLocation boatLocation = new BoatLocation(
mark.getSourceID(),
mark.getPosition().getLatitude(),
mark.getPosition().getLongitude(),
0,
0,
this.totalTimeElapsed + this.startTime
);
boatLocationSequenceNumber,
0, 0,
totalTimeElapsed + startTime);
//Iterates the sequence number.
boatLocationSequenceNumber++;
this.latestMessages.setBoatLocation(boatLocation);
}
@@ -206,14 +207,19 @@ public class MockRace extends Race {
*/
private void parseIndividualBoatLocation(MockBoat boat) {
this.mockOutput.parseBoatLocation(
BoatLocation boatLocation = new BoatLocation(
boat.getSourceID(),
boat.getCurrentPosition().getLatitude(),
boat.getCurrentPosition().getLongitude(),
boatLocationSequenceNumber,
boat.getBearing().degrees(),
boat.getCurrentSpeed(),
startTime + totalTimeElapsed
);
startTime + totalTimeElapsed);
//Iterates the sequence number.
boatLocationSequenceNumber++;
this.latestMessages.setBoatLocation(boatLocation);
}
@@ -272,7 +278,6 @@ public class MockRace extends Race {
boatStatuses.add(boatStatus);
}
//TODO REFACTOR for consistency, could send parameters to mockOutput instead of the whole racestatus. This will also fix the sequence number issue.
//Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class.
int windDirectionInt = AC35UnitConverter.encodeHeading(this.windDirection.degrees());
@@ -283,12 +288,14 @@ public class MockRace extends Race {
System.currentTimeMillis(),
this.raceId,
this.getRaceStatusEnum().getValue(),
this.startTime, windDirectionInt,
this.startTime,
windDirectionInt,
windSpeedInt,
this.getRaceType().getValue(),
boatStatuses );
boatStatuses);
mockOutput.parseRaceStatus(raceStatus);
this.latestMessages.setRaceStatus(raceStatus);
}
@@ -427,7 +434,6 @@ public class MockRace extends Race {
parseRaceStatus();
if (iters > 500) {
mockOutput.stop();
stop();
}
iters++;