Map wind rotation works with multiplayer xml. #story[1092]
This commit is contained in:
@@ -4,12 +4,7 @@ import mock.dataInput.PolarParser;
|
|||||||
import mock.exceptions.EventConstructionException;
|
import mock.exceptions.EventConstructionException;
|
||||||
import mock.model.*;
|
import mock.model.*;
|
||||||
import mock.model.commandFactory.CompositeCommand;
|
import mock.model.commandFactory.CompositeCommand;
|
||||||
import mock.model.MockRace;
|
|
||||||
import mock.model.Polars;
|
|
||||||
import mock.xml.RaceXMLCreator;
|
import mock.xml.RaceXMLCreator;
|
||||||
import mock.model.RaceLogic;
|
|
||||||
import mock.model.SourceIdAllocator;
|
|
||||||
import mock.model.commandFactory.CompositeCommand;
|
|
||||||
import network.Messages.LatestMessages;
|
import network.Messages.LatestMessages;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import shared.dataInput.*;
|
import shared.dataInput.*;
|
||||||
@@ -20,13 +15,11 @@ import shared.exceptions.InvalidRegattaDataException;
|
|||||||
import shared.exceptions.XMLReaderException;
|
import shared.exceptions.XMLReaderException;
|
||||||
import shared.model.Bearing;
|
import shared.model.Bearing;
|
||||||
import shared.model.Constants;
|
import shared.model.Constants;
|
||||||
import shared.xml.Race.XMLRace;
|
|
||||||
import shared.xml.XMLUtilities;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@@ -93,55 +86,32 @@ public class Event {
|
|||||||
|
|
||||||
//Read XML files.
|
//Read XML files.
|
||||||
try {
|
try {
|
||||||
this.raceXML = RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90);
|
this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90);
|
||||||
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
|
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
|
||||||
this.regattaXML = XMLReader.readXMLFileToString(regattaXMLFile, StandardCharsets.UTF_8);
|
this.regattaXML = XMLReader.readXMLFileToString(regattaXMLFile, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
} catch (XMLReaderException e) {
|
} catch (XMLReaderException e) {
|
||||||
throw new EventConstructionException("Could not read XML files.", e);
|
throw new EventConstructionException("Could not read XML files.", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (SAXException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvalidRaceDataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.xmlFileType = XMLFileType.Contents;
|
this.xmlFileType = XMLFileType.Contents;
|
||||||
|
|
||||||
this.boatPolars = PolarParser.parse("mock/polars/acc_polars.csv");
|
this.boatPolars = PolarParser.parse("mock/polars/acc_polars.csv");
|
||||||
|
|
||||||
this.latestMessages = new LatestMessages();
|
|
||||||
this.connectionAcceptor = new ConnectionAcceptor(latestMessages);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Event getEvent() {
|
|
||||||
return theEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAddress() throws UnknownHostException {
|
|
||||||
return connectionAcceptor.getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPort() {
|
|
||||||
return connectionAcceptor.getServerPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the initial race data and then begins race simulation.
|
|
||||||
* @throws InvalidRaceDataException Thrown if the race xml file cannot be parsed.
|
|
||||||
* @throws XMLReaderException Thrown if any of the xml files cannot be parsed.
|
|
||||||
* @throws InvalidBoatDataException Thrown if the boat xml file cannot be parsed.
|
|
||||||
* @throws InvalidRegattaDataException Thrown if the regatta xml file cannot be parsed.
|
|
||||||
* @throws ParserConfigurationException Error in parsing XML
|
|
||||||
* @throws JAXBException error in mapping the xml to a schema
|
|
||||||
* @throws SAXException error in reading the schema
|
|
||||||
* @throws IOException error in finding the schema
|
|
||||||
*/
|
|
||||||
public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException, ParserConfigurationException, JAXBException, SAXException, IOException {
|
|
||||||
new Thread(connectionAcceptor, "Event.Start()->ConnectionAcceptor thread").start();
|
|
||||||
|
|
||||||
sendXMLs();
|
|
||||||
|
|
||||||
|
//Parse the XML files into data sources.
|
||||||
try {
|
try {
|
||||||
this.raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
|
this.raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
|
||||||
XMLRace race = (XMLRace) XMLUtilities.xmlToClass(raceXML,
|
|
||||||
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
|
|
||||||
XMLRace.class);
|
|
||||||
this.boatDataSource = new BoatXMLReader(this.boatXML, this.xmlFileType);
|
this.boatDataSource = new BoatXMLReader(this.boatXML, this.xmlFileType);
|
||||||
this.regattaDataSource = new RegattaXMLReader(this.regattaXML, this.xmlFileType);
|
this.regattaDataSource = new RegattaXMLReader(this.regattaXML, this.xmlFileType);
|
||||||
|
|
||||||
@@ -215,21 +185,4 @@ public class Event {
|
|||||||
|
|
||||||
connectionAcceptor.setBoatsXml(boatXML);
|
connectionAcceptor.setBoatsXml(boatXML);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//The start time is current time + 4 minutes. prestart is 3 minutes, and we add another minute.
|
|
||||||
long millisecondsToAdd = Constants.RacePreStartTime + Duration.ofMinutes(1).toMillis();
|
|
||||||
long secondsToAdd = millisecondsToAdd / 1000;
|
|
||||||
//Scale the time using our time scalar.
|
|
||||||
secondsToAdd = secondsToAdd / Constants.RaceTimeScale;
|
|
||||||
|
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
|
||||||
ZonedDateTime creationTime = ZonedDateTime.now();
|
|
||||||
raceXML = raceXML.replace("CREATION_TIME", dateFormat.format(creationTime));
|
|
||||||
|
|
||||||
raceXML = raceXML.replace("START_TIME", dateFormat.format(creationTime.plusSeconds(secondsToAdd)));
|
|
||||||
|
|
||||||
return raceXML;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -399,8 +399,7 @@ public class MockRace extends Race {
|
|||||||
double lastAngle = -1;
|
double lastAngle = -1;
|
||||||
boolean lastAngleWasGood = false;
|
boolean lastAngleWasGood = false;
|
||||||
|
|
||||||
//Check all bearings between [0his.latestMessages = new LatestMessages();
|
//Check all bearings between [0, 360)
|
||||||
thi, 360).
|
|
||||||
for (double angle = 0; angle < 360; angle += 1) {
|
for (double angle = 0; angle < 360; angle += 1) {
|
||||||
|
|
||||||
//Create bearing from angle.
|
//Create bearing from angle.
|
||||||
@@ -636,8 +635,6 @@ public class MockRace extends Race {
|
|||||||
protected int getNumberOfActiveBoats() {
|
protected int getNumberOfActiveBoats() {
|
||||||
|
|
||||||
int numberOfActiveBoats = 0;
|
int numberOfActiveBoats = 0;
|
||||||
his.latestMessages = new LatestMessages();
|
|
||||||
thi
|
|
||||||
for (MockBoat boat : this.boats) {
|
for (MockBoat boat : this.boats) {
|
||||||
|
|
||||||
//If the boat is currently racing, count it.
|
//If the boat is currently racing, count it.
|
||||||
@@ -710,6 +707,7 @@ his.latestMessages = new LatestMessages();
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<CompoundMark> getCompoundMarks() {
|
||||||
|
return compoundMarks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<Race>
|
<Race>
|
||||||
<RaceID>5326</RaceID>
|
<RaceID>5326</RaceID>
|
||||||
<RaceType>FLEET</RaceType>
|
<RaceType>FLEET</RaceType>
|
||||||
<CreationTimeDate>CREATION_TIME</CreationTimeDate>
|
<CreationTimeDate>2017-08-03T02:13:14+1200</CreationTimeDate>
|
||||||
<RaceStartTime Postpone="false" Time="START_TIME"/>
|
<RaceStartTime Postpone="false" Time="2017-08-03T02:08:10+1200"/>
|
||||||
<Participants>
|
<Participants>
|
||||||
<Yacht SourceID="126"/>
|
<Yacht SourceID="126"/>
|
||||||
</Participants>
|
</Participants>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<Race>
|
<Race>
|
||||||
<RaceID>5326</RaceID>
|
<RaceID>5326</RaceID>
|
||||||
<RaceType>FLEET</RaceType>
|
<RaceType>FLEET</RaceType>
|
||||||
<CreationTimeDate>CREATION_TIME</CreationTimeDate>
|
<CreationTimeDate>2017-08-03T02:13:14+1200</CreationTimeDate>
|
||||||
<RaceStartTime Postpone="false" Time="START_TIME"/>
|
<RaceStartTime Postpone="false" Time="2017-08-03T02:08:10+1200"/>
|
||||||
<Participants>
|
<Participants>
|
||||||
<Yacht SourceID="121"/>
|
<Yacht SourceID="121"/>
|
||||||
<Yacht SourceID="122"/>
|
<Yacht SourceID="122"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user