Race now has a 10 minute delay before starting (which is increased whenever it falls below 5 minutes).
The start button (visible to host) starts the race in whatever the prepatory time is. #story[1352]
This commit is contained in:
@@ -116,14 +116,17 @@ public class Event {
|
|||||||
|
|
||||||
//Read XML files.
|
//Read XML files.
|
||||||
try {
|
try {
|
||||||
//this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90);
|
|
||||||
this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8));
|
|
||||||
if(mapIndex==4){
|
if(mapIndex==4){
|
||||||
//this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8), 1000, 5000);
|
//This is the tutorial map.
|
||||||
this.raceXML = RaceXMLCreator.alterRaceToWind(this.raceXML, XMLFileType.Contents, -1, true);
|
this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8), 1000, 5000);
|
||||||
|
this.raceXML = RaceXMLCreator.alterRaceToWind(this.raceXML, XMLFileType.Contents, -1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.raceXML = RaceXMLCreator.alterRaceToWind(this.raceXML, XMLFileType.Contents, windAngle, false);
|
this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8));
|
||||||
|
this.raceXML = RaceXMLCreator.alterRaceToWind(this.raceXML, XMLFileType.Contents, windAngle);
|
||||||
this.raceXML = RaceXMLCreator.scaleRaceSize(raceXML, windSpeed, 15 * 60 * 1000);
|
this.raceXML = RaceXMLCreator.scaleRaceSize(raceXML, windSpeed, 15 * 60 * 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
|
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
|
||||||
@@ -219,16 +222,13 @@ public class Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String setRaceXMLAtCurrentTimeToNow(String raceXML, long racePreStartTime, long racePreparatoryTime){
|
public static String setRaceXMLAtCurrentTimeToNow(String raceXML, long racePreStartTime, long racePreparatoryTime){
|
||||||
//The start time is current time + 4 minutes. prestart is 3 minutes, and we add another minute.
|
|
||||||
|
|
||||||
long millisecondsToAdd = racePreStartTime + racePreparatoryTime;
|
long minutesToAdd = 10;
|
||||||
|
|
||||||
long secondsToAdd = millisecondsToAdd / 1000;
|
|
||||||
|
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||||
ZonedDateTime creationTime = ZonedDateTime.now();
|
ZonedDateTime creationTime = ZonedDateTime.now();
|
||||||
raceXML = raceXML.replace("RACE_CREATION_TIME", dateFormat.format(creationTime));
|
raceXML = raceXML.replace("RACE_CREATION_TIME", dateFormat.format(creationTime));
|
||||||
raceXML = raceXML.replace("RACE_START_TIME", dateFormat.format(creationTime.plusSeconds(secondsToAdd)));
|
raceXML = raceXML.replace("RACE_START_TIME", dateFormat.format(creationTime.plusMinutes(minutesToAdd)));
|
||||||
|
|
||||||
return raceXML;
|
return raceXML;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ public class MockRace extends RaceState {
|
|||||||
|
|
||||||
private long racePreparatoryTime = Constants.RacePreparatoryTime;
|
private long racePreparatoryTime = Constants.RacePreparatoryTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the race has been manually started, false otherwise.
|
||||||
|
*/
|
||||||
|
private boolean hasBeenStarted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a race object with a given RaceDataSource, BoatDataSource, and RegattaDataSource and sends events to the given mockOutput.
|
* Constructs a race object with a given RaceDataSource, BoatDataSource, and RegattaDataSource and sends events to the given mockOutput.
|
||||||
* @param boatDataSource Data source for boat related data (yachts and marker boats).
|
* @param boatDataSource Data source for boat related data (yachts and marker boats).
|
||||||
@@ -157,6 +162,23 @@ public class MockRace extends RaceState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delays the start of the race, if needed, to ensure that the race doesn't start until host wants it to.
|
||||||
|
* If the time until start is less that 5 minutes, it is extended to 10 minutes.
|
||||||
|
*/
|
||||||
|
public void delayRaceStart() {
|
||||||
|
long timeToStart = getRaceDataSource().getStartDateTime().toInstant().toEpochMilli() - System.currentTimeMillis();
|
||||||
|
|
||||||
|
long fiveMinutesMilli = 5 * 60 * 1000;
|
||||||
|
long tenMinutesMilli = 10 * 60 * 1000;
|
||||||
|
|
||||||
|
if ((timeToStart < fiveMinutesMilli) && (timeToStart > 0) && !hasBeenStarted) {
|
||||||
|
startRace(tenMinutesMilli, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the race status enumeration based on the current time.
|
* Updates the race status enumeration based on the current time.
|
||||||
*/
|
*/
|
||||||
@@ -165,7 +187,6 @@ public class MockRace extends RaceState {
|
|||||||
//The millisecond duration of the race. Negative means it hasn't started, so we flip sign.
|
//The millisecond duration of the race. Negative means it hasn't started, so we flip sign.
|
||||||
long timeToStart = - this.getRaceClock().getDurationMilli();
|
long timeToStart = - this.getRaceClock().getDurationMilli();
|
||||||
|
|
||||||
|
|
||||||
if (timeToStart > racePreStartTime) {
|
if (timeToStart > racePreStartTime) {
|
||||||
//Time > 3 minutes is the prestart period.
|
//Time > 3 minutes is the prestart period.
|
||||||
this.setRaceStatusEnum(RaceStatusEnum.PRESTART);
|
this.setRaceStatusEnum(RaceStatusEnum.PRESTART);
|
||||||
@@ -203,9 +224,16 @@ public class MockRace extends RaceState {
|
|||||||
/**
|
/**
|
||||||
* Starts the race in #timeToStartMilli milliseconds.
|
* Starts the race in #timeToStartMilli milliseconds.
|
||||||
* @param timeToStartMilli Millseconds before starting the race.
|
* @param timeToStartMilli Millseconds before starting the race.
|
||||||
|
* @param manualStart True if the race has been manually started, false otherwise.
|
||||||
*/
|
*/
|
||||||
public void startRace(long timeToStartMilli) {
|
public void startRace(long timeToStartMilli, boolean manualStart) {
|
||||||
//TODO
|
this.hasBeenStarted = manualStart;
|
||||||
|
ZonedDateTime startTime = ZonedDateTime.now().plus(timeToStartMilli, ChronoUnit.MILLIS);
|
||||||
|
|
||||||
|
getRaceDataSource().setStartDateTime(startTime);
|
||||||
|
getRaceDataSource().incrementSequenceNumber();
|
||||||
|
|
||||||
|
this.getRaceClock().setStartingTime(getRaceDataSource().getStartDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
|
|||||||
//Update race time.
|
//Update race time.
|
||||||
race.updateRaceTime(currentTime);
|
race.updateRaceTime(currentTime);
|
||||||
|
|
||||||
|
race.delayRaceStart();
|
||||||
|
|
||||||
//Update the race status based on the current time.
|
//Update the race status based on the current time.
|
||||||
race.updateRaceStatusEnum();
|
race.updateRaceStatusEnum();
|
||||||
|
|
||||||
|
|||||||
@@ -56,13 +56,12 @@ public class RaceXMLCreator {
|
|||||||
* Rotates the race in a specified direction.
|
* Rotates the race in a specified direction.
|
||||||
* @param s xml file name or contents.
|
* @param s xml file name or contents.
|
||||||
* @param fileType Whether s is a file name or contents.
|
* @param fileType Whether s is a file name or contents.
|
||||||
* @param degrees degrees to rotate
|
* @param degrees degrees to rotate. -1 means don't rotate.
|
||||||
* @param tutorial Whether we wish to run the tutorial - this changes the race start time.
|
|
||||||
* @return the new xml file as a string
|
* @return the new xml file as a string
|
||||||
* @throws XMLReaderException if the xml is not readable
|
* @throws XMLReaderException if the xml is not readable
|
||||||
* @throws InvalidRaceDataException if the race is invalid
|
* @throws InvalidRaceDataException if the race is invalid
|
||||||
*/
|
*/
|
||||||
public static String alterRaceToWind(String s, XMLFileType fileType, double degrees, boolean tutorial) throws XMLReaderException, InvalidRaceDataException {
|
public static String alterRaceToWind(String s, XMLFileType fileType, double degrees) throws XMLReaderException, InvalidRaceDataException {
|
||||||
|
|
||||||
RaceXMLReader reader = new RaceXMLReader(s, fileType);
|
RaceXMLReader reader = new RaceXMLReader(s, fileType);
|
||||||
|
|
||||||
@@ -73,11 +72,6 @@ public class RaceXMLCreator {
|
|||||||
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
|
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
|
||||||
XMLRace.class);
|
XMLRace.class);
|
||||||
|
|
||||||
if(tutorial){
|
|
||||||
setRaceXMLAtCurrentTimeToNow(race, 1000l, 5000l);
|
|
||||||
} else {
|
|
||||||
setRaceXMLAtCurrentTimeToNow(race);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CompoundMark leewardGate = getLeewardGate(reader);
|
CompoundMark leewardGate = getLeewardGate(reader);
|
||||||
|
|||||||
@@ -151,4 +151,9 @@ public class EmptyRaceDataSource implements RaceDataSource {
|
|||||||
public void incrementSequenceNumber() {
|
public void incrementSequenceNumber() {
|
||||||
sequenceNumber++;
|
sequenceNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStartDateTime(ZonedDateTime time) {
|
||||||
|
raceStartTime = time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ public interface RaceDataSource {
|
|||||||
*/
|
*/
|
||||||
ZonedDateTime getStartDateTime();
|
ZonedDateTime getStartDateTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the start time/date of the race.
|
||||||
|
* @param time Time to start at.
|
||||||
|
*/
|
||||||
|
void setStartDateTime(ZonedDateTime time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the creation time/date of the race xml file.
|
* Returns the creation time/date of the race xml file.
|
||||||
* @return The race xml file's creation time.
|
* @return The race xml file's creation time.
|
||||||
|
|||||||
@@ -507,4 +507,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
public void incrementSequenceNumber() {
|
public void incrementSequenceNumber() {
|
||||||
sequenceNumber++;
|
sequenceNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStartDateTime(ZonedDateTime time) {
|
||||||
|
raceStartTime = time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,7 +270,6 @@ public class InGameLobbyController extends Controller {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//If the race has reached the preparatory phase, or has started...
|
//If the race has reached the preparatory phase, or has started...
|
||||||
if (raceStatus == RaceStatusEnum.PREPARATORY || raceStatus == RaceStatusEnum.STARTED) {
|
if (raceStatus == RaceStatusEnum.PREPARATORY || raceStatus == RaceStatusEnum.STARTED) {
|
||||||
//Stop this timer.
|
//Stop this timer.
|
||||||
@@ -360,7 +359,7 @@ public class InGameLobbyController extends Controller {
|
|||||||
* Start button pressed. Currently only prints out start
|
* Start button pressed. Currently only prints out start
|
||||||
*/
|
*/
|
||||||
public void startBtnPressed(){
|
public void startBtnPressed(){
|
||||||
App.game.getRaceLogic().getRace().startRace(App.game.getRaceLogic().getRace().getRacePreparatoryTime());
|
App.game.getRaceLogic().getRace().startRace(App.game.getRaceLogic().getRace().getRacePreparatoryTime(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinSpecPressed(){
|
public void joinSpecPressed(){
|
||||||
|
|||||||
Reference in New Issue
Block a user