Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
bc6d4ea6
Commit
bc6d4ea6
authored
5 years ago
by
Terry D. Norbraten
Browse files
Options
Downloads
Patches
Plain Diff
don't create object in a loop
parent
774e3ab6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/nps/moves/dis7/examples/EspduSenderNIO.java
+14
-8
14 additions, 8 deletions
src/edu/nps/moves/dis7/examples/EspduSenderNIO.java
with
14 additions
and
8 deletions
src/edu/nps/moves/dis7/examples/EspduSenderNIO.java
+
14
−
8
View file @
bc6d4ea6
...
...
@@ -34,10 +34,10 @@ public class EspduSenderNIO
public
static
void
main
(
String
args
[])
{
EntityStatePdu
espdu
=
new
EntityStatePdu
();
MulticastSocket
socket
;
InetAddress
address
;
EntityStatePdu
espdu
=
new
EntityStatePdu
();
espdu
.
setExerciseID
((
byte
)
0
);
// The EID is the unique identifier for objects in the world. This
...
...
@@ -52,6 +52,12 @@ public class EspduSenderNIO
socket
=
new
MulticastSocket
(
PORT
);
address
=
InetAddress
.
getByName
(
MULTICAST_GROUP
);
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
)
{
for
(
int
idx
=
0
;
idx
<
100
;
idx
++)
{
...
...
@@ -65,13 +71,13 @@ public class EspduSenderNIO
espdu
.
setTimestamp
(
timestamp
);
// Modify the x-axis position of the object
Vector3Double
location
=
espdu
.
getEntityLocation
();
location
=
espdu
.
getEntityLocation
();
location
.
setX
(
idx
);
location
.
setY
(
idx
);
// Do some rotation to make sure that works
EulerAngles
orientation
=
espdu
.
getEntityOrientation
();
float
psi
=
orientation
.
getPsi
();
orientation
=
espdu
.
getEntityOrientation
();
psi
=
orientation
.
getPsi
();
psi
=
psi
+
idx
;
orientation
.
setPsi
(
psi
);
orientation
.
setTheta
((
float
)
(
orientation
.
getTheta
()
+
idx
/
2.0
));
...
...
@@ -79,8 +85,8 @@ public class EspduSenderNIO
// Marshal out the object to a byte array, then send a datagram
// packet with that data in it. This uses Robert Harder's NIO
// code for marshalling.
byte
data
[]
=
espdu
.
marshal
();
DatagramPacket
packet
=
new
DatagramPacket
(
data
,
data
.
length
,
address
,
PORT
);
data
=
espdu
.
marshal
();
packet
.
setData
(
data
);
socket
.
send
(
packet
);
...
...
@@ -88,12 +94,12 @@ public class EspduSenderNIO
// slows down the send rate so the receiver has enough time to process it
Thread
.
sleep
(
1000
);
System
.
out
.
println
(
"Sending espdu
"
);
System
.
out
.
println
(
"Sending
"
+
espdu
.
getClass
().
getName
()
);
}
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
System
.
err
.
println
(
e
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment