Skip to content
Snippets Groups Projects
Commit bc6d4ea6 authored by Terry D. Norbraten's avatar Terry D. Norbraten
Browse files

don't create object in a loop

parent 774e3ab6
No related branches found
No related tags found
No related merge requests found
...@@ -34,10 +34,10 @@ public class EspduSenderNIO ...@@ -34,10 +34,10 @@ public class EspduSenderNIO
public static void main(String args[]) public static void main(String args[])
{ {
EntityStatePdu espdu = new EntityStatePdu();
MulticastSocket socket; MulticastSocket socket;
InetAddress address; InetAddress address;
EntityStatePdu espdu = new EntityStatePdu();
espdu.setExerciseID((byte) 0); espdu.setExerciseID((byte) 0);
// The EID is the unique identifier for objects in the world. This // The EID is the unique identifier for objects in the world. This
...@@ -52,6 +52,12 @@ public class EspduSenderNIO ...@@ -52,6 +52,12 @@ public class EspduSenderNIO
socket = new MulticastSocket(PORT); socket = new MulticastSocket(PORT);
address = InetAddress.getByName(MULTICAST_GROUP); address = InetAddress.getByName(MULTICAST_GROUP);
socket.joinGroup(address); socket.joinGroup(address);
Vector3Double location;
EulerAngles orientation;
float psi;
byte[] data = new byte[144];
DatagramPacket packet = new DatagramPacket(data, data.length, address, PORT);
while (true) { while (true) {
for (int idx = 0; idx < 100; idx++) { for (int idx = 0; idx < 100; idx++) {
...@@ -65,13 +71,13 @@ public class EspduSenderNIO ...@@ -65,13 +71,13 @@ public class EspduSenderNIO
espdu.setTimestamp(timestamp); espdu.setTimestamp(timestamp);
// Modify the x-axis position of the object // Modify the x-axis position of the object
Vector3Double location = espdu.getEntityLocation(); location = espdu.getEntityLocation();
location.setX(idx); location.setX(idx);
location.setY(idx); location.setY(idx);
// Do some rotation to make sure that works // Do some rotation to make sure that works
EulerAngles orientation = espdu.getEntityOrientation(); orientation = espdu.getEntityOrientation();
float psi = orientation.getPsi(); psi = orientation.getPsi();
psi = psi + idx; psi = psi + idx;
orientation.setPsi(psi); orientation.setPsi(psi);
orientation.setTheta((float) (orientation.getTheta() + idx / 2.0)); orientation.setTheta((float) (orientation.getTheta() + idx / 2.0));
...@@ -79,8 +85,8 @@ public class EspduSenderNIO ...@@ -79,8 +85,8 @@ public class EspduSenderNIO
// Marshal out the object to a byte array, then send a datagram // Marshal out the object to a byte array, then send a datagram
// packet with that data in it. This uses Robert Harder's NIO // packet with that data in it. This uses Robert Harder's NIO
// code for marshalling. // code for marshalling.
byte data[] = espdu.marshal(); data = espdu.marshal();
DatagramPacket packet = new DatagramPacket(data, data.length, address, PORT); packet.setData(data);
socket.send(packet); socket.send(packet);
...@@ -88,12 +94,12 @@ public class EspduSenderNIO ...@@ -88,12 +94,12 @@ public class EspduSenderNIO
// slows down the send rate so the receiver has enough time to process it // slows down the send rate so the receiver has enough time to process it
Thread.sleep(1000); Thread.sleep(1000);
System.out.println("Sending espdu"); System.out.println("Sending " + espdu.getClass().getName());
} }
} }
} }
catch (Exception e) { catch (Exception e) {
System.out.println(e); System.err.println(e);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment