Mockoutput's main loop now pops messages off the message queue, rather than iterating over it like an array, and clearing it (this could have threading issues where the iteration starts (with e.g., 5 messages), as it is sending the messages another one is added, and then it ends up clearing the sent messages, and the unsent message.

Made a few quick fixes (to be tidied a bit later) to Mock.Race class. It now has this.startTime, instead of the AnimationTimers having their own starTime value. RaceStatus messages are now sent properly (still need a refactor though), so they actually send the race star time - this means that the visualizer using the mock data source displays the correct time instead of (midnight, jan 1, 1970).

Removed one of the constructors from RaceStatus - it allowed for constructing and sending essentially invalid RaceStatus messages, and simply wasn't needed.

Added a temporary title ("RaceVision - Team 7") to the visualiser - may be worth changing when we decide on a team name.

Fixed a bug with the order of operations in visualiser.StartController.countdownTimer(). Calling begin race before hiding panes caused them to never be hidden.

Mock.Event. Changed the scaleFactor to 5x for the time being - to easier testing of things like pre-race timers, countdowns, etc...

#story[778,782]
main
fjc40 9 years ago
parent 01224c509a
commit 83ce9b99d2

@ -9,7 +9,6 @@ import seng302.DataInput.RaceXMLReader;
import seng302.DataInput.RegattaDataSource;
import seng302.DataInput.RegattaXMLReader;
import seng302.Model.Event;
import java.io.OutputStream;
import javax.xml.parsers.ParserConfigurationException;

@ -1,7 +1,6 @@
package seng302;
import seng302.Model.Boat;
import seng302.Networking.BinaryMessageEncoder;
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
@ -23,6 +22,9 @@ public class MockOutput implements Runnable
///Timestamp of the last sent heartbeat message.
private long lastHeartbeatTime;
///Period for the heartbeat - that is, how often we send it.
private double heartbeatPeriod = 5.0;
///Port to expose server on.
private int serverPort = 4942;
///Socket used to listen for clients on.
@ -33,7 +35,7 @@ public class MockOutput implements Runnable
private DataOutputStream outToVisualiser;
///A queue that contains items that are waiting to be sent.
private ArrayBlockingQueue<byte[]> messagesToSendBuffer = new ArrayBlockingQueue<>(99999999);
private ArrayBlockingQueue<byte[]> messagesToSendQueue = new ArrayBlockingQueue<>(99999999);
///Sequence numbers used in messages.
private short messageNumber = 1;
@ -41,6 +43,7 @@ public class MockOutput implements Runnable
private int heartbeatSequenceNum = 1;
private int boatLocationSequenceNumber = 1;
private int raceStatusSequenceNumber = 1;
///Strings containing XML data as strings.
private String raceXml;
private String regattaXml;
@ -152,7 +155,7 @@ public class MockOutput implements Runnable
* @param messagesToSendBuffer message to add to the buffer
*/
private synchronized void addMessageToBufferToSend(byte[] messagesToSendBuffer) {
this.messagesToSendBuffer.add(messagesToSendBuffer);
this.messagesToSendQueue.add(messagesToSendBuffer);
}
public void run() {
@ -163,7 +166,6 @@ public class MockOutput implements Runnable
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
/*******************************Test********************************/
while(boatsXml == null || regattaXml == null || raceXml == null) {
@ -173,24 +175,23 @@ public class MockOutput implements Runnable
parseXMLString(regattaXml, XMLMessage.XMLTypeRegatta);
parseXMLString(boatsXml, XMLMessage.XMLTypeBoat);
/*******************************Test********************************/
while(true) {
try {
//sends a heartbeat every 5 seconds
if (timeSinceHeartbeat() >= 5.00) {
//Sends a heartbeat every so often.
if (timeSinceHeartbeat() >= heartbeatPeriod) {
outToVisualiser.write(heartbeat());
lastHeartbeatTime = System.currentTimeMillis();
}
//checks the buffer to see if there is anything to send
if (messagesToSendBuffer.size() > 0) {
for (byte[] binaryMessage : messagesToSendBuffer) {
//sends the message to the visualiser
outToVisualiser.write(binaryMessage);
}
//cleans out buffer
messagesToSendBuffer.clear();
//Checks the buffer to see if there is anything to send.
while (messagesToSendQueue.size() > 0) {
//Grabs message from head of queue.
byte[] binaryMessage = messagesToSendQueue.remove();
//sends the message to the visualiser
outToVisualiser.write(binaryMessage);
}
}catch(SocketException e){
break;

@ -44,7 +44,9 @@ public class Event {
sendRaceData();
System.out.println("Sending Boat");
sendBoatData();
Race newRace = new Race(raceDataSource, 15, mockOutput);
int scaleFactor = 5;//TEMP - was 15.
Race newRace = new Race(raceDataSource, scaleFactor, mockOutput);
new Thread((newRace)).start();
}

@ -33,6 +33,7 @@ public class Race implements Runnable {
protected long totalTimeElapsed;
protected int scaleFactor=25;
protected int PRERACE_TIME = 180000; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
private long startTime;
protected boolean countdownFinish = false;
protected boolean runRace = true;
private int lastFPS = 20;
@ -56,9 +57,11 @@ public class Race implements Runnable {
this.legs = legs;
this.legs.add(new Leg("Finish", this.legs.size()));
this.raceId = raceID;
this.scaleFactor = 50;
this.scaleFactor = scaleFactor;
this.mockOutput = mockOutput;
//TODO refactor
this.startTime = System.currentTimeMillis() + (this.PRERACE_TIME / this.scaleFactor);
if (startingBoats != null && startingBoats.size() > 0) {
initialiseBoats();
@ -111,7 +114,7 @@ public class Race implements Runnable {
protected void countdownTimer() {
AnimationTimer timer = new AnimationTimer() {
long currentTime = System.currentTimeMillis();
long startTime = currentTime + (PRERACE_TIME / scaleFactor);
//long startTime = currentTime + (PRERACE_TIME / scaleFactor);
//long minutes;
//long hours;
long timeLeft;
@ -132,7 +135,7 @@ public class Race implements Runnable {
boatOffset = (boatOffset + 1) % (startingBoats.size());
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, startTime, 0, 2300, 1, boatStatusMessages);
mockOutput.parseRaceStatus(raceStatus);
}
else if (timeLeft <= 0) {
@ -143,7 +146,7 @@ public class Race implements Runnable {
stop();
}
else {
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, startTime, 0, 2300,1, boatStatusMessages);
mockOutput.parseRaceStatus(raceStatus);
}
currentTime = System.currentTimeMillis();
@ -197,7 +200,7 @@ public class Race implements Runnable {
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
}
if (startingBoats.size()==finished){
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, 2, boatStatusMessages);
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, startTime, 0, 2300, 2, boatStatusMessages);//TODO FIX the second currentTime is a placeholder! Also, replace magic values.
mockOutput.parseRaceStatus(raceStatus);
}
} else {
@ -205,7 +208,7 @@ public class Race implements Runnable {
}
}
boatOffset = (boatOffset + 1) % (startingBoats.size());
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, 2, boatStatusMessages);
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, startTime, 0, 2300, 2, boatStatusMessages);//TODO FIX the second currentTime is a placeholder! Also, replace magic values.
mockOutput.parseRaceStatus(raceStatus);
}
}

@ -27,14 +27,8 @@ public class RaceStatus extends AC35Data{
this.boatStatusMessages = boatStatusMessages;//note this is a copy so any alterations to the parent will affect this.
}
public RaceStatus( long currentTime, int raceID, int raceStatus, int raceType, ArrayList<BoatStatusMessage> boatStatusMessages) {
super(MessageType.RACESTATUS);
this.currentTime = currentTime;
this.raceID = raceID;
this.raceStatus = raceStatus;
this.raceType = raceType;
this.boatStatusMessages = boatStatusMessages;
}
///Getters.
public long getCurrentTime()

@ -36,6 +36,7 @@ public class App extends Application {
Parent root = loader.load();
Scene scene = new Scene(root, 1200, 800);
stage.setScene(scene);
stage.setTitle("RaceVision - Team 7");
stage.show();
}
}

@ -98,10 +98,13 @@ public class StartController extends Controller implements Observer {
raceStat = visualiserInput.getRaceStatus().getRaceStatus();
raceStatusLabel.setText("Race Status: " + visualiserInput.getRaceStatus().getRaceStatus());
if (raceStat==2 || raceStat == 3) {
System.out.println("countdown finished!");//TEMP DEBUG REMOVE
stop();
parent.beginRace(visualiserInput, raceClock);
startWrapper.setVisible(false);
start.setVisible(false);
parent.beginRace(visualiserInput, raceClock);
}
}
}.start();

@ -27,7 +27,7 @@ import static seng302.Networking.Utils.MessageType.*;
*/
public class VisualiserInput implements Runnable
{
//time since last heartbeat
//Time since last heartbeat.
private long lastHeartbeatTime;
//socket port 4945 as 4940 is ac35 live port and 4941 is ac35 test port

Loading…
Cancel
Save