mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Various bug fixes
- Made canvas fill entire screen - Made window scale to screens that aren't 1920x1080 - Changed boat speeds in mock so they aren't too fast - Added command line options to switch server Tags: #story[829]
This commit is contained in:
@@ -16,27 +16,40 @@ public class App extends Application
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml"));
|
||||
primaryStage.setTitle("RaceVision");
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setMaximized(true);
|
||||
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
StreamReceiver sr;
|
||||
StreamReceiver sr = null;
|
||||
|
||||
new ServerThread("Racevision Test Server");
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (args.length > 1){
|
||||
sr = new StreamReceiver("localhost", 8085, "RaceStream");
|
||||
if (args.length == 3 && args[0].equals("-server")){
|
||||
sr = new StreamReceiver(args[1], Integer.valueOf(args[2]), "RaceStream");
|
||||
}
|
||||
else if(args.length == 2 && args[0].equals("-server")){
|
||||
switch (args[1]) {
|
||||
case "internal":
|
||||
sr = new StreamReceiver("localhost", 8085, "RaceStream");
|
||||
break;
|
||||
case "staffserver":
|
||||
sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
|
||||
break;
|
||||
case "official":
|
||||
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"RaceStream");
|
||||
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
|
||||
// sr = new StreamReceiver("localhost", 8085, "RaceStream");
|
||||
sr = new StreamReceiver("localhost", 8085, "RaceStream");
|
||||
}
|
||||
|
||||
sr.start();
|
||||
|
||||
@@ -132,7 +132,7 @@ public class CanvasController {
|
||||
}
|
||||
};
|
||||
for (Mark m : raceViewController.getRace().getCourse()) {
|
||||
System.out.println(m.getName());
|
||||
//System.out.println(m.getName());
|
||||
}
|
||||
//timer.start();
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ public class Event {
|
||||
private final double ORIGIN_LON = -64.857063;
|
||||
private final double SCALE = 16000;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Event class containing the time of specific event, related team/boat, and
|
||||
* event location such as leg.
|
||||
|
||||
@@ -57,7 +57,7 @@ public class StreamParser extends Thread{
|
||||
*/
|
||||
public void run(){
|
||||
try {
|
||||
System.out.println("START OF STREAM");
|
||||
System.out.println("[CLIENT] Start of stream");
|
||||
streamStatus = true;
|
||||
xmlObject = new XMLParser();
|
||||
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
|
||||
@@ -94,7 +94,7 @@ public class StreamParser extends Thread{
|
||||
*
|
||||
*/
|
||||
public void start () {
|
||||
System.out.println("Starting " + threadName );
|
||||
System.out.println("[CLIENT] Starting " + threadName );
|
||||
if (t == null) {
|
||||
t = new Thread (this, threadName);
|
||||
t.start ();
|
||||
@@ -181,18 +181,18 @@ public class StreamParser extends Thread{
|
||||
currentTimeString = format.format((new Date (currentTime)).getTime());
|
||||
if (timeTillStart > 0) {
|
||||
timeSinceStart = timeTillStart;
|
||||
System.out.println("Time till start: " + timeTillStart + " Seconds");
|
||||
//System.out.println("Time till start: " + timeTillStart + " Seconds");
|
||||
} else {
|
||||
if (raceStatus == 4 || raceStatus == 8){
|
||||
raceFinished = true;
|
||||
raceStarted = false;
|
||||
System.out.println("RACE HAS FINISHED");
|
||||
System.out.println("[CLIENT] Race has finished");
|
||||
} else if (!raceStarted){
|
||||
raceStarted = true;
|
||||
raceFinished = false;
|
||||
System.out.println("RACE HAS STARTED");
|
||||
System.out.println("[CLIENT] Race has started");
|
||||
}
|
||||
System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
||||
//System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
||||
timeSinceStart = timeTillStart;
|
||||
}
|
||||
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
||||
|
||||
@@ -24,6 +24,7 @@ public class StreamReceiver extends Thread {
|
||||
|
||||
public StreamReceiver(String hostAddress, int hostPort, String threadName) {
|
||||
this.threadName = threadName;
|
||||
this.setDaemon(true);
|
||||
try {
|
||||
host = new Socket(hostAddress, hostPort);
|
||||
} catch (IOException e) {
|
||||
@@ -44,7 +45,7 @@ public class StreamReceiver extends Thread {
|
||||
}
|
||||
|
||||
public void start () {
|
||||
System.out.println("Starting " + threadName );
|
||||
System.out.println("[CLIENT] Starting " + threadName );
|
||||
if (t == null) {
|
||||
t = new Thread (this, threadName);
|
||||
t.start ();
|
||||
@@ -95,7 +96,6 @@ public class StreamReceiver extends Thread {
|
||||
} catch (Exception e) {
|
||||
moreBytes = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,10 @@ public class ServerThread implements Runnable, Observer {
|
||||
Map<Integer,Boolean> boatsFinished = new HashMap<>();
|
||||
private List<Boat> boats;
|
||||
private Simulator raceSimulator;
|
||||
private boolean sendingRaceFinishedLocationMessages = true;
|
||||
|
||||
private final int HEARTBEAT_PERIOD = 5000;
|
||||
private final int RACE_STATUS_PERIOD = 1000;
|
||||
private final int RACE_STATUS_PERIOD = 1000/2;
|
||||
private final int RACE_START_STATUS_PERIOD = 1000;
|
||||
private final int BOAT_LOCATION_PERIOD = 1000/5;
|
||||
private final int PORT_NUMBER = 8085;
|
||||
@@ -31,6 +32,8 @@ public class ServerThread implements Runnable, Observer {
|
||||
|
||||
public ServerThread(String threadName){
|
||||
runner = new Thread(this, threadName);
|
||||
runner.setDaemon(true);
|
||||
|
||||
serverLog("Spawning Server", 0);
|
||||
|
||||
raceSimulator = new Simulator(BOAT_LOCATION_PERIOD);
|
||||
@@ -128,7 +131,7 @@ public class ServerThread implements Runnable, Observer {
|
||||
raceStatus = RaceStatus.TERMINATED;
|
||||
}
|
||||
|
||||
return new RaceStatusMessage(1, raceStatus, startTime, WindDirection.EAST,
|
||||
return new RaceStatusMessage(1, raceStatus, startTime, WindDirection.SOUTH,
|
||||
100, boats.size(), RaceType.MATCH_RACE, 1, boatSubMessages);
|
||||
}
|
||||
|
||||
@@ -256,6 +259,30 @@ public class ServerThread implements Runnable, Observer {
|
||||
startSendingRaceStatusMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start sending static boat position updates when race has finished
|
||||
*/
|
||||
private void startSendingRaceFinishedBoatPostions(){
|
||||
Timer t = new Timer();
|
||||
t.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (Boat b : raceSimulator.getBoats()){
|
||||
Message m = new BoatLocationMessage(b.getSourceID(), server.getSequenceNumber(), b.getLat(),
|
||||
b.getLng(), b.getLastPassedCorner().getBearingToNextCorner(),
|
||||
((long) 0));
|
||||
|
||||
server.send(m);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
}, 0, BOAT_LOCATION_PERIOD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a boat location message when they are updated by the simulator
|
||||
* @param o .
|
||||
@@ -271,7 +298,7 @@ public class ServerThread implements Runnable, Observer {
|
||||
|
||||
for (Boat b : (List<Boat>) arg){
|
||||
try {
|
||||
Message m = new BoatLocationMessage(b.getSourceID(), 1, b.getLat(),
|
||||
Message m = new BoatLocationMessage(b.getSourceID(), server.getSequenceNumber(), b.getLat(),
|
||||
b.getLng(), b.getLastPassedCorner().getBearingToNextCorner(),
|
||||
((long) b.getSpeed()));
|
||||
server.send(m);
|
||||
|
||||
@@ -42,6 +42,7 @@ public class BoatLocationMessage extends Message {
|
||||
* @param boatSpeed The boats speed
|
||||
*/
|
||||
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
|
||||
boatSpeed /= 10;
|
||||
messageVersionNumber = 1;
|
||||
time = System.currentTimeMillis() / 1000L;
|
||||
this.sourceId = sourceId;
|
||||
@@ -54,8 +55,8 @@ public class BoatLocationMessage extends Message {
|
||||
this.pitch = 0;
|
||||
this.roll = 0;
|
||||
this.boatSpeed = boatSpeed;
|
||||
this.COG = 0;
|
||||
this.SOG = 0;
|
||||
this.COG = 2;
|
||||
this.SOG = boatSpeed ;
|
||||
this.apparentWindSpeed = 0;
|
||||
this.apparentWindAngle = 0;
|
||||
this.trueWindSpeed = 0;
|
||||
@@ -146,7 +147,7 @@ public class BoatLocationMessage extends Message {
|
||||
putInt(headingToSend, 2);
|
||||
putInt((int) pitch, 2);
|
||||
putInt((int) roll, 2);
|
||||
putUnsignedInt((int) boatSpeed, 2);
|
||||
putInt((int) boatSpeed, 2);
|
||||
putUnsignedInt((int) COG, 2);
|
||||
putUnsignedInt((int) SOG, 2);
|
||||
putUnsignedInt((int) apparentWindSpeed, 2);
|
||||
|
||||
@@ -185,7 +185,6 @@ public abstract class Message {
|
||||
* @return
|
||||
*/
|
||||
public static byte[] intToByteArray(long val, int len){
|
||||
long vor = val;
|
||||
int index = 0;
|
||||
byte[] data = new byte[len];
|
||||
|
||||
@@ -210,4 +209,8 @@ public abstract class Message {
|
||||
}
|
||||
}
|
||||
|
||||
public int wat(){
|
||||
return bufferPosition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Simulator extends Observable implements Runnable {
|
||||
boat.setLng(startLng);
|
||||
boat.setLastPassedCorner(course.get(0));
|
||||
boat.setHeadingCorner(course.get(1));
|
||||
boat.setSpeed(ThreadLocalRandom.current().nextInt(400000, 600000 + 1));
|
||||
boat.setSpeed(ThreadLocalRandom.current().nextInt(40000, 60000 + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user