WIP. Probably need to cherry pick stuff out of here.
Added ClientConnection and server-side handshake. Added MessageSerialiser and Deserialiser. #story[1095]
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package mock.model;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import mock.model.commandFactory.CompositeCommand;
|
||||
import network.Messages.Enums.BoatStatusEnum;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import network.Messages.LatestMessages;
|
||||
import shared.model.Race;
|
||||
|
||||
|
||||
|
||||
public class RaceLogic implements Runnable {
|
||||
|
||||
/**
|
||||
* State of current race modified by this object
|
||||
*/
|
||||
@@ -16,14 +19,18 @@ public class RaceLogic implements Runnable {
|
||||
*/
|
||||
private RaceServer server;
|
||||
|
||||
private CompositeCommand commands;
|
||||
|
||||
/**
|
||||
* Initialises race loop with state and server message queue
|
||||
* @param race state of race to modify
|
||||
* @param messages to send to server
|
||||
* @param compositeCommand Commands from clients to execute.
|
||||
*/
|
||||
public RaceLogic(MockRace race, LatestMessages messages) {
|
||||
public RaceLogic(MockRace race, LatestMessages messages, CompositeCommand compositeCommand) {
|
||||
this.race = race;
|
||||
this.server = new RaceServer(race, messages);
|
||||
this.commands = compositeCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,17 +63,13 @@ public class RaceLogic implements Runnable {
|
||||
//Provide boat's with an estimated time at next mark until the race starts.
|
||||
race.setBoatsTimeNextMark(race.getRaceClock().getCurrentTime());
|
||||
|
||||
//Parse the boat locations.
|
||||
server.parseBoatLocations();
|
||||
|
||||
//Parse the marks.
|
||||
server.parseMarks();
|
||||
//Parse the race snapshot.
|
||||
server.parseSnapshot();
|
||||
|
||||
// Change wind direction
|
||||
race.changeWindDirection();
|
||||
|
||||
//Parse the race status.
|
||||
server.parseRaceStatus();
|
||||
|
||||
|
||||
|
||||
if (race.getRaceStatusEnum() == RaceStatusEnum.STARTED) {
|
||||
@@ -109,6 +112,9 @@ public class RaceLogic implements Runnable {
|
||||
//Get the current time.
|
||||
currentTime = System.currentTimeMillis();
|
||||
|
||||
//Execute commands from clients.
|
||||
commands.execute(race);
|
||||
|
||||
//Update race time.
|
||||
race.updateRaceTime(currentTime);
|
||||
|
||||
@@ -123,7 +129,6 @@ public class RaceLogic implements Runnable {
|
||||
|
||||
//If it is still racing, update its position.
|
||||
if (boat.getStatus() == BoatStatusEnum.RACING) {
|
||||
|
||||
race.updatePosition(boat, framePeriod, race.getRaceClock().getDurationMilli());
|
||||
|
||||
}
|
||||
@@ -141,15 +146,8 @@ public class RaceLogic implements Runnable {
|
||||
// Change wind direction
|
||||
race.changeWindDirection();
|
||||
|
||||
//Parse the boat locations.
|
||||
server.parseBoatLocations();
|
||||
|
||||
//Parse the marks.
|
||||
server.parseMarks();
|
||||
|
||||
//Parse the race status.
|
||||
server.parseRaceStatus();
|
||||
|
||||
//Parse the race snapshot.
|
||||
server.parseSnapshot();
|
||||
|
||||
//Update the last frame time.
|
||||
this.lastFrameTime = currentTime;
|
||||
@@ -165,7 +163,7 @@ public class RaceLogic implements Runnable {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
|
||||
server.parseRaceStatus();
|
||||
server.parseSnapshot();
|
||||
|
||||
if (iters > 500) {
|
||||
stop();
|
||||
@@ -173,4 +171,5 @@ public class RaceLogic implements Runnable {
|
||||
iters++;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user