Merge remote-tracking branch 'origin/master' into issue_28_36_decoders

# Conflicts:
#	racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java
#	racevisionGame/src/main/java/mock/app/Event.java
#	racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java
This commit is contained in:
fjc40
2017-08-10 13:12:26 +12:00
21 changed files with 537 additions and 117 deletions
@@ -25,7 +25,7 @@ public class MockBoat extends Boat {
/**
* Stores whether the boat is on autoVMG or not
*/
private boolean autoVMG = true;
private boolean autoVMG = false;
@@ -1,12 +1,20 @@
package mock.model;
import javafx.animation.AnimationTimer;
import mock.model.commandFactory.Command;
import mock.model.commandFactory.CommandFactory;
import mock.model.commandFactory.CompositeCommand;
import network.Messages.Enums.BoatActionEnum;
import network.Messages.Enums.BoatStatusEnum;
import network.Messages.Enums.RaceStatusEnum;
import network.Messages.LatestMessages;
import shared.model.Race;
import visualiser.gameController.ControllerServer;
public class RaceLogic implements Runnable {
import java.util.Observable;
import java.util.Observer;
import java.util.Stack;
public class RaceLogic implements Observer, Runnable {
/**
* State of current race modified by this object
*/
@@ -16,6 +24,8 @@ public class RaceLogic implements Runnable {
*/
private RaceServer server;
private CompositeCommand commands;
/**
* Initialises race loop with state and server message queue
* @param race state of race to modify
@@ -24,6 +34,7 @@ public class RaceLogic implements Runnable {
public RaceLogic(MockRace race, LatestMessages messages) {
this.race = race;
this.server = new RaceServer(race, messages);
this.commands = new CompositeCommand();
}
/**
@@ -123,7 +134,7 @@ public class RaceLogic implements Runnable {
//If it is still racing, update its position.
if (boat.getStatus() == BoatStatusEnum.RACING) {
commands.execute();
race.updatePosition(boat, framePeriod, race.getRaceClock().getDurationMilli());
}
@@ -173,4 +184,13 @@ public class RaceLogic implements Runnable {
iters++;
}
};
@Override
public void update(Observable o, Object arg) {
ControllerServer server = (ControllerServer)o;
BoatActionEnum action = server.getAction();
MockBoat boat = race.getBoats().get(0);
commands.addCommand(CommandFactory.createCommand(race, boat, action));
}
}
@@ -19,6 +19,8 @@ public class CommandFactory {
switch(action) {
case AUTO_PILOT: return new VMGCommand(race, boat);
case TACK_GYBE: return new TackGybeCommand(race, boat);
case UPWIND: return new WindCommand(race, boat, true);
case DOWNWIND: return new WindCommand(race, boat, false);
default: return null; // TODO - please please have discussion over what to default to
}
}
@@ -0,0 +1,24 @@
package mock.model.commandFactory;
import java.util.ArrayDeque;
import java.util.Queue;
/**
* Wraps multiple commands into a composite to execute queued commands during a frame.
*/
public class CompositeCommand implements Command {
private Queue<Command> commands;
public CompositeCommand() {
this.commands = new ArrayDeque<>();
}
public void addCommand(Command command) {
commands.add(command);
}
@Override
public void execute() {
while(!commands.isEmpty()) commands.remove().execute();
}
}
@@ -18,6 +18,9 @@ public class TackGybeCommand implements Command {
//The refactoring of MockRace will require changes to be made
@Override
public void execute() {
boat.setAutoVMG(false);
/*VMG newVMG = boat.getPolars().calculateVMG(
race.getWindDirection(),
race.getWindSpeed(),
@@ -18,6 +18,7 @@ public class VMGCommand implements Command {
//The refactoring of MockRace will require changes to be made
@Override
public void execute() {
boat.setAutoVMG(true);
/*VMG newVMG = boat.getPolars().calculateVMG(
race.getWindDirection(),
race.getWindSpeed(),
@@ -0,0 +1,37 @@
package mock.model.commandFactory;
import mock.model.MockBoat;
import mock.model.MockRace;
import shared.model.Bearing;
/**
* Created by connortaylorbrown on 4/08/17.
*/
public class WindCommand implements Command {
private MockRace race;
private MockBoat boat;
private int direction;
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
this.race = race;
this.boat = boat;
this.direction = upwind? -1 : 1;
}
@Override
public void execute() {
boat.setAutoVMG(false);
double wind = race.getWindDirection().degrees();
double heading = boat.getBearing().degrees();
double offset = 3.0;
offset *= direction;
double headWindDelta = wind - heading;
if ((headWindDelta < 0) || (headWindDelta > 180)) offset *= -1;
boat.setBearing(Bearing.fromDegrees(heading + offset));
}
}