Merged race scaling with Http Match Discovery.
This commit is contained in:
@@ -154,6 +154,12 @@ public class RaceXMLCreator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an estimate of how long a race will take using an average Speed
|
||||||
|
* @param race race to estimate
|
||||||
|
* @param averageSpeed average speed that the boats move at
|
||||||
|
* @return the estimated amount of time it will take a boat to finish the race (skewed to minimum).
|
||||||
|
*/
|
||||||
public static double getRaceLength(XMLRace race, double averageSpeed){
|
public static double getRaceLength(XMLRace race, double averageSpeed){
|
||||||
double raceRoundingTime = 5000; //5 seconds to round a mark
|
double raceRoundingTime = 5000; //5 seconds to round a mark
|
||||||
double totalDistance = 0; //in nautical miles
|
double totalDistance = 0; //in nautical miles
|
||||||
@@ -175,13 +181,24 @@ public class RaceXMLCreator {
|
|||||||
return totalTime;
|
return totalTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the destance between two marks
|
||||||
|
* @param a mark 1
|
||||||
|
* @param b mark 2
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private static double getDistance(XMLMark a, XMLMark b){
|
private static double getDistance(XMLMark a, XMLMark b){
|
||||||
GPSCoordinate coorda = new GPSCoordinate(a.getTargetLat(), a.getTargetLng());
|
GPSCoordinate coorda = new GPSCoordinate(a.getTargetLat(), a.getTargetLng());
|
||||||
GPSCoordinate coordb = new GPSCoordinate(b.getTargetLat(), b.getTargetLng());
|
GPSCoordinate coordb = new GPSCoordinate(b.getTargetLat(), b.getTargetLng());
|
||||||
return GPSCoordinate.calculateDistanceNauticalMiles(coorda, coordb);
|
return GPSCoordinate.calculateDistanceNauticalMiles(coorda, coordb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scales the race based on the windspeed the race is running at and the amount of time it should be completed in.
|
||||||
|
* @param race Race to scale
|
||||||
|
* @param windSpeed windspeed of the race, this is used with the polars
|
||||||
|
* @param milliseconds milliseconds the race should take.
|
||||||
|
*/
|
||||||
private static void scaleRace(XMLRace race, double windSpeed, double milliseconds) {
|
private static void scaleRace(XMLRace race, double windSpeed, double milliseconds) {
|
||||||
GPSCoordinate center = getCenter(race);
|
GPSCoordinate center = getCenter(race);
|
||||||
//sort the compound marks
|
//sort the compound marks
|
||||||
@@ -214,8 +231,12 @@ public class RaceXMLCreator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scales a point from the the center(pivot)
|
||||||
|
* @param mark mark the scale
|
||||||
|
* @param center center as pivot
|
||||||
|
* @param scale scale to scale at.
|
||||||
|
*/
|
||||||
private static void scalePoint(XMLMark mark, GPSCoordinate center, double scale){
|
private static void scalePoint(XMLMark mark, GPSCoordinate center, double scale){
|
||||||
double latDiff = mark.getTargetLat() - center.getLatitude();
|
double latDiff = mark.getTargetLat() - center.getLatitude();
|
||||||
double longDiff = mark.getTargetLng() - center.getLongitude();
|
double longDiff = mark.getTargetLng() - center.getLongitude();
|
||||||
|
|||||||
@@ -9,10 +9,16 @@ import java.net.URL;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gondr on 23/05/2017.
|
* A helper class that has functions to read information from a url to json object.
|
||||||
*/
|
*/
|
||||||
public class JsonReader {
|
public class JsonReader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads all data from a Reader
|
||||||
|
* @param rd reader to read from
|
||||||
|
* @return string that the reader has currently read
|
||||||
|
* @throws IOException if the reader is invalid
|
||||||
|
*/
|
||||||
private static String readAll(Reader rd) throws IOException {
|
private static String readAll(Reader rd) throws IOException {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
int cp;
|
int cp;
|
||||||
@@ -22,6 +28,13 @@ public class JsonReader {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a Json Object from a URL
|
||||||
|
* @param url url to read from
|
||||||
|
* @return JSONObject that has been read
|
||||||
|
* @throws IOException if the reader cannot obtain information
|
||||||
|
* @throws JSONException if the read information is not json parsable.
|
||||||
|
*/
|
||||||
public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
|
public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
|
||||||
InputStream is = new URL(url).openStream();
|
InputStream is = new URL(url).openStream();
|
||||||
try {
|
try {
|
||||||
@@ -36,6 +49,13 @@ public class JsonReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a Json Array from a URL
|
||||||
|
* @param url url to read from
|
||||||
|
* @return JSONArray that has been read
|
||||||
|
* @throws IOException if the reader cannot obtain information
|
||||||
|
* @throws JSONException if the read information is not json parsable.
|
||||||
|
*/
|
||||||
public static JSONArray readJsonFromUrlArray(String url) throws IOException, JSONException {
|
public static JSONArray readJsonFromUrlArray(String url) throws IOException, JSONException {
|
||||||
InputStream is = new URL(url).openStream();
|
InputStream is = new URL(url).openStream();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ import java.io.IOException;
|
|||||||
public class HttpMatchBrowserClient extends Thread {
|
public class HttpMatchBrowserClient extends Thread {
|
||||||
public ObservableList<RaceConnection> connections = FXCollections.observableArrayList();
|
public ObservableList<RaceConnection> connections = FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the matches that have been running in the past 5 seconds.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(!Thread.interrupted()) {
|
while(!Thread.interrupted()) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gondr on 19/09/2017.
|
* Creates an Http connection that hosts a game
|
||||||
*/
|
*/
|
||||||
public class HttpMatchBrowserHost extends Thread {
|
public class HttpMatchBrowserHost extends Thread {
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
@@ -25,6 +25,12 @@ public class HttpMatchBrowserHost extends Thread {
|
|||||||
|
|
||||||
public static HttpMatchBrowserHost httpMatchBrowserHost = null;
|
public static HttpMatchBrowserHost httpMatchBrowserHost = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor, this sends out the creation message of the race.
|
||||||
|
* the thread should be run as soon as possible as the race is only valid for 5 seconds
|
||||||
|
* until it requires a heartbeat from the start function.
|
||||||
|
* @throws IOException if the hosting url is unreachable.
|
||||||
|
*/
|
||||||
public HttpMatchBrowserHost() throws IOException {
|
public HttpMatchBrowserHost() throws IOException {
|
||||||
httpMatchBrowserHost = this;
|
httpMatchBrowserHost = this;
|
||||||
httpClient = HttpClients.createDefault();
|
httpClient = HttpClients.createDefault();
|
||||||
@@ -38,6 +44,11 @@ public class HttpMatchBrowserHost extends Thread {
|
|||||||
System.out.println("Register Match");
|
System.out.println("Register Match");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a post to a server.
|
||||||
|
* @param domain url of to send to
|
||||||
|
* @throws IOException if the url is unreachable.
|
||||||
|
*/
|
||||||
public void sendHttp(String domain) throws IOException {
|
public void sendHttp(String domain) throws IOException {
|
||||||
HttpPost httppost = new HttpPost(domain);
|
HttpPost httppost = new HttpPost(domain);
|
||||||
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||||
@@ -58,6 +69,9 @@ public class HttpMatchBrowserHost extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* THe host starts sending out heartbeat messages every 2 seconds.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(!Thread.interrupted()){
|
while(!Thread.interrupted()){
|
||||||
|
|||||||
Reference in New Issue
Block a user