Open Rails is organized into three major components – Launcher, Menu, and RunActivity. A few words on each is in order.
Launcher
Launcher.exe (Launcher/Program) checks to see if prerequisite software (i.e., libraries) is installed. If all is well, Launcher starts Menu.exe and terminates.
Menu
Menu.exe (Launcher/Program) presents a dialog that allows the user to select a route and activity. Upon completion, it starts RunActivity.exe, passing an argument that contains the full route path and filename of the activity to be run. Menu remains resident while RunActivity runs, and the Menu dialog will be presented after RunActivity terminates at the end of the operating session.
RunActivity
RunActivity.exe (RunActivity/_Main) is passed a string argument with the full file specification of the activity to be started.[1] Main (_Main.cs) calls Start with the filespec as an argument. Start instantiates Simulator, whose constructor:
- Creates an object TRK (instantiated from class TRKFile), whose constructor verifies that the specified folder contains a .trk file for either MSTS or ORTS. It instantiates either Tr_RouteFile (MSTS) or ORTRKData (ORTS), whose methods will parse the file.
- Creates a TDB object (instantiated from TDBFile), whose constructor verifies the track database and returns.
- TSectionDat (instantiated from TSectionDatFile) constructor verifies track sections and adds them to the class. Also does TrackShapes.
- Activity (instantiated from ACTFile) constructor creates Tr_Activity_File (instantiated from Tr_Activity_File), which parses the activity file.
Immediately after Simulator’s constructor returns, Start calls Simulator.Start, which does the following:
- Initializes any time recording required by the activity.
- Aligns all switches to their default positions, as specified by the activity. The internal Track Data Base (TDB) data structure is traversed in order to do this.
- Places the player train.
- Places static consists.
- Signals will be initialized here when implemented.
- Creates a queue of AI trains.
When Simulator.Start returns, Start instantiates Viewer (from class Viewer3D). Viewer’s constructor does the following:
- Sets up user game settings.
- Creates and initializes the sound engine.
- Initializes the environment according to the activity.
- Reads TTYPE.DAT and builds an internal data structure.
- Instantiates a Tile class object whose constructor initializes an 8x8 (x, z) buffer of tile objects.
- Creates subsidiary two or three subsidiary threads, one for rendering, one for loading, and (if the PC has multiple processors) one for updating. Three classes are instantiated to run in these threads: RenderProcess, LoaderProcess, and UpdaterProcess. (Their constructors run immediately upon instantiation.) More on this below.
Immediately following the return of Viewer’s constructor, Start calls Viewer.Run which calls RenderProcess.Run. RenderProcess.Run runs in the RenderProcess thread, and it calls XNA Run (“game loop”).
| Up to: Design Overview | Next section: Three Threads |
[1] To run RunActivity in Debug mode under Visual C#, insert a file specification (in quotes)in project Properties/Debug/ Command line arguments, and launch the project with Debug.