| 1 |
|
| 2 |
Internals |
| 3 |
--------- |
| 4 |
|
| 5 |
The core of FlightGear is the property system. This is a tree like internal |
| 6 |
representation of global variables. The property system is explained more |
| 7 |
in detail later on. |
| 8 |
|
| 9 |
FlightGear' way of doing things is breaking it up into small pieces. There is |
| 10 |
(for example) animation code that reacts on property changes. There is also a |
| 11 |
Flight Dynamics model (FDM) that (amongst other things) updates properties. |
| 12 |
There is a menu system that can display and alter properties. Then we have |
| 13 |
sound code that plays sound based on ... properties. |
| 14 |
|
| 15 |
Maybe you see a pattern evolve by now. |
| 16 |
|
| 17 |
All subsystems are almost self containing. Most of the time they only read the |
| 18 |
values of some properties, and sometimes they alter other properties. This is |
| 19 |
the basic way of communicating between subsystems. |
| 20 |
|
| 21 |
|
| 22 |
Property System |
| 23 |
--------------- |
| 24 |
|
| 25 |
The property system is best described as an in-memory LDAP database which holds |
| 26 |
the state of global variables. The system has a tree like hierarchy (like a |
| 27 |
file system) and has a root node, sub nodes (like subdirectories) and end-nodes |
| 28 |
(variables). |
| 29 |
|
| 30 |
All variables are kept internally as raw values and can be converted to any |
| 31 |
other supported type (boolean, int, float double and string). |
| 32 |
|
| 33 |
Like a file system, every node can be accessed relative to the current node, or |
| 34 |
absolute to the root node. |
| 35 |
|
| 36 |
The property system also allows aliasing nodes to other nodes (like symbolic |
| 37 |
linking files or directories to other files or directories) and may be assigned |
| 38 |
read-only or read-write. |
| 39 |
|
| 40 |
If necessary it would be possible for parts of the program to hold it's own |
| 41 |
property tree, which is inaccessible from the global property tree, by keeping |
| 42 |
track of it's own root-node. |
| 43 |
|
| 44 |
Property I/O code allows one to easily read the tree from, or write the tree to |
| 45 |
an XML file. |
| 46 |
|
| 47 |
|
| 48 |
Subsystems |
| 49 |
---------- |
| 50 |
|
| 51 |
To add a new subsystem you would have to create a derived class from |
| 52 |
SGSubsystem and define at least a small set of functions: |
| 53 |
|
| 54 |
class FGSubsystemExample : public SGSubsystem |
| 55 |
{ |
| 56 |
public: |
| 57 |
FGSubsystemExample(); |
| 58 |
virtual ~FGSubsystemExample(); |
| 59 |
|
| 60 |
// Subsystem API. |
| 61 |
void bind() override; |
| 62 |
void init() override; |
| 63 |
void reinit() override; |
| 64 |
void unbind() override; |
| 65 |
void update(double dt) override; |
| 66 |
|
| 67 |
// Subsystem identification. |
| 68 |
static const char* staticSubsystemClassId() { return "subsystem-example"; } |
| 69 |
}; |
| 70 |
|
| 71 |
To register the subsystem with the subsystem manager, for non-instanced |
| 72 |
subsystems add: |
| 73 |
|
| 74 |
// Register the subsystem. |
| 75 |
SGSubsystemMgr::Registrant<FGSubsystemExample> registrantFGSubsystemExample |
| 76 |
|
| 77 |
Or to define a specific subsystem manager group, e.g. DISPLAY, and add any |
| 78 |
dependencies: |
| 79 |
|
| 80 |
// Register the subsystem. |
| 81 |
SGSubsystemMgr::Registrant<FGSubsystemExample> registrantFGSubsystemExample( |
| 82 |
SGSubsystemMgr::DISPLAY, |
| 83 |
{{"viewer", SGSubsystemMgr::Dependency::HARD}, |
| 84 |
{"FGRenderer", SGSubsystemMgr::Dependency::NONSUBSYSTEM_HARD}}); |
| 85 |
|
| 86 |
The init() functions should make sure everything is set and ready so the |
| 87 |
update() function can be run by the main loop. The reinit() function handles |
| 88 |
everything in case of a reset by the user. |
| 89 |
|
| 90 |
The bind() and unbind() functions can be used to tie and untie properties. |
| 91 |
|
| 92 |
Finally to create and have the subsystem managed: |
| 93 |
|
| 94 |
globals->get_subsystem_mgr()->add<FGSubsystemExample>(); |
| 95 |
|
| 96 |
or: |
| 97 |
|
| 98 |
globals->get_subsystem_mgr()->add("example"); |
| 99 |
|
| 100 |
Now the subsystem manager calls the update() function of this class every |
| 101 |
frame. dt is the time (in seconds) elapsed since the last call. |
| 102 |
|
| 103 |
|
| 104 |
Scripting |
| 105 |
--------- |
| 106 |
|
| 107 |
The scripting language Nasal can also read and modify properties but it can also |
| 108 |
be incorporated into the menu system. The documentation for Nasal can be found |
| 109 |
here: http://www.plausible.org/nasal/flightgear.html |
| 110 |
|