Merge branch 'master' into new_issue#19
This commit is contained in:
@@ -2,6 +2,8 @@ package shared.model;
|
||||
|
||||
|
||||
import javafx.beans.property.*;
|
||||
import mock.model.collider.Collider;
|
||||
import mock.model.collider.Collision;
|
||||
import network.Messages.Enums.BoatStatusEnum;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -10,7 +12,7 @@ import java.time.ZonedDateTime;
|
||||
/**
|
||||
* Boat Model that is used to store information on the boats that are running in the race.
|
||||
*/
|
||||
public class Boat {
|
||||
public class Boat extends Collider {
|
||||
/**
|
||||
* The name of the boat/team.
|
||||
*/
|
||||
@@ -30,7 +32,7 @@ public class Boat {
|
||||
/**
|
||||
* The current position of the boat.
|
||||
*/
|
||||
private GPSCoordinate currentPosition;
|
||||
private GPSCoordinate position;
|
||||
|
||||
/**
|
||||
* The country or team abbreviation of the boat.
|
||||
@@ -57,7 +59,7 @@ public class Boat {
|
||||
/**
|
||||
* The boat's position within the race (e.g., 5th).
|
||||
*/
|
||||
private StringProperty positionInRace = new SimpleStringProperty();
|
||||
private StringProperty placing = new SimpleStringProperty();
|
||||
|
||||
|
||||
/**
|
||||
@@ -107,7 +109,7 @@ public class Boat {
|
||||
|
||||
this.bearing = Bearing.fromDegrees(0d);
|
||||
|
||||
setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
setPosition(new GPSCoordinate(0, 0));
|
||||
|
||||
this.status = BoatStatusEnum.UNDEFINED;
|
||||
}
|
||||
@@ -256,41 +258,32 @@ public class Boat {
|
||||
* Returns the position within the race the boat has (e.g., 5th).
|
||||
* @return The boat's position in race.
|
||||
*/
|
||||
public StringProperty positionProperty() {
|
||||
return positionInRace;
|
||||
public StringProperty placingProperty() {
|
||||
return placing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position within the race the boat has (e.g., 5th).
|
||||
* @param position The boat's position in race.
|
||||
*/
|
||||
public void setPosition(String position) {
|
||||
this.positionInRace.set(position);
|
||||
public void setPlacing(String position) {
|
||||
this.placing.set(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position within the race the boat has (e.g., 5th).
|
||||
* @return The boat's position in race.
|
||||
*/
|
||||
public String getPosition() {
|
||||
return this.positionInRace.get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current position of the boat.
|
||||
* @return The current position of the boat.
|
||||
*/
|
||||
public GPSCoordinate getCurrentPosition() {
|
||||
return currentPosition;
|
||||
public GPSCoordinate getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current position of the boat.
|
||||
* @param currentPosition The new position for the boat.
|
||||
* @param position The new position for the boat.
|
||||
*/
|
||||
public void setCurrentPosition(GPSCoordinate currentPosition) {
|
||||
this.currentPosition = currentPosition;
|
||||
public void setPosition(GPSCoordinate position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
|
||||
@@ -399,4 +392,22 @@ public class Boat {
|
||||
this.timeAtLastMark = timeAtLastMark;
|
||||
}
|
||||
|
||||
public void bounce(double repulsionRadius) {
|
||||
Azimuth reverseAzimuth = Azimuth.fromDegrees(getBearing().degrees() - 180d);
|
||||
setPosition(GPSCoordinate.calculateNewPosition(getPosition(), 2 * repulsionRadius, reverseAzimuth));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rayCast(Boat boat) {
|
||||
if(boat != this) {
|
||||
return rayCast(boat, 100);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCollisionEnter(Boat collider, Collision e) {
|
||||
if(e.getBearing().degrees() > 270 || e.getBearing().degrees() < 90) {
|
||||
collider.bounce(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package shared.model;
|
||||
|
||||
|
||||
import shared.enums.RoundingType;
|
||||
|
||||
/**
|
||||
@@ -117,7 +116,7 @@ public class CompoundMark {
|
||||
* @return The position of the second mark in the compound mark.
|
||||
*/
|
||||
public GPSCoordinate getMark2Position() {
|
||||
return mark2.getPosition();
|
||||
return mark2 == null? mark1.getPosition() : mark2.getPosition();
|
||||
}
|
||||
|
||||
|
||||
@@ -135,13 +134,6 @@ public class CompoundMark {
|
||||
* @return The average coordinate of the compound mark.
|
||||
*/
|
||||
private GPSCoordinate calculateAverage() {
|
||||
|
||||
//If the compound mark only contains one mark, the average is simply the first mark's position.
|
||||
if (this.mark2 == null) {
|
||||
return this.getMark1Position();
|
||||
}
|
||||
|
||||
|
||||
//Otherwise, calculate the average of both marks.
|
||||
GPSCoordinate averageCoordinate = GPSCoordinate.calculateAverageCoordinate(this.getMark1Position(), this.getMark2Position());
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package shared.model;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 16/08/17.
|
||||
*/
|
||||
public interface Locatable {
|
||||
GPSCoordinate getPosition();
|
||||
void setPosition(GPSCoordinate position);
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package shared.model;
|
||||
|
||||
import mock.model.collider.Collider;
|
||||
import mock.model.collider.Collision;
|
||||
|
||||
/**
|
||||
* Represents an individual mark.
|
||||
* Has a source ID, name, and position.
|
||||
*/
|
||||
public class Mark {
|
||||
public class Mark extends Collider {
|
||||
|
||||
/**
|
||||
* The source ID of the mark.
|
||||
@@ -21,6 +24,10 @@ public class Mark {
|
||||
*/
|
||||
private GPSCoordinate position;
|
||||
|
||||
/**
|
||||
* Repulsion radius of the mark
|
||||
*/
|
||||
private double repulsionRadius = 50;
|
||||
|
||||
/**
|
||||
* Constructs a mark with a given source ID, name, and position.
|
||||
@@ -75,4 +82,14 @@ public class Mark {
|
||||
public void setPosition(GPSCoordinate position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rayCast(Boat boat) {
|
||||
return rayCast(boat, repulsionRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCollisionEnter(Boat collider, Collision e) {
|
||||
collider.bounce(repulsionRadius);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,108 +4,87 @@ import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import mock.model.collider.ColliderRegistry;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import network.Messages.Enums.RaceTypeEnum;
|
||||
import shared.dataInput.BoatDataSource;
|
||||
import shared.dataInput.RaceDataSource;
|
||||
import shared.dataInput.RegattaDataSource;
|
||||
import visualiser.model.VisualiserRaceEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a yacht race.
|
||||
* This is a base class inherited by {@link mock.model.MockRace} and {@link VisualiserRaceEvent}.
|
||||
* Has a course, state, wind, boundaries, etc.... Boats are added by inheriting classes (see {@link Boat}, {@link mock.model.MockBoat}, {@link visualiser.model.VisualiserBoat}.
|
||||
*/
|
||||
public abstract class Race {
|
||||
|
||||
|
||||
/**
|
||||
* The source of race related data.
|
||||
*/
|
||||
protected RaceDataSource raceDataSource;
|
||||
|
||||
/**
|
||||
* The source of boat related data.
|
||||
*/
|
||||
protected BoatDataSource boatDataSource;
|
||||
|
||||
/**
|
||||
* The source of regatta related data.
|
||||
*/
|
||||
protected RegattaDataSource regattaDataSource;
|
||||
|
||||
|
||||
/**
|
||||
* A list of compound marks in the race.
|
||||
*/
|
||||
protected List<CompoundMark> compoundMarks;
|
||||
|
||||
/**
|
||||
* A list of legs in the race.
|
||||
*/
|
||||
protected List<Leg> legs;
|
||||
|
||||
/**
|
||||
* A list of coordinates describing the boundary of the course.
|
||||
*/
|
||||
protected List<GPSCoordinate> boundary;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The clock which tracks the race's start time, current time, and elapsed duration.
|
||||
*/
|
||||
protected RaceClock raceClock;
|
||||
|
||||
|
||||
/**
|
||||
* The race ID of the course.
|
||||
*/
|
||||
protected int raceId;
|
||||
|
||||
/**
|
||||
* The name of the regatta.
|
||||
*/
|
||||
protected String regattaName;
|
||||
|
||||
/**
|
||||
* The current status of the race.
|
||||
*/
|
||||
protected RaceStatusEnum raceStatusEnum;
|
||||
|
||||
/**
|
||||
* The type of race this is.
|
||||
*/
|
||||
protected RaceTypeEnum raceType;
|
||||
|
||||
|
||||
/**
|
||||
* The race's wind.
|
||||
*/
|
||||
protected Property<Wind> raceWind = new SimpleObjectProperty<>();
|
||||
|
||||
|
||||
/**
|
||||
* Registry for all collider object in this race
|
||||
*/
|
||||
protected ColliderRegistry colliderRegistry;
|
||||
/**
|
||||
* The number of frames per second.
|
||||
* We essentially track the number of frames generated per second, over a one second period. When {@link #lastFpsResetTime} reaches 1 second, {@link #currentFps} is reset.
|
||||
* We essentially track the number of frames generated per second, over a one second period. When {@link #lastFpsResetTime} reaches 1 second, currentFps is reset.
|
||||
*/
|
||||
private int currentFps = 0;
|
||||
|
||||
/**
|
||||
* The number of frames per second we generated over the last 1 second period.
|
||||
*/
|
||||
private IntegerProperty lastFps = new SimpleIntegerProperty(0);
|
||||
|
||||
/**
|
||||
* The time, in milliseconds, since we last reset our {@link #currentFps} counter.
|
||||
*/
|
||||
private long lastFpsResetTime;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a race object with a given BoatDataSource, RaceDataSource, and RegattaDataSource.
|
||||
* @param boatDataSource Data source for boat related data (yachts and marker boats).
|
||||
@@ -119,39 +98,36 @@ public abstract class Race {
|
||||
this.boatDataSource = boatDataSource;
|
||||
this.regattaDataSource = regattaDataSource;
|
||||
|
||||
|
||||
|
||||
//Marks.
|
||||
this.compoundMarks = raceDataSource.getCompoundMarks();
|
||||
|
||||
//Boundaries.
|
||||
this.boundary = raceDataSource.getBoundary();
|
||||
|
||||
|
||||
//Legs.
|
||||
this.useLegsList(raceDataSource.getLegs());
|
||||
|
||||
|
||||
//Race ID.
|
||||
this.raceId = raceDataSource.getRaceId();
|
||||
|
||||
//Regatta name.
|
||||
this.regattaName = regattaDataSource.getRegattaName();
|
||||
|
||||
//Race clock.
|
||||
this.raceClock = new RaceClock(this.raceDataSource.getStartDateTime());
|
||||
|
||||
//Race status.
|
||||
this.setRaceStatusEnum(RaceStatusEnum.NOT_ACTIVE);
|
||||
//Race type.
|
||||
this.raceType = raceDataSource.getRaceType();
|
||||
|
||||
//Wind.
|
||||
this.setWind(Bearing.fromDegrees(0), 0);
|
||||
// Set up colliders
|
||||
this.colliderRegistry = new ColliderRegistry();
|
||||
|
||||
for(CompoundMark mark: compoundMarks) {
|
||||
colliderRegistry.addCollider(mark.getMark1());
|
||||
if(mark.getMark2() != null) colliderRegistry.addCollider(mark.getMark2());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ColliderRegistry getColliderRegistry() {
|
||||
return colliderRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the boats in the race.
|
||||
@@ -159,7 +135,6 @@ public abstract class Race {
|
||||
*/
|
||||
protected abstract void initialiseBoats();
|
||||
|
||||
|
||||
/**
|
||||
* Updates the race to use a new list of legs, and adds a dummy "Finish" leg at the end.
|
||||
* @param legs The new list of legs to use.
|
||||
@@ -191,10 +166,6 @@ public abstract class Race {
|
||||
return legID == lastLegID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current race status.
|
||||
* @return The current race status.
|
||||
@@ -211,7 +182,6 @@ public abstract class Race {
|
||||
this.raceStatusEnum = raceStatusEnum;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the type of race this is.
|
||||
* @return The type of race this is.
|
||||
@@ -228,13 +198,12 @@ public abstract class Race {
|
||||
return regattaName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the race to have a specified wind bearing and speed.
|
||||
* @param windBearing New wind bearing.
|
||||
* @param windSpeedKnots New wind speed, in knots.
|
||||
*/
|
||||
public void setWind(Bearing windBearing, double windSpeedKnots) {
|
||||
protected void setWind(Bearing windBearing, double windSpeedKnots) {
|
||||
Wind wind = new Wind(windBearing, windSpeedKnots);
|
||||
setWind(wind);
|
||||
}
|
||||
@@ -243,11 +212,10 @@ public abstract class Race {
|
||||
* Updates the race to have a specified wind (bearing and speed).
|
||||
* @param wind New wind.
|
||||
*/
|
||||
public void setWind(Wind wind) {
|
||||
protected void setWind(Wind wind) {
|
||||
this.raceWind.setValue(wind);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the wind bearing.
|
||||
* @return The wind bearing.
|
||||
@@ -265,14 +233,6 @@ public abstract class Race {
|
||||
return raceWind.getValue().getWindSpeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the race's wind.
|
||||
* @return The race's wind.
|
||||
*/
|
||||
public Property<Wind> windProperty() {
|
||||
return raceWind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RaceClock for this race.
|
||||
* This is used to track the start time, current time, and elapsed duration of the race.
|
||||
@@ -282,7 +242,6 @@ public abstract class Race {
|
||||
return raceClock;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the RaceDataSource used for the race.
|
||||
* @return The RaceDataSource used for the race.
|
||||
@@ -300,7 +259,6 @@ public abstract class Race {
|
||||
return legs.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the race boundary.
|
||||
* @return The race boundary.
|
||||
@@ -326,14 +284,6 @@ public abstract class Race {
|
||||
return legs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of frames generated per second.
|
||||
* @return Frames per second.
|
||||
*/
|
||||
public int getFps() {
|
||||
return lastFps.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fps property.
|
||||
* @return The fps property.
|
||||
@@ -342,8 +292,6 @@ public abstract class Race {
|
||||
return lastFps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Increments the FPS counter, and adds timePeriod milliseconds to our FPS reset timer.
|
||||
* @param timePeriod Time, in milliseconds, to add to {@link #lastFpsResetTime}.
|
||||
|
||||
Reference in New Issue
Block a user