Another fix for race xml stuff - the xml was fine, but the data sources would sometimes be overridden by empty ones, due to threading stuff.
This commit is contained in:
@@ -22,7 +22,7 @@ public class EmptyBoatDataSource implements BoatDataSource {
|
||||
private final Map<Integer, Mark> markerMap = new HashMap<>();
|
||||
|
||||
|
||||
private int sequenceNumber = 0;
|
||||
private int sequenceNumber = -1;
|
||||
|
||||
|
||||
public EmptyBoatDataSource() {
|
||||
|
||||
@@ -84,7 +84,7 @@ public class EmptyRaceDataSource implements RaceDataSource {
|
||||
private RaceTypeEnum raceType = RaceTypeEnum.NOT_A_RACE_TYPE;
|
||||
|
||||
|
||||
private int sequenceNumber = 0;
|
||||
private int sequenceNumber = -1;
|
||||
|
||||
|
||||
public EmptyRaceDataSource() {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class EmptyRegattaDataSource implements RegattaDataSource {
|
||||
|
||||
|
||||
|
||||
private int sequenceNumber = 0;
|
||||
private int sequenceNumber = -1;
|
||||
|
||||
|
||||
public EmptyRegattaDataSource() {
|
||||
|
||||
@@ -148,9 +148,11 @@ public abstract class RaceState extends Observable{
|
||||
* @param raceDataSource New race data source.
|
||||
*/
|
||||
public void setRaceDataSource(RaceDataSource raceDataSource) {
|
||||
this.raceDataSource = raceDataSource;
|
||||
this.getRaceClock().setStartingTime(raceDataSource.getStartDateTime());
|
||||
useLegsList(raceDataSource.getLegs());
|
||||
if ((this.raceDataSource == null) || (raceDataSource.getSequenceNumber() > this.raceDataSource.getSequenceNumber())) {
|
||||
this.raceDataSource = raceDataSource;
|
||||
this.getRaceClock().setStartingTime(raceDataSource.getStartDateTime());
|
||||
useLegsList(raceDataSource.getLegs());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +160,9 @@ public abstract class RaceState extends Observable{
|
||||
* @param boatDataSource New boat data source.
|
||||
*/
|
||||
public void setBoatDataSource(BoatDataSource boatDataSource) {
|
||||
this.boatDataSource = boatDataSource;
|
||||
if ((this.boatDataSource == null) || (boatDataSource.getSequenceNumber() > this.boatDataSource.getSequenceNumber())) {
|
||||
this.boatDataSource = boatDataSource;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +170,9 @@ public abstract class RaceState extends Observable{
|
||||
* @param regattaDataSource New regatta data source.
|
||||
*/
|
||||
public void setRegattaDataSource(RegattaDataSource regattaDataSource) {
|
||||
this.regattaDataSource = regattaDataSource;
|
||||
if ((this.regattaDataSource == null) || (regattaDataSource.getSequenceNumber() > this.regattaDataSource.getSequenceNumber())) {
|
||||
this.regattaDataSource = regattaDataSource;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,11 +15,13 @@ import javafx.scene.control.Label;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import mock.app.Event;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import network.Messages.Enums.RequestToJoinEnum;
|
||||
import shared.model.Boat;
|
||||
import visualiser.app.App;
|
||||
import visualiser.gameController.ControllerClient;
|
||||
import visualiser.layout.SeaSurface;
|
||||
@@ -124,61 +126,67 @@ public class InGameLobbyController extends Controller {
|
||||
|
||||
@Override
|
||||
public void onChanged(Change change) {
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
while (change.next()){
|
||||
if (change.wasAdded() || change.wasRemoved() || change.wasUpdated()){
|
||||
try{
|
||||
resetLobby();
|
||||
int count = 0;
|
||||
int row = 0;
|
||||
for (VisualiserBoat boat :visualiserRaceEvent.getVisualiserRaceState().getBoats()) {
|
||||
View3D playerBoatToSet = new View3D();
|
||||
playerBoatToSet.setItems(subjects);
|
||||
|
||||
playerContainer.add(playerBoatToSet, (count % 3) , row);
|
||||
playerContainer.setMargin(playerBoatToSet, new Insets(10, 10, 10, 10));
|
||||
|
||||
SeaSurface sea = new SeaSurface(750, 200);
|
||||
sea.setX(250);
|
||||
sea.setZ(210);
|
||||
subjects.add(sea);
|
||||
|
||||
MeshView mesh = new MeshView(importer.getImport());
|
||||
PhongMaterial boatColorMat = new PhongMaterial(boat.getColor());
|
||||
mesh.setMaterial(boatColorMat);
|
||||
Subject3D subject = new Subject3D(mesh,0);
|
||||
subjects.add(subject);
|
||||
|
||||
playerBoatToSet.setDistance(50);
|
||||
playerBoatToSet.setYaw(45);
|
||||
playerBoatToSet.setPitch(20);
|
||||
|
||||
|
||||
|
||||
AnimationTimer rotate = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
subject.setHeading(subject.getHeading().getAngle() + 0.1);
|
||||
}
|
||||
};
|
||||
rotate.start();
|
||||
|
||||
allPlayerLabels.get(count).setText(boat.getName());
|
||||
allPlayerLabels.get(count).toFront();
|
||||
count += 1;
|
||||
if (count > 2){
|
||||
row = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ConcurrentModificationException e){
|
||||
}
|
||||
}
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
while (change.next()) {
|
||||
if (change.wasAdded() || change.wasRemoved() || change.wasUpdated()) {
|
||||
populateLobby();
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void populateLobby() {
|
||||
|
||||
try{
|
||||
resetLobby();
|
||||
int count = 0;
|
||||
int row = 0;
|
||||
|
||||
for (VisualiserBoat boat :visualiserRaceEvent.getVisualiserRaceState().getBoats()) {
|
||||
View3D playerBoatToSet = new View3D();
|
||||
playerBoatToSet.setItems(subjects);
|
||||
|
||||
playerContainer.add(playerBoatToSet, (count % 3) , row);
|
||||
playerContainer.setMargin(playerBoatToSet, new Insets(10, 10, 10, 10));
|
||||
|
||||
SeaSurface sea = new SeaSurface(750, 200);
|
||||
sea.setX(250);
|
||||
sea.setZ(210);
|
||||
subjects.add(sea);
|
||||
|
||||
MeshView mesh = new MeshView(importer.getImport());
|
||||
PhongMaterial boatColorMat = new PhongMaterial(boat.getColor());
|
||||
mesh.setMaterial(boatColorMat);
|
||||
Subject3D subject = new Subject3D(mesh,0);
|
||||
subjects.add(subject);
|
||||
|
||||
playerBoatToSet.setDistance(50);
|
||||
playerBoatToSet.setYaw(45);
|
||||
playerBoatToSet.setPitch(20);
|
||||
|
||||
|
||||
|
||||
AnimationTimer rotate = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
subject.setHeading(subject.getHeading().getAngle() + 0.1);
|
||||
}
|
||||
};
|
||||
rotate.start();
|
||||
|
||||
allPlayerLabels.get(count).setText(boat.getName());
|
||||
allPlayerLabels.get(count).toFront();
|
||||
count += 1;
|
||||
if (count > 2){
|
||||
row = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ConcurrentModificationException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
private void populatePlayers(ListChangeListener.Change change){
|
||||
@@ -191,7 +199,6 @@ public class InGameLobbyController extends Controller {
|
||||
//Initialises the race clock.
|
||||
initialiseRaceClock(this.visualiserRaceEvent.getVisualiserRaceState());
|
||||
|
||||
|
||||
//Starts the race countdown timer.
|
||||
countdownTimer();
|
||||
}
|
||||
@@ -227,7 +234,6 @@ public class InGameLobbyController extends Controller {
|
||||
new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
|
||||
//Get the current race status.
|
||||
RaceStatusEnum raceStatus = visualiserRaceEvent.getVisualiserRaceState().getRaceStatusEnum();
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ public class VisualiserRaceState extends RaceState {
|
||||
super.setRaceDataSource(raceDataSource);
|
||||
|
||||
if (getBoatDataSource() != null) {
|
||||
this.generateVisualiserBoats(this.boats, getBoatDataSource().getBoats(), raceDataSource.getParticipants(), unassignedColors);
|
||||
this.generateVisualiserBoats(this.boats, getBoatDataSource().getBoats(), getRaceDataSource().getParticipants(), unassignedColors);
|
||||
}
|
||||
|
||||
initialiseLegCompletionOrder();
|
||||
@@ -109,7 +109,7 @@ public class VisualiserRaceState extends RaceState {
|
||||
super.setBoatDataSource(boatDataSource);
|
||||
|
||||
if (getRaceDataSource() != null) {
|
||||
this.generateVisualiserBoats(this.boats, boatDataSource.getBoats(), getRaceDataSource().getParticipants(), unassignedColors);
|
||||
this.generateVisualiserBoats(this.boats, getBoatDataSource().getBoats(), getRaceDataSource().getParticipants(), unassignedColors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user