1
2Internals
3---------
4
5The core of FlightGear is the property system. This is a tree like internal
6representation of global variables. The property system is explained more
7in detail later on.
8
9FlightGear' 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
11Flight Dynamics model (FDM) that (amongst other things) updates properties.
12There is a menu system that can display and alter properties. Then we have
13sound code that plays sound based on ... properties.
14
15Maybe you see a pattern evolve by now.
16
17All subsystems are almost self containing. Most of the time they only read the
18values of some properties, and sometimes they alter other properties. This is
19the basic way of communicating between subsystems.
20
21
22Property System
23---------------
24
25The property system is best described as an in-memory LDAP database which holds
26the state of global variables. The system has a tree like hierarchy (like a
27file system) and has a root node, sub nodes (like subdirectories) and end-nodes
28(variables).
29
30All variables are kept internally as raw values and can be converted to any
31other supported type (boolean, int, float double and string).
32
33Like a file system, every node can be accessed relative to the current node, or
34absolute to the root node.
35
36The property system also allows aliasing nodes to other nodes (like symbolic
37linking files or directories to other files or directories) and may be assigned
38read-only or read-write.
39
40If necessary it would be possible for parts of the program to hold it's own
41property tree, which is inaccessible from the global property tree, by keeping
42track of it's own root-node.
43
44Property I/O code allows one to easily read the tree from, or write the tree to
45an XML file.
46
47
48Subsystems
49----------
50
51To add a new subsystem you would have to create a derived class from
52SGSubsystem 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
68The init() functions should make sure everything is set and ready so the
69update() function can be run by the main loop. The reinit() function handles
70everything in case of a reset by the user.
71
72The bind() and unbind() functions can be used to tie and untie properties.
73
74After that you can register this class at the subsystem manager:
75
76    globals->add_subsystem("fx", new FGFX);
77
78Now the subsystem manager calls the update() function of this class every
79frame. dt is the time (in seconds) elapsed since the last call.
80
81
82Scripting
83---------
84
85The scripting langage Nasal can also read and modify properties but it can also
86be incorporated into the menu system. The documentation for Nasal can be found
87here:  http://www.plausible.org/nasal/flightgear.html
88
89