mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Removed unneeded files, also fixed heading calculation
Tags #story[829]
This commit is contained in:
@@ -17,14 +17,13 @@ public class ServerThread implements Runnable, Observer {
|
||||
private StreamingServerSocket server;
|
||||
private long startTime;
|
||||
boolean raceStarted = false;
|
||||
boolean raceFinished = false;
|
||||
Map<Integer,Boolean> boatsFinished = new HashMap<>();
|
||||
private List<Boat> boats;
|
||||
private Simulator raceSimulator;
|
||||
|
||||
private final int HEARTBEAT_PERIOD = 5000;
|
||||
private final int RACE_STATUS_PERIOD = 1000/2;
|
||||
private final int RACE_START_STATUS_PERIOD = 1000/2;
|
||||
private final int RACE_STATUS_PERIOD = 1000;
|
||||
private final int RACE_START_STATUS_PERIOD = 1000;
|
||||
private final int BOAT_LOCATION_PERIOD = 1000/5;
|
||||
private final int PORT_NUMBER = 8085;
|
||||
private final int TIME_TILL_RACE_START = 20*1000;
|
||||
@@ -188,6 +187,7 @@ public class ServerThread implements Runnable, Observer {
|
||||
* Start sending race start status messages until race starts
|
||||
*/
|
||||
private void startSendingRaceStatusMessages(){
|
||||
serverLog("Sending race status messages", 0);
|
||||
Timer t = new Timer();
|
||||
t.schedule(new TimerTask() {
|
||||
@Override
|
||||
@@ -248,9 +248,6 @@ public class ServerThread implements Runnable, Observer {
|
||||
sendXml();
|
||||
startSendingRaceStartStatusMessages();
|
||||
startSendingRaceStatusMessages();
|
||||
|
||||
//serverLog("Sending Race Status Messages", 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,16 +264,15 @@ public class ServerThread implements Runnable, Observer {
|
||||
|
||||
for (Boat b : ((Simulator) o).getBoats()){
|
||||
try {
|
||||
|
||||
Message m = new BoatLocationMessage(b.getSourceID(), 1, b.getLat(),
|
||||
b.getLng(), b.getHeadingCorner().getBearingToNextCorner(),
|
||||
((long) b.getSpeed()));
|
||||
server.send(m);
|
||||
} catch (IOException e) {
|
||||
serverLog("Couldn't send a boat status message", 1);
|
||||
serverLog("Couldn't send a boat status message", 3);
|
||||
return;
|
||||
}
|
||||
catch (NullPointerException e){
|
||||
//raceFinished = true;
|
||||
serverLog("Boat " + b.getSourceID() + " finished the race", 1);
|
||||
boatsFinished.put(b.getSourceID(), true);
|
||||
}
|
||||
|
||||
@@ -16,14 +16,12 @@ import java.util.List;
|
||||
class StreamingServerSocket {
|
||||
private ServerSocketChannel socket;
|
||||
private SocketChannel client;
|
||||
private List<Socket> clients;
|
||||
private short seqNum;
|
||||
private boolean isServerStarted;
|
||||
|
||||
StreamingServerSocket(int port) throws IOException{
|
||||
socket = ServerSocketChannel.open();
|
||||
socket.socket().bind(new InetSocketAddress("localhost", port));
|
||||
clients = new ArrayList<>();
|
||||
//socket.setSoTimeout(10000);
|
||||
seqNum = 0;
|
||||
isServerStarted = false;
|
||||
@@ -50,11 +48,8 @@ class StreamingServerSocket {
|
||||
return;
|
||||
}
|
||||
|
||||
//DataOutputStream outputStream = new DataOutputStream(client.getOutputStream());
|
||||
//System.out.println(client);
|
||||
message.send(client);
|
||||
|
||||
|
||||
seqNum++;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,9 +133,7 @@ public class BoatLocationMessage extends Message {
|
||||
allocateBuffer();
|
||||
writeHeaderToBuffer();
|
||||
|
||||
heading = (heading + 180.0) % 360.0;
|
||||
|
||||
long headingToSend = (long)((heading/360.0)*49152.0);
|
||||
long headingToSend = (long)((heading/360.0) * 65535.0);
|
||||
|
||||
putByte((byte) messageVersionNumber);
|
||||
putInt(time, 6);
|
||||
|
||||
@@ -3,6 +3,7 @@ package seng302.server.messages;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.SocketChannel;
|
||||
@@ -170,7 +171,6 @@ public abstract class Message {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rewind the buffer to the beginning
|
||||
*/
|
||||
@@ -185,11 +185,13 @@ public abstract class Message {
|
||||
* @return
|
||||
*/
|
||||
public static byte[] intToByteArray(long val, int len){
|
||||
long vor = val;
|
||||
int index = 0;
|
||||
byte[] data = new byte[len];
|
||||
|
||||
for (int i = 0; i < len; i++){
|
||||
data[len - index - 1] = (byte) ((val >>> (8 * index)));
|
||||
data[len - index - 1] = (byte) (val & 0xFF);
|
||||
val >>>= 8;
|
||||
index++;
|
||||
}
|
||||
|
||||
@@ -202,9 +204,9 @@ public abstract class Message {
|
||||
*/
|
||||
public static void reverse(byte[] data) {
|
||||
for (int left = 0, right = data.length - 1; left < right; left++, right--) {
|
||||
byte temp = data[left];
|
||||
data[left] = data[right];
|
||||
data[right] = temp;
|
||||
byte temp = (byte) (data[left] & 0xff);
|
||||
data[left] = (byte) (data[right] & 0xff);
|
||||
data[right] = (byte) (temp & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package seng302.server.messages;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.List;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import seng302.server.simulator.parsers.RaceParser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Simulator extends Observable implements Runnable {
|
||||
|
||||
@@ -34,7 +35,7 @@ public class Simulator extends Observable implements Runnable {
|
||||
boat.setLng(startLng);
|
||||
boat.setLastPassedCorner(course.get(0));
|
||||
boat.setHeadingCorner(course.get(1));
|
||||
boat.setSpeed(50000);
|
||||
boat.setSpeed(ThreadLocalRandom.current().nextInt(40000, 60000 + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user