From 7c39368126ebf15519c92cc07a2406a1897038b3 Mon Sep 17 00:00:00 2001 From: Calum Date: Wed, 17 May 2017 17:23:10 +1200 Subject: [PATCH] Removed unnecessary constant --- src/main/java/seng302/models/BoatGroup.java | 43 +++++++++---------- src/main/java/seng302/models/Wake.java | 2 +- .../seng302/models/parsers/StreamParser.java | 5 ++- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index cc6b3e22..d4c08344 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -48,10 +48,6 @@ public class BoatGroup extends RaceObject{ private boolean isMaximized= true; private List lineStorage = new ArrayList<>(); private int setCallCount = 5; - private int frameCount = 90; - - private double lastX; - private double lastY; /** * Creates a BoatGroup with the default triangular boat polygon. @@ -126,8 +122,8 @@ public class BoatGroup extends RaceObject{ * @param dy The amount to move the Y coordinate by */ public void moveGroupBy(double dx, double dy, double rotation) { - boatPoly.setLayoutX(lastX + dx); - boatPoly.setLayoutY(lastY + dy); + boatPoly.setLayoutX(boatPoly.getLayoutX() + dx); + boatPoly.setLayoutY(boatPoly.getLayoutY() + dy); teamNameObject.setLayoutX(teamNameObject.getLayoutX() + dx); teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy); velocityObject.setLayoutX(velocityObject.getLayoutX() + dx); @@ -178,21 +174,26 @@ public class BoatGroup extends RaceObject{ distanceTravelled += Math.abs(dx) + Math.abs(dy); moveGroupBy(dx, dy, rotation); //Draw a new section of the trail every 20 pixels of movement. - if (frameCount-- == 0) { - frameCount = (int) (300 - boat.getVelocity() * 10); + if (distanceTravelled > 20) { + distanceTravelled = 0; if (lastPoint != null) { Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - lastX, - lastY + lastPoint.getX() * 3 - 1000, + lastPoint.getY() * 3 - 1000, + boatPoly.getLayoutX() * 3 - 1000, + boatPoly.getLayoutY() * 3 - 1000 ); l.getStrokeDashArray().setAll(3d, 7d); l.setStroke(boatPoly.getFill()); + if (lastPoint.getX() * 3 - 1000 < 0 || lastPoint.getY() * 3 - 1000 < 0 || boatPoly.getLayoutX() * 3 - 1000 < 0 || boatPoly.getLayoutY() * 3 - 1000 < 0) + l.setVisible(false); + else + l.setVisible(true); + lineGroup.getChildren().add(l); } if (destinationSet) { //Only begin drawing after the first destination is set - lastPoint = new Point2D(lastX, lastY); + lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); } } wake.updatePosition(timeInterval); @@ -213,8 +214,8 @@ public class BoatGroup extends RaceObject{ boat.setVelocity(groundSpeed); if (currentRotation < 0) currentRotation = 360 - currentRotation; - double dx = newXValue - lastX; - double dy = newYValue - lastY; + double dx = newXValue - boatPoly.getLayoutX(); + double dy = newYValue - boatPoly.getLayoutY(); //Check movement is reasonable. Assumes a 1000 * 1000 canvas // if (Math.abs(dx) > 50 || Math.abs(dy) > 50) { // dx = 0; @@ -224,8 +225,6 @@ public class BoatGroup extends RaceObject{ pixelVelocityX = dx / expectedUpdateInterval; pixelVelocityY = dy / expectedUpdateInterval; - lastX = newXValue; - lastY = newYValue; rotationalGoal = rotation; calculateRotationalVelocity(); if (Math.abs(rotationalVelocity) > 0.075) { @@ -250,10 +249,10 @@ public class BoatGroup extends RaceObject{ setCallCount = 5; if (lastPoint != null) { Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - newXValue, - newYValue + lastPoint.getX() * 1.5, + lastPoint.getY() * 1.5, + newXValue * 1.5, + newYValue * 1.5 ); l.getStrokeDashArray().setAll(3d, 7d); l.setStroke(boatPoly.getFill()); @@ -273,7 +272,7 @@ public class BoatGroup extends RaceObject{ double rotation = Math.abs( Math.toDegrees( Math.atan( - (newYValue - lastY) / (newXValue - lastX) + (newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX()) ) ) ); diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index 664e7501..7c9bb14c 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -18,7 +18,7 @@ class Wake extends Group { //The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less. private final double MAX_DIFF = 75; //Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation. - private final int UNIFICATION_SPEED = 500; + private final int UNIFICATION_SPEED = 750; private Arc[] arcs = new Arc[numWakes]; diff --git a/src/main/java/seng302/models/parsers/StreamParser.java b/src/main/java/seng302/models/parsers/StreamParser.java index deea3184..12e4b538 100644 --- a/src/main/java/seng302/models/parsers/StreamParser.java +++ b/src/main/java/seng302/models/parsers/StreamParser.java @@ -17,6 +17,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.PriorityBlockingQueue; /** @@ -36,8 +37,8 @@ public class StreamParser extends Thread{ private static boolean raceFinished = false; private static boolean streamStatus = false; private static long timeSinceStart = -1; - private static Map boats = new HashMap<>(); - private static Map boatsPos = new TreeMap<>(); + private static Map boats = new ConcurrentHashMap<>(); + private static Map boatsPos = new ConcurrentSkipListMap<>(); private static double windDirection = 0; private static String currentTimeString; private static boolean appRunning;