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
e990d63e
Commit
e990d63e
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
initializeSimulationEntities(), SimulationManager addition
parent
49a870de
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
+72
-32
72 additions, 32 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
examples/src/OpenDis7Examples/ExampleSimulationProgramLog.txt
+68
-67
68 additions, 67 deletions
...ples/src/OpenDis7Examples/ExampleSimulationProgramLog.txt
with
140 additions
and
99 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
+
72
−
32
View file @
e990d63e
...
...
@@ -12,6 +12,8 @@ import edu.nps.moves.dis7.pdus.*;
import
edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface
;
import
edu.nps.moves.dis7.utilities.PduFactory
;
import
edu.nps.moves.dis7.utilities.stream.PduRecorder
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
...
...
@@ -29,6 +31,7 @@ public class ExampleSimulationProgram
static
final
int
NETWORK_PORT_DEFAULT
=
3000
;
String
networkAddress
=
NETWORK_ADDRESS_DEFAULT
;
int
networkPort
=
NETWORK_PORT_DEFAULT
;
String
thisHostName
=
"localhost"
;
String
DEFAULT_OUTPUT_DIRECTORY
=
"./pduLog"
;
/** seconds for real-time execution (not simulation time, which may or may not be the same) */
...
...
@@ -42,6 +45,57 @@ public class ExampleSimulationProgram
* Output prefix to help with logging by identifying this class (overridden in subclass).
*/
protected
static
String
TRACE_PREFIX
;
/* Declare DIS Protocol Data Unit (PDU) classes for simulation entities */
PduFactory
.
TimestampStyle
timestampStyle
=
PduFactory
.
TimestampStyle
.
YEAR
;
PduFactory
pduFactory
=
new
PduFactory
(
timestampStyle
);
protected
EntityID
entityID_1
=
new
EntityID
();
protected
EntityID
entityID_2
=
new
EntityID
();
protected
EntityStatePdu
entityStatePdu_1
=
pduFactory
.
makeEntityStatePdu
();
protected
EntityStatePdu
entityStatePdu_2
=
pduFactory
.
makeEntityStatePdu
();
protected
FirePdu
firePdu_1a
=
pduFactory
.
makeFirePdu
();
// for entity 1 first weapon (if any)
// protected FirePdu firePdu_1b = pduFactory.makeFirePdu(); // for entity 1 second weapon (if any)
protected
MunitionDescriptor
munitionDescriptor1
=
new
MunitionDescriptor
();
SimulationManager
simulationManager
=
new
SimulationManager
();
/** Get ready, get set... initialize simulation entities
*/
public
void
initializeSimulationEntities
()
{
// Your model setup: define participants. who's who in this zoo?
// Assuming you keep track of entity objects... here is some support for for Entity 1.
// PDU objects are already created, now set their values.
entityID_1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
3
);
// 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_1
.
setEntityID
(
entityID_1
);
entityStatePdu_1
.
setForceId
(
ForceID
.
FRIENDLY
);
entityStatePdu_1
.
setEntityType
(
new
_001Poseidon
());
// note import statement above
entityStatePdu_1
.
setMarking
(
"Entity #1"
);
entityStatePdu_1
.
getMarkingString
();
// check
entityStatePdu_2
.
setEntityID
(
entityID_2
);
entityStatePdu_2
.
setForceId
(
ForceID
.
OPPOSING
);
entityStatePdu_2
.
setEntityType
(
new
_002Triton
());
// note import statement above
entityStatePdu_2
.
setMarking
(
"Entity #2"
);
// TODO how should we customize this munition? what is it for your simulation?
munitionDescriptor1
.
setQuantity
(
1
);
firePdu_1a
.
setDescriptor
(
munitionDescriptor1
).
setRange
(
1000.0f
);
// TODO simulation management PDUs for startup, planning to design special class support
// simulationManager.addEntity();
simulationManager
.
setDescriptor
(
"ExampleSimulationProgram"
);
simulationManager
.
addHost
(
thisHostName
);
simulationManager
.
setDisThreadedNetworkInterface
(
disNetworkInterface
);
}
/**
* This runSimulationLoops() method is for you, a customizable programmer-modifiable
...
...
@@ -69,35 +123,10 @@ public class ExampleSimulationProgram
pduRecorder
.
setVerbose
(
true
);
// Your model setup: define participants. who's who in this zoo?
// Assuming you keep track of entity objects... here is some support for for Entity 1.
initializeSimulationEntities
();
// create PDU objects and set their values.
EntityID
entityID_1
=
new
EntityID
();
entityID_1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
3
);
// made-up example ID;
EntityID
entityID_2
=
new
EntityID
();
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
();
entityStatePdu_1
.
setEntityID
(
entityID_1
);
entityStatePdu_1
.
setForceId
(
ForceID
.
FRIENDLY
);
entityStatePdu_1
.
setEntityType
(
new
_001Poseidon
());
// note import statement above
entityStatePdu_1
.
setMarking
(
"Entity #1"
);
entityStatePdu_1
.
getMarkingString
();
// check
EntityStatePdu
entityStatePdu_2
=
pduFactory
.
makeEntityStatePdu
();
entityStatePdu_2
.
setEntityID
(
entityID_2
);
entityStatePdu_2
.
setForceId
(
ForceID
.
OPPOSING
);
entityStatePdu_2
.
setEntityType
(
new
_002Triton
());
// note import statement above
entityStatePdu_2
.
setMarking
(
"Entity #2"
);
FirePdu
firePdu_1a
=
pduFactory
.
makeFirePdu
();
// for entity 1 first weapon (if any)
// FirePdu firePdu_1b = pduFactory.makeFirePdu(); // for entity 1 second weapon (if any)
// should we customize this munition? what is it for your simulation?
// TODO simulation management PDUs for startup, planning to design special class support
simulationManager
.
simulationJoin
();
simulationManager
.
simulationStart
();
// ===================================================================================================
// loop the simulation while allowed, programmer can set additional conditions to break out and finish
...
...
@@ -162,7 +191,10 @@ public class ExampleSimulationProgram
narrativeMessage2
=
"runSimulation() completed successfully"
;
// all done
sendCommentPdu
(
narrativeComment
,
narrativeMessage1
,
narrativeMessage2
,
narrativeMessage3
);
System
.
out
.
println
(
"... [final CommentPdu successfully sent for simulation]"
);
// TODO simulation management PDUs
simulationManager
.
simulationStop
();
simulationManager
.
simulationLeave
();
}
catch
(
InterruptedException
iex
)
// handle any exception that your code might choose to provoke!
{
...
...
@@ -184,8 +216,6 @@ public class ExampleSimulationProgram
VariableRecordType
otherComment
=
VariableRecordType
.
OTHER
;
// class variables
PduFactory
pduFactory
=
new
PduFactory
();
PduFactory
.
TimestampStyle
timestampStyle
=
PduFactory
.
TimestampStyle
.
YEAR
;
DisThreadedNetworkInterface
disNetworkInterface
;
DisThreadedNetworkInterface
.
PduListener
pduListener
;
Pdu
receivedPdu
;
...
...
@@ -198,6 +228,16 @@ public class ExampleSimulationProgram
public
ExampleSimulationProgram
()
{
pduFactory
.
setTimestampStyle
(
timestampStyle
);
try
{
thisHostName
=
InetAddress
.
getLocalHost
().
getHostName
();
System
.
out
.
println
(
TRACE_PREFIX
+
"thisHostName="
+
thisHostName
);
}
catch
(
UnknownHostException
uhe
)
{
System
.
out
.
println
(
TRACE_PREFIX
+
thisHostName
+
"not connected to network: "
+
uhe
.
getMessage
());
}
}
/**
...
...
@@ -207,7 +247,7 @@ public class ExampleSimulationProgram
*/
public
ExampleSimulationProgram
(
String
address
,
int
port
)
{
super
();
// if code block is provided
super
();
setNetworkAddress
(
address
);
...
...
@@ -388,7 +428,7 @@ public class ExampleSimulationProgram
}
/**
* Initial execution via main() method: handle args array of initialization arguments here
* Initial execution via main() method: handle args array of
command-line
initialization
(CLI)
arguments here
* @param args command-line parameters: network address and port
*/
protected
void
handleArgs
(
String
[]
args
)
...
...
This diff is collapsed.
Click to expand it.
examples/src/OpenDis7Examples/ExampleSimulationProgramLog.txt
+
68
−
67
View file @
e990d63e
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