mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'add-fps-counter'
This commit is contained in:
@@ -45,7 +45,7 @@ public class CanvasController {
|
|||||||
@FXML
|
@FXML
|
||||||
private BoatPositionController teamPositionsController;
|
private BoatPositionController teamPositionsController;
|
||||||
@FXML
|
@FXML
|
||||||
private CheckBox toggleAnnotation;
|
private CheckBox toggleAnnotation, toggleFps;
|
||||||
|
|
||||||
private Race race;
|
private Race race;
|
||||||
private GraphicsContext gc;
|
private GraphicsContext gc;
|
||||||
@@ -61,6 +61,7 @@ public class CanvasController {
|
|||||||
private final int SCALE = 16000;
|
private final int SCALE = 16000;
|
||||||
|
|
||||||
private boolean annotationCheck = true;
|
private boolean annotationCheck = true;
|
||||||
|
private boolean displayFps = true;
|
||||||
|
|
||||||
///test
|
///test
|
||||||
private HashSet<Integer> headingTest = new HashSet<>();
|
private HashSet<Integer> headingTest = new HashSet<>();
|
||||||
@@ -78,15 +79,19 @@ public class CanvasController {
|
|||||||
// overriding the handle so that it can clean canvas and redraw boats and course marks
|
// overriding the handle so that it can clean canvas and redraw boats and course marks
|
||||||
AnimationTimer timer = new AnimationTimer() {
|
AnimationTimer timer = new AnimationTimer() {
|
||||||
private long lastUpdate = 0;
|
private long lastUpdate = 0;
|
||||||
|
private long lastFpsUpdate = 0;
|
||||||
|
private int lastFpsCount = 0;
|
||||||
|
private int fpsCount = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
if (now - lastUpdate >= 33000000){
|
if (true){ //if statement for limiting refresh rate if needed
|
||||||
gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
|
gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
|
||||||
gc.setFill(Color.SKYBLUE);
|
gc.setFill(Color.SKYBLUE);
|
||||||
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
|
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
|
||||||
drawCourse();
|
drawCourse();
|
||||||
drawBoats();
|
drawBoats();
|
||||||
|
drawFps(lastFpsCount);
|
||||||
|
|
||||||
// If race has started, draw the boats and play the timeline
|
// If race has started, draw the boats and play the timeline
|
||||||
if (race.getRaceTime() > 1){
|
if (race.getRaceTime() > 1){
|
||||||
@@ -98,6 +103,12 @@ public class CanvasController {
|
|||||||
pauseTimelines();
|
pauseTimelines();
|
||||||
}
|
}
|
||||||
lastUpdate = now;
|
lastUpdate = now;
|
||||||
|
fpsCount ++;
|
||||||
|
if (now - lastFpsUpdate >= 1000000000){
|
||||||
|
lastFpsCount = fpsCount;
|
||||||
|
fpsCount = 0;
|
||||||
|
lastFpsUpdate = now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -139,6 +150,12 @@ public class CanvasController {
|
|||||||
annotationCheck = !annotationCheck;
|
annotationCheck = !annotationCheck;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
toggleFps.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||||
|
displayFps = !displayFps;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
||||||
double windDirection = new ConfigParser("/config.xml").getWindDirection();
|
double windDirection = new ConfigParser("/config.xml").getWindDirection();
|
||||||
@@ -256,6 +273,15 @@ public class CanvasController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawFps(int fps){
|
||||||
|
if (displayFps){
|
||||||
|
gc.setFill(Color.BLACK);
|
||||||
|
gc.setFont(new Font(14));
|
||||||
|
gc.setLineWidth(3);
|
||||||
|
gc.fillText(fps + " FPS", 5, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws all the boats.
|
* Draws all the boats.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ public class Race {
|
|||||||
* @param boat The boat that has finished the race
|
* @param boat The boat that has finished the race
|
||||||
*/
|
*/
|
||||||
public void setBoatFinished(Boat boat){
|
public void setBoatFinished(Boat boat){
|
||||||
System.out.println(boat.getTeamName() + " finished");
|
|
||||||
this.finishingOrder.add(boat);
|
this.finishingOrder.add(boat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3">
|
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3">
|
||||||
<children>
|
<children>
|
||||||
<Label layoutX="11.0" layoutY="259.0" text="Team Position" />
|
<Label layoutX="11.0" layoutY="259.0" text="Team Position" />
|
||||||
<Label layoutX="13.0" layoutY="432.0" text="Annotation toggle" />
|
<Label layoutX="13.0" layoutY="432.0" text="Settings" />
|
||||||
<Label layoutX="11.0" layoutY="14.0" text="Timer" />
|
<Label layoutX="11.0" layoutY="14.0" text="Timer" />
|
||||||
<Label layoutX="11.0" layoutY="88.0" text="Wind direction" />
|
<Label layoutX="11.0" layoutY="88.0" text="Wind direction" />
|
||||||
<Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" />
|
<Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" />
|
||||||
@@ -45,7 +45,8 @@
|
|||||||
<fx:include fx:id="teamPositions" source="TeamPositions.fxml" />
|
<fx:include fx:id="teamPositions" source="TeamPositions.fxml" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
<CheckBox fx:id="toggleAnnotation" layoutX="27.0" layoutY="462.0" mnemonicParsing="false" text="Toggle annotation" />
|
<CheckBox fx:id="toggleAnnotation" layoutX="27.0" layoutY="462.0" mnemonicParsing="false" selected="true" text="Show annotations" />
|
||||||
|
<CheckBox fx:id="toggleFps" layoutX="27.0" layoutY="488.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="143.0" selected="true" text="Show FPS" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
<AnchorPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" GridPane.columnIndex="1" GridPane.rowSpan="3">
|
<AnchorPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" GridPane.columnIndex="1" GridPane.rowSpan="3">
|
||||||
|
|||||||
Reference in New Issue
Block a user