Merge branch 'bindWind' into 'sprint4_master'

Bind wind



See merge request !14
main
Connor Taylor Brown 9 years ago
commit ea02752dc0

@ -12,6 +12,7 @@ import seng302.Networking.Messages.Enums.BoatStatusEnum;
import seng302.Networking.Messages.Enums.RaceStatusEnum; import seng302.Networking.Messages.Enums.RaceStatusEnum;
import seng302.Networking.Messages.Enums.RaceTypeEnum; import seng302.Networking.Messages.Enums.RaceTypeEnum;
import seng302.Networking.Messages.RaceStatus; import seng302.Networking.Messages.RaceStatus;
import seng302.Networking.Utils.AC35UnitConverter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -109,8 +110,11 @@ public class Race implements Runnable {
*/ */
private double windSpeed; private double windSpeed;
private int windDir; private double windDirDegrees;
private double windDir;
private int changeWind = 4; private int changeWind = 4;
private static final int windUpperBound = 235;
private static final int windLowerBound = 215;
@ -272,7 +276,7 @@ public class Race implements Runnable {
//TODO REFACTOR for consistency, could send parameters to mockOutput instead of the whole racestatus. This will also fix the sequence number issue. //TODO REFACTOR for consistency, could send parameters to mockOutput instead of the whole racestatus. This will also fix the sequence number issue.
//Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class. //Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class.
int windDirectionInt = BoatLocation.convertHeadingDoubleToInt(this.windDirection.degrees()); int windDirectionInt = AC35UnitConverter.encodeHeading(this.windDirection.degrees());
int windSpeedInt = (int) (windSpeed * Constants.KnotsToMMPerSecond); int windSpeedInt = (int) (windSpeed * Constants.KnotsToMMPerSecond);
//Create race status object, and send it. //Create race status object, and send it.
@ -632,9 +636,9 @@ public class Race implements Runnable {
} }
} }
} }
this.updateEstimatedTime(boat); this.updateEstimatedTime(boat);
//Check the boats position (update leg and stuff). //Check the boats position (update leg and stuff).
this.checkPosition(boat, totalTimeElapsed); this.checkPosition(boat, totalTimeElapsed);
@ -877,32 +881,29 @@ public class Race implements Runnable {
} }
protected void initialiseWindDir(){ protected void initialiseWindDir(){
windDir = new Random().nextInt(65535+1); windDirDegrees = 225;
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir)); windDir = AC35UnitConverter.convertHeading(windDirDegrees);
/*windDir = new Random().nextInt(65535+1);
windDir = BoatLocation.convertHeadingIntToDouble(255);*/
this.windDirection = new Bearing((int)windDir);
} }
protected void changeWindDir(){ protected void changeWindDir(){
int r = new Random().nextInt(changeWind)+1; int r = new Random().nextInt(changeWind)+1;
if(r==1){ if(r==1){
windDir+=100; windDirDegrees = (0.5 + windDirDegrees) % 360;
} else if (r==2){ } else if (r==2){
windDir-=100; windDirDegrees = ((windDirDegrees - 0.5) + 360) % 360;///keep the degrees positive when below 0
} }
if (windDir > 65535){ if (windDirDegrees > windUpperBound){
windDir -= 65535; windDirDegrees = windUpperBound;
} }
if (windDir < 0){ if (windDirDegrees < windLowerBound){
windDir += 65535; windDirDegrees = windLowerBound;
} }
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir)); windDir = AC35UnitConverter.convertHeading(windDirDegrees);
} this.windDirection = new Bearing(windDirDegrees);
protected void setWindDir(int wind){
if (wind>=0 && wind<=65535){
windDir = wind;
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
}
} }
protected void setChangeWind(int changeVal){ protected void setChangeWind(int changeVal){
@ -912,7 +913,7 @@ public class Race implements Runnable {
} }
protected int getWind(){ protected int getWind(){
return windDir; return (int)windDir;
} }
/** /**

@ -1,6 +1,7 @@
package seng302.Networking.Messages; package seng302.Networking.Messages;
import seng302.Networking.Messages.Enums.MessageType; import seng302.Networking.Messages.Enums.MessageType;
import seng302.Networking.Utils.AC35UnitConverter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -18,7 +19,6 @@ public class RaceStatus extends AC35Data {
private int windSpeed; private int windSpeed;
private int raceType; private int raceType;
private List<BoatStatus> boatStatuses; private List<BoatStatus> boatStatuses;
private static final double windDirectionScalar = 360.0 / 65536.0; // 0x10000 / 360
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, List<BoatStatus> boatStatuses){ public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, List<BoatStatus> boatStatuses){
super(MessageType.RACESTATUS); super(MessageType.RACESTATUS);
@ -29,7 +29,7 @@ public class RaceStatus extends AC35Data {
this.windDirection = windDirection; this.windDirection = windDirection;
this.windSpeed = windSpeed; this.windSpeed = windSpeed;
this.raceType = raceType; this.raceType = raceType;
this.boatStatuses = boatStatuses;//note this is a copy so any alterations to the parent will affect this. this.boatStatuses = boatStatuses;//note this is not a copy so any alterations to the parent will affect this.
} }
@ -125,6 +125,6 @@ public class RaceStatus extends AC35Data {
} }
public double getScaledWindDirection() { public double getScaledWindDirection() {
return (double) windDirection * windDirectionScalar; return (double) AC35UnitConverter.convertHeading(windDirection);
} }
} }

@ -19,6 +19,23 @@ public class AC35UnitConverter {
return (double) value * 360.0/65536.0;//2^15 return (double) value * 360.0/65536.0;//2^15
} }
public static double convertHeading(int value){
return (double) value * 360.0/65536.0;//2^15
}
public static double convertHeading(double value){
return value * 360.0/65536.0;//2^15
}
public static int encodeHeading(int value){
return (int) (value / 360.0 * 65536.0);//2^15
}
public static int encodeHeading(double value){
return (int) (value / 360.0 * 65536.0);//2^15
}
public static double convertTrueWindAngle(long value){ public static double convertTrueWindAngle(long value){
return (double) value * 180.0/32768.0;//-2^15 to 2^15 return (double) value * 180.0/32768.0;//-2^15 to 2^15
} }

@ -31,6 +31,8 @@ public class RaceController extends Controller {
private Map<String, Boolean> annoShownBeforeHide; private Map<String, Boolean> annoShownBeforeHide;
private int buttonChecked;//button currently checked allows the checkboxes to know whether or not to put it's state in history (if not hidden then store) private int buttonChecked;//button currently checked allows the checkboxes to know whether or not to put it's state in history (if not hidden then store)
private int prevBtnChecked;//button to keep track of previous pressed button incase we want to check a checkbox straight from hidden we do not wish for all previous to come on. private int prevBtnChecked;//button to keep track of previous pressed button incase we want to check a checkbox straight from hidden we do not wish for all previous to come on.
private boolean radioBtnChecked;
private boolean selectShow = false; //button to make it so that show doesn't run the listener
private static String nameCheckAnno = "name"; private static String nameCheckAnno = "name";
private static String abbrevCheckAnno = "abbrev"; private static String abbrevCheckAnno = "abbrev";
@ -352,7 +354,21 @@ public class RaceController extends Controller {
} }
private void storeCurrentAnnotationState(){ private void storeCurrentAnnotationState(String dictionaryAnnotationKey, boolean selected){
if (buttonChecked != hideBtn) {
//if we are checking the box straight out of hide instead of using the radio buttons
annoShownBeforeHide.put(dictionaryAnnotationKey, selected);
if (prevBtnChecked == hideBtn && buttonChecked == noBtn){
storeCurrentAnnotationDictionary();
}
if (buttonChecked == noBtn) {
selectShow = false;
annotationGroup.selectToggle(showAnnoRBTN);
}
}
}
private void storeCurrentAnnotationDictionary(){
annoShownBeforeHide.put(nameCheckAnno, showName.isSelected()); annoShownBeforeHide.put(nameCheckAnno, showName.isSelected());
annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected()); annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected());
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected()); annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
@ -386,109 +402,54 @@ public class RaceController extends Controller {
showName.selectedProperty().addListener((ov, old_val, new_val) -> { showName.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoName(); raceMap.toggleAnnoName();
radioBtnChecked = false;
storeCurrentAnnotationState(nameCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
//if we are checking the box straight out of hide instead of using the radio buttons
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(nameCheckAnno, showName.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
//listener for show abbreviation for annotation //listener for show abbreviation for annotation
showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> { showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoAbbrev(); raceMap.toggleAnnoAbbrev();
radioBtnChecked = false;
storeCurrentAnnotationState(abbrevCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
//listener for show boat path for annotation //listener for show boat path for annotation
showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> { showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleBoatPath(); raceMap.toggleBoatPath();
radioBtnChecked = false;
storeCurrentAnnotationState(pathCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
//listener to show speed for annotation //listener to show speed for annotation
showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> { showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoSpeed(); raceMap.toggleAnnoSpeed();
radioBtnChecked = false;
storeCurrentAnnotationState(speedCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(speedCheckAnno, showSpeed.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
showTime.selectedProperty().addListener((ov, old_val, new_val) -> { showTime.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoTime(); raceMap.toggleAnnoTime();
radioBtnChecked = false;
storeCurrentAnnotationState(timeCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(timeCheckAnno, showTime.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
prevBtnChecked = noBtn;
raceMap.update();
}); });
showEstTime.selectedProperty().addListener((ov, old_val, new_val) -> { showEstTime.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoEstTime(); raceMap.toggleAnnoEstTime();
radioBtnChecked = false;
storeCurrentAnnotationState(estTimeCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(estTimeCheckAnno, showEstTime.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
prevBtnChecked = noBtn;
raceMap.update();
}); });
//listener to save currently selected annotation //listener to save currently selected annotation
saveAnno.setOnAction(event -> { saveAnno.setOnAction(event -> {
@ -501,35 +462,39 @@ public class RaceController extends Controller {
presetAnno.add(showEstTime.isSelected()); presetAnno.add(showEstTime.isSelected());
}); });
//listener for hiding //listener for hiding
hideAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ hideAnnoRBTN.setOnAction((e)->{
buttonChecked = hideBtn; buttonChecked = hideBtn;
//raceMap.hideAnnotations(); selectShow = false;
showName.setSelected(false); showName.setSelected(false);
showAbbrev.setSelected(false); showAbbrev.setSelected(false);
showBoatPath.setSelected(false); showBoatPath.setSelected(false);
showSpeed.setSelected(false); showSpeed.setSelected(false);
showTime.setSelected(false); showTime.setSelected(false);
showEstTime.setSelected(false); showEstTime.setSelected(false);
annotationGroup.selectToggle(hideAnnoRBTN);
raceMap.update(); raceMap.update();
buttonChecked = noBtn; buttonChecked = noBtn;
prevBtnChecked = hideBtn; prevBtnChecked = hideBtn;
selectShow = true;
}); });
//listener for showing all annotations //listener for showing all annotations
showAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ showAnnoRBTN.setOnAction((e)->{
buttonChecked = showBtn; if (selectShow) {
showName.setSelected(annoShownBeforeHide.get(nameCheckAnno)); buttonChecked = showBtn;
showAbbrev.setSelected(annoShownBeforeHide.get(abbrevCheckAnno)); showName.setSelected(annoShownBeforeHide.get(nameCheckAnno));
showBoatPath.setSelected(annoShownBeforeHide.get(pathCheckAnno)); showAbbrev.setSelected(annoShownBeforeHide.get(abbrevCheckAnno));
showSpeed.setSelected(annoShownBeforeHide.get(speedCheckAnno)); showBoatPath.setSelected(annoShownBeforeHide.get(pathCheckAnno));
showTime.setSelected(annoShownBeforeHide.get(timeCheckAnno)); showSpeed.setSelected(annoShownBeforeHide.get(speedCheckAnno));
showEstTime.setSelected(annoShownBeforeHide.get(estTimeCheckAnno)); showTime.setSelected(annoShownBeforeHide.get(timeCheckAnno));
raceMap.update(); showEstTime.setSelected(annoShownBeforeHide.get(estTimeCheckAnno));
buttonChecked = noBtn; raceMap.update();
prevBtnChecked = showBtn; buttonChecked = noBtn;
prevBtnChecked = showBtn;
}
selectShow = true;
}); });
//listener for showing all important //listener for showing all important
partialAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ partialAnnoRBTN.setOnAction((e)->{
selectShow = false;
buttonChecked = partialBtn; buttonChecked = partialBtn;
showName.setSelected(false); showName.setSelected(false);
showAbbrev.setSelected(true); showAbbrev.setSelected(true);
@ -537,13 +502,15 @@ public class RaceController extends Controller {
showBoatPath.setSelected(false); showBoatPath.setSelected(false);
showTime.setSelected(false); showTime.setSelected(false);
showEstTime.setSelected(false); showEstTime.setSelected(false);
annotationGroup.selectToggle(partialAnnoRBTN);
raceMap.update(); raceMap.update();
buttonChecked = noBtn; buttonChecked = noBtn;
prevBtnChecked = partialBtn; prevBtnChecked = partialBtn;
selectShow = true;
}); });
//listener for showing all important //listener for showing all important
importantAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ importantAnnoRBTN.setOnAction((e) ->{
selectShow = false;
buttonChecked = importantBtn; buttonChecked = importantBtn;
if (presetAnno.size() > 0) { if (presetAnno.size() > 0) {
showName.setSelected(presetAnno.get(0)); showName.setSelected(presetAnno.get(0));
@ -552,11 +519,12 @@ public class RaceController extends Controller {
showBoatPath.setSelected(presetAnno.get(3)); showBoatPath.setSelected(presetAnno.get(3));
showTime.setSelected(presetAnno.get(4)); showTime.setSelected(presetAnno.get(4));
showEstTime.setSelected(presetAnno.get(5)); showEstTime.setSelected(presetAnno.get(5));
annotationGroup.selectToggle(importantAnnoRBTN); storeCurrentAnnotationDictionary();
raceMap.update(); raceMap.update();
} }
buttonChecked = noBtn; buttonChecked = noBtn;
prevBtnChecked = importantBtn; prevBtnChecked = importantBtn;
selectShow = true;
}); });
annotationGroup.selectToggle(showAnnoRBTN); annotationGroup.selectToggle(showAnnoRBTN);
} }

Loading…
Cancel
Save