Minor structural changes. GameState now has a thread which updates itself so its update

rate can be independent of sending packets to the client in the MainServerThread

#story[986] #pair[wmu16, ptg19]
This commit is contained in:
William Muir
2017-07-26 14:48:32 +12:00
parent 2bfa6cb038
commit 5e6b402bf5
4 changed files with 47 additions and 51 deletions
+10 -21
View File
@@ -117,28 +117,17 @@ public class Yacht {
* @param timeInterval since last update in milliseconds
*/
public void update(Long timeInterval) {
Double secondsElapsed = timeInterval / 1000000.0;
Double windSpeedKnots = GameState.getWindSpeedKnots();
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
Double maxBoatSpeed = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
if (sailIn && velocity <= maxBoatSpeed) { // Acceleration
if (velocity < maxBoatSpeed) {
velocity += maxBoatSpeed / 25;
if (velocity > maxBoatSpeed) {
velocity = maxBoatSpeed;
}
}
} else { // Deceleration
if (velocity > 0) {
velocity = velocity -= maxBoatSpeed / 25;
if (velocity < 0) {
velocity = 0d;
}
}
if (sailIn) {
Double secondsElapsed = timeInterval / 1000000.0;
Double windSpeedKnots = GameState.getWindSpeedKnots();
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
Double metersCovered = velocity * secondsElapsed;
location = getGeoCoordinate(location, heading, metersCovered);
} else {
velocity = 0d;
}
Double metersCovered = velocity * secondsElapsed;
location = getGeoCoordinate(location, heading, metersCovered);
}