Made FPS marker not draw on canvas.

Have to revert the use of the observer pattern since there is no time to change how and when data is passed.
This commit is contained in:
Calum
2017-05-24 17:17:06 +12:00
parent d22d758757
commit 14a7305a2d
5 changed files with 27 additions and 56 deletions
@@ -14,7 +14,7 @@ import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import seng302.fxObjects.BoatGroup;
import seng302.models.Colors;
import seng302.models.Yacht;
@@ -64,6 +64,7 @@ public class CanvasController {
private List<MarkGroup> markGroups = new ArrayList<>();
private List<BoatGroup> boatGroups = new ArrayList<>();
private Text FPSdisplay = new Text();
//FRAME RATE
private Double frameRate = 60.0;
@@ -102,6 +103,10 @@ public class CanvasController {
gc.fillRect(0,0, CANVAS_WIDTH, CANVAS_HEIGHT);
gc.restore();
fitMarksToCanvas();
FPSdisplay.setLayoutX(5);
FPSdisplay.setLayoutY(20);
FPSdisplay.setStrokeWidth(2);
group.getChildren().add(FPSdisplay);
// TODO: 1/05/17 wmu16 - Change this call to now draw the marks as from the xml
@@ -315,17 +320,10 @@ public class CanvasController {
private void drawFps(int fps){
if (raceViewController.isDisplayFps()){
gc.clearRect(5,5,50,20);
gc.setFill(Color.SKYBLUE);
gc.fillRect(4,4,51,21);
gc.setFill(Color.BLACK);
gc.setFont(new Font(14));
gc.setLineWidth(3);
gc.fillText(fps + " FPS", 5, 20);
FPSdisplay.setVisible(true);
FPSdisplay.setText(String.format("%d FPS", fps));
} else {
gc.clearRect(5,5,50,20);
gc.setFill(Color.SKYBLUE);
gc.fillRect(4,4,51,21);
FPSdisplay.setVisible(false);
}
}
@@ -32,6 +32,13 @@ public class BoatAnnotations extends Group{
private Text legTimeObject;
private Long lastMarkTime;
public enum Annotations {
TEAM_NAME,
VELOCITY_OBJECT,
TTNEXT,
LEG_TIME,
}
BoatAnnotations (Yacht boat, Color theme) {
super.setCache(true);
background.setX(15d);
@@ -40,7 +47,7 @@ public class BoatAnnotations extends Group{
background.setHeight(55);
background.setArcHeight(10);
background.setArcWidth(10);
background.setFill(new Color(1, 1, 1, 0.25));
background.setFill(new Color(1, 1, 1, 0.35));
background.setStroke(theme);
background.setStrokeWidth(2);
background.setCache(true);
+7 -43
View File
@@ -48,6 +48,8 @@ public class BoatGroup extends Group {
private Point2D lastPoint;
private boolean destinationSet;
private Color textColor = Color.RED;
private double rotationalVelocity;
private double rotation;
private BoatAnnotations boatAnnotations;
@@ -122,35 +124,6 @@ public class BoatGroup extends Group {
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED);
// teamNameObject = getTextObject(boat.getShortName(), textColor);
// velocityObject = getTextObject(boat.getVelocity().toString(), textColor);
//
// teamNameObject.setX(TEAMNAME_X_OFFSET);
// teamNameObject.setY(TEAMNAME_Y_OFFSET);
// teamNameObject.relocate(teamNameObject.getX(), teamNameObject.getY());
//
// velocityObject.setX(VELOCITY_X_OFFSET);
// velocityObject.setY(VELOCITY_Y_OFFSET);
// velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
////
//// updateLastMarkRoundingTime();
//// updateTimeTillNextMark();
//
// if (estTimeToNextMarkObject != null) {
// estTimeToNextMarkObject.setX(ESTTIMETONEXTMARK_X_OFFSET);
// estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET);
// estTimeToNextMarkObject
// .relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY());
// }
//
// if (legTimeObject != null) {
// legTimeObject.setX(LEGTIME_X_OFFSET);
// legTimeObject.setY(LEGTIME_Y_OFFSET);
// legTimeObject.relocate(legTimeObject.getX(), legTimeObject.getY());
//
// }
boatAnnotations = new BoatAnnotations(boat, color);
wake = new Wake(0, -BOAT_HEIGHT);
@@ -181,10 +154,6 @@ public class BoatGroup extends Group {
boatPoly.setLayoutY(boatPoly.getLayoutY() + dy);
boatAnnotations.setLayoutX(boatAnnotations.getLayoutX() + dx);
boatAnnotations.setLayoutY(boatAnnotations.getLayoutY() + dy);
// for (Node node : boatAnnotations.getkiddies()) {
// node.setLayoutX(node.getLayoutX() + dx);
// node.setLayoutY(node.getLayoutY() + dy);
// }
wake.setLayoutX(wake.getLayoutX() + dx);
wake.setLayoutY(wake.getLayoutY() + dy);
}
@@ -214,6 +183,7 @@ public class BoatGroup extends Group {
}
private void rotateTo(double rotation) {
this.rotation = rotation;
boatPoly.getTransforms().setAll(new Rotate(rotation));
}
@@ -286,7 +256,7 @@ public class BoatGroup extends Group {
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
}
}
rotateTo(rotation + rotationalVelocity * 1000 / 60);
wake.updatePosition(1000 / 60);
}
@@ -295,7 +265,7 @@ public class BoatGroup extends Group {
* currentRotation.
*/
private Double calculateRotationalVelocity(Double rotationalGoal) {
Double rotationalVelocity = 0.0;
Double rotationalVelocity;
if (Math.abs(rotationalGoal - lastRotation) > 180) {
if (rotationalGoal - lastRotation >= 0.0) {
@@ -306,12 +276,6 @@ public class BoatGroup extends Group {
} else {
rotationalVelocity = (rotationalGoal - lastRotation) / 200;
}
//Sometimes the rotation is too large to be realistic. In that case just do it instantly.
if (Math.abs(rotationalVelocity) > 1) {
rotationalVelocity = 0.0;
}
return rotationalVelocity;
}
@@ -338,7 +302,7 @@ public class BoatGroup extends Group {
destinationSet = true;
Double rotationalVelocity = calculateRotationalVelocity(rotation);
rotationalVelocity = calculateRotationalVelocity(rotation);
// updateTimeTillNextMark();
// updateLastMarkRoundingTime();
@@ -348,7 +312,7 @@ public class BoatGroup extends Group {
wake.rotate(rotation);
}
rotateTo(rotation);
//rotateTo(rotation);
boat.setVelocity(groundSpeed);
wake.setRotationalVelocity(rotationalVelocity, groundSpeed);
lastTimeValid = timeValid;
+1 -1
View File
@@ -40,7 +40,7 @@ class Wake extends Group {
//Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg.
arc = new Arc(0, 0, 0, 0, -110, 40);
arc.setCache(true);
arc.setCacheHint(CacheHint.SPEED);
arc.setCacheHint(CacheHint.SCALE_AND_ROTATE);
arc.setType(ArcType.OPEN);
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
arc.setStrokeWidth(3.0);
@@ -394,6 +394,8 @@ public class StreamParser extends Thread{
//type 1 is a racing yacht and type 3 is a mark, needed for updating positions of the mark and boat
if (deviceType == 1){
Yacht boat = boats.get((int) boatId);
boat.setVelocity(groundSpeed);
BoatPositionPacket boatPacket = new BoatPositionPacket(boatId, timeValid, lat, lon, heading, groundSpeed);
//add a new priority que to the boatPositions HashMap