FlightGear run levels: Difference between revisions

Jump to navigation Jump to search
Line 42: Line 42:
Once core features and subsystems are initialized via properties, it would be possible to even implement complex run level setups in scripting space.
Once core features and subsystems are initialized via properties, it would be possible to even implement complex run level setups in scripting space.


Some more details are currently covered at [[Howto:Optimizing FlightGear for mobile devices#Optimizing at the Source Code Level]].
Also see: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg03418.html


Also see: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg03418.html
== A Listener based Allocator/Deallocator for SGSubsystems ==
It would probably make sense to introduce a custom class template for "optional" subsystems, so that these can be easily made optional by registering listeners and invoking callbacks to new/delete SGSubsystems dynamically '''after''' recursively loading/releasing dependant subsystems by also firing signals. For example:
<syntaxhighlight lang="cpp">
template <class T>
class SGOptional : public SGPropertyChangeListener {
public:
SGOptional(const char* p) : _toggle_switch(p) {
  fgAddChangeListener(p, this);
  valueChanged(); // pick up initial property value (i.e. --prop args)
}
 
void valueChanged() {
// enable/disable system, call notification callbacks, set properties and allocate/free memory
}
 
void startup_dependencies() {
// set properties to startup dependencies (if not initialized already)
}
 
// TODO: add one method to manage the refcount for dependencies (allocation/deallocation)
 
protected:
private:
SGPropertyNode_ptr _toggle_switch;
T _type;
};
</syntaxhighlight>
 
Just by overloading a bunch of operators, most of the existing source code would not need to be changed.
So that globals.hxx could be directly changed accordingly.
 
For example, instead of having this::
 
<syntaxhighlight lang="cpp">
  // Global autopilot "route"
    FGRouteMgr *route_mgr;
    // ATC manager
    FGATISMgr *ATIS_mgr;
 
    // Navigational Aids
    FGNavList *navlist;
    FGNavList *loclist;
    FGNavList *gslist;
    FGNavList *dmelist;
    FGNavList *tacanlist;
    FGNavList *carrierlist;
    FGTACANList *channellist;
</syntaxhighlight>
 
One could use the new SGOptional<T> template:
 
<syntaxhighlight lang="cpp">
  // Global autopilot "route"
    SGOptional<FGRouteMgr*> route_mgr;
    // ATC manager
    SGOptional<FGATISMgr*> ATIS_mgr;
 
    // Navigational Aids
    SGOptional<FGNavList*> navlist;
    SGOptional<FGNavList*> loclist;
    SGOptional<FGNavList*> gslist;
    SGOptional<FGNavList*> dmelist;
    SGOptional<FGNavList*> tacanlist;
    SGOptional<FGNavList*> carrierlist;
    SGOptional<FGTACANList*> channellist;
</syntaxhighlight>
 
This would make it possible to neatly encapsulate optional subsystems, which could also be linked to a property listener - so that features could be switched on/off at runtime.
 
The initialization code in fg_init.cxx would then need to be adapted to delegate subsystem initialization to corresponding SGOptional<T> specialization, which would make this dependant on a property switch:
 
<syntaxhighlight lang="cpp">
    ////////////////////////////////////////////////////////////////////
    // Initialize the sound subsystem.
    ////////////////////////////////////////////////////////////////////
    // Sound manager uses an own subsystem group "SOUND" which is the last
    // to be updated in every loop.
    // Sound manager is updated last so it can use the CPU while the GPU
    // is processing the scenery (doubled the frame-rate for me) -EMH-
    globals->add_subsystem("sound", new SGOptional<SGSoundMgr>("/enable/sound"), SGSubsystemMgr::SOUND);
</syntaxhighlight>
 
It's also worth mentioning that base package files (XML, Nasal etc) may be trying to use disabled subsystems, so this needs further attention by only loading Nasal modules via listeners,so that they can be cleanly shut down when a subsystem is terminated.


== Nasal Scripts ==
== Nasal Scripts ==

Navigation menu