| 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 FGFX : public SGSubsystem |
| 55 |
{ |
| 56 |
public: |
| 57 |
|
| 58 |
FGFX (); |
| 59 |
virtual ~FGFX (); |
| 60 |
|
| 61 |
virtual void init (); |
| 62 |
virtual void reinit (); |
| 63 |
virtual void bind (); |
| 64 |
virtual void unbind (); |
| 65 |
virtual void update (double dt); |
| 66 |
} |
| 67 |
|
| 68 |
The init() functions should make sure everything is set and ready so the |
| 69 |
update() function can be run by the main loop. The reinit() function handles |
| 70 |
everything in case of a reset by the user. |
| 71 |
|
| 72 |
The bind() and unbind() functions can be used to tie and untie properties. |
| 73 |
|
| 74 |
After that you can register this class at the subsystem manager: |
| 75 |
|
| 76 |
globals->add_subsystem("fx", new FGFX); |
| 77 |
|
| 78 |
Now the subsystem manager calls the update() function of this class every |
| 79 |
frame. dt is the time (in seconds) elapsed since the last call. |
| 80 |
|
| 81 |
|
| 82 |
Scripting |
| 83 |
--------- |
| 84 |
|
| 85 |
The scripting langage Nasal can also read and modify properties but it can also |
| 86 |
be incorporated into the menu system. The documentation for Nasal can be found |
| 87 |
here: http://www.plausible.org/nasal/flightgear.html |
| 88 |
|