Added fixed opacity points of fading and modified race time to keep updating when the race is finished. Pair [jjg64, cbt24] Story [758]
This commit is contained in:
@@ -28,10 +28,9 @@ public class BoatInRace extends Boat {
|
|||||||
private StringProperty currentLegName;
|
private StringProperty currentLegName;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private StringProperty position;
|
private StringProperty position;
|
||||||
|
|
||||||
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
||||||
private long nextValidTime = 0;
|
private long nextValidTime = 0;
|
||||||
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 2 seconds
|
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 1 seconds
|
||||||
private final int TRACK_POINT_LIMIT = 10;
|
private final int TRACK_POINT_LIMIT = 10;
|
||||||
private boolean trackVisible = false;
|
private boolean trackVisible = false;
|
||||||
|
|
||||||
@@ -261,7 +260,7 @@ public class BoatInRace extends Boat {
|
|||||||
|
|
||||||
public boolean addTrackPoint(GPSCoordinate coordinate) {
|
public boolean addTrackPoint(GPSCoordinate coordinate) {
|
||||||
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
||||||
if (added && this.started && !this.finished) {
|
if (added && this.started) {
|
||||||
nextValidTime = System.currentTimeMillis() + TRACK_POINT_TIME_INTERVAL;
|
nextValidTime = System.currentTimeMillis() + TRACK_POINT_TIME_INTERVAL;
|
||||||
track.add(coordinate);
|
track.add(coordinate);
|
||||||
if (track.size() > TRACK_POINT_LIMIT) {
|
if (track.size() > TRACK_POINT_LIMIT) {
|
||||||
@@ -282,4 +281,11 @@ public class BoatInRace extends Boat {
|
|||||||
public void setTrackVisible(boolean trackVisible) {
|
public void setTrackVisible(boolean trackVisible) {
|
||||||
this.trackVisible = trackVisible;
|
this.trackVisible = trackVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getTrackPointColour(int queuePos) {
|
||||||
|
float alphaScale = 1f / (float) (TRACK_POINT_LIMIT);
|
||||||
|
float alpha = 1f - (float) (this.track.size() - queuePos) * alphaScale;
|
||||||
|
Color boatColour = this.colour;
|
||||||
|
return new Color(boatColour.getRed(), boatColour.getBlue(), boatColour.getGreen(), alpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,15 +209,17 @@ 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
|
|
||||||
}
|
}
|
||||||
|
controller.updateMap(startingBoats);
|
||||||
|
// } 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) {
|
||||||
updateFPS(fps);
|
updateFPS(fps);
|
||||||
|
|||||||
@@ -290,10 +290,13 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void drawTrackPoint(BoatInRace boat) {
|
private void drawTrackPoint(BoatInRace boat) {
|
||||||
|
int queuePos = 0;
|
||||||
for (GPSCoordinate coordinate : boat.getTrack()) {
|
for (GPSCoordinate coordinate : boat.getTrack()) {
|
||||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
||||||
gc.setFill(boat.getColour());
|
Color colour = boat.getTrackPointColour(queuePos);
|
||||||
|
gc.setFill(colour);
|
||||||
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
|
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
|
||||||
|
queuePos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user