From 9cedbeb6f650dedb1283e05713b30058a6a17b75 Mon Sep 17 00:00:00 2001 From: Peter Galloway Date: Wed, 26 Jul 2017 22:02:46 +1200 Subject: [PATCH 1/2] Fixed latency issues caused by clientside movement packets queueing up but currently the trails aren't working anymore #fix #refactor --- src/main/java/seng302/fxObjects/BoatGroup.java | 14 +++++++------- .../java/seng302/gameServer/MainServerThread.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/seng302/fxObjects/BoatGroup.java b/src/main/java/seng302/fxObjects/BoatGroup.java index 8faaca60..b83e99ba 100644 --- a/src/main/java/seng302/fxObjects/BoatGroup.java +++ b/src/main/java/seng302/fxObjects/BoatGroup.java @@ -210,14 +210,14 @@ public class BoatGroup extends Group { double groundSpeed, long timeValid, double frameRate) { if (lastTimeValid == 0) { lastTimeValid = timeValid - 200; - moveTo(newXValue, newYValue, 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; + moveTo(newXValue, newYValue, 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; destinationSet = true; diff --git a/src/main/java/seng302/gameServer/MainServerThread.java b/src/main/java/seng302/gameServer/MainServerThread.java index 85d5c698..f72b17fd 100644 --- a/src/main/java/seng302/gameServer/MainServerThread.java +++ b/src/main/java/seng302/gameServer/MainServerThread.java @@ -23,7 +23,7 @@ import java.util.logging.Logger; public class MainServerThread extends Observable implements Runnable, ClientConnectionDelegate{ private static final int PORT = 4942; - private static final Integer CLIENT_UPDATES_PER_SECOND = 5; + private static final Integer CLIENT_UPDATES_PER_SECOND = 10; private static final int LOG_LEVEL = 1; private Thread thread; From b56fa5cba328bb80ac983227ec1f94048a2d2e4e Mon Sep 17 00:00:00 2001 From: Peter Galloway Date: Wed, 26 Jul 2017 22:42:37 +1200 Subject: [PATCH 2/2] refactored to make boat trails work again #fix #refactor --- .../seng302/controllers/CanvasController.java | 5 +- .../java/seng302/fxObjects/BoatGroup.java | 70 +++++++------------ 2 files changed, 26 insertions(+), 49 deletions(-) diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 03d42872..f30969a5 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -250,11 +250,8 @@ public class CanvasController { // some raceObjects will have multiple ID's (for instance gate marks) //checking if the current "ID" has any updates associated with it if (ClientPacketParser.boatLocations.containsKey(boatGroup.getRaceId())) { - if (boatGroup.isStopped()) { - updateBoatGroup(boatGroup); - } + updateBoatGroup(boatGroup); } - boatGroup.move(); } for (MarkGroup markGroup : markGroups) { for (Long id : markGroup.getRaceIds()) { diff --git a/src/main/java/seng302/fxObjects/BoatGroup.java b/src/main/java/seng302/fxObjects/BoatGroup.java index b83e99ba..2446f9d4 100644 --- a/src/main/java/seng302/fxObjects/BoatGroup.java +++ b/src/main/java/seng302/fxObjects/BoatGroup.java @@ -163,18 +163,33 @@ public class BoatGroup extends Group { boatPoly.getTransforms().setAll(new Rotate(rotation)); } - public void move() { - double dx = xIncrement * framesToMove; - double dy = yIncrement * framesToMove; + /** + * Sets the destination of the boat and the headng it should have once it reaches + * + * @param newXValue The X co-ordinate the boat needs to move to. + * @param newYValue The Y co-ordinate the boat needs to move to. + * @param rotation Rotation to move graphics to. + * @param timeValid the time the position values are valid for + */ + public void setDestination(double newXValue, double newYValue, double rotation, + double groundSpeed, long timeValid, double frameRate) { - distanceTravelled += Math.abs(dx) + Math.abs(dy); - moveGroupBy(xIncrement, yIncrement); - framesToMove = framesToMove - 1; + destinationSet = true; + Double dx = Math.abs(boatPoly.getLayoutX() - newXValue); + Double dy = Math.abs(boatPoly.getLayoutY() - newYValue); + moveTo(newXValue, newYValue, rotation); - if (framesToMove <= 0) { - isStopped = true; - } - if (distanceTravelled > 70 && isPlayer) { + + rotateTo(rotation); + wake.setRotation(rotation, groundSpeed); + boat.setVelocity(groundSpeed); + isStopped = false; + lastRotation = rotation; + boatAnnotations.update(); + + distanceTravelled += Math.sqrt((dx * dx) + (dy * dy)); + + if (distanceTravelled > 10 && isPlayer) { distanceTravelled = 0d; if (lastPoint != null) { @@ -190,45 +205,10 @@ public class BoatGroup extends Group { l.setCacheHint(CacheHint.SPEED); lineGroup.getChildren().add(l); } - if (destinationSet) { lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); } } -// wake.updatePosition(); - } - - /** - * Sets the destination of the boat and the headng it should have once it reaches - * - * @param newXValue The X co-ordinate the boat needs to move to. - * @param newYValue The Y co-ordinate the boat needs to move to. - * @param rotation Rotation to move graphics to. - * @param timeValid the time the position values are valid for - */ - public void setDestination(double newXValue, double newYValue, double rotation, - double groundSpeed, long timeValid, double frameRate) { - if (lastTimeValid == 0) { - lastTimeValid = timeValid - 200; - } - moveTo(newXValue, newYValue, 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; - - destinationSet = true; - - rotateTo(rotation); -// wake.rotate(rotation); - wake.setRotation(rotation, groundSpeed); - boat.setVelocity(groundSpeed); - lastTimeValid = timeValid; - isStopped = false; - lastRotation = rotation; - boatAnnotations.update(); }