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
f33042aa
Commit
f33042aa
authored
5 years ago
by
Terry D. Norbraten
Browse files
Options
Downloads
Patches
Plain Diff
minimize object creation in loops
parent
75661dad
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/EspduSender.java
+21
-18
21 additions, 18 deletions
src/edu/nps/moves/dis7/examples/EspduSender.java
with
21 additions
and
18 deletions
src/edu/nps/moves/dis7/examples/EspduSender.java
+
21
−
18
View file @
f33042aa
...
@@ -202,7 +202,7 @@ public class EspduSender
...
@@ -202,7 +202,7 @@ public class EspduSender
// The x and y values will change, but the z value should not.
// The x and y values will change, but the z value should not.
//lon = lon + (double)((double)idx / 100000.0);
//lon = lon + (double)((double)idx / 100000.0);
//System.out.println("lla=" + lat + "," + lon + ", 0.0");
//System.out.println("lla=" + lat + "," + lon + ", 0.0");
double
direction
=
Math
.
pow
((
double
)
(-
1.0
)
,
(
double
)
(
idx
)
)
;
double
direction
=
Math
.
pow
(-
1.0
,
idx
);
lon
=
lon
+
(
direction
*
0.00006
);
lon
=
lon
+
(
direction
*
0.00006
);
System
.
out
.
println
(
lon
);
System
.
out
.
println
(
lon
);
...
@@ -236,17 +236,17 @@ public class EspduSender
...
@@ -236,17 +236,17 @@ public class EspduSender
// The byte array here is the packet in DIS format. We put that into a
// The byte array here is the packet in DIS format. We put that into a
// datagram and send it.
// datagram and send it.
byte
[]
data
=
baos
.
toByteArray
();
byte
[]
data
=
baos
.
toByteArray
();
broadcastAddresses
=
getBroadcastAddresses
();
broadcastAddresses
=
getBroadcastAddresses
();
Iterator
it
=
broadcastAddresses
.
iterator
()
;
DatagramPacket
packet
;
while
(
it
.
hasNext
())
{
InetAddress
broadcast
=
(
InetAddress
)
it
.
next
();
for
(
InetAddress
broadcast
:
broadcastAddresses
)
{
System
.
out
.
println
(
"Sending broadcast datagram packet to "
+
broadcast
);
System
.
out
.
println
(
"Sending broadcast datagram packet to "
+
broadcast
);
DatagramPacket
packet
=
new
DatagramPacket
(
data
,
data
.
length
,
broadcast
,
3000
);
packet
=
new
DatagramPacket
(
data
,
data
.
length
,
broadcast
,
3000
);
socket
.
send
(
packet
);
socket
.
send
(
packet
);
// TODO experiment with these! 8)
// TODO experiment with these! 8)
packet
=
new
DatagramPacket
(
fireArray
,
fireArray
.
length
,
broadcast
,
3000
);
// alternate
packet
=
new
DatagramPacket
(
fireArray
,
fireArray
.
length
,
broadcast
,
3000
);
// alternate
socket
.
send
(
packet
);
socket
.
send
(
packet
);
}
}
// Send every 1 sec. Otherwise this will be all over in a fraction of a second.
// Send every 1 sec. Otherwise this will be all over in a fraction of a second.
...
@@ -281,22 +281,25 @@ public class EspduSender
...
@@ -281,22 +281,25 @@ public class EspduSender
public
static
Set
<
InetAddress
>
getBroadcastAddresses
()
public
static
Set
<
InetAddress
>
getBroadcastAddresses
()
{
{
Set
<
InetAddress
>
broadcastAddresses
=
new
HashSet
<>();
Set
<
InetAddress
>
broadcastAddresses
=
new
HashSet
<>();
Enumeration
interfaces
;
Enumeration
<
NetworkInterface
>
interfaces
;
try
{
try
{
interfaces
=
NetworkInterface
.
getNetworkInterfaces
();
interfaces
=
NetworkInterface
.
getNetworkInterfaces
();
Iterator
<
InterfaceAddress
>
it
;
InterfaceAddress
anAddress
;
InetAddress
broadcastAddress
;
while
(
interfaces
.
hasMoreElements
())
{
while
(
interfaces
.
hasMoreElements
())
{
NetworkInterface
anInterface
=
(
NetworkInterface
)
interfaces
.
nextElement
();
NetworkInterface
anInterface
=
interfaces
.
nextElement
();
if
(
anInterface
.
isUp
())
{
if
(
anInterface
.
isUp
())
{
Iterator
it
=
anInterface
.
getInterfaceAddresses
().
iterator
();
it
=
anInterface
.
getInterfaceAddresses
().
iterator
();
while
(
it
.
hasNext
())
{
while
(
it
.
hasNext
())
{
InterfaceAddress
anAddress
=
(
InterfaceAddress
)
it
.
next
();
anAddress
=
it
.
next
();
if
((
anAddress
==
null
||
anAddress
.
getAddress
().
isLinkLocalAddress
()))
if
((
anAddress
==
null
||
anAddress
.
getAddress
().
isLinkLocalAddress
()))
continue
;
continue
;
//System.out.println("Getting broadcast address for " + anAddress);
//System.out.println("Getting broadcast address for " + anAddress);
InetAddress
broadcastAddress
=
anAddress
.
getBroadcast
();
broadcastAddress
=
anAddress
.
getBroadcast
();
if
(
broadcastAddress
!=
null
)
if
(
broadcastAddress
!=
null
)
broadcastAddresses
.
add
(
broadcastAddress
);
broadcastAddresses
.
add
(
broadcastAddress
);
}
}
...
@@ -304,8 +307,8 @@ public class EspduSender
...
@@ -304,8 +307,8 @@ public class EspduSender
}
}
}
}
catch
(
SocketException
e
)
{
catch
(
SocketException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
(
System
.
err
);
System
.
out
.
println
(
e
);
System
.
err
.
println
(
e
);
}
}
return
broadcastAddresses
;
return
broadcastAddresses
;
}
}
...
...
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