diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 22096b58..26d7fec7 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -188,18 +188,12 @@ public class CanvasController { } private void updateBoatGroup(BoatGroup boatGroup) { - System.out.println("StreamParser.boatPositions.size()2 = " + StreamParser.boatPositions.size()); PriorityBlockingQueue movementQueue = StreamParser.boatPositions.get(boatGroup.getRaceId()); // giving the movementQueue a 5 packet buffer to account for slightly out of order packets - if (movementQueue.size() > 5){ + if (movementQueue.size() > 0){ try { BoatPositionPacket positionPacket = movementQueue.take(); 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(); boatGroup.setDestination(p2d.getX(), p2d.getY(), heading, positionPacket.getGroundSpeed(), positionPacket.getTimeValid(), frameRate, boatGroup.getRaceId()); } catch (InterruptedException e){ @@ -389,31 +383,6 @@ public class CanvasController { 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 allPoints = StreamParser.getXmlObject().getRaceXML().getCompoundMarks(); -// List 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) { return findScaledXY (unscaled.getLatitude(), unscaled.getLongitude()); } diff --git a/src/main/java/seng302/controllers/Controller.java b/src/main/java/seng302/controllers/Controller.java index 00397dee..c27e6192 100644 --- a/src/main/java/seng302/controllers/Controller.java +++ b/src/main/java/seng302/controllers/Controller.java @@ -133,7 +133,6 @@ public class Controller implements Initializable { public void switchToRaceView() { switchedToRaceView = true; setContentPane("/views/RaceView.fxml"); - System.out.println("boatPositions.size()1 = " + boatPositions.size()); StreamParser.boatPositions.clear(); } diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index 8a09619e..85029772 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -25,7 +25,6 @@ import seng302.controllers.annotations.ImportantAnnotationController; import seng302.controllers.annotations.ImportantAnnotationDelegate; import seng302.controllers.annotations.ImportantAnnotationsState; import seng302.models.BoatGroup; -import seng302.models.RaceObject; import seng302.models.Yacht; import seng302.models.stream.StreamParser; diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 3de6d3a8..0218a70b 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -1,16 +1,10 @@ package seng302.models; -import javafx.geometry.Point2D; import javafx.scene.Group; import javafx.scene.paint.Color; -import javafx.scene.shape.Line; import javafx.scene.shape.Polygon; import javafx.scene.text.Text; 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. @@ -34,14 +28,6 @@ public class BoatGroup extends Group{ private double yIncrement; private long lastTimeValid = 0; 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 private Yacht boat; private Group lineGroup = new Group(); @@ -163,21 +149,12 @@ public class BoatGroup extends Group{ lastTimeValid = timeValid - 200; moveTo(newXValue, newYValue, rotation); } - - - rotateTo(rotation); framesToMove = Math.round((frameRate/(1000.0f/(timeValid-lastTimeValid)))); - double dx = newXValue - boatPoly.getLayoutX(); double dy = newYValue - boatPoly.getLayoutY(); - xIncrement = dx/framesToMove; yIncrement = dy/framesToMove; - - if (id == 106){ - System.out.println(framesToMove); - System.out.println("xIncrement = " + xIncrement); - } + rotateTo(rotation); velocityObject.setText(String.format("%.2f m/s", groundSpeed)); lastTimeValid = timeValid; @@ -186,10 +163,6 @@ public class BoatGroup extends Group{ - - - - public void setTeamNameObjectVisible(Boolean visible) { teamNameObject.setVisible(visible); } @@ -210,20 +183,6 @@ public class BoatGroup extends Group{ 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. * diff --git a/src/main/java/seng302/models/RaceObject.java b/src/main/java/seng302/models/RaceObject.java deleted file mode 100644 index 706bfd48..00000000 --- a/src/main/java/seng302/models/RaceObject.java +++ /dev/null @@ -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 (); -}