Attempt to fix sails in / out colliding issue. Going to test on dev for a better visual representation. #story[1297]

This commit is contained in:
Joseph Gardner
2017-09-25 13:48:03 +13:00
parent 5a1dbc83b5
commit 332722e099
5 changed files with 13 additions and 12 deletions
@@ -61,7 +61,7 @@ public class MockRace extends RaceState {
*/
private Polars polars;
private ActiveObserverCommand activeObserverCommand;
private Map<Integer, ActiveObserverCommand> activeObserverCommands;
private long racePreStartTime = Constants.RacePreStartTime;
@@ -82,7 +82,7 @@ public class MockRace extends RaceState {
this.setRaceDataSource(raceDataSource);
this.setRegattaDataSource(regattaDataSource);
this.activeObserverCommand = new ActiveObserverCommand();
this.activeObserverCommands = new HashMap<>();
this.polars = polars;
this.scaleFactor = timeScale;
@@ -127,6 +127,7 @@ public class MockRace extends RaceState {
getRaceDataSource().getParticipants().add(sourceID);
this.boats.add(mockBoat);
this.activeObserverCommands.put(boat.getSourceID(), new ActiveObserverCommand());
getRaceDataSource().incrementSequenceNumber();
@@ -711,11 +712,11 @@ public class MockRace extends RaceState {
super.setChanged();
}
public void addVelocityCommand(ObserverCommand c) {
this.activeObserverCommand.changeVelocityCommand(this, c);
public void addVelocityCommand(ObserverCommand c, int boatId) {
this.activeObserverCommands.get(boatId).changeVelocityCommand(this, c);
}
public void addAngularCommand(ObserverCommand c) {
this.activeObserverCommand.changeAngularCommand(this, c);
public void addAngularCommand(ObserverCommand c, int boatId) {
this.activeObserverCommands.get(boatId).changeAngularCommand(this, c);
}
}
@@ -13,7 +13,7 @@ public class SailsCommand extends ObserverCommand {
public SailsCommand(MockRace race, MockBoat boat, boolean sailsOut) {
super(race, boat);
race.addVelocityCommand(this);
race.addVelocityCommand(this, boat.getSourceID());
this.sailsOut = sailsOut;
}
@@ -38,10 +38,10 @@ public class SailsCommand extends ObserverCommand {
double acceleration = 0.5;
if(sailsOut && boat.getCurrentSpeed() < goalVelocity) {
boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
if (!boat.isColliding()) boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
// Apply deceleration to strictly 0 speed
boat.setCurrentSpeed(Math.max(0, boat.getCurrentSpeed() - acceleration));
if (!boat.isColliding()) boat.setCurrentSpeed(Math.max(0, boat.getCurrentSpeed() - acceleration));
} else {
// Release boat from SailsCommand control
if(sailsOut) boat.setVelocityDefault(true);
@@ -22,7 +22,7 @@ public class TackGybeCommand extends ObserverCommand {
*/
public TackGybeCommand(MockRace race, MockBoat boat) {
super(race, boat);
race.addAngularCommand(this);
race.addAngularCommand(this, boat.getSourceID());
}
@Override
@@ -24,7 +24,7 @@ public class VMGCommand extends ObserverCommand {
*/
public VMGCommand(MockRace race, MockBoat boat) {
super(race, boat);
race.addAngularCommand(this);
race.addAngularCommand(this, boat.getSourceID());
}
@Override
@@ -20,7 +20,7 @@ public class WindCommand extends ObserverCommand {
*/
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
super(race, boat);
race.addAngularCommand(this);
race.addAngularCommand(this, boat.getSourceID());
this.direction = upwind? -1 : 1;
}