mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
problems appear to be fixed and the boats are updating properly from the timeValid field of the boat location. #story[820]
This commit is contained in:
@@ -109,7 +109,7 @@ public class CanvasController {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
|
||||
|
||||
//fps stuff
|
||||
long oldFrameTime = frameTimes[frameTimeIndex] ;
|
||||
frameTimes[frameTimeIndex] = now ;
|
||||
frameTimeIndex = (frameTimeIndex + 1) % frameTimes.length ;
|
||||
@@ -122,50 +122,9 @@ public class CanvasController {
|
||||
Double frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ;
|
||||
drawFps(frameRate.intValue());
|
||||
}
|
||||
for (RaceObject raceObject : raceObjects) {
|
||||
raceObject.updatePosition(1000 / 60);
|
||||
for (long id : raceObject.getRaceIds()) {
|
||||
if (StreamParser.boatPositions.containsKey(id)) {
|
||||
|
||||
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(id);
|
||||
if (movementQueue.size() > 0){
|
||||
BoatPositionPacket positionPacket = movementQueue.peek();
|
||||
updateRaceObjects();
|
||||
|
||||
int delayTime = 5000;
|
||||
int loopTime = delayTime + 1000;
|
||||
//System.out.println("id = " + id);
|
||||
long timeDiff = (System.currentTimeMillis()%loopTime - positionPacket.getTimeValid()%loopTime);
|
||||
if (timeDiff < 0){
|
||||
timeDiff = loopTime + timeDiff;
|
||||
}
|
||||
if (id == 106) {
|
||||
//System.out.println("timeDiff = " + timeDiff);
|
||||
//System.out.println("movementQueue.size() = " + movementQueue.size());
|
||||
}
|
||||
//System.out.println("timeDiff = " + timeDiff);
|
||||
//System.out.println("movementQueue.size() = " + movementQueue.size());
|
||||
if (timeDiff > delayTime) {
|
||||
if (id == 106){
|
||||
//System.out.println("processing");
|
||||
}
|
||||
try {
|
||||
positionPacket = movementQueue.take();
|
||||
|
||||
Point2D p2d = latLonToXY(positionPacket.getLat(), positionPacket.getLon());
|
||||
double heading = 360.0 / 0xffff * positionPacket.getHeading();
|
||||
raceObject.setDestination(p2d.getX(), p2d.getY(), heading, (int) id);
|
||||
|
||||
} catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//StreamParser.boatPositions.remove((long) id);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
for (Mark m : raceViewController.getRace().getCourse()) {
|
||||
@@ -174,6 +133,46 @@ public class CanvasController {
|
||||
//timer.start();
|
||||
}
|
||||
|
||||
private void updateRaceObjects(){
|
||||
for (RaceObject raceObject : raceObjects) {
|
||||
raceObject.updatePosition(1000 / 60);
|
||||
// some raceObjects will have multiply ID's (for instance gate marks)
|
||||
for (long id : raceObject.getRaceIds()) {
|
||||
//checking if the current "ID" has any updates associated with it
|
||||
if (StreamParser.boatPositions.containsKey(id)) {
|
||||
move(id, raceObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void move(long id, RaceObject raceObject){
|
||||
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(id);
|
||||
if (movementQueue.size() > 0){
|
||||
BoatPositionPacket positionPacket = movementQueue.peek();
|
||||
|
||||
//this code adds a delay to reading from the movementQueue
|
||||
//in case things being put into the movement queue are slightly
|
||||
//out of order
|
||||
int delayTime = 1000;
|
||||
int loopTime = delayTime * 10;
|
||||
long timeDiff = (System.currentTimeMillis()%loopTime - positionPacket.getTimeValid()%loopTime);
|
||||
if (timeDiff < 0){
|
||||
timeDiff = loopTime + timeDiff;
|
||||
}
|
||||
if (timeDiff > delayTime) {
|
||||
try {
|
||||
positionPacket = movementQueue.take();
|
||||
Point2D p2d = latLonToXY(positionPacket.getLat(), positionPacket.getLon());
|
||||
double heading = 360.0 / 0xffff * positionPacket.getHeading();
|
||||
raceObject.setDestination(p2d.getX(), p2d.getY(), heading, (int) id);
|
||||
} catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ResizableCanvas extends Canvas {
|
||||
|
||||
public ResizableCanvas() {
|
||||
|
||||
@@ -51,21 +51,20 @@ public class StreamParser extends Thread{
|
||||
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
|
||||
Thread.sleep(1);
|
||||
}
|
||||
while (StreamReceiver.packetBuffer.peek() != null){
|
||||
while (true){
|
||||
StreamPacket packet = StreamReceiver.packetBuffer.peek();
|
||||
//this code adds a delay to reading from the packetBuffer so
|
||||
//out of order packets have time to order themselves in the queue
|
||||
int delayTime = 1000;
|
||||
int loopTime = delayTime + 1000;
|
||||
long sleepTime = 0;
|
||||
int loopTime = delayTime * 10;
|
||||
long transitTime = (System.currentTimeMillis()%loopTime - packet.getTimeStamp()%loopTime);
|
||||
if (transitTime < 0){
|
||||
transitTime = loopTime + transitTime;
|
||||
}
|
||||
if (transitTime < delayTime) {
|
||||
sleepTime = delayTime - (transitTime);
|
||||
long sleepTime = delayTime - (transitTime);
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
// System.out.println(sleepTime);
|
||||
|
||||
packet = StreamReceiver.packetBuffer.take();
|
||||
parsePacket(packet);
|
||||
Thread.sleep(1);
|
||||
@@ -73,7 +72,6 @@ public class StreamParser extends Thread{
|
||||
Thread.sleep(1);
|
||||
}
|
||||
}
|
||||
System.out.println("END OF STREAM");
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -317,7 +315,7 @@ public class StreamParser extends Thread{
|
||||
byte[] headingBytes = Arrays.copyOfRange(payload,28,30);
|
||||
byte[] groundSpeedBytes = Arrays.copyOfRange(payload,38,40);
|
||||
|
||||
long timeValid = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||
long timeValid = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||
// int boatSeq = ByteBuffer.wrap(seqBytes).getInt();
|
||||
long seq = bytesToLong(seqBytes);
|
||||
long boatId = bytesToLong(boatIdBytes);
|
||||
@@ -326,15 +324,11 @@ public class StreamParser extends Thread{
|
||||
double lat = ((180d * (double)rawLat)/Math.pow(2,31));
|
||||
double lon = ((180d *(double)rawLon)/Math.pow(2,31));
|
||||
long heading = bytesToLong(headingBytes);
|
||||
// long speed = extractTimeStamp(speedBytes, 2);
|
||||
double groundSpeed = bytesToLong(groundSpeedBytes)/1000.0;
|
||||
short s = (short) ((groundSpeedBytes[1] & 0xFF) << 8 | (groundSpeedBytes[0] & 0xFF));
|
||||
if ((int)deviceType == 1){
|
||||
|
||||
BoatPositionPacket boatPacket = new BoatPositionPacket(boatId, timeValid, lat, lon, heading, groundSpeed);
|
||||
if (boatId == 106){
|
||||
System.out.println("timeValid = " + timeValid);
|
||||
}
|
||||
|
||||
if (!boatPositions.containsKey(boatId)){
|
||||
boatPositions.put(boatId, new PriorityBlockingQueue<BoatPositionPacket>(256, new Comparator<BoatPositionPacket>() {
|
||||
|
||||
Reference in New Issue
Block a user