diff --git a/examples/src/OpenDis7Examples/ExampleSimulationProgram.java b/examples/src/OpenDis7Examples/ExampleSimulationProgram.java index 679b1bcf2663b355839833f08a906f21a50bc9a4..db21cc89de0f3614884fee4e7d32c8cc1da318ca 100644 --- a/examples/src/OpenDis7Examples/ExampleSimulationProgram.java +++ b/examples/src/OpenDis7Examples/ExampleSimulationProgram.java @@ -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 */ - private final static String TRACE_PREFIX = "[" + ExampleSimulationProgram.class.getName() + "] "; + protected 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 clock to zero each time for consistent outputs - + // TODO reset Clock 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, timeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + sendAllPdusForLoopTimestep(entityStatePdu_1, firePdu_1a, currentTimeStepComment, 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 timeStepComment = VariableRecordType.APPLICATION_TIMESTEP; - VariableRecordType otherComment = VariableRecordType.OTHER; + VariableRecordType descriptionComment = VariableRecordType.DESCRIPTION; + VariableRecordType narrativeComment = VariableRecordType.COMPLETE_EVENT_REPORT; + VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS; + VariableRecordType currentTimeStepComment = VariableRecordType.APPLICATION_TIMESTEP; + VariableRecordType otherComment = VariableRecordType.OTHER; // class variables PduFactory pduFactory = new PduFactory(); @@ -192,7 +193,7 @@ public class ExampleSimulationProgram */ public ExampleSimulationProgram() { - // Constructor is under consideration. Constructor is not currently needed. + // Potential constructor 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 threading lets go + System.exit(0); // ensure all threads and sockets released } }