Fixed so the animation timer will exit when all boats finish the race
-Moved listeners for annotation to initialize -Fixed compass arrow not rescaling properly with canvas -Fixed scaling issue with race clock
This commit is contained in:
@@ -25,7 +25,7 @@ public class Constants {
|
|||||||
{new BoatInRace("Oracle Team USA", 30.0, Color.BLUEVIOLET, "Oracle"),
|
{new BoatInRace("Oracle Team USA", 30.0, Color.BLUEVIOLET, "Oracle"),
|
||||||
new BoatInRace("Land Rover BAR", 23.0, Color.BLACK, "BAR"),
|
new BoatInRace("Land Rover BAR", 23.0, Color.BLACK, "BAR"),
|
||||||
new BoatInRace("SoftBank Team Japan", 27.0, Color.RED, "JAP"),
|
new BoatInRace("SoftBank Team Japan", 27.0, Color.RED, "JAP"),
|
||||||
new BoatInRace("Groupama Team France", 25.0, Color.ORANGE, "FRN"),
|
new BoatInRace("Groupama Team France", 25.0, Color.ORANGE, "FRA"),
|
||||||
new BoatInRace("Artemis Racing", 22.5, Color.DARKOLIVEGREEN, "ART"),
|
new BoatInRace("Artemis Racing", 22.5, Color.DARKOLIVEGREEN, "ART"),
|
||||||
new BoatInRace("Emirates Team New Zealand", 62, Color.LIMEGREEN, "ETNZ")};
|
new BoatInRace("Emirates Team New Zealand", 62, Color.LIMEGREEN, "ETNZ")};
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public class RaceController extends Controller{
|
|||||||
@FXML
|
@FXML
|
||||||
Label FPS;
|
Label FPS;
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
TableView<BoatInRace> boatInfoTable;
|
TableView<BoatInRace> boatInfoTable;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -119,7 +118,17 @@ public class RaceController extends Controller{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
//listener for fps
|
||||||
|
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
|
public void changed(ObservableValue<? extends Boolean> ov,
|
||||||
|
Boolean old_val, Boolean new_val) {
|
||||||
|
if (showFPS.isSelected()){
|
||||||
|
FPS.setVisible(true);
|
||||||
|
} else {
|
||||||
|
FPS.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -160,26 +169,15 @@ public class RaceController extends Controller{
|
|||||||
ArrayList<Leg> legs = raceXMLReader.getLegs();
|
ArrayList<Leg> legs = raceXMLReader.getLegs();
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
|
||||||
|
|
||||||
|
//start race
|
||||||
new Thread((race)).start();
|
new Thread((race)).start();
|
||||||
|
|
||||||
//listener for fps
|
|
||||||
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
|
||||||
public void changed(ObservableValue<? extends Boolean> ov,
|
|
||||||
Boolean old_val, Boolean new_val) {
|
|
||||||
if (showFPS.isSelected()){
|
|
||||||
FPS.setVisible(true);
|
|
||||||
} else {
|
|
||||||
FPS.setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//listener for annotation
|
//listener for annotation
|
||||||
showAnno.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
showAnno.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
public void changed(ObservableValue<? extends Boolean> ov,
|
public void changed(ObservableValue<? extends Boolean> ov,
|
||||||
Boolean old_val, Boolean new_val) {
|
Boolean old_val, Boolean new_val) {
|
||||||
raceMap.toggleAnno();
|
raceMap.toggleAnno();
|
||||||
raceMap.drawRaceMap();
|
raceMap.drawRaceMap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class Boat {
|
|||||||
*/
|
*/
|
||||||
public Boat(String name, double velocity, String abbrev) {
|
public Boat(String name, double velocity, String abbrev) {
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
this.velocityProp = new SimpleStringProperty(String.valueOf(velocity* 1.94384));
|
this.velocityProp = new SimpleStringProperty(String.valueOf(velocity));
|
||||||
this.abbrev = abbrev;
|
this.abbrev = abbrev;
|
||||||
this.name = new SimpleStringProperty(name);
|
this.name = new SimpleStringProperty(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ public abstract class Race implements Runnable {
|
|||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
|
|
||||||
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
||||||
protected int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
|
protected int PRERACE_TIME = 5000; //time in milliseconds to pause during pre-race
|
||||||
private boolean timerEnabled = true;
|
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initailiser for Race
|
* Initailiser for Race
|
||||||
@@ -147,7 +147,7 @@ public abstract class Race implements Runnable {
|
|||||||
long remainingSeconds;
|
long remainingSeconds;
|
||||||
long hours;
|
long hours;
|
||||||
|
|
||||||
currentTimeInSeconds = (totalTimeElapsed / 1000) * scaleFactor;
|
currentTimeInSeconds = (totalTimeElapsed * scaleFactor)/ 1000;
|
||||||
minutes = currentTimeInSeconds / 60;
|
minutes = currentTimeInSeconds / 60;
|
||||||
remainingSeconds = currentTimeInSeconds % 60;
|
remainingSeconds = currentTimeInSeconds % 60;
|
||||||
hours = minutes / 60;
|
hours = minutes / 60;
|
||||||
@@ -177,13 +177,11 @@ public abstract class Race implements Runnable {
|
|||||||
*/
|
*/
|
||||||
private void simulateRace() {
|
private void simulateRace() {
|
||||||
|
|
||||||
System.setProperty("javafx.animation.fullspeed", "true");
|
|
||||||
|
|
||||||
new AnimationTimer() {
|
new AnimationTimer() {
|
||||||
|
|
||||||
long timeRaceStarted = System.currentTimeMillis();
|
long timeRaceStarted = System.currentTimeMillis(); //start time of loop
|
||||||
int fps = 0;
|
int fps = 0; //init fps value
|
||||||
long timeCurrent = System.currentTimeMillis();
|
long timeCurrent = System.currentTimeMillis(); //current time
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long arg0) {
|
public void handle(long arg0) {
|
||||||
@@ -205,6 +203,11 @@ public abstract class Race implements Runnable {
|
|||||||
if (controller != null) controller.updateMap(startingBoats);
|
if (controller != null) controller.updateMap(startingBoats);
|
||||||
if (timerEnabled)
|
if (timerEnabled)
|
||||||
updateTime(calcTimer());
|
updateTime(calcTimer());
|
||||||
|
} else {
|
||||||
|
//Exit animation timer
|
||||||
|
updateTime(calcTimer());
|
||||||
|
updateFPS(0); //race ended so fps = 0
|
||||||
|
stop(); //exit animation timer
|
||||||
}
|
}
|
||||||
fps++;
|
fps++;
|
||||||
if ((System.currentTimeMillis()-timeCurrent) > 1000){
|
if ((System.currentTimeMillis()-timeCurrent) > 1000){
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package seng302.Model;
|
|||||||
|
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -17,6 +18,7 @@ import java.awt.*;
|
|||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This creates a JavaFX Canvas that is fills it's parent.
|
* This creates a JavaFX Canvas that is fills it's parent.
|
||||||
@@ -200,8 +202,8 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//display wind direction arrow - specify origin point and angle
|
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
||||||
displayArrow(new GraphCoordinate(500, 20), 100);
|
displayArrow(new GraphCoordinate((int)getWidth()-40, 40), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user