Merge branch 'bindWind' into 'sprint4_master'
Bind wind See merge request !14
This commit is contained in:
@@ -12,6 +12,7 @@ import seng302.Networking.Messages.Enums.BoatStatusEnum;
|
||||
import seng302.Networking.Messages.Enums.RaceStatusEnum;
|
||||
import seng302.Networking.Messages.Enums.RaceTypeEnum;
|
||||
import seng302.Networking.Messages.RaceStatus;
|
||||
import seng302.Networking.Utils.AC35UnitConverter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -109,8 +110,11 @@ public class Race implements Runnable {
|
||||
*/
|
||||
private double windSpeed;
|
||||
|
||||
private int windDir;
|
||||
private double windDirDegrees;
|
||||
private double windDir;
|
||||
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.
|
||||
|
||||
//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);
|
||||
|
||||
//Create race status object, and send it.
|
||||
@@ -877,32 +881,29 @@ public class Race implements Runnable {
|
||||
}
|
||||
|
||||
protected void initialiseWindDir(){
|
||||
windDir = new Random().nextInt(65535+1);
|
||||
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
|
||||
windDirDegrees = 225;
|
||||
windDir = AC35UnitConverter.convertHeading(windDirDegrees);
|
||||
/*windDir = new Random().nextInt(65535+1);
|
||||
windDir = BoatLocation.convertHeadingIntToDouble(255);*/
|
||||
this.windDirection = new Bearing((int)windDir);
|
||||
}
|
||||
|
||||
protected void changeWindDir(){
|
||||
int r = new Random().nextInt(changeWind)+1;
|
||||
if(r==1){
|
||||
windDir+=100;
|
||||
windDirDegrees = (0.5 + windDirDegrees) % 360;
|
||||
} else if (r==2){
|
||||
windDir-=100;
|
||||
windDirDegrees = ((windDirDegrees - 0.5) + 360) % 360;///keep the degrees positive when below 0
|
||||
}
|
||||
if (windDir > 65535){
|
||||
windDir -= 65535;
|
||||
if (windDirDegrees > windUpperBound){
|
||||
windDirDegrees = windUpperBound;
|
||||
}
|
||||
if (windDir < 0){
|
||||
windDir += 65535;
|
||||
if (windDirDegrees < windLowerBound){
|
||||
windDirDegrees = windLowerBound;
|
||||
}
|
||||
|
||||
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
|
||||
}
|
||||
|
||||
protected void setWindDir(int wind){
|
||||
if (wind>=0 && wind<=65535){
|
||||
windDir = wind;
|
||||
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
|
||||
}
|
||||
windDir = AC35UnitConverter.convertHeading(windDirDegrees);
|
||||
this.windDirection = new Bearing(windDirDegrees);
|
||||
}
|
||||
|
||||
protected void setChangeWind(int changeVal){
|
||||
@@ -912,7 +913,7 @@ public class Race implements Runnable {
|
||||
}
|
||||
|
||||
protected int getWind(){
|
||||
return windDir;
|
||||
return (int)windDir;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package seng302.Networking.Messages;
|
||||
|
||||
import seng302.Networking.Messages.Enums.MessageType;
|
||||
import seng302.Networking.Utils.AC35UnitConverter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -18,7 +19,6 @@ public class RaceStatus extends AC35Data {
|
||||
private int windSpeed;
|
||||
private int raceType;
|
||||
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){
|
||||
super(MessageType.RACESTATUS);
|
||||
@@ -29,7 +29,7 @@ public class RaceStatus extends AC35Data {
|
||||
this.windDirection = windDirection;
|
||||
this.windSpeed = windSpeed;
|
||||
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() {
|
||||
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
|
||||
}
|
||||
|
||||
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){
|
||||
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 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 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 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(abbrevCheckAnno, showAbbrev.isSelected());
|
||||
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
|
||||
@@ -386,109 +402,54 @@ public class RaceController extends Controller {
|
||||
showName.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (old_val != new_val) {
|
||||
raceMap.toggleAnnoName();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
radioBtnChecked = false;
|
||||
storeCurrentAnnotationState(nameCheckAnno, new_val);
|
||||
raceMap.update();
|
||||
prevBtnChecked = noBtn;
|
||||
}
|
||||
});
|
||||
//listener for show abbreviation for annotation
|
||||
showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (old_val != new_val) {
|
||||
raceMap.toggleAnnoAbbrev();
|
||||
}
|
||||
if (buttonChecked != hideBtn) {
|
||||
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
|
||||
storeCurrentAnnotationState();
|
||||
} else {
|
||||
annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected());
|
||||
}
|
||||
if (buttonChecked == noBtn) {
|
||||
annotationGroup.selectToggle(showAnnoRBTN);
|
||||
}
|
||||
}
|
||||
radioBtnChecked = false;
|
||||
storeCurrentAnnotationState(abbrevCheckAnno, new_val);
|
||||
raceMap.update();
|
||||
prevBtnChecked = noBtn;
|
||||
}
|
||||
});
|
||||
|
||||
//listener for show boat path for annotation
|
||||
showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (old_val != new_val) {
|
||||
raceMap.toggleBoatPath();
|
||||
}
|
||||
if (buttonChecked != hideBtn) {
|
||||
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
|
||||
storeCurrentAnnotationState();
|
||||
} else {
|
||||
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
|
||||
}
|
||||
if (buttonChecked == noBtn) {
|
||||
annotationGroup.selectToggle(showAnnoRBTN);
|
||||
}
|
||||
}
|
||||
radioBtnChecked = false;
|
||||
storeCurrentAnnotationState(pathCheckAnno, new_val);
|
||||
raceMap.update();
|
||||
prevBtnChecked = noBtn;
|
||||
}
|
||||
});
|
||||
//listener to show speed for annotation
|
||||
showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (old_val != new_val) {
|
||||
raceMap.toggleAnnoSpeed();
|
||||
}
|
||||
if (buttonChecked != hideBtn) {
|
||||
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
|
||||
storeCurrentAnnotationState();
|
||||
} else {
|
||||
annoShownBeforeHide.put(speedCheckAnno, showSpeed.isSelected());
|
||||
}
|
||||
if (buttonChecked == noBtn) {
|
||||
annotationGroup.selectToggle(showAnnoRBTN);
|
||||
}
|
||||
}
|
||||
radioBtnChecked = false;
|
||||
storeCurrentAnnotationState(speedCheckAnno, new_val);
|
||||
raceMap.update();
|
||||
prevBtnChecked = noBtn;
|
||||
}
|
||||
});
|
||||
showTime.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (old_val != new_val) {
|
||||
raceMap.toggleAnnoTime();
|
||||
}
|
||||
if (buttonChecked != hideBtn) {
|
||||
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
|
||||
storeCurrentAnnotationState();
|
||||
} else {
|
||||
annoShownBeforeHide.put(timeCheckAnno, showTime.isSelected());
|
||||
}
|
||||
if (buttonChecked == noBtn) {
|
||||
annotationGroup.selectToggle(showAnnoRBTN);
|
||||
}
|
||||
}
|
||||
prevBtnChecked = noBtn;
|
||||
radioBtnChecked = false;
|
||||
storeCurrentAnnotationState(timeCheckAnno, new_val);
|
||||
raceMap.update();
|
||||
}
|
||||
});
|
||||
showEstTime.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (old_val != new_val) {
|
||||
raceMap.toggleAnnoEstTime();
|
||||
}
|
||||
if (buttonChecked != hideBtn) {
|
||||
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
|
||||
storeCurrentAnnotationState();
|
||||
} else {
|
||||
annoShownBeforeHide.put(estTimeCheckAnno, showEstTime.isSelected());
|
||||
}
|
||||
if (buttonChecked == noBtn) {
|
||||
annotationGroup.selectToggle(showAnnoRBTN);
|
||||
}
|
||||
}
|
||||
prevBtnChecked = noBtn;
|
||||
radioBtnChecked = false;
|
||||
storeCurrentAnnotationState(estTimeCheckAnno, new_val);
|
||||
raceMap.update();
|
||||
}
|
||||
});
|
||||
//listener to save currently selected annotation
|
||||
saveAnno.setOnAction(event -> {
|
||||
@@ -501,22 +462,23 @@ public class RaceController extends Controller {
|
||||
presetAnno.add(showEstTime.isSelected());
|
||||
});
|
||||
//listener for hiding
|
||||
hideAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
|
||||
hideAnnoRBTN.setOnAction((e)->{
|
||||
buttonChecked = hideBtn;
|
||||
//raceMap.hideAnnotations();
|
||||
selectShow = false;
|
||||
showName.setSelected(false);
|
||||
showAbbrev.setSelected(false);
|
||||
showBoatPath.setSelected(false);
|
||||
showSpeed.setSelected(false);
|
||||
showTime.setSelected(false);
|
||||
showEstTime.setSelected(false);
|
||||
annotationGroup.selectToggle(hideAnnoRBTN);
|
||||
raceMap.update();
|
||||
buttonChecked = noBtn;
|
||||
prevBtnChecked = hideBtn;
|
||||
selectShow = true;
|
||||
});
|
||||
//listener for showing all annotations
|
||||
showAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
|
||||
showAnnoRBTN.setOnAction((e)->{
|
||||
if (selectShow) {
|
||||
buttonChecked = showBtn;
|
||||
showName.setSelected(annoShownBeforeHide.get(nameCheckAnno));
|
||||
showAbbrev.setSelected(annoShownBeforeHide.get(abbrevCheckAnno));
|
||||
@@ -527,9 +489,12 @@ public class RaceController extends Controller {
|
||||
raceMap.update();
|
||||
buttonChecked = noBtn;
|
||||
prevBtnChecked = showBtn;
|
||||
}
|
||||
selectShow = true;
|
||||
});
|
||||
//listener for showing all important
|
||||
partialAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
|
||||
partialAnnoRBTN.setOnAction((e)->{
|
||||
selectShow = false;
|
||||
buttonChecked = partialBtn;
|
||||
showName.setSelected(false);
|
||||
showAbbrev.setSelected(true);
|
||||
@@ -537,13 +502,15 @@ public class RaceController extends Controller {
|
||||
showBoatPath.setSelected(false);
|
||||
showTime.setSelected(false);
|
||||
showEstTime.setSelected(false);
|
||||
annotationGroup.selectToggle(partialAnnoRBTN);
|
||||
|
||||
raceMap.update();
|
||||
buttonChecked = noBtn;
|
||||
prevBtnChecked = partialBtn;
|
||||
selectShow = true;
|
||||
});
|
||||
//listener for showing all important
|
||||
importantAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
|
||||
importantAnnoRBTN.setOnAction((e) ->{
|
||||
selectShow = false;
|
||||
buttonChecked = importantBtn;
|
||||
if (presetAnno.size() > 0) {
|
||||
showName.setSelected(presetAnno.get(0));
|
||||
@@ -552,11 +519,12 @@ public class RaceController extends Controller {
|
||||
showBoatPath.setSelected(presetAnno.get(3));
|
||||
showTime.setSelected(presetAnno.get(4));
|
||||
showEstTime.setSelected(presetAnno.get(5));
|
||||
annotationGroup.selectToggle(importantAnnoRBTN);
|
||||
storeCurrentAnnotationDictionary();
|
||||
raceMap.update();
|
||||
}
|
||||
buttonChecked = noBtn;
|
||||
prevBtnChecked = importantBtn;
|
||||
selectShow = true;
|
||||
});
|
||||
annotationGroup.selectToggle(showAnnoRBTN);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user