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
1f038717
Commit
1f038717
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
improved documentation
parent
446c1965
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
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
+23
-14
23 additions, 14 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
with
23 additions
and
14 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
+
23
−
14
View file @
1f038717
...
@@ -18,23 +18,30 @@ import java.util.logging.Level;
...
@@ -18,23 +18,30 @@ import java.util.logging.Level;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
/** The purpose of this program is to provide an easily modifiable example simulation program
/** The purpose of this program is to provide an easily modifiable example simulation program
* that includes DIS-capable entities doing tasks and reporting them. */
* that includes DIS-capable entities doing tasks and reporting them to the network.
* Default settings include PDU recording turned on by default.
*/
public
class
ExampleSimulationProgram
public
class
ExampleSimulationProgram
{
{
/**
/**
* runSimulation is for you! This block is programmer-modifiable method for defining and running a new simulation of interest.
* This runSimulation() method is for you! This block is programmer-modifiable method
* for defining and running a new simulation of interest.
* Support include DIS EntityStatePdu, FirePdu and CommentPdu all available for
* Support include DIS EntityStatePdu, FirePdu and CommentPdu all available for
* modification and sending in a simulation loop.
* modification and sending in a simulation loop.
* Continuous improvement efforts seek to make this program as easy and straightforward
* as possible for new simulationists to use and adapt.
* All of the other methods are setup, teardown and configuration that you don't have to worry about.
*/
*/
@SuppressWarnings
(
"SleepWhileInLoop"
)
@SuppressWarnings
(
"SleepWhileInLoop"
)
public
void
runSimulation
()
public
void
runSimulation
()
{
{
try
try
{
{
final
double
LOOP_DURATION_SECONDS
=
1.0
;
// seconds
/** seconds for real-time execution (not simulation time, which may or may not be the same) */
final
int
MAX_LOOP_COUNT
=
10
;
final
double
LOOP_DURATION_SECONDS
=
1.0
;
int
loopCount
=
0
;
final
int
MAX_LOOP_COUNT
=
10
;
// be deliberate out out there!
boolean
simulationComplete
=
false
;
// sentinel variable as termination condition
int
loopCount
=
0
;
// initialized at 0
boolean
simulationComplete
=
false
;
// sentinel variable as termination condition,, are we done yet?
// TODO reset clock to zero each time for consistent outputs
// TODO reset clock to zero each time for consistent outputs
...
@@ -42,7 +49,8 @@ public class ExampleSimulationProgram
...
@@ -42,7 +49,8 @@ public class ExampleSimulationProgram
// create PDU objects and set their values
// create PDU objects and set their values
EntityID
entityID_1
=
new
EntityID
();
EntityID
entityID_1
=
new
EntityID
();
entityID_1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
3
);
// made-up example ID
entityID_1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
3
);
// made-up example ID;
// TODO use enumerations; is there a unique site triplet for MOVES Institute?
EntityStatePdu
entityStatePdu
=
pduFactory
.
makeEntityStatePdu
();
EntityStatePdu
entityStatePdu
=
pduFactory
.
makeEntityStatePdu
();
entityStatePdu
.
setEntityID
(
entityID_1
);
entityStatePdu
.
setEntityID
(
entityID_1
);
...
@@ -53,17 +61,18 @@ public class ExampleSimulationProgram
...
@@ -53,17 +61,18 @@ public class ExampleSimulationProgram
// TODO simulation management PDUs for startup
// TODO simulation management PDUs for startup
// loop the simulation while allowed, programmer can set additional conditions to break out and finish
// loop the simulation while allowed, programmer can set additional conditions to break out and finish
while
(
loopCount
<
MAX_LOOP_COUNT
)
while
(
loopCount
<
MAX_LOOP_COUNT
)
// are we done yet?
{
{
// initialize loop variables
loopCount
++;
// good practice: increment loop counter as first action
loopCount
++;
// =============================================================================================
// =============================================================================================
// your own simulation code starts here!
// your own simulation code starts here!
// are there any other variables to modify at the beginning of your loop?
// compute a track, update an ESPDU, whatever it is that your model is doing...
// compute a track, update an ESPDU, whatever it is that your model is doing...
// Where is my entity?
// Where is my entity?
Insert changes in position.
entityStatePdu
.
getEntityLocation
().
setX
(
entityStatePdu
.
getEntityLocation
().
getX
()
+
1.0
);
// 1m per timestep
entityStatePdu
.
getEntityLocation
().
setX
(
entityStatePdu
.
getEntityLocation
().
getX
()
+
1.0
);
// 1m per timestep
// decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at!
// decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at!
...
@@ -156,7 +165,7 @@ public class ExampleSimulationProgram
...
@@ -156,7 +165,7 @@ public class ExampleSimulationProgram
}
}
/**
/**
* Utility Constructor
* Utility Constructor
that allows your example simulation program to override default network address and port
* @param address network address to use
* @param address network address to use
* @param port corresponding network port to use
* @param port corresponding network port to use
*/
*/
...
@@ -180,7 +189,7 @@ public class ExampleSimulationProgram
...
@@ -180,7 +189,7 @@ public class ExampleSimulationProgram
*/
*/
public
final
void
setNetworkAddress
(
String
newNetworkAddress
)
public
final
void
setNetworkAddress
(
String
newNetworkAddress
)
{
{
this
.
networkAddress
=
newNetworkAddress
;
ExampleSimulationProgram
.
networkAddress
=
newNetworkAddress
;
}
}
/**
/**
...
@@ -196,7 +205,7 @@ public class ExampleSimulationProgram
...
@@ -196,7 +205,7 @@ public class ExampleSimulationProgram
*/
*/
public
final
void
setNetworkPort
(
int
newNetworkPort
)
public
final
void
setNetworkPort
(
int
newNetworkPort
)
{
{
this
.
networkPort
=
newNetworkPort
;
ExampleSimulationProgram
.
networkPort
=
newNetworkPort
;
}
}
/**
/**
...
...
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