Boats now tack only every 15 seconds (see tackPeriod variable).
Also doesn't attempt to calculate VMG (expensive operation) if it won't be used.
main
fjc40 9 years ago
parent 7f3500202f
commit 5d8380be8d

@ -66,7 +66,7 @@ public class Race implements Runnable {
* Frame periods are multiplied by this to get the amount of time a single frame represents. * Frame periods are multiplied by this to get the amount of time a single frame represents.
* E.g., frame period = 20ms, scale = 5, frame represents 20 * 5 = 100ms, and so boats are simulated for 100ms, even though only 20ms actually occurred. * E.g., frame period = 20ms, scale = 5, frame represents 20 * 5 = 100ms, and so boats are simulated for 100ms, even though only 20ms actually occurred.
*/ */
private int scaleFactor = 30; private int scaleFactor = 15;
/** /**
* The race ID of the course. * The race ID of the course.
@ -587,6 +587,11 @@ public class Race implements Runnable {
boat.moveForwards(distanceTravelledMeters, updatePeriodMilliseconds * this.scaleFactor); boat.moveForwards(distanceTravelledMeters, updatePeriodMilliseconds * this.scaleFactor);
//Only get a new VMG if the boat will go outside the course, or X seconds have elapsed.
boolean willStayInsideCourse = this.checkBearingInsideCourse(boat.getBearing(), boat.getCurrentPosition());
long tackPeriod = 15000;
if (!willStayInsideCourse || (boat.getTimeSinceTackChange() > tackPeriod)) {
//Calculate the boat's bearing bounds, to ensure that it doesn't go out of the course. //Calculate the boat's bearing bounds, to ensure that it doesn't go out of the course.
Bearing[] bearingBounds = this.calculateBearingBounds(boat); Bearing[] bearingBounds = this.calculateBearingBounds(boat);
@ -598,13 +603,15 @@ public class Race implements Runnable {
//If the new vmg improves velocity, use it. //If the new vmg improves velocity, use it.
if (improvesVelocity(boat, newVMG)) { if (improvesVelocity(boat, newVMG)) {
boat.setVMG(newVMG); boat.setVMG(newVMG);
} else { } else {
//We also need to use the new VMG if our current bearing will take us out of the course. //We also need to use the new VMG if our current bearing will take us out of the course.
if (!this.checkBearingInsideCourse(boat.getBearing(), boat.getCurrentPosition())) { if (!willStayInsideCourse) {
boat.setVMG(newVMG); boat.setVMG(newVMG);
} }
} }
}
//Check the boats position (update leg and stuff). //Check the boats position (update leg and stuff).

Loading…
Cancel
Save