mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Removed the parser from queing packets incorrectly. Used the marker boat location packets to get the live updates of the marker positions and implemented the markers being updated much like the boats currently are. This means the course more closely resembles the actual intended course design.
#story[820]
This commit is contained in:
@@ -148,6 +148,7 @@ public class BoatGroup extends RaceObject{
|
||||
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
||||
destinationSet = true;
|
||||
boat.setVelocity(StreamParser.boatSpeeds.get((long)boat.getId()));
|
||||
velocityObject.setText(String.valueOf(boat.getVelocity()));
|
||||
if (hasRaceId(raceIds)) {
|
||||
this.pixelVelocityX = (newXValue - boatPoly.getLayoutX()) / expectedUpdateInterval;
|
||||
this.pixelVelocityY = (newYValue - boatPoly.getLayoutY()) / expectedUpdateInterval;
|
||||
|
||||
@@ -17,10 +17,10 @@ public abstract class Mark {
|
||||
* @param name the name of the mark
|
||||
* @param markType the type of mark. either GATE_MARK or SINGLE_MARK.
|
||||
*/
|
||||
public Mark (String name, MarkType markType) {
|
||||
public Mark (String name, MarkType markType, int id) {
|
||||
this.name = name;
|
||||
this.markType = markType;
|
||||
id = 0;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Mark(String name, MarkType markType, double latitude, double longitude) {
|
||||
|
||||
@@ -39,6 +39,9 @@ public class MarkGroup extends RaceObject {
|
||||
System.out.println("HERE ARE THE CHILDREN LOL");
|
||||
if (mark.getMarkType() == MarkType.SINGLE_MARK) {
|
||||
super.getChildren().add(new Circle(0, 0, MARK_RADIUS, color));
|
||||
nodeDestinations = new Point2D[]{
|
||||
new Point2D(super.getChildren().get(0).getLayoutX()
|
||||
, super.getChildren().get(0).getLayoutY())};
|
||||
} else {
|
||||
marks.add(((GateMark) mark).getSingleMark1());
|
||||
marks.add(((GateMark) mark).getSingleMark2());
|
||||
@@ -96,6 +99,7 @@ public class MarkGroup extends RaceObject {
|
||||
setDestinationGroup(x, y);
|
||||
childrenIndex++;
|
||||
}
|
||||
updateChildren();
|
||||
}
|
||||
|
||||
|
||||
@@ -105,9 +109,13 @@ public class MarkGroup extends RaceObject {
|
||||
this.nodeDestinations[childIndex] = new Point2D(relativeX, relativeY);
|
||||
this.nodePixelVelocitiesX[childIndex] = (relativeX - super.getChildren().get(childIndex).getLayoutX()) / expectedUpdateInterval;
|
||||
this.nodePixelVelocitiesY[childIndex] = (relativeY - super.getChildren().get(childIndex).getLayoutY()) / expectedUpdateInterval;
|
||||
|
||||
}
|
||||
|
||||
private void setDestinationGroup (double x, double y) {
|
||||
double relativeX = x - super.getLayoutX();
|
||||
double relativeY = y - super.getLayoutY();
|
||||
this.nodeDestinations[0] = new Point2D(relativeX, relativeY);
|
||||
pixelVelocityX = (x - super.getLayoutX()) / expectedUpdateInterval;
|
||||
pixelVelocityY = (y - super.getLayoutY()) / expectedUpdateInterval;
|
||||
}
|
||||
@@ -119,11 +127,11 @@ public class MarkGroup extends RaceObject {
|
||||
}
|
||||
|
||||
public void updatePosition (long timeInterval) {
|
||||
double x = pixelVelocityX * timeInterval;
|
||||
double y = pixelVelocityY * timeInterval;
|
||||
double rotation = rotationalVelocity * timeInterval;
|
||||
moveGroupBy(x, y, rotation);
|
||||
updateChildren(timeInterval);
|
||||
// double x = pixelVelocityX * timeInterval;
|
||||
// double y = pixelVelocityY * timeInterval;
|
||||
// double rotation = rotationalVelocity * timeInterval;
|
||||
// moveGroupBy(x, y, rotation);
|
||||
// updateChildren(timeInterval);
|
||||
}
|
||||
|
||||
public void moveGroupBy (double x, double y, double rotation) {
|
||||
@@ -132,42 +140,59 @@ public class MarkGroup extends RaceObject {
|
||||
rotateTo(rotation);
|
||||
}
|
||||
|
||||
private void updateChildren (double timeInterval) {
|
||||
private void updateChildren () {
|
||||
|
||||
if (mainMark.getMarkType() != MarkType.SINGLE_MARK) {
|
||||
Line line = (Line) super.getChildren().get(2);
|
||||
for (int childIndex = 0; childIndex < 2; childIndex++){
|
||||
Circle mark = (Circle) super.getChildren().get(childIndex);
|
||||
Point2D dest = nodeDestinations[childIndex];
|
||||
mark.setCenterY(dest.getY());
|
||||
mark.setCenterX(dest.getX());
|
||||
}
|
||||
line.setStartX(nodeDestinations[0].getX());
|
||||
line.setStartY(nodeDestinations[0].getY());
|
||||
line.setEndX(nodeDestinations[1].getX());
|
||||
line.setEndY(nodeDestinations[1].getY());
|
||||
// Circle mark = (Circle) super.getChildren().get(0);
|
||||
// if (nodePixelVelocitiesX[0] > 0 && mark.getLayoutX() >= nodeDestinations[0].getX()) {
|
||||
// nodePixelVelocitiesX[0] = 0;
|
||||
// } else if (nodePixelVelocitiesX[0] < 0 && mark.getLayoutX() <= nodeDestinations[0].getX()) {
|
||||
// nodePixelVelocitiesX[0] = 0;
|
||||
// } else {
|
||||
// mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[0] * timeInterval);
|
||||
// mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[0] * timeInterval);
|
||||
// }
|
||||
// if (nodePixelVelocitiesY[0] >= 0 && mark.getLayoutY() > nodeDestinations[0].getY()) {
|
||||
// nodePixelVelocitiesY[0] = 0;
|
||||
// } else if (nodePixelVelocitiesY[0] < 0 && mark.getLayoutY() <= nodeDestinations[0].getY()) {
|
||||
// nodePixelVelocitiesY[0] = 0;
|
||||
// } else {
|
||||
// mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[0] * timeInterval);
|
||||
// mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[0] * timeInterval);
|
||||
// }
|
||||
// mark = (Circle) super.getChildren().get(1);
|
||||
// if (nodePixelVelocitiesX[1] > 0 && mark.getLayoutX() >= nodeDestinations[1].getX()) {
|
||||
// nodePixelVelocitiesX[1] = 0;
|
||||
// } else if (nodePixelVelocitiesX[1] < 0 && mark.getLayoutX() <= nodeDestinations[1].getX()) {
|
||||
// nodePixelVelocitiesX[1] = 0;
|
||||
// } else {
|
||||
// mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[1] * timeInterval);
|
||||
// mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[1] * timeInterval);
|
||||
// }
|
||||
// if (nodePixelVelocitiesY[1] >= 0 && mark.getLayoutY() > nodeDestinations[1].getY()) {
|
||||
// nodePixelVelocitiesY[1] = 0;
|
||||
// } else if (nodePixelVelocitiesY[1] < 0 && mark.getLayoutY() <= nodeDestinations[1].getY()) {
|
||||
// nodePixelVelocitiesY[1] = 0;
|
||||
// } else {
|
||||
// mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[1] * timeInterval);
|
||||
// mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[1] * timeInterval);
|
||||
// }
|
||||
} else {
|
||||
Circle mark = (Circle) super.getChildren().get(0);
|
||||
if (nodePixelVelocitiesX[0] > 0 && mark.getLayoutX() >= nodeDestinations[0].getX()) {
|
||||
nodePixelVelocitiesX[0] = 0;
|
||||
} else if (nodePixelVelocitiesX[0] < 0 && mark.getLayoutX() <= nodeDestinations[0].getX()) {
|
||||
nodePixelVelocitiesX[0] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[0] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[0] * timeInterval);
|
||||
}
|
||||
if (nodePixelVelocitiesY[0] >= 0 && mark.getLayoutY() > nodeDestinations[0].getY()) {
|
||||
nodePixelVelocitiesY[0] = 0;
|
||||
} else if (nodePixelVelocitiesY[0] < 0 && mark.getLayoutY() <= nodeDestinations[0].getY()) {
|
||||
nodePixelVelocitiesY[0] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[0] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[0] * timeInterval);
|
||||
}
|
||||
mark = (Circle) super.getChildren().get(1);
|
||||
if (nodePixelVelocitiesX[1] > 0 && mark.getLayoutX() >= nodeDestinations[1].getX()) {
|
||||
nodePixelVelocitiesX[1] = 0;
|
||||
} else if (nodePixelVelocitiesX[1] < 0 && mark.getLayoutX() <= nodeDestinations[1].getX()) {
|
||||
nodePixelVelocitiesX[1] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[1] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[1] * timeInterval);
|
||||
}
|
||||
if (nodePixelVelocitiesY[1] >= 0 && mark.getLayoutY() > nodeDestinations[1].getY()) {
|
||||
nodePixelVelocitiesY[1] = 0;
|
||||
} else if (nodePixelVelocitiesY[1] < 0 && mark.getLayoutY() <= nodeDestinations[1].getY()) {
|
||||
nodePixelVelocitiesY[1] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[1] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[1] * timeInterval);
|
||||
}
|
||||
Point2D dest = nodeDestinations[0];
|
||||
mark.setCenterY(dest.getY());
|
||||
mark.setCenterX(dest.getX());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ public class SingleMark extends Mark {
|
||||
private double lat;
|
||||
private double lon;
|
||||
private String name;
|
||||
private int id;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,10 +19,11 @@ public class SingleMark extends Mark {
|
||||
* @param lat, the latitude of the marker
|
||||
* @param lon, the longitude of the marker
|
||||
*/
|
||||
public SingleMark(String name, double lat, double lon) {
|
||||
super(name, MarkType.SINGLE_MARK);
|
||||
public SingleMark(String name, double lat, double lon, int id) {
|
||||
super(name, MarkType.SINGLE_MARK, id);
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,9 +32,10 @@ public class SingleMark extends Mark {
|
||||
* @param name, the name of the marker
|
||||
*/
|
||||
public SingleMark(String name) {
|
||||
super(name, MarkType.SINGLE_MARK);
|
||||
super(name, MarkType.SINGLE_MARK, 0);
|
||||
this.lat = 0;
|
||||
this.lon = 0;
|
||||
this.id = 0;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
|
||||
@@ -35,7 +35,8 @@ public class CourseParser extends FileParser {
|
||||
String name = element.getElementsByTagName("name").item(0).getTextContent();
|
||||
double lat = Double.valueOf(element.getElementsByTagName("latitude").item(0).getTextContent());
|
||||
double lon = Double.valueOf(element.getElementsByTagName("longitude").item(0).getTextContent());
|
||||
SingleMark singleMark = new SingleMark(name, lat, lon);
|
||||
int id = Integer.valueOf(element.getElementsByTagName("id").item(0).getTextContent());
|
||||
SingleMark singleMark = new SingleMark(name, lat, lon, id);
|
||||
return singleMark;
|
||||
} else {
|
||||
throw new NoSuchElementException("Cannot generate a mark by given node.");
|
||||
|
||||
@@ -48,21 +48,20 @@ public class StreamParser extends Thread{
|
||||
Thread.sleep(1);
|
||||
}
|
||||
while (StreamReceiver.packetBuffer.peek() != null){
|
||||
StreamPacket packet = StreamReceiver.packetBuffer.peek();
|
||||
int delayTime = 1000;
|
||||
int loopTime = delayTime + 1000;
|
||||
long sleepTime = 0;
|
||||
long transitTime = (System.currentTimeMillis()%loopTime - packet.getTimeStamp()%loopTime);
|
||||
if (transitTime < 0){
|
||||
transitTime = loopTime + delayTime;
|
||||
}
|
||||
if (transitTime < delayTime) {
|
||||
sleepTime = delayTime - (transitTime);
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
System.out.println(sleepTime);
|
||||
|
||||
packet = StreamReceiver.packetBuffer.take();
|
||||
// StreamPacket packet = StreamReceiver.packetBuffer.peek();
|
||||
// int delayTime = 1000;
|
||||
// int loopTime = delayTime + 1000;
|
||||
// long sleepTime = 0;
|
||||
// long transitTime = (System.currentTimeMillis()%loopTime - packet.getTimeStamp()%loopTime);
|
||||
// if (transitTime < 0){
|
||||
// transitTime = loopTime + delayTime;
|
||||
// }
|
||||
// if (transitTime < delayTime) {
|
||||
// sleepTime = delayTime - (transitTime);
|
||||
// Thread.sleep(sleepTime);
|
||||
// }
|
||||
// System.out.println(sleepTime);
|
||||
StreamPacket packet = StreamReceiver.packetBuffer.take();
|
||||
parsePacket(packet);
|
||||
Thread.sleep(1);
|
||||
while (StreamReceiver.packetBuffer.peek() == null) {
|
||||
@@ -228,7 +227,6 @@ public class StreamParser extends Thread{
|
||||
while (payloadStream.available() > 0 && (currentChar = payloadStream.read()) != 0) {
|
||||
xmlMessage += (char)currentChar;
|
||||
}
|
||||
|
||||
//Create XML document Object
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = null;
|
||||
@@ -323,7 +321,7 @@ public class StreamParser extends Thread{
|
||||
// long speed = extractTimeStamp(speedBytes, 2);
|
||||
double groundSpeed = bytesToLong(groundSpeedBytes)/1000.0;
|
||||
short s = (short) ((groundSpeedBytes[1] & 0xFF) << 8 | (groundSpeedBytes[0] & 0xFF));
|
||||
if ((int)deviceType == 1 || (int)deviceType == 4){
|
||||
if ((int)deviceType == 1 || (int)deviceType == 3){
|
||||
// System.out.println("boatId = " + boatId);
|
||||
// System.out.println("deviceType = " + (long)deviceType);
|
||||
// System.out.println("seq = " + seq);
|
||||
|
||||
@@ -8,17 +8,20 @@
|
||||
<name>Start1</name>
|
||||
<latitude>57.6703330</latitude>
|
||||
<longitude>11.8278330</longitude>
|
||||
<id>122</id>
|
||||
</mark>
|
||||
<mark>
|
||||
<name>Start2</name>
|
||||
<latitude>57.6706330</latitude>
|
||||
<longitude>11.8281330</longitude>
|
||||
<id>123</id>
|
||||
</mark>
|
||||
</gate>
|
||||
<mark>
|
||||
<name>Mid Mark</name>
|
||||
<latitude>57.6675700</latitude>
|
||||
<longitude>11.8359880</longitude>
|
||||
<id>131</id>
|
||||
</mark>
|
||||
<gate>
|
||||
<name>Leeward Gate</name>
|
||||
@@ -26,11 +29,13 @@
|
||||
<name>Leeward Gate1</name>
|
||||
<latitude>57.6708220</latitude>
|
||||
<longitude>11.8433900</longitude>
|
||||
<id>124</id>
|
||||
</mark>
|
||||
<mark>
|
||||
<name>Leeward Gate2</name>
|
||||
<latitude>57.6711220</latitude>
|
||||
<longitude>11.8436900</longitude>
|
||||
<id>125</id>
|
||||
</mark>
|
||||
</gate>
|
||||
<gate>
|
||||
@@ -39,11 +44,13 @@
|
||||
<name>Windward Gate1</name>
|
||||
<latitude>57.6650170</latitude>
|
||||
<longitude>11.8279170</longitude>
|
||||
<id>126</id>
|
||||
</mark>
|
||||
<mark>
|
||||
<name>Windward Gate2</name>
|
||||
<latitude>57.6653170</latitude>
|
||||
<longitude>11.8282170</longitude>
|
||||
<id>127</id>
|
||||
</mark>
|
||||
</gate>
|
||||
<gate type="finish-line">
|
||||
@@ -52,11 +59,13 @@
|
||||
<name>Finish1</name>
|
||||
<latitude>57.6715240</latitude>
|
||||
<longitude>11.8444950</longitude>
|
||||
<id>128</id>
|
||||
</mark>
|
||||
<mark>
|
||||
<name>Finish2</name>
|
||||
<latitude>57.6718240</latitude>
|
||||
<longitude>11.8447950</longitude>
|
||||
<id>129</id>
|
||||
</mark>
|
||||
</gate>
|
||||
</marks>
|
||||
|
||||
Reference in New Issue
Block a user