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
8265d054
Commit
8265d054
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
main() javadoc logging and inheritance-interoperability improvements
parent
d2468a56
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
-27
23 additions, 27 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
with
23 additions
and
27 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
+
23
−
27
View file @
8265d054
...
...
@@ -16,9 +16,10 @@ import java.util.ArrayList;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
/** The purpose of this program is to provide an easily modifiable example simulation program
* that includes DIS-capable entities doing tasks and reporting them to the network.
* Default settings include PDU recording turned on by default.
/** The purpose of this inheritable class is to provide an easily modifiable example simulation program
* that includes DIS-capable entities performing tasks of interest, and then reporting activity via PDUs
* to the network.
* Default program initialization includes PDU recording turned on by default.
*/
public
class
ExampleSimulationProgram
{
...
...
@@ -39,7 +40,7 @@ public class ExampleSimulationProgram
/**
* Output prefix to identify this class (override in subclass), helps with logging
*/
pr
ivate
final
static
String
TRACE_PREFIX
=
"["
+
ExampleSimulationProgram
.
class
.
getName
()
+
"] "
;
pr
otected
static
String
TRACE_PREFIX
;
/**
* This runSimulationLoops() method is for you, a programmer-modifiable code block
...
...
@@ -63,8 +64,8 @@ public class ExampleSimulationProgram
int
simulationLoopCount
=
0
;
// variable, initialized at 0
boolean
simulationComplete
=
false
;
// sentinel variable as termination condition, are we done yet?
// TODO reset
c
lock
to zero each time for consistent outputs
// TODO reset
C
lock
Time to today's date and timestamp to zero, providing consistent outputs for each simulation run
pduRecorder
.
setVerbose
(
true
);
// Your model setup: define participants. who's who in this zoo?
...
...
@@ -72,10 +73,10 @@ public class ExampleSimulationProgram
// create PDU objects and set their values.
EntityID
entityID_1
=
new
EntityID
();
entityID_1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
3
);
// made-up example ID;
// create PDU objects and set their values.
entityID_1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
3
);
// made-up example ID;
EntityID
entityID_2
=
new
EntityID
();
entityID_
1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
4
);
// made-up example ID;
entityID_
2
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
4
);
// made-up example ID;
// TODO someday, use enumerations; is there a unique site triplet for MOVES Institute?
EntityStatePdu
entityStatePdu_1
=
pduFactory
.
makeEntityStatePdu
();
...
...
@@ -142,7 +143,7 @@ public class ExampleSimulationProgram
// OK now send the status PDUs for this loop, and then continue
System
.
out
.
println
(
"sending PDUs for simulation step "
+
simulationLoopCount
+
", monitor loopback to confirm sent"
);
sendAllPdusForLoopTimestep
(
entityStatePdu_1
,
firePdu_1a
,
t
imeStepComment
,
narrativeMessage1
,
narrativeMessage2
,
narrativeMessage3
);
sendAllPdusForLoopTimestep
(
entityStatePdu_1
,
firePdu_1a
,
currentT
imeStepComment
,
narrativeMessage1
,
narrativeMessage2
,
narrativeMessage3
);
sendSinglePdu
(
entityStatePdu_2
);
// me too i.e. 2!
System
.
out
.
println
(
"... [PDUs successfully sent for this loop]"
);
...
...
@@ -173,11 +174,11 @@ public class ExampleSimulationProgram
/* VariableRecordType enumerations have potential use with CommentPdu logs */
/* TODO contrast to EntityType */
VariableRecordType
descriptionComment
=
VariableRecordType
.
DESCRIPTION
;
VariableRecordType
narrativeComment
=
VariableRecordType
.
COMPLETE_EVENT_REPORT
;
VariableRecordType
statusComment
=
VariableRecordType
.
APPLICATION_STATUS
;
VariableRecordType
t
imeStepComment
=
VariableRecordType
.
APPLICATION_TIMESTEP
;
VariableRecordType
otherComment
=
VariableRecordType
.
OTHER
;
VariableRecordType
descriptionComment
=
VariableRecordType
.
DESCRIPTION
;
VariableRecordType
narrativeComment
=
VariableRecordType
.
COMPLETE_EVENT_REPORT
;
VariableRecordType
statusComment
=
VariableRecordType
.
APPLICATION_STATUS
;
VariableRecordType
currentT
imeStepComment
=
VariableRecordType
.
APPLICATION_TIMESTEP
;
VariableRecordType
otherComment
=
VariableRecordType
.
OTHER
;
// class variables
PduFactory
pduFactory
=
new
PduFactory
();
...
...
@@ -192,7 +193,7 @@ public class ExampleSimulationProgram
*/
public
ExampleSimulationProgram
()
{
//
C
onstructor is under consideration. Constructor is not currently needed.
//
Potential c
onstructor is under consideration. Constructor is not currently needed.
}
/**
...
...
@@ -266,7 +267,6 @@ public class ExampleSimulationProgram
String
outputDirectory
=
DEFAULT_OUTPUT_DIRECTORY
;
System
.
out
.
println
(
"Beginning pdu save to directory "
+
outputDirectory
);
pduRecorder
=
new
PduRecorder
(
outputDirectory
,
getNetworkAddress
(),
getNetworkPort
());
// assumes save
pduRecorder
.
setDescriptor
(
"ExampleSimulationProgram pduRecorder"
);
pduRecorder
.
setEncodingPduLog
(
PduRecorder
.
ENCODING_PLAINTEXT
);
pduRecorder
.
setVerbose
(
true
);
// either sending, receiving or both
pduRecorder
.
start
();
// begin running
...
...
@@ -275,13 +275,7 @@ public class ExampleSimulationProgram
/** All done, release network resources */
public
void
tearDownNetworkInterface
()
{
pduRecorder
.
stop
();
// handles disNetworkInterface.close()
// disNetworkInterface.removeListener(pduListener);
//
// disNetworkInterface.close();
// disNetworkInterface.kill(); // renamed as close(), deprecated
// disNetworkInterface = null; // making sure no possibility of zombie process remaining...
pduRecorder
.
stop
();
// handles disNetworkInterface.close(), teards down threads and sockets
}
/**
...
...
@@ -404,15 +398,17 @@ public class ExampleSimulationProgram
*/
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
TRACE_PREFIX
+
"main() started..."
)
;
TRACE_PREFIX
=
"["
+
ExampleSimulationProgram
.
class
.
getName
()
+
"] "
;
// OK here we go...
System
.
out
.
println
(
TRACE_PREFIX
+
"main() started..."
);
thisProgram
=
new
ExampleSimulationProgram
();
// creates instance of self within static main() method
thisProgram
.
handleArgs
(
args
);
// process command-line invocation arguments
thisProgram
.
setUpNetworkInterface
();
// thisProgram.pduRecorder.setDescriptor (TRACE_PREFIX.replace("[","").replace("]","") + " pduRecorder");
thisProgram
.
runSimulationLoops
();
// ... your simulation execution code goes in there ...
...
...
@@ -420,6 +416,6 @@ public class ExampleSimulationProgram
System
.
out
.
println
(
TRACE_PREFIX
+
"complete."
);
// report successful completion
System
.
exit
(
0
);
// ensure all thread
ing lets go
System
.
exit
(
0
);
// ensure all thread
s and sockets released
}
}
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