mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
cleaned up code for merging back to develop #story[923]
This commit is contained in:
@@ -188,18 +188,12 @@ public class CanvasController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateBoatGroup(BoatGroup boatGroup) {
|
private void updateBoatGroup(BoatGroup boatGroup) {
|
||||||
System.out.println("StreamParser.boatPositions.size()2 = " + StreamParser.boatPositions.size());
|
|
||||||
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(boatGroup.getRaceId());
|
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(boatGroup.getRaceId());
|
||||||
// giving the movementQueue a 5 packet buffer to account for slightly out of order packets
|
// giving the movementQueue a 5 packet buffer to account for slightly out of order packets
|
||||||
if (movementQueue.size() > 5){
|
if (movementQueue.size() > 0){
|
||||||
try {
|
try {
|
||||||
BoatPositionPacket positionPacket = movementQueue.take();
|
BoatPositionPacket positionPacket = movementQueue.take();
|
||||||
Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon());
|
Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon());
|
||||||
if (boatGroup.getRaceId() == 106){
|
|
||||||
// System.out.println("p2d.getX() = " + p2d.getX());
|
|
||||||
// System.out.println("p2d.getY() = " + p2d.getY());
|
|
||||||
// System.out.println("positionPacket.getTimeValid() = " + positionPacket.getTimeValid());
|
|
||||||
}
|
|
||||||
double heading = 360.0 / 0xffff * positionPacket.getHeading();
|
double heading = 360.0 / 0xffff * positionPacket.getHeading();
|
||||||
boatGroup.setDestination(p2d.getX(), p2d.getY(), heading, positionPacket.getGroundSpeed(), positionPacket.getTimeValid(), frameRate, boatGroup.getRaceId());
|
boatGroup.setDestination(p2d.getX(), p2d.getY(), heading, positionPacket.getGroundSpeed(), positionPacket.getTimeValid(), frameRate, boatGroup.getRaceId());
|
||||||
} catch (InterruptedException e){
|
} catch (InterruptedException e){
|
||||||
@@ -389,31 +383,6 @@ public class CanvasController {
|
|||||||
return horiDistance;
|
return horiDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Give all markers in the course an x,y location relative to a given reference with a known x,y location. Distances
|
|
||||||
* are scaled according to the distanceScaleFactor variable.
|
|
||||||
*/
|
|
||||||
// DEPRECATED create an initialize marks method like the initialize boats method
|
|
||||||
private void givePointsXY() {
|
|
||||||
// List<XMLParser.RaceXMLObject.CompoundMark> allPoints = StreamParser.getXmlObject().getRaceXML().getCompoundMarks();
|
|
||||||
// List<XMLParser.RaceXMLObject.CompoundMark> processed = new ArrayList<>();
|
|
||||||
// MarkGroup markGroup;
|
|
||||||
//
|
|
||||||
// for (XMLParser.RaceXMLObject.CompoundMark mark : allPoints) {
|
|
||||||
// if (!processed.contains(mark)) {
|
|
||||||
// if (mark.getMarkType() != MarkType.SINGLE_MARK) {
|
|
||||||
// markGroup = new MarkGroup(mark, findScaledXY(mark.getMarks().get(0)), findScaledXY(mark.getMarks().get(1)));
|
|
||||||
// markGroups.add(markGroup);
|
|
||||||
// } else {
|
|
||||||
// markGroup = new MarkGroup(mark, findScaledXY(mark.getMarks().get(0)));
|
|
||||||
// markGroups.add(markGroup);
|
|
||||||
// }
|
|
||||||
// processed.add(mark);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
group.getChildren().addAll(boatGroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Point2D findScaledXY (Mark unscaled) {
|
private Point2D findScaledXY (Mark unscaled) {
|
||||||
return findScaledXY (unscaled.getLatitude(), unscaled.getLongitude());
|
return findScaledXY (unscaled.getLatitude(), unscaled.getLongitude());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ public class Controller implements Initializable {
|
|||||||
public void switchToRaceView() {
|
public void switchToRaceView() {
|
||||||
switchedToRaceView = true;
|
switchedToRaceView = true;
|
||||||
setContentPane("/views/RaceView.fxml");
|
setContentPane("/views/RaceView.fxml");
|
||||||
System.out.println("boatPositions.size()1 = " + boatPositions.size());
|
|
||||||
StreamParser.boatPositions.clear();
|
StreamParser.boatPositions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import seng302.controllers.annotations.ImportantAnnotationController;
|
|||||||
import seng302.controllers.annotations.ImportantAnnotationDelegate;
|
import seng302.controllers.annotations.ImportantAnnotationDelegate;
|
||||||
import seng302.controllers.annotations.ImportantAnnotationsState;
|
import seng302.controllers.annotations.ImportantAnnotationsState;
|
||||||
import seng302.models.BoatGroup;
|
import seng302.models.BoatGroup;
|
||||||
import seng302.models.RaceObject;
|
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
import seng302.models.stream.StreamParser;
|
import seng302.models.stream.StreamParser;
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
import javafx.geometry.Point2D;
|
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Line;
|
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat.
|
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat.
|
||||||
@@ -34,14 +28,6 @@ public class BoatGroup extends Group{
|
|||||||
private double yIncrement;
|
private double yIncrement;
|
||||||
private long lastTimeValid = 0;
|
private long lastTimeValid = 0;
|
||||||
private long framesToMove;
|
private long framesToMove;
|
||||||
private Point2D lastPoint;
|
|
||||||
double oldTime;
|
|
||||||
double newTime;
|
|
||||||
double lastYValue = 0;
|
|
||||||
double lastXValue = 0;
|
|
||||||
private double pixelVelocityX;
|
|
||||||
private double pixelVelocityY;
|
|
||||||
private static final int expectedUpdateInterval = 200;
|
|
||||||
//Graphical objects
|
//Graphical objects
|
||||||
private Yacht boat;
|
private Yacht boat;
|
||||||
private Group lineGroup = new Group();
|
private Group lineGroup = new Group();
|
||||||
@@ -163,21 +149,12 @@ public class BoatGroup extends Group{
|
|||||||
lastTimeValid = timeValid - 200;
|
lastTimeValid = timeValid - 200;
|
||||||
moveTo(newXValue, newYValue, rotation);
|
moveTo(newXValue, newYValue, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rotateTo(rotation);
|
|
||||||
framesToMove = Math.round((frameRate/(1000.0f/(timeValid-lastTimeValid))));
|
framesToMove = Math.round((frameRate/(1000.0f/(timeValid-lastTimeValid))));
|
||||||
|
|
||||||
double dx = newXValue - boatPoly.getLayoutX();
|
double dx = newXValue - boatPoly.getLayoutX();
|
||||||
double dy = newYValue - boatPoly.getLayoutY();
|
double dy = newYValue - boatPoly.getLayoutY();
|
||||||
|
|
||||||
xIncrement = dx/framesToMove;
|
xIncrement = dx/framesToMove;
|
||||||
yIncrement = dy/framesToMove;
|
yIncrement = dy/framesToMove;
|
||||||
|
rotateTo(rotation);
|
||||||
if (id == 106){
|
|
||||||
System.out.println(framesToMove);
|
|
||||||
System.out.println("xIncrement = " + xIncrement);
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityObject.setText(String.format("%.2f m/s", groundSpeed));
|
velocityObject.setText(String.format("%.2f m/s", groundSpeed));
|
||||||
lastTimeValid = timeValid;
|
lastTimeValid = timeValid;
|
||||||
@@ -186,10 +163,6 @@ public class BoatGroup extends Group{
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setTeamNameObjectVisible(Boolean visible) {
|
public void setTeamNameObjectVisible(Boolean visible) {
|
||||||
teamNameObject.setVisible(visible);
|
teamNameObject.setVisible(visible);
|
||||||
}
|
}
|
||||||
@@ -210,20 +183,6 @@ public class BoatGroup extends Group{
|
|||||||
return boat;
|
return boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Returns true if this BoatGroup contains at least one of the given IDs.
|
|
||||||
// *
|
|
||||||
// * @param raceIds The ID's to check the BoatGroup for.
|
|
||||||
// * @return True if the BoatGroup contains at east one of the given IDs, false otherwise.
|
|
||||||
// */
|
|
||||||
// public boolean hasRaceId (long... raceIds) {
|
|
||||||
// for (long id : raceIds) {
|
|
||||||
// if (id == boat.getSourceID())
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all raceIds associated with this group. For BoatGroups the ID's are for the boat.
|
* Returns all raceIds associated with this group. For BoatGroups the ID's are for the boat.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
package seng302.models;
|
|
||||||
|
|
||||||
import javafx.geometry.Point2D;
|
|
||||||
import javafx.scene.Group;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RaceObject defines the behaviour that animated objects whose position is updated from a yacht race data stream must
|
|
||||||
* adhere to.
|
|
||||||
*/
|
|
||||||
public abstract class RaceObject extends Group {
|
|
||||||
|
|
||||||
//Time between sections of race
|
|
||||||
protected static double expectedUpdateInterval = 200;
|
|
||||||
|
|
||||||
protected double rotationalGoal;
|
|
||||||
protected double currentRotation;
|
|
||||||
protected double rotationalVelocity;
|
|
||||||
protected double pixelVelocityX;
|
|
||||||
protected double pixelVelocityY;
|
|
||||||
|
|
||||||
public Point2D getPosition () {
|
|
||||||
return new Point2D(super.getLayoutX(), getLayoutY());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getExpectedUpdateInterval() {
|
|
||||||
return expectedUpdateInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static void setExpectedUpdateInterval(double expectedUpdateInterval) {
|
|
||||||
RaceObject.expectedUpdateInterval = expectedUpdateInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the rotational velocity required to reach the rotationalGoal from the currentRotation.
|
|
||||||
*/
|
|
||||||
protected void calculateRotationalVelocity () {
|
|
||||||
if (Math.abs(rotationalGoal - currentRotation) > 180) {
|
|
||||||
if (rotationalGoal - currentRotation >= 0) {
|
|
||||||
this.rotationalVelocity = ((rotationalGoal - currentRotation) - 360) / expectedUpdateInterval;
|
|
||||||
} else {
|
|
||||||
this.rotationalVelocity = (360 + (rotationalGoal - currentRotation)) / expectedUpdateInterval;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.rotationalVelocity = (rotationalGoal - currentRotation) / expectedUpdateInterval;
|
|
||||||
}
|
|
||||||
//Sometimes the rotation is too large to be realistic. In that case just do it instantly.
|
|
||||||
// if (Math.abs(rotationalVelocity) > 1) {
|
|
||||||
// rotationalVelocity = 0;
|
|
||||||
// rotateTo(rotationalGoal);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) with the given rotation.
|
|
||||||
* @param x X co-ordinate to move the graphics to.
|
|
||||||
* @param y Y co-ordinate to move the graphics to.
|
|
||||||
* @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, double groundSpeed, int... raceIds);
|
|
||||||
|
|
||||||
public abstract void updatePosition (long timeInterval);
|
|
||||||
|
|
||||||
public abstract void moveTo (double x, double y, double rotation);
|
|
||||||
|
|
||||||
public abstract void moveGroupBy(double x, double y, double rotation);
|
|
||||||
|
|
||||||
public abstract boolean hasRaceId (int... raceIds);
|
|
||||||
|
|
||||||
public abstract int[] getRaceIds ();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user