commented out buffered code and cleaned up some other areas to try and make the boatgroup clear enough to modify #story[923]

This commit is contained in:
Peter Galloway
2017-05-15 17:53:11 +12:00
parent 85d4d63287
commit ed8d70c3b3
7 changed files with 61 additions and 165 deletions
+5 -43
View File
@@ -122,7 +122,8 @@ public class BoatGroup extends RaceObject{
velocityObject.setLayoutY(velocityObject.getLayoutY() + dy);
wake.setLayoutX(wake.getLayoutX() + dx);
wake.setLayoutY(wake.getLayoutY() + dy);
rotateTo(rotation + currentRotation);
currentRotation = rotation + currentRotation;
boatPoly.getTransforms().setAll(new Rotate(rotation));
}
/**
@@ -132,16 +133,8 @@ public class BoatGroup extends RaceObject{
* @param rotation The heading in degrees from north the boat should rotate to.
*/
public void moveTo (double x, double y, double rotation) {
rotateTo(rotation);
moveTo(x, y);
}
/**
* Moves the boat and its children annotations to coordinates specified
* @param x The X coordinate to move the boat to
* @param y The Y coordinate to move the boat to
*/
public void moveTo (double x, double y) {
currentRotation = rotation;
boatPoly.getTransforms().setAll(new Rotate(rotation));
boatPoly.setLayoutX(x);
boatPoly.setLayoutY(y);
teamNameObject.setLayoutX(x);
@@ -165,6 +158,7 @@ public class BoatGroup extends RaceObject{
double rotation = rotationalVelocity * timeInterval;
distanceTravelled += Math.abs(dx) + Math.abs(dy);
moveGroupBy(dx, dy, rotation);
//Draw a new section of the trail every 20 pixels of movement.
if (distanceTravelled > 20) {
distanceTravelled = 0;
@@ -203,12 +197,6 @@ public class BoatGroup extends RaceObject{
currentRotation = 360 - currentRotation;
double dx = newXValue - boatPoly.getLayoutX();
double dy = newYValue - boatPoly.getLayoutY();
//Check movement is reasonable. Assumes a 1000 * 1000 canvas
if (Math.abs(dx) > 50 || Math.abs(dy) > 50) {
dx = 0;
dy = 0;
moveTo(newXValue, newYValue);
}
pixelVelocityX = dx / expectedUpdateInterval;
pixelVelocityY = dy / expectedUpdateInterval;
@@ -217,7 +205,6 @@ public class BoatGroup extends RaceObject{
if (wakeGenerationDelay > 0) {
wake.rotate(rotationalGoal);
rotateTo(rotationalGoal); //Need to test with this removed.
rotationalVelocity = 0;
wakeGenerationDelay--;
} else {
@@ -254,31 +241,6 @@ public class BoatGroup extends RaceObject{
}
}
public void setDestination (double newXValue, double newYValue, double groundSpeed, int... raceIDs) {
destinationSet = true;
if (hasRaceId(raceIDs)) {
double rotation = Math.abs(
Math.toDegrees(
Math.atan(
(newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX())
)
)
);
setDestination(newXValue, newYValue, rotation, groundSpeed, raceIDs);
}
}
public void rotateTo (double rotation) {
currentRotation = rotation;
boatPoly.getTransforms().setAll(new Rotate(rotation));
}
public void forceRotation () {
rotateTo (rotationalGoal);
wake.rotate(rotationalGoal);
}
public void setTeamNameObjectVisible(Boolean visible) {
teamNameObject.setVisible(visible);
}
+4 -16
View File
@@ -47,10 +47,10 @@ public abstract class RaceObject extends Group {
this.rotationalVelocity = (rotationalGoal - currentRotation) / expectedUpdateInterval;
}
//Sometimes the rotation is too large to be realistic. In that case just do it instantly.
if (Math.abs(rotationalVelocity) > 1) {
rotationalVelocity = 0;
rotateTo(rotationalGoal);
}
// if (Math.abs(rotationalVelocity) > 1) {
// rotationalVelocity = 0;
// rotateTo(rotationalGoal);
// }
}
/**
@@ -62,25 +62,13 @@ public abstract class RaceObject extends Group {
* @param raceIds RaceID of the object to move.
*/
public abstract void setDestination (double x, double y, double rotation, double groundSpeed, int... raceIds);
/**
* Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is
* set to the co-ordinates (x, y).
* @param x X co-ordinate to move the graphic to.
* @param y Y co-ordinate to move the graphic to.
* @param raceIds RaceID to the object to move.
*/
public abstract void setDestination (double x, double y, double groundSpeed, int... raceIds);
public abstract void updatePosition (long timeInterval);
public abstract void moveTo (double x, double y, double rotation);
public abstract void moveTo (double x, double y);
public abstract void moveGroupBy(double x, double y, double rotation);
public abstract void rotateTo (double rotation);
public abstract boolean hasRaceId (int... raceIds);
public abstract int[] getRaceIds ();
@@ -92,16 +92,12 @@ public class MarkGroup extends RaceObject {
}
public void setDestination (double x, double y, double rotation, double groundSpeed, int... raceIds) {
setDestination(x, y, 0, raceIds);
this.rotationalGoal = rotation;
calculateRotationalVelocity();
}
public void setDestination (double x, double y, double groundSpeed, int... raceIds) {
for (int i = 0; i < marks.size(); i++)
for (int id : raceIds)
if (id == marks.get(i).getId())
setDestinationChild(x, y, 0, Math.max(0, i-1));
this.rotationalGoal = rotation;
calculateRotationalVelocity();
}
@@ -1,44 +0,0 @@
package seng302.models.parsers;
/**
* Created by kre39 on 23/04/17.
*/
public class StreamPacket {
//Change int to an ENUM for the type
private PacketType type;
private long messageLength;
private long timeStamp;
private byte[] payload;
StreamPacket(int type, long messageLength, long timeStamp, byte[] payload) {
this.type = PacketType.assignPacketType(type);
this.messageLength = messageLength;
this.timeStamp = timeStamp;
this.payload = payload;
// System.out.println("type = " + this.type.toString());
//switch the packet type to deal with what ever specific packet you want to deal with
// if (this.type == PacketType.XML_MESSAGE){
// //System.out.println("--------");
// System.out.println(new String(payload));
// //StreamParser.parsePacket(this);
// }
}
PacketType getType() {
return type;
}
public long getMessageLength() {
return messageLength;
}
byte[] getPayload() {
return payload;
}
long getTimeStamp() {
return timeStamp;
}
}
@@ -66,20 +66,20 @@ public class StreamParser extends Thread{
Thread.sleep(1);
}
while (appRunning){
StreamPacket packet = StreamReceiver.packetBuffer.peek();
// 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 * 10;
long transitTime = (System.currentTimeMillis()%loopTime - packet.getTimeStamp()%loopTime);
if (transitTime < 0){
transitTime = loopTime + transitTime;
}
if (transitTime < delayTime) {
long sleepTime = delayTime - (transitTime);
Thread.sleep(sleepTime);
}
packet = StreamReceiver.packetBuffer.take();
// int delayTime = 1000;
// int loopTime = delayTime * 10;
// long transitTime = (System.currentTimeMillis()%loopTime - packet.getTimeStamp()%loopTime);
// if (transitTime < 0){
// transitTime = loopTime + transitTime;
// }
// if (transitTime < delayTime) {
// long sleepTime = delayTime - (transitTime);
// Thread.sleep(sleepTime);
// }
StreamPacket packet = StreamReceiver.packetBuffer.take();
parsePacket(packet);
Thread.sleep(1);
while (StreamReceiver.packetBuffer.peek() == null) {