Merge remote-tracking branch 'origin/issue58_sails_collision_fix' into story1297_sails

main
Fan-Wu Yang 8 years ago
commit 980d1d7977

@ -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;
@ -87,7 +87,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;
@ -132,6 +132,7 @@ public class MockRace extends RaceState {
getRaceDataSource().getParticipants().add(sourceID);
this.boats.add(mockBoat);
this.activeObserverCommands.put(boat.getSourceID(), new ActiveObserverCommand());
getRaceDataSource().incrementSequenceNumber();
@ -752,11 +753,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);
}
}

@ -36,6 +36,7 @@ public class CollisionCommand extends ObserverCommand {
@Override
public void update(Observable o, Object arg) {
if(GPSCoordinate.calculateDistanceMeters(boat.getPosition(), startingPosition) < distance) {
boat.setVelocityDefault(false);
boat.setPosition(GPSCoordinate.calculateNewPosition(boat.getPosition(), 3, azimuth));
} else {
race.deleteObserver(this);

@ -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;
}
@ -37,15 +37,18 @@ public class SailsCommand extends ObserverCommand {
public void update(Observable o, Object arg) {
double acceleration = 0.5;
if(sailsOut && boat.getCurrentSpeed() < goalVelocity) {
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));
} else {
// Release boat from SailsCommand control
if(sailsOut) boat.setVelocityDefault(true);
race.deleteObserver(this);
if (!boat.isColliding()) {
boat.setVelocityDefault(false);
if (sailsOut && boat.getCurrentSpeed() < goalVelocity) {
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));
} else {
// Release boat from SailsCommand control
if (sailsOut) boat.setVelocityDefault(true);
race.deleteObserver(this);
}
}
}
}

@ -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;
}

Loading…
Cancel
Save