Howto:Add new fgcommands to FlightGear: Difference between revisions

Jump to navigation Jump to search
m
→‎Reaching out to subsystems: https://gitorious.org/fg/flightgear/commit/b21bb90ae57864c6bc565ae480036f3c11f7efe6#comment_110790
m (→‎Reaching out to subsystems: https://gitorious.org/fg/flightgear/commit/b21bb90ae57864c6bc565ae480036f3c11f7efe6#comment_110790)
Line 233: Line 233:
Quite possibly, you may need to reach out to some other subsystems to implement a certain fgcommand, such as accessing the sound system, the networking system or the FDM system, this is accomplished by using the globals-> pointer, which allows you to access other subsystems easily. Please refer to [http://gitorious.org/fg/flightgear/blobs/next/src/Main/globals.cxx#line120 $FG_SRC/Main/globals.cxx] and its header file [http://gitorious.org/fg/flightgear/blobs/next/src/Main/globals.hxx globals.hxx]. A number of helpful usage examples can be found by searching fg_commands.cxx for "globals->".
Quite possibly, you may need to reach out to some other subsystems to implement a certain fgcommand, such as accessing the sound system, the networking system or the FDM system, this is accomplished by using the globals-> pointer, which allows you to access other subsystems easily. Please refer to [http://gitorious.org/fg/flightgear/blobs/next/src/Main/globals.cxx#line120 $FG_SRC/Main/globals.cxx] and its header file [http://gitorious.org/fg/flightgear/blobs/next/src/Main/globals.hxx globals.hxx]. A number of helpful usage examples can be found by searching fg_commands.cxx for "globals->".


In general, you will always want to add a NULL pointer check to ensure that the corresponding subsystem handle could actually be retrieved:
<syntaxhighlight lang="cpp">
FGMultiplayMgr * self = (FGMultiplayMgr*) globals->get_subsystem("mp");
if (!self) {
SG_LOG(SG_NETWORK, SG_WARN, "Multiplayer subsystem not available.");
return false;
}
</syntaxhighlight>
Equally, it may be appropriate to wrap code in between try/catch blocks, too.


A list of methods available to access certain subsystems is provided here in [http://gitorious.org/fg/flightgear/blobs/next/src/Main/globals.hxx#line220 globals.hxx, beginning in line 220].
A list of methods available to access certain subsystems is provided here in [http://gitorious.org/fg/flightgear/blobs/next/src/Main/globals.hxx#line220 globals.hxx, beginning in line 220].

Navigation menu