Merge branch 'isolatingMock' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into isolatingMock
This commit is contained in:
@@ -2,6 +2,7 @@ package seng302.Model;
|
|||||||
|
|
||||||
|
|
||||||
import com.sun.org.apache.xpath.internal.SourceTree;
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
||||||
|
import com.sun.xml.internal.bind.v2.TODO;
|
||||||
import javafx.animation.AnimationTimer;
|
import javafx.animation.AnimationTimer;
|
||||||
|
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
@@ -32,7 +33,8 @@ public class Race implements Runnable {
|
|||||||
protected long totalTimeElapsed;
|
protected long totalTimeElapsed;
|
||||||
private int lastFPS = 20;
|
private int lastFPS = 20;
|
||||||
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
||||||
|
protected int heartbeat = 0;
|
||||||
|
protected boolean raceFinish = false;
|
||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
|
|
||||||
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
||||||
@@ -64,9 +66,35 @@ public class Race implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
initialiseBoats();
|
initialiseBoats();
|
||||||
|
outputHeartbeat();
|
||||||
countdownTimer();
|
countdownTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void outputHeartbeat() {
|
||||||
|
AnimationTimer heartbeatTimer = new AnimationTimer() {
|
||||||
|
long currentHeartbeatTime = System.currentTimeMillis();
|
||||||
|
long endHeartbeatTime = System.currentTimeMillis() + 5000;
|
||||||
|
@Override
|
||||||
|
public void handle(long now) {
|
||||||
|
if (currentHeartbeatTime >= endHeartbeatTime) {
|
||||||
|
System.out.println("-------");
|
||||||
|
System.out.println("Heartbeat value: " + heartbeat);
|
||||||
|
System.out.println("-------");
|
||||||
|
endHeartbeatTime = System.currentTimeMillis() + 5000;
|
||||||
|
heartbeat++;
|
||||||
|
//TODO: Send heartbeat value
|
||||||
|
}
|
||||||
|
/*if (raceFinish) {
|
||||||
|
System.out.println("Heartbeat stopping");
|
||||||
|
stop();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
currentHeartbeatTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
heartbeatTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
||||||
*/
|
*/
|
||||||
@@ -143,6 +171,10 @@ public class Race implements Runnable {
|
|||||||
if (boat != null && !boat.isFinished()) {
|
if (boat != null && !boat.isFinished()) {
|
||||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||||
checkPosition(boat, totalTimeElapsed);
|
checkPosition(boat, totalTimeElapsed);
|
||||||
|
} else {
|
||||||
|
System.out.println("Race is over");
|
||||||
|
//raceFinish = true;
|
||||||
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,11 +190,12 @@ public class Race implements Runnable {
|
|||||||
for(BoatInRace boat: startingBoats) {
|
for(BoatInRace boat: startingBoats) {
|
||||||
if(boat != null) {
|
if(boat != null) {
|
||||||
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
||||||
System.out.println(boat.getName() + boat.getPosition());
|
System.out.println(boat.toString() + " " + boat.getPosition());
|
||||||
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
|
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
|
||||||
boat.setPosition("-");
|
boat.setPosition("-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("=====");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialiseBoats() {
|
public void initialiseBoats() {
|
||||||
|
|||||||
@@ -23,6 +23,21 @@ public class BoatLocationMessage
|
|||||||
|
|
||||||
///Device type of the message (physical source of the message).
|
///Device type of the message (physical source of the message).
|
||||||
private byte deviceType;
|
private byte deviceType;
|
||||||
|
public static final byte Unknown = 0;
|
||||||
|
public static final byte RacingYacht = 1;
|
||||||
|
public static final byte CommitteeBoat = 2;
|
||||||
|
public static final byte Mark = 3;
|
||||||
|
public static final byte Pin = 4;
|
||||||
|
public static final byte ChaseBoat = 5;
|
||||||
|
public static final byte MedicalBoat = 6;
|
||||||
|
public static final byte MarshallBoat = 7;
|
||||||
|
public static final byte UmpireBoat = 8;
|
||||||
|
public static final byte UmpireSoftwareApplication = 9;
|
||||||
|
public static final byte PrincipalRaceOfficerApplication = 10;
|
||||||
|
public static final byte WeatherStation = 11;
|
||||||
|
public static final byte Helicopter = 12;
|
||||||
|
public static final byte DataProcessingApplication = 13;
|
||||||
|
|
||||||
|
|
||||||
///Latitude of the boat.
|
///Latitude of the boat.
|
||||||
private int latitude;
|
private int latitude;
|
||||||
@@ -74,7 +89,7 @@ public class BoatLocationMessage
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor.
|
* Ctor. Default.
|
||||||
*/
|
*/
|
||||||
public BoatLocationMessage()
|
public BoatLocationMessage()
|
||||||
{
|
{
|
||||||
@@ -342,4 +357,89 @@ public class BoatLocationMessage
|
|||||||
{
|
{
|
||||||
this.rudderAngle = rudderAngle;
|
this.rudderAngle = rudderAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a double representing a latitude or longitude coordinate to an int, as required by the streaming spec format.
|
||||||
|
* @param coordinate Latitude or longitude to convert. Double.
|
||||||
|
* @return int representation of coordinate.
|
||||||
|
*/
|
||||||
|
public static int convertCoordinateDoubleToInt(double coordinate)
|
||||||
|
{
|
||||||
|
int coordinateInt = (int) ((coordinate / 180.0) * 2147483648.0);
|
||||||
|
|
||||||
|
return coordinateInt;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an int representing a latitude or longitude coordinate to a double, as required by the streaming spec format.
|
||||||
|
* @param coordinate Latitude or longitude to convert. int.
|
||||||
|
* @return double representation of coordinate.
|
||||||
|
*/
|
||||||
|
public static double convertCoordinateIntToDouble(int coordinate)
|
||||||
|
{
|
||||||
|
double coordinateDouble = (double) ((coordinate * 180.0) / 2147483648.0);
|
||||||
|
|
||||||
|
return coordinateDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an int representing a heading to a double, as required by the streaming spec format.
|
||||||
|
* @param heading Heading to convert. int.
|
||||||
|
* @return double representation of heading.
|
||||||
|
*/
|
||||||
|
public static double convertHeadingIntToDouble(int heading)
|
||||||
|
{
|
||||||
|
|
||||||
|
double headingDouble = (double) ((heading * 360.0) / 65536.0);
|
||||||
|
|
||||||
|
return headingDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a double representing a heading to an int, as required by the streaming spec format.
|
||||||
|
* @param heading Heading to convert. double.
|
||||||
|
* @return int representation of heading.
|
||||||
|
*/
|
||||||
|
public static int convertHeadingDoubleToInt(double heading)
|
||||||
|
{
|
||||||
|
|
||||||
|
int headingInt = (int) ((heading / 360.0) * 65536.0);
|
||||||
|
|
||||||
|
return headingInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a short representing the wind's true angle to a double, as required by the streaming spec format.
|
||||||
|
* @param angle Angle to convert. short.
|
||||||
|
* @return double representation of heading.
|
||||||
|
*/
|
||||||
|
public static double convertTrueWindAngleShortToDouble(short angle)
|
||||||
|
{
|
||||||
|
|
||||||
|
double angleDouble = (double) ((angle * 180.0) / 32768.0);
|
||||||
|
|
||||||
|
return angleDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a double representing the wind's true angle to a short, as required by the streaming spec format.
|
||||||
|
* @param angle Angle to convert. double.
|
||||||
|
* @return short representation of heading.
|
||||||
|
*/
|
||||||
|
public static short convertTrueWindAngleShortToDouble(double angle)
|
||||||
|
{
|
||||||
|
|
||||||
|
short angleShort = (short) ((angle / 180.0) * 32768.0);
|
||||||
|
|
||||||
|
return angleShort;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user