mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
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:
@@ -14,7 +14,7 @@ import javafx.scene.canvas.Canvas;
|
|||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Text;
|
||||||
import seng302.fxObjects.BoatGroup;
|
import seng302.fxObjects.BoatGroup;
|
||||||
import seng302.models.Colors;
|
import seng302.models.Colors;
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
@@ -64,6 +64,7 @@ public class CanvasController {
|
|||||||
|
|
||||||
private List<MarkGroup> markGroups = new ArrayList<>();
|
private List<MarkGroup> markGroups = new ArrayList<>();
|
||||||
private List<BoatGroup> boatGroups = new ArrayList<>();
|
private List<BoatGroup> boatGroups = new ArrayList<>();
|
||||||
|
private Text FPSdisplay = new Text();
|
||||||
|
|
||||||
//FRAME RATE
|
//FRAME RATE
|
||||||
private Double frameRate = 60.0;
|
private Double frameRate = 60.0;
|
||||||
@@ -102,6 +103,10 @@ public class CanvasController {
|
|||||||
gc.fillRect(0,0, CANVAS_WIDTH, CANVAS_HEIGHT);
|
gc.fillRect(0,0, CANVAS_WIDTH, CANVAS_HEIGHT);
|
||||||
gc.restore();
|
gc.restore();
|
||||||
fitMarksToCanvas();
|
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
|
// 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){
|
private void drawFps(int fps){
|
||||||
if (raceViewController.isDisplayFps()){
|
if (raceViewController.isDisplayFps()){
|
||||||
gc.clearRect(5,5,50,20);
|
FPSdisplay.setVisible(true);
|
||||||
gc.setFill(Color.SKYBLUE);
|
FPSdisplay.setText(String.format("%d FPS", fps));
|
||||||
gc.fillRect(4,4,51,21);
|
|
||||||
gc.setFill(Color.BLACK);
|
|
||||||
gc.setFont(new Font(14));
|
|
||||||
gc.setLineWidth(3);
|
|
||||||
gc.fillText(fps + " FPS", 5, 20);
|
|
||||||
} else {
|
} else {
|
||||||
gc.clearRect(5,5,50,20);
|
FPSdisplay.setVisible(false);
|
||||||
gc.setFill(Color.SKYBLUE);
|
|
||||||
gc.fillRect(4,4,51,21);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ public class BoatAnnotations extends Group{
|
|||||||
private Text legTimeObject;
|
private Text legTimeObject;
|
||||||
private Long lastMarkTime;
|
private Long lastMarkTime;
|
||||||
|
|
||||||
|
public enum Annotations {
|
||||||
|
TEAM_NAME,
|
||||||
|
VELOCITY_OBJECT,
|
||||||
|
TTNEXT,
|
||||||
|
LEG_TIME,
|
||||||
|
}
|
||||||
|
|
||||||
BoatAnnotations (Yacht boat, Color theme) {
|
BoatAnnotations (Yacht boat, Color theme) {
|
||||||
super.setCache(true);
|
super.setCache(true);
|
||||||
background.setX(15d);
|
background.setX(15d);
|
||||||
@@ -40,7 +47,7 @@ public class BoatAnnotations extends Group{
|
|||||||
background.setHeight(55);
|
background.setHeight(55);
|
||||||
background.setArcHeight(10);
|
background.setArcHeight(10);
|
||||||
background.setArcWidth(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.setStroke(theme);
|
||||||
background.setStrokeWidth(2);
|
background.setStrokeWidth(2);
|
||||||
background.setCache(true);
|
background.setCache(true);
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public class BoatGroup extends Group {
|
|||||||
private Point2D lastPoint;
|
private Point2D lastPoint;
|
||||||
private boolean destinationSet;
|
private boolean destinationSet;
|
||||||
private Color textColor = Color.RED;
|
private Color textColor = Color.RED;
|
||||||
|
private double rotationalVelocity;
|
||||||
|
private double rotation;
|
||||||
|
|
||||||
private BoatAnnotations boatAnnotations;
|
private BoatAnnotations boatAnnotations;
|
||||||
|
|
||||||
@@ -122,35 +124,6 @@ public class BoatGroup extends Group {
|
|||||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||||
boatPoly.setCache(true);
|
boatPoly.setCache(true);
|
||||||
boatPoly.setCacheHint(CacheHint.SPEED);
|
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);
|
boatAnnotations = new BoatAnnotations(boat, color);
|
||||||
|
|
||||||
wake = new Wake(0, -BOAT_HEIGHT);
|
wake = new Wake(0, -BOAT_HEIGHT);
|
||||||
@@ -181,10 +154,6 @@ public class BoatGroup extends Group {
|
|||||||
boatPoly.setLayoutY(boatPoly.getLayoutY() + dy);
|
boatPoly.setLayoutY(boatPoly.getLayoutY() + dy);
|
||||||
boatAnnotations.setLayoutX(boatAnnotations.getLayoutX() + dx);
|
boatAnnotations.setLayoutX(boatAnnotations.getLayoutX() + dx);
|
||||||
boatAnnotations.setLayoutY(boatAnnotations.getLayoutY() + dy);
|
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.setLayoutX(wake.getLayoutX() + dx);
|
||||||
wake.setLayoutY(wake.getLayoutY() + dy);
|
wake.setLayoutY(wake.getLayoutY() + dy);
|
||||||
}
|
}
|
||||||
@@ -214,6 +183,7 @@ public class BoatGroup extends Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void rotateTo(double rotation) {
|
private void rotateTo(double rotation) {
|
||||||
|
this.rotation = rotation;
|
||||||
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +256,7 @@ public class BoatGroup extends Group {
|
|||||||
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rotateTo(rotation + rotationalVelocity * 1000 / 60);
|
||||||
wake.updatePosition(1000 / 60);
|
wake.updatePosition(1000 / 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +265,7 @@ public class BoatGroup extends Group {
|
|||||||
* currentRotation.
|
* currentRotation.
|
||||||
*/
|
*/
|
||||||
private Double calculateRotationalVelocity(Double rotationalGoal) {
|
private Double calculateRotationalVelocity(Double rotationalGoal) {
|
||||||
Double rotationalVelocity = 0.0;
|
Double rotationalVelocity;
|
||||||
|
|
||||||
if (Math.abs(rotationalGoal - lastRotation) > 180) {
|
if (Math.abs(rotationalGoal - lastRotation) > 180) {
|
||||||
if (rotationalGoal - lastRotation >= 0.0) {
|
if (rotationalGoal - lastRotation >= 0.0) {
|
||||||
@@ -306,12 +276,6 @@ public class BoatGroup extends Group {
|
|||||||
} else {
|
} else {
|
||||||
rotationalVelocity = (rotationalGoal - lastRotation) / 200;
|
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;
|
return rotationalVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +302,7 @@ public class BoatGroup extends Group {
|
|||||||
|
|
||||||
destinationSet = true;
|
destinationSet = true;
|
||||||
|
|
||||||
Double rotationalVelocity = calculateRotationalVelocity(rotation);
|
rotationalVelocity = calculateRotationalVelocity(rotation);
|
||||||
|
|
||||||
// updateTimeTillNextMark();
|
// updateTimeTillNextMark();
|
||||||
// updateLastMarkRoundingTime();
|
// updateLastMarkRoundingTime();
|
||||||
@@ -348,7 +312,7 @@ public class BoatGroup extends Group {
|
|||||||
wake.rotate(rotation);
|
wake.rotate(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
rotateTo(rotation);
|
//rotateTo(rotation);
|
||||||
boat.setVelocity(groundSpeed);
|
boat.setVelocity(groundSpeed);
|
||||||
wake.setRotationalVelocity(rotationalVelocity, groundSpeed);
|
wake.setRotationalVelocity(rotationalVelocity, groundSpeed);
|
||||||
lastTimeValid = timeValid;
|
lastTimeValid = timeValid;
|
||||||
|
|||||||
@@ -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.
|
//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 = new Arc(0, 0, 0, 0, -110, 40);
|
||||||
arc.setCache(true);
|
arc.setCache(true);
|
||||||
arc.setCacheHint(CacheHint.SPEED);
|
arc.setCacheHint(CacheHint.SCALE_AND_ROTATE);
|
||||||
arc.setType(ArcType.OPEN);
|
arc.setType(ArcType.OPEN);
|
||||||
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
|
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
|
||||||
arc.setStrokeWidth(3.0);
|
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
|
//type 1 is a racing yacht and type 3 is a mark, needed for updating positions of the mark and boat
|
||||||
if (deviceType == 1){
|
if (deviceType == 1){
|
||||||
|
Yacht boat = boats.get((int) boatId);
|
||||||
|
boat.setVelocity(groundSpeed);
|
||||||
BoatPositionPacket boatPacket = new BoatPositionPacket(boatId, timeValid, lat, lon, heading, groundSpeed);
|
BoatPositionPacket boatPacket = new BoatPositionPacket(boatId, timeValid, lat, lon, heading, groundSpeed);
|
||||||
|
|
||||||
//add a new priority que to the boatPositions HashMap
|
//add a new priority que to the boatPositions HashMap
|
||||||
|
|||||||
Reference in New Issue
Block a user