Story 49 Marks move with boat location.

- Commented out blocking array as it was unecessary
- Added Observable list for markers to the race canvas
- Added SourceId's to Marker
- Added updating Markers from the Streamed Race loop.
#story[881] #pair[fwy13, jam339]
main
Fan-Wu Yang 9 years ago
parent 43757b34d1
commit 9e19ddb1f4

@ -48,8 +48,9 @@ public class RaceController extends Controller {
* @param boats boats that are to be displayed in the race
* @see ResizableRaceCanvas
*/
public void updateMap(ObservableList<Boat> boats) {
public void updateMap(ObservableList<Boat> boats, ObservableList<Marker> boatMarkers) {
raceMap.setBoats(boats);
raceMap.setBoatMarkers(boatMarkers);
raceMap.update();
raceBoundaries.draw();
//stop if the visualiser is no longer running

@ -165,8 +165,9 @@ public class StreamedCourseXMLReader extends XMLReader {
Marker marker;
switch(nMarks.getLength()) {
case 1: marker = new Marker(getCoordinate((Element)nMarks.item(0))); break;
case 2: marker = new Marker(getCoordinate((Element)nMarks.item(0)), getCoordinate((Element)nMarks.item(1))); break;
case 1: marker = new Marker(getCoordinate((Element)nMarks.item(0)),getSourceId((Element)nMarks.item(0))); break;
case 2: marker = new Marker(getCoordinate((Element)nMarks.item(0)), getCoordinate((Element)nMarks.item(1)),
getSourceId((Element)nMarks.item(0)), getSourceId((Element)nMarks.item(1))); break;
default: throw new StreamedCourseXMLException();
}
@ -179,6 +180,10 @@ public class StreamedCourseXMLReader extends XMLReader {
return new GPSCoordinate(lat,lon);
}
private int getSourceId(Element mark) {
return Integer.parseInt(mark.getAttribute("SourceID"));
}
/**
* Reads "compoundMarkID" attribute of CompoundMark or Corner element
* @param element with "compoundMarkID" attribute

@ -98,6 +98,28 @@ public class StreamedRace extends Race {
}
}
/**
* Updates the boat's gps coordinates
*
* @param mark to be updated
*/
protected void updateMarker(Marker mark) {
int sourceID = mark.getSourceId1();
BoatLocation boatLocation1 = visualiserInput.getBoatLocationMessage(sourceID);
if(boatLocation1 != null) {
double lat = boatLocation1.getLatitudeDouble();
double lon = boatLocation1.getLongitudeDouble();
mark.setCurrentPosition1(new GPSCoordinate(lat, lon));
}
int sourceID2 = mark.getSourceId2();
BoatLocation boatLocation2 = visualiserInput.getBoatLocationMessage(sourceID2);
if(boatLocation1 != null) {
double lat = boatLocation2.getLatitudeDouble();
double lon = boatLocation2.getLongitudeDouble();
mark.setCurrentPosition2(new GPSCoordinate(lat, lon));
}
}
/**
* sets the position of a boat from coordinate
* @param boat the boat to set

@ -10,25 +10,42 @@ import java.awt.geom.Point2D;
*/
public class Marker {
private final GPSCoordinate averageGPSCoordinate;
private final GPSCoordinate mark1;
private final GPSCoordinate mark2;
public Marker(GPSCoordinate mark1) {
this.mark1 = mark1;
this.mark2 = mark1;
this.averageGPSCoordinate = calculateAverage();
private GPSCoordinate mark1;
private GPSCoordinate mark2;
private final int sourceId1;
private final int sourceId2;
public Marker(GPSCoordinate mark1, int sourceId) {
this(mark1, mark1, sourceId, sourceId);
}
public Marker(GPSCoordinate mark1, GPSCoordinate mark2) {
public Marker(GPSCoordinate mark1, GPSCoordinate mark2, int sourceId1, int sourceId2) {
this.mark1 = mark1;
this.mark2 = mark2;
this.averageGPSCoordinate = calculateAverage();
this.sourceId1 = sourceId1;
this.sourceId2 = sourceId2;
}
/**
* @deprecated
* @param mark1 Mark coordinates.
*/
public Marker(GPSCoordinate mark1) {
this(mark1, mark1, 0,0);
}
/**
* @deprecated
* @param mark1 Mark one coordinate
* @param mark2 Mark two coordinate
*/
public Marker(GPSCoordinate mark1, GPSCoordinate mark2) {
this(mark1, mark2, 0,0);
}
public GPSCoordinate getMark1() {
return mark1;
}
@ -66,4 +83,19 @@ public class Marker {
}
public void setCurrentPosition1(GPSCoordinate gpsCoordinate){
mark1 = gpsCoordinate;
}
public void setCurrentPosition2(GPSCoordinate gpsCoordinate){
mark2 = gpsCoordinate;
}
public int getSourceId1() {
return sourceId1;
}
public int getSourceId2() {
return sourceId2;
}
}

@ -17,6 +17,7 @@ import java.util.List;
*/
public abstract class Race implements Runnable {
protected final ObservableList<Boat> startingBoats;
protected final ObservableList<Marker> boatMarkers;
protected final List<Leg> legs;
private RaceController controller;
protected FinishController finishController;
@ -33,9 +34,10 @@ public abstract class Race implements Runnable {
* @param controller race controller
* @param scaleFactor for race
*/
private Race(List<Boat> boats, List<Leg> legs, RaceController controller, int scaleFactor) {
private Race(List<Boat> boats, List<Marker> boatMarkers, List<Leg> legs, RaceController controller, int scaleFactor) {
this.startingBoats = FXCollections.observableArrayList(boats);
this.boatMarkers = FXCollections.observableArrayList(boatMarkers);
this.legs = legs;
this.legs.add(new Leg("Finish", this.legs.size()));
this.controller = controller;
@ -45,7 +47,7 @@ public abstract class Race implements Runnable {
}
protected Race(RaceDataSource raceData, RaceController controller, int scaleFactor) {
this(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor);
this(raceData.getBoats(), raceData.getMarkers(), raceData.getLegs(), controller, scaleFactor);
}
/**
@ -56,7 +58,7 @@ public abstract class Race implements Runnable {
* @param scaleFactor factor to scale by
*/
public Race(Boat[] startingBoats, List<Leg> legs, RaceController controller, int scaleFactor) {
this(Arrays.asList(startingBoats), legs, controller, scaleFactor);
this(Arrays.asList(startingBoats), null, legs, controller, scaleFactor);
}
public void setController(RaceController controller) {
@ -80,6 +82,8 @@ public abstract class Race implements Runnable {
*/
protected abstract void checkPosition(Boat boat, long timeElapsed);
protected abstract void updateMarker(Marker mark);
/**
* Updates the boat's gps coordinates
*
@ -140,12 +144,17 @@ public abstract class Race implements Runnable {
boatsFinished++;
}
}
for (Marker mark: boatMarkers){
if (mark != null){
updateMarker(mark);
}
}
//System.out.println(boatsFinished + ":" + startingBoats.size());
} else {
controller.finishRace(startingBoats);
stop();
}
controller.updateMap(startingBoats);
controller.updateMap(startingBoats, boatMarkers);
fps++;
if ((System.currentTimeMillis() - timeCurrent) > 1000) {
updateFPS(fps);

@ -1,6 +1,7 @@
package seng302.Model;
import javafx.collections.ObservableList;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.transform.Rotate;
@ -22,6 +23,7 @@ import java.util.List;
public class ResizableRaceCanvas extends ResizableCanvas {
private RaceMap map;
private List<Boat> boats;
private List<Marker> boatMarkers;
private boolean raceAnno = true;
private boolean annoName = true;
private boolean annoAbbrev = true;
@ -56,6 +58,16 @@ public class ResizableRaceCanvas extends ResizableCanvas {
this.boats = boats;
}
/**
* Sets the boat markers that are to be displayed in this race.
*
* @param boatMarkers in race
*/
public void setBoatMarkers(ObservableList<Marker> boatMarkers) {
this.boatMarkers = boatMarkers;
}
/**
* Sets the RaceMap that the RaceCanvas is to be displaying for.
*

@ -1,6 +1,7 @@
package seng302;
import org.xml.sax.SAXException;
import seng302.Mock.*;
import seng302.Model.Boat;
import seng302.Networking.BinaryMessageDecoder;
import seng302.Networking.Exceptions.InvalidMessageException;
import seng302.Networking.Messages.*;
@ -13,6 +14,7 @@ import java.nio.ByteBuffer;
import java.text.ParseException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
@ -219,7 +221,7 @@ public class VisualiserInput implements Runnable {
//If no heartbeat has been received in more the heartbeat period
//then the connection will need to be restarted.
System.out.println("time since last heartbeat: " + timeSinceHeartbeat());//TEMP REMOVE
//System.out.println("time since last heartbeat: " + timeSinceHeartbeat());//TEMP REMOVE
long heartBeatPeriod = 10 * 1000;
if (timeSinceHeartbeat() > heartBeatPeriod) {
System.out.println("Connection has stopped, trying to reconnect.");
@ -258,10 +260,10 @@ public class VisualiserInput implements Runnable {
System.err.println("Unable to read message: " + e.getMessage());
//Continue to the next loop iteration/message.
continue;
}
}/*
//Add it to message queue.
this.messagesReceivedQueue.add(message);
this.messagesReceivedQueue.add(message);*/
//Checks which message is being received and does what is needed for that message.
@ -379,7 +381,6 @@ public class VisualiserInput implements Runnable {
//If the map _doesn't_ already contain a message for this boat, insert the message.
this.boatLocationMap.put(boatLocation.getSourceID(), boatLocation);
}
}
//MarkRounding.
else if (message instanceof MarkRounding) {

Loading…
Cancel
Save