Refactored mock.Event to work with MockRace.

Fixed the networking imports.
Race now keeps a reference to its Race, Boat, and Regatta data sources.
VisualiserRace can be provided with new Race/Boat/Regatta data sources during runtime. Currently it updates boundary and legs with a new RaceDataSource, and marker boats with a new BoatDataSource.
This commit is contained in:
fjc40
2017-07-06 15:25:00 +12:00
parent 8d36d89570
commit 3a0b81834f
30 changed files with 179 additions and 83 deletions
@@ -1,7 +1,11 @@
package network;
import seng302.Networking.Exceptions.InvalidMessageException;
import seng302.Networking.Messages.Enums.MessageType;
import network.Exceptions.InvalidMessageException;
import network.MessageDecoders.*;
import network.Messages.*;
import network.Messages.Enums.MessageType;
import static network.Utils.ByteConverter.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
@@ -69,20 +73,20 @@ public class BinaryMessageDecoder {
this.headerMessageType = this.messageHeader[2];
//Get the header timestamp.
this.headerTimeStamp = ByteConverter.bytesToLong(Arrays.copyOfRange(this.messageHeader, 3, 9));
this.headerTimeStamp = bytesToLong(Arrays.copyOfRange(this.messageHeader, 3, 9));
//Get the source ID for the message.
this.headerSourceID = ByteConverter.bytesToInt(Arrays.copyOfRange(this.messageHeader, 9, 13));
this.headerSourceID = bytesToInt(Arrays.copyOfRange(this.messageHeader, 9, 13));
//Get the length of the message body.
this.messageBodyLength = ByteConverter.bytesToInt(Arrays.copyOfRange(this.messageHeader, 13, 15));
this.messageBodyLength = bytesToInt(Arrays.copyOfRange(this.messageHeader, 13, 15));
//Get the messageBody.
this.messageBody = Arrays.copyOfRange(this.fullMessage, this.headerLength, this.headerLength + this.messageBodyLength);
//Get the CRC value.
this.messageCRCValue = ByteConverter.bytesToLong(Arrays.copyOfRange(this.fullMessage, this.fullMessage.length - CRCLength, this.fullMessage.length));
this.messageCRCValue = bytesToLong(Arrays.copyOfRange(this.fullMessage, this.fullMessage.length - CRCLength, this.fullMessage.length));
//Combine the header and body into a single array.
ByteBuffer headerBodyByteBuffer = ByteBuffer.allocate(messageHeader.length + messageBody.length);
@@ -131,7 +135,7 @@ public class BinaryMessageDecoder {
//System.out.println("Decoding HeartBeat Message!");
//TODO maybe use HeartbeatDecoder.decode(message).
//TODO also, decoders for each message type should encapsulate the constructing of the object. E.g., return HeartbeatDecoder.decode(message);.
return new Heartbeat(ByteConverter.bytesToLong(messageBody));
return new Heartbeat(bytesToLong(messageBody));
case RACESTATUS:
//System.out.println("Race Status Message");