Reverting some new graphics classes back to how they were on master.

This commit is contained in:
Calum
2017-07-31 23:35:28 +12:00
parent b82d0d0137
commit 47c5e6f155
8 changed files with 77 additions and 62 deletions
@@ -1,6 +1,5 @@
package seng302.model.mark; package seng302.model.mark;
import com.sun.deploy.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -31,9 +30,13 @@ public class CompoundMark {
*/ */
@Override @Override
public String toString(){ public String toString(){
String info = String.format("CompoundMark: %d (%s), [", compoundMarkId, name); String info = String.format(
info += StringUtils.join(marks, ", ") + "]"; "CompoundMark: %d (%s), [%s", compoundMarkId, name, marks.get(0).toString()
return info; );
if (marks.size() > 1) {
info += String.format(", %s", marks.get(1).toString());
}
return info + "]";
} }
public int getId() { public int getId() {
@@ -43,5 +43,4 @@ public class RaceXMLData {
public List<Limit> getCourseLimit() { public List<Limit> getCourseLimit() {
return courseLimit; return courseLimit;
} }
} }
@@ -147,6 +147,7 @@ public class ClientToServerThread implements Runnable {
clientLog(e.getMessage(), 1); clientLog(e.getMessage(), 1);
return; return;
} }
System.out.println("streamPackets.size() = " + streamPackets.size());
} }
closeSocket(); closeSocket();
clientLog("Closed connection to Server", 0); clientLog("Closed connection to Server", 0);
@@ -1,6 +1,7 @@
package seng302.visualiser; package seng302.visualiser;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.Map; import java.util.Map;
@@ -12,6 +13,11 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.gameServer.MainServerThread; import seng302.gameServer.MainServerThread;
import seng302.model.RaceState; import seng302.model.RaceState;
@@ -173,7 +179,18 @@ public class GameClient {
break; break;
case RACE_XML: case RACE_XML:
System.out.println("RACE XML"); try {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(StreamParser.extractXmlMessage(packet)),
new StreamResult(writer));
// String output = writer.getBuffer().toString().replaceAll("\n|\r", "");
System.out.println(writer.getBuffer().toString());
}catch (Exception e) {
e.printStackTrace();
}
courseData = XMLParser.parseRace( courseData = XMLParser.parseRace(
StreamParser.extractXmlMessage(packet) StreamParser.extractXmlMessage(packet)
); );
+30 -15
View File
@@ -59,13 +59,16 @@ public class GameView extends Pane {
/* Note that if either of these is null then values for it have not been added and the other /* Note that if either of these is null then values for it have not been added and the other
should be used as the limits of the map. */ should be used as the limits of the map. */
private List<Limit> borderPoints; private List<Limit> borderPoints;
private List<CompoundMark> course;
private Map<Mark, Marker> markerObjects; private Map<Mark, Marker> markerObjects;
private Map<Yacht, BoatObject> boatObjects = new HashMap<>(); private Map<Yacht, BoatObject> boatObjects = new HashMap<>();
private Map<Yacht, AnnotationBox> annotations = new HashMap<>(); private Map<Yacht, AnnotationBox> annotations = new HashMap<>();
private List<Corner> markSequence;
private ObservableList<Node> gameObjects; private ObservableList<Node> gameObjects;
private Group annotationsGroup = new Group();
private Group wakesGroup = new Group();
private Group boatObjectGroup = new Group();
private Group trails = new Group();
private Group markers = new Group();
private ImageView mapImage = new ImageView(); private ImageView mapImage = new ImageView();
@@ -93,6 +96,7 @@ public class GameView extends Pane {
fpsDisplay.setStrokeWidth(2); fpsDisplay.setStrokeWidth(2);
gameObjects.add(fpsDisplay); gameObjects.add(fpsDisplay);
gameObjects.add(raceBorder); gameObjects.add(raceBorder);
gameObjects.add(markers);
initializeTimer(); initializeTimer();
// this.widthProperty().addListener(resize -> { // this.widthProperty().addListener(resize -> {
// canvasWidth = this.getWidth(); // canvasWidth = this.getWidth();
@@ -182,12 +186,12 @@ public class GameView extends Pane {
* @param newCourse the mark objects that make up the course. * @param newCourse the mark objects that make up the course.
*/ */
public void updateCourse(List<CompoundMark> newCourse, List<Corner> sequence) { public void updateCourse(List<CompoundMark> newCourse, List<Corner> sequence) {
course = newCourse;
this.markSequence = sequence;
markerObjects = new HashMap<>(); markerObjects = new HashMap<>();
Paint colour = Color.BLACK; Paint colour = Color.BLACK;
markers.getChildren().clear();
//Creates new markers //Creates new markers
for (CompoundMark cMark : course) { System.out.println(newCourse.size());
for (CompoundMark cMark : newCourse) {
//Set start and end colour //Set start and end colour
if (cMark.getId() == sequence.get(0).getCompoundMarkID()) { if (cMark.getId() == sequence.get(0).getCompoundMarkID()) {
colour = Color.GREEN; colour = Color.GREEN;
@@ -209,6 +213,7 @@ public class GameView extends Pane {
} }
} }
colour = Color.BLACK; colour = Color.BLACK;
System.out.println("cMark.toString() = " + cMark.toString());
} }
//Set X,Y co-ordinates //Set X,Y co-ordinates
if (borderPoints == null) { if (borderPoints == null) {
@@ -222,6 +227,7 @@ public class GameView extends Pane {
marker.setCenterX(p2d.getX()); marker.setCenterX(p2d.getX());
marker.setCenterY(p2d.getY()); marker.setCenterY(p2d.getY());
})); }));
markers.getChildren().addAll(markerObjects.values());
} }
/** /**
@@ -261,6 +267,7 @@ public class GameView extends Pane {
gate.endYProperty().bind( gate.endYProperty().bind(
m2.centerYProperty() m2.centerYProperty()
); );
markers.getChildren().addAll(gate);
} }
/** /**
@@ -293,18 +300,13 @@ public class GameView extends Pane {
findMinMaxPoint(limitingCoordinates); findMinMaxPoint(limitingCoordinates);
double minLonToMaxLon = scaleRaceExtremities(); double minLonToMaxLon = scaleRaceExtremities();
calculateReferencePointLocation(minLonToMaxLon); calculateReferencePointLocation(minLonToMaxLon);
drawGoogleMap(); // drawGoogleMap();
} }
/** /**
* Draws all the boats. * Draws all the boats.
*/ */
public void setBoats(List<Yacht> yachts) { public void setBoats(List<Yacht> yachts) {
Group annotationsGroup = new Group();
Group wakesGroup = new Group();
Group boatObjectGroup = new Group();
Group trails = new Group();
BoatObject newBoat; BoatObject newBoat;
for (Yacht yacht : yachts) { for (Yacht yacht : yachts) {
newBoat = new BoatObject(); newBoat = new BoatObject();
@@ -314,6 +316,7 @@ public class GameView extends Pane {
BoatObject bo = boatObjects.get(boat); BoatObject bo = boatObjects.get(boat);
Point2D p2d = findScaledXY(lat, lon); Point2D p2d = findScaledXY(lat, lon);
bo.moveTo(p2d.getX(), p2d.getY(), heading); bo.moveTo(p2d.getX(), p2d.getY(), heading);
annotations.get(boat).setLocation(p2d.getX(), p2d.getY());
bo.setTrajectory( bo.setTrajectory(
heading, heading,
velocity, velocity,
@@ -331,6 +334,18 @@ public class GameView extends Pane {
gameObjects.addAll(boatObjectGroup); gameObjects.addAll(boatObjectGroup);
} }
// private void updateBoatObject (Yacht correspondingYacht) {
// BoatObject bo = boatObjects.get(correspondingYacht);
// Point2D p2d = findScaledXY(lat, lon);
// bo.moveTo(p2d.getX(), p2d.getY(), heading);
// annotations.get(boat).moveTo(p2d.getX(), p2d.getY());
// bo.setTrajectory(
// heading,
// velocity,
// metersPerPixelX,
// metersPerPixelY);
// }
private void createAndBindAnnotationBox (Yacht yacht) { private void createAndBindAnnotationBox (Yacht yacht) {
AnnotationBox newAnnotation; AnnotationBox newAnnotation;
newAnnotation = new AnnotationBox(); newAnnotation = new AnnotationBox();
@@ -339,7 +354,7 @@ public class GameView extends Pane {
newAnnotation.addAnnotation( newAnnotation.addAnnotation(
"velocity", "velocity",
yacht.getVelocityProperty(), yacht.getVelocityProperty(),
(velocity) -> String.format("%.2f ms", velocity.doubleValue()) (velocity) -> String.format("Speed: %.2f ms", velocity.doubleValue())
); );
newAnnotation.addAnnotation( newAnnotation.addAnnotation(
"nextMark", "nextMark",
@@ -477,7 +492,7 @@ public class GameView extends Pane {
distanceFromReference = GeoUtility.getDistance( distanceFromReference = GeoUtility.getDistance(
minLatPoint, new GeoPoint(unscaledLat, unscaledLon) minLatPoint, new GeoPoint(unscaledLat, unscaledLon)
); );
System.out.println("distanceFromReference = " + distanceFromReference); // System.out.println("distanceFromReference = " + distanceFromReference);
if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) { if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) {
xAxisLocation += Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); xAxisLocation += Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference); yAxisLocation -= Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
@@ -497,8 +512,8 @@ public class GameView extends Pane {
if(horizontalInversion) { if(horizontalInversion) {
xAxisLocation = canvasWidth - bufferSize - (xAxisLocation - bufferSize); xAxisLocation = canvasWidth - bufferSize - (xAxisLocation - bufferSize);
} }
System.out.println("yAxisLocation = " + yAxisLocation + " " + unscaledLat); // System.out.println("yAxisLocation = " + yAxisLocation + " " + unscaledLat);
System.out.println("xAxisLocation = " + xAxisLocation + " " + unscaledLon); // System.out.println("xAxisLocation = " + xAxisLocation + " " + unscaledLon);
return new Point2D(xAxisLocation, yAxisLocation); return new Point2D(xAxisLocation, yAxisLocation);
} }
@@ -3,7 +3,6 @@ package seng302.visualiser.fxObjects;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.scene.CacheHint;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint; import javafx.scene.paint.Paint;
@@ -80,7 +79,7 @@ public class AnnotationBox extends Group{
private Map<String, Annotation> annotationsByName = new HashMap<>(); private Map<String, Annotation> annotationsByName = new HashMap<>();
public AnnotationBox() { public AnnotationBox() {
this.setCache(true); // this.setCache(true);
background.setX(BACKGROUND_X); background.setX(BACKGROUND_X);
background.setY(BACKGROUND_Y); background.setY(BACKGROUND_Y);
background.setWidth(backgroundWidth); background.setWidth(backgroundWidth);
@@ -90,8 +89,8 @@ public class AnnotationBox extends Group{
background.setFill(new Color(1, 1, 1, 0.75)); background.setFill(new Color(1, 1, 1, 0.75));
background.setStroke(theme); background.setStroke(theme);
background.setStrokeWidth(2); background.setStrokeWidth(2);
background.setCache(true); // background.setCache(true);
background.setCacheHint(CacheHint.SPEED); // background.setCacheHint(CacheHint.SPEED);
this.getChildren().add(background); this.getChildren().add(background);
} }
@@ -99,11 +98,15 @@ public class AnnotationBox extends Group{
annotationsByName.put(annotationName, annotation); annotationsByName.put(annotationName, annotation);
this.getChildren().add(annotation.getText()); this.getChildren().add(annotation.getText());
visibleAnnotations++; visibleAnnotations++;
update();
} }
public void addAnnotation (String annotationName, String annotationText) { public void addAnnotation (String annotationName, String annotationText) {
Text text = getTextObject(); Text text = getTextObject();
annotationsByName.put(annotationName, new Annotation(text, annotationText)); annotationsByName.put(annotationName, new Annotation(text, annotationText));
this.getChildren().add(text);
visibleAnnotations++;
update();
} }
public <E> void addAnnotation (String annotationName, ObservableValue<E> observable) { public <E> void addAnnotation (String annotationName, ObservableValue<E> observable) {
@@ -116,6 +119,7 @@ public class AnnotationBox extends Group{
annotationsByName.put(annotationName, new Annotation<>(newText, observable, formatter)); annotationsByName.put(annotationName, new Annotation<>(newText, observable, formatter));
this.getChildren().add(newText); this.getChildren().add(newText);
visibleAnnotations++; visibleAnnotations++;
update();
} }
public void setAnnotationVisibility (String annotationName, boolean visibility) { public void setAnnotationVisibility (String annotationName, boolean visibility) {
@@ -144,8 +148,8 @@ public class AnnotationBox extends Group{
} }
public void setLocation (double x, double y) { public void setLocation (double x, double y) {
this.setLayoutX(x); this.setTranslateX(x);
this.setLayoutY(y); this.setTranslateY(y);
} }
public void setWidth (double width) { public void setWidth (double width) {
@@ -172,8 +176,8 @@ public class AnnotationBox extends Group{
Text text = new Text(); Text text = new Text();
text.setFill(theme); text.setFill(theme);
text.setStrokeWidth(2); text.setStrokeWidth(2);
text.setCacheHint(CacheHint.SPEED); // text.setCacheHint(CacheHint.SPEED);
text.setCache(true); // text.setCache(true);
return text; return text;
} }
@@ -80,8 +80,8 @@ public class BoatObject extends Group {
boatPoly.setStroke(Color.BLACK); boatPoly.setStroke(Color.BLACK);
}); });
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected)); boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
boatPoly.setCache(true); // boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED); // boatPoly.setCacheHint(CacheHint.SPEED);
// annotationBox = new AnnotationBox(); // annotationBox = new AnnotationBox();
// annotationBox.setFill(colour); // annotationBox.setFill(colour);
+7 -31
View File
@@ -28,30 +28,6 @@
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" /> <Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" /> <Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark> </CompoundMark>
<CompoundMark CompoundMarkID="5" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
</CompoundMark>
<CompoundMark CompoundMarkID="6" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark>
<CompoundMark CompoundMarkID="7" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
</CompoundMark>
<CompoundMark CompoundMarkID="8" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark>
<CompoundMark CompoundMarkID="9" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
</CompoundMark>
<CompoundMark CompoundMarkID="10" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark>
<CompoundMark CompoundMarkID="11" Name="Mark4"> <CompoundMark CompoundMarkID="11" Name="Mark4">
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="128" /> <Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="128" />
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="129" /> <Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="129" />
@@ -62,13 +38,13 @@
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3" /> <Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3" />
<Corner SeqID="3" CompoundMarkID="3" Rounding="SP" ZoneSize="3" /> <Corner SeqID="3" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="3" /> <Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
<Corner SeqID="5" CompoundMarkID="5" Rounding="SP" ZoneSize="3" /> <Corner SeqID="5" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
<Corner SeqID="6" CompoundMarkID="6" Rounding="PS" ZoneSize="3" /> <Corner SeqID="6" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
<Corner SeqID="7" CompoundMarkID="7" Rounding="SP" ZoneSize="3" /> <Corner SeqID="7" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
<Corner SeqID="8" CompoundMarkID="8" Rounding="PS" ZoneSize="3" /> <Corner SeqID="8" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
<Corner SeqID="9" CompoundMarkID="9" Rounding="SP" ZoneSize="3" /> <Corner SeqID="9" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
<Corner SeqID="10" CompoundMarkID="10" Rounding="PS" ZoneSize="3" /> <Corner SeqID="10" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
<Corner SeqID="11" CompoundMarkID="11" Rounding="PS" ZoneSize="3" /> <Corner SeqID="11" CompoundMarkID="5" Rounding="PS" ZoneSize="3" />
</CompoundMarkSequence> </CompoundMarkSequence>
<CourseLimit> <CourseLimit>
<Limit SeqID="1" Lat="57.6739450" Lon="11.8417100" /> <Limit SeqID="1" Lat="57.6739450" Lon="11.8417100" />