From fd8ed92f886f7f733a67e0f6d0ff6fb87948369d Mon Sep 17 00:00:00 2001 From: Calum Date: Thu, 4 May 2017 13:20:50 +1200 Subject: [PATCH] Fix for wakes on internal data #bug --- src/main/java/seng302/App.java | 2 +- src/main/java/seng302/models/BoatGroup.java | 5 +- src/main/java/seng302/models/Wake.java | 7 +- .../java/seng302/models/MarkGroupTest.java | 65 +++++++++++++++++-- 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 998558ec..dd58de7c 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -55,7 +55,7 @@ public class App extends Application } //Change the StreamReceiver in this else block to change the default data source. else{ - sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); + sr = new StreamReceiver("localhost", 8085, "RaceStream"); } sr.start(); diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 190c537b..78af2408 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -214,18 +214,19 @@ public class BoatGroup extends RaceObject{ pixelVelocityY = dy / expectedUpdateInterval; rotationalGoal = rotation; calculateRotationalVelocity(); + if (wakeGenerationDelay > 0) { wake.rotate(rotationalGoal); rotateTo(rotationalGoal); //Need to test with this removed. rotationalVelocity = 0; wakeGenerationDelay--; } else { - wake.setRotationalVelocity(rotationalVelocity, currentRotation, boat.getVelocity()); + wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity()); } velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); } else { setToInitialLocation = true; - rotationalGoal = rotation;; + rotationalGoal = rotation; moveTo(newXValue, newYValue, rotation); } } diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index eaf28ba5..55d4381c 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -54,14 +54,15 @@ class Wake extends Group { void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocity) { sum -= Math.abs(velocities[(velocityIndices[0] + 10) % 13]); sum += Math.abs(rotationalVelocity); -// System.out.println("sum = " + sum); max = Math.max(max, rotationalVelocity); -// System.out.println("max = " + max); if (sum < (max / 3)) rotate (rotationGoal); //In relatively straight segments the wake snaps to match the boats current position. //This stops the wake from eventually becoming out of sync with the boat. - if (Math.abs(rotationalVelocity) > 0.5) { + //This accounts for rogue rotations that are greater than what would be realistic. Value is kinda rough. + //Basically just for our internal mock. + if (Math.abs(rotationalVelocity) > 0.05) { rotationalVelocity = 0; + rotate(rotationGoal); } //Update the index of the array of recent velocities that each wake uses. Each wake is 3 velocities behind the //next smallest wake. diff --git a/src/test/java/seng302/models/MarkGroupTest.java b/src/test/java/seng302/models/MarkGroupTest.java index ea31bdeb..4a0de560 100644 --- a/src/test/java/seng302/models/MarkGroupTest.java +++ b/src/test/java/seng302/models/MarkGroupTest.java @@ -51,14 +51,71 @@ public class MarkGroupTest { } @Test - public void correctMovementCorrectId () { + public void correctMovementCorrectIdSingle () { double originalX = singleMG.getChildren().get(0).getLayoutX(); double originalY = singleMG.getChildren().get(0).getLayoutY(); - long timeinterval = 100/60; + long timeinterval = 1000/60; double expectedChange = 10 / 200 * timeinterval; singleMG.setDestination(originalX + 10, originalY + 10, 0, 0); singleMG.updatePosition(timeinterval); - Assert.assertTrue(originalX == singleMG.getChildren().get(0).getLayoutX()); - Assert.assertTrue(originalY == singleMG.getChildren().get(0).getLayoutY()); + Assert.assertTrue(originalX + expectedChange == singleMG.getChildren().get(0).getLayoutX()); + Assert.assertTrue(originalY + expectedChange == singleMG.getChildren().get(0).getLayoutY()); + } + + @Test + public void correctMovementCorrectIDGate () { + double originalX1 = gateMG.getChildren().get(0).getLayoutX(); + double originalY1 = gateMG.getChildren().get(0).getLayoutY(); + double originalX2 = gateMG.getChildren().get(1).getLayoutX(); + double originalY2 = gateMG.getChildren().get(1).getLayoutY(); + long timeinterval = 1000/60; + double expectedChange = 10 / 200 * timeinterval; + gateMG.setDestination(originalX1 + 10, originalY1 + 10, 0, 1); + gateMG.setDestination(originalX2 + 10, originalY2 + 10, 0, 2); + gateMG.updatePosition(timeinterval); + Assert.assertTrue(originalX1 + expectedChange == gateMG.getChildren().get(0).getLayoutX()); + Assert.assertTrue(originalY1 + expectedChange == gateMG.getChildren().get(0).getLayoutY()); + Assert.assertTrue(originalX2 + expectedChange == gateMG.getChildren().get(1).getLayoutX()); + Assert.assertTrue(originalY2 + expectedChange == gateMG.getChildren().get(1).getLayoutY()); + } + + @Test + public void correctMovementCorrectIDGateBothIDS () { + double originalX1 = gateMG.getChildren().get(0).getLayoutX(); + double originalY1 = gateMG.getChildren().get(0).getLayoutY(); + double originalX2 = gateMG.getChildren().get(1).getLayoutX(); + double originalY2 = gateMG.getChildren().get(1).getLayoutY(); + long timeinterval = 1000/60; + double expectedChange = 10 / 200 * timeinterval; + gateMG.setDestination(originalX1 + 10, originalY1 + 10, 0, 1, 2); + gateMG.updatePosition(timeinterval); + Assert.assertTrue(originalX1 + expectedChange == gateMG.getChildren().get(0).getLayoutX()); + Assert.assertTrue(originalY1 + expectedChange == gateMG.getChildren().get(0).getLayoutY()); + Assert.assertTrue(originalX2 + expectedChange == gateMG.getChildren().get(1).getLayoutX()); + Assert.assertTrue(originalY2 + expectedChange == gateMG.getChildren().get(1).getLayoutY()); + } + +// @Test +// public void correctMovementOneCorrectIDGateBothIDS () { +// double originalX1 = gateMG.getChildren().get(0).getLayoutX(); +// double originalY1 = gateMG.getChildren().get(0).getLayoutY(); +// double originalX2 = gateMG.getChildren().get(1).getLayoutX(); +// double originalY2 = gateMG.getChildren().get(1).getLayoutY(); +// long timeinterval = 1000/60; +// double expectedChange = 10 / 200 * timeinterval; +// gateMG.setDestination(originalX1 + 10, originalY1 + 10, 0, 1, 3); +// gateMG.updatePosition(timeinterval); +// System.out.println("gateMG.getChildren().get(1).getLayoutX() = " + gateMG.getChildren().get(1).getLayoutX()); +// System.out.println("gateMG.getChildren().get(0).getLayoutX() = " + gateMG.getChildren().get(0).getLayoutX()); +// Assert.assertTrue(originalX1 + expectedChange == gateMG.getChildren().get(0).getLayoutX()); +// Assert.assertTrue(originalY1 + expectedChange == gateMG.getChildren().get(0).getLayoutY()); +// Assert.assertTrue(originalX2 + expectedChange != gateMG.getChildren().get(1).getLayoutX()); +// Assert.assertTrue(originalY2 + expectedChange != gateMG.getChildren().get(1).getLayoutY()); +// } + + + @Test + public void lineUpdatesCorrectly () { + } }