mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Removed broken time extracting method and replaced it with currently existing long extractor. Added speed to the setDestination method for the raceObject abstract class.
#story[820]
This commit is contained in:
@@ -179,10 +179,10 @@ public class BoatGroup extends RaceObject{
|
||||
* @param rotation Rotation to move graphics to.
|
||||
* @param raceIds RaceID of the object to move.
|
||||
*/
|
||||
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
||||
public void setDestination (double newXValue, double newYValue, double rotation, double speed, int... raceIds) {
|
||||
if (hasRaceId(raceIds)) {
|
||||
destinationSet = true;
|
||||
boat.setVelocity(StreamParser.boatSpeeds.get((long)boat.getId()));
|
||||
boat.setVelocity(speed);
|
||||
if (currentRotation < 0)
|
||||
currentRotation = 360 - currentRotation;
|
||||
double dx = newXValue - boatPoly.getLayoutX();
|
||||
@@ -226,7 +226,7 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
}
|
||||
|
||||
public void setDestination (double newXValue, double newYValue, int... raceIDs) {
|
||||
public void setDestination (double newXValue, double newYValue, double speed, int... raceIDs) {
|
||||
destinationSet = true;
|
||||
|
||||
if (hasRaceId(raceIDs)) {
|
||||
@@ -237,7 +237,7 @@ public class BoatGroup extends RaceObject{
|
||||
)
|
||||
)
|
||||
);
|
||||
setDestination(newXValue, newYValue, rotation, raceIDs);
|
||||
setDestination(newXValue, newYValue, rotation, speed, raceIDs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class RaceObject extends Group {
|
||||
* @param rotation Rotation to move graphics to.
|
||||
* @param raceIds RaceID of the object to move.
|
||||
*/
|
||||
public abstract void setDestination (double x, double y, double rotation, int... raceIds);
|
||||
public abstract void setDestination (double x, double y, double rotation, double speed, int... raceIds);
|
||||
/**
|
||||
* Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is
|
||||
* set to the co-ordinates (x, y).
|
||||
@@ -69,7 +69,7 @@ public abstract class RaceObject extends Group {
|
||||
* @param y Y co-ordinate to move the graphic to.
|
||||
* @param raceIds RaceID to the object to move.
|
||||
*/
|
||||
public abstract void setDestination (double x, double y, int... raceIds);
|
||||
public abstract void setDestination (double x, double y, double speed, int... raceIds);
|
||||
|
||||
public abstract void updatePosition (long timeInterval);
|
||||
|
||||
|
||||
@@ -102,21 +102,21 @@ public class MarkGroup extends RaceObject {
|
||||
//moveTo(points[0].getX(), points[0].getY());
|
||||
}
|
||||
|
||||
public void setDestination (double x, double y, double rotation, int... raceIds) {
|
||||
setDestination(x, y, raceIds);
|
||||
public void setDestination (double x, double y, double rotation, double speed, int... raceIds) {
|
||||
setDestination(x, y, 0, raceIds);
|
||||
this.rotationalGoal = rotation;
|
||||
calculateRotationalVelocity();
|
||||
}
|
||||
|
||||
public void setDestination (double x, double y, int... raceIds) {
|
||||
public void setDestination (double x, double y, double speed, int... raceIds) {
|
||||
for (int i = 0; i < marks.size(); i++)
|
||||
for (int id : raceIds)
|
||||
if (id == marks.get(i).getId())
|
||||
setDestinationChild(x, y, Math.max(0, i-1));
|
||||
setDestinationChild(x, y, 0, Math.max(0, i-1));
|
||||
}
|
||||
|
||||
|
||||
private void setDestinationChild (double x, double y, int childIndex) {
|
||||
private void setDestinationChild (double x, double y, double speed, int childIndex) {
|
||||
//double relativeX = x - super.getLayoutX();
|
||||
//double relativeY = y - super.getLayoutY();
|
||||
Circle markCircle = (Circle) super.getChildren().get(childIndex);
|
||||
|
||||
@@ -30,8 +30,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class StreamParser extends Thread{
|
||||
|
||||
public static ConcurrentHashMap<Long,Point3D> boatPositions = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<Long,Double> boatSpeeds = new ConcurrentHashMap<>();
|
||||
private static ConcurrentHashMap<Long,Point3D> boatPositions = new ConcurrentHashMap<>();
|
||||
private static ConcurrentHashMap<Long,Double> boatSpeeds = new ConcurrentHashMap<>();
|
||||
private String threadName;
|
||||
private Thread t;
|
||||
private static boolean raceStarted = false;
|
||||
@@ -156,11 +156,11 @@ public class StreamParser extends Thread{
|
||||
private static void extractRaceStatus(StreamPacket packet){
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
long currentTime = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long currentTime = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,7,11));
|
||||
int raceStatus = payload[11];
|
||||
// System.out.println("raceStatus = " + raceStatus);
|
||||
long expectedStartTime = extractTimeStamp(Arrays.copyOfRange(payload,12,18), 6);
|
||||
long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18));
|
||||
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
|
||||
@@ -193,8 +193,8 @@ public class StreamParser extends Thread{
|
||||
boatStatus += "\nLegNumber: " + (int)payload[29 + (i * 20)];
|
||||
boatStatus += "\nPenaltiesAwarded: " + (int)payload[29 + (i * 20)];
|
||||
boatStatus += "\nPenaltiesServed: " + (int)payload[30 + (i * 20)];
|
||||
boatStatus += "\nEstTimeAtNextMark: " + extractTimeStamp(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20)), 6);
|
||||
boatStatus += "\nEstTimeAtFinish: " + extractTimeStamp(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)), 6);
|
||||
boatStatus += "\nEstTimeAtNextMark: " + bytesToLong(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20)));
|
||||
boatStatus += "\nEstTimeAtFinish: " + bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)));
|
||||
boatStatuses.add(boatStatus);
|
||||
}
|
||||
}
|
||||
@@ -252,8 +252,8 @@ public class StreamParser extends Thread{
|
||||
private static void extractRaceStartStatus(StreamPacket packet){
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long raceStartTime = extractTimeStamp(Arrays.copyOfRange(payload,9,15), 6);
|
||||
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
long raceStartTime = bytesToLong(Arrays.copyOfRange(payload,9,15));
|
||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,15,19));
|
||||
int notificationType = payload[19];
|
||||
}
|
||||
@@ -266,7 +266,7 @@ public class StreamParser extends Thread{
|
||||
private static void extractYachtEventCode(StreamPacket packet){
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
||||
long subjectId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
||||
long incidentId = bytesToLong(Arrays.copyOfRange(payload,17,21));
|
||||
@@ -281,7 +281,7 @@ public class StreamParser extends Thread{
|
||||
private static void extractYachtActionCode(StreamPacket packet){
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
long subjectId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
||||
long incidentId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
||||
int eventId = payload[17];
|
||||
@@ -315,14 +315,14 @@ public class StreamParser extends Thread{
|
||||
byte[] headingBytes = Arrays.copyOfRange(payload,28,30);
|
||||
byte[] groundSpeedBytes = Arrays.copyOfRange(payload,38,40);
|
||||
|
||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
// int boatSeq = ByteBuffer.wrap(seqBytes).getInt();
|
||||
long seq = bytesToLong(seqBytes);
|
||||
long boatId = bytesToLong(boatIdBytes);
|
||||
long lat = bytesToLong(latBytes);
|
||||
long lon = bytesToLong(lonBytes);
|
||||
long heading = bytesToLong(headingBytes);
|
||||
// long speed = extractTimeStamp(speedBytes, 2);
|
||||
// long speed = bytesToLong(speedBytes);
|
||||
double groundSpeed = bytesToLong(groundSpeedBytes)/1000.0;
|
||||
short s = (short) ((groundSpeedBytes[1] & 0xFF) << 8 | (groundSpeedBytes[0] & 0xFF));
|
||||
if ((int)deviceType == 1 || (int)deviceType == 3){
|
||||
@@ -345,7 +345,7 @@ public class StreamParser extends Thread{
|
||||
private static void extractMarkRounding(StreamPacket packet){
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
||||
long subjectId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
||||
int boatStatus = payload[17];
|
||||
@@ -362,7 +362,7 @@ public class StreamParser extends Thread{
|
||||
ArrayList<String> windInfo = new ArrayList<>();
|
||||
for (int i = 0; i < loopCount; i++){
|
||||
String wind = "WindId: " + payload[3 + (20 * i)];
|
||||
wind += "\nTime: " + extractTimeStamp(Arrays.copyOfRange(payload,4 + (20 * i),10 + (20 * i)), 6);
|
||||
wind += "\nTime: " + bytesToLong(Arrays.copyOfRange(payload,4 + (20 * i),10 + (20 * i)));
|
||||
wind += "\nRaceId: " + bytesToLong(Arrays.copyOfRange(payload,10 + (20 * i),14 + (20 * i)));
|
||||
wind += "\nWindDirection: " + bytesToLong(Arrays.copyOfRange(payload,14 + (20 * i),16 + (20 * i)));
|
||||
wind += "\nWindSpeed: " + bytesToLong(Arrays.copyOfRange(payload,16 + (20 * i),18 + (20 * i)));
|
||||
@@ -376,7 +376,7 @@ public class StreamParser extends Thread{
|
||||
private static void extractAvgWind(StreamPacket packet){
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
long rawPeriod = bytesToLong(Arrays.copyOfRange(payload,7,9));
|
||||
long rawSamplePeriod = bytesToLong(Arrays.copyOfRange(payload,9,11));
|
||||
long period2 = bytesToLong(Arrays.copyOfRange(payload,11,13));
|
||||
@@ -387,16 +387,6 @@ public class StreamParser extends Thread{
|
||||
long speed4 = bytesToLong(Arrays.copyOfRange(payload,21,23));
|
||||
}
|
||||
|
||||
private static long extractTimeStamp(byte[] timeStampBytes, int noOfBytes){
|
||||
long timeStamp = 0;
|
||||
long multiplier=1;
|
||||
for(int i = 0;i < noOfBytes;i++) {
|
||||
timeStamp += timeStampBytes[i]*multiplier;
|
||||
multiplier *= 256;
|
||||
}
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* takes an array of up to 7 bytes and returns a positive
|
||||
* long constructed from the input bytes
|
||||
@@ -461,6 +451,13 @@ public class StreamParser extends Thread{
|
||||
return boats;
|
||||
}
|
||||
|
||||
public static ConcurrentHashMap<Long, Point3D> getBoatPositions() {
|
||||
return boatPositions;
|
||||
}
|
||||
|
||||
public static ConcurrentHashMap<Long, Double> getBoatSpeeds() {
|
||||
return boatSpeeds;
|
||||
}
|
||||
|
||||
public static XMLParser getXmlObject() {
|
||||
return xmlObject;
|
||||
|
||||
Reference in New Issue
Block a user