1
0
Fork 0

Templated subsystem handling

- remove explicit FGControls var from globals, as part of work
  towards unit-testing infrastructure.
This commit is contained in:
James Turner 2015-12-10 15:05:54 -06:00
parent 6446d67431
commit d7a680e848
5 changed files with 34 additions and 18 deletions

View file

@ -78,7 +78,6 @@ FGControls::FGControls() :
}
reset_all();
globals->set_controls( this );
}
@ -162,9 +161,8 @@ void FGControls::reset_all()
// Destructor
FGControls::~FGControls() {
if (globals)
globals->set_controls( NULL );
FGControls::~FGControls()
{
}

View file

@ -639,6 +639,7 @@ public:
// controls/autoflight/autopilot[n]/
void set_autopilot_engage( int ap, bool val );
static const char* subsystemName() { return "controls"; }
private:
inline void do_autocoordination() {
// check for autocoordination

View file

@ -849,7 +849,7 @@ void fgCreateSubsystems(bool duringReset) {
// Initialize the controls subsystem.
////////////////////////////////////////////////////////////////////
globals->add_subsystem("controls", new FGControls, SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<FGControls>(SGSubsystemMgr::GENERAL);
////////////////////////////////////////////////////////////////////
// Initialize the input subsystem.

View file

@ -160,7 +160,6 @@ FGGlobals::FGGlobals() :
time_params( NULL ),
ephem( NULL ),
route_mgr( NULL ),
controls( NULL ),
viewmgr( NULL ),
commands( SGCommandMgr::instance() ),
channel_options_list( NULL ),
@ -509,7 +508,7 @@ FGGlobals::get_subsystem_mgr () const
}
SGSubsystem *
FGGlobals::get_subsystem (const char * name)
FGGlobals::get_subsystem (const char * name) const
{
if (!subsystem_mgr) {
return NULL;
@ -751,6 +750,11 @@ void FGGlobals::set_matlib( SGMaterialLib *m )
matlib = m;
}
FGControls *FGGlobals::get_controls() const
{
return get_subsystem<FGControls>();
}
FGSampleQueue* FGGlobals::get_chatter_queue() const
{
return _chatter_queue;

View file

@ -123,9 +123,6 @@ private:
// Global autopilot "route"
FGRouteMgr *route_mgr;
// control input state
FGControls *controls;
// viewer manager
FGViewMgr *viewmgr;
@ -180,19 +177,36 @@ public:
virtual FGRenderer *get_renderer () const;
void set_renderer(FGRenderer* render);
virtual SGSubsystemMgr *get_subsystem_mgr () const;
SGSubsystemMgr *get_subsystem_mgr () const;
virtual SGSubsystem *get_subsystem (const char * name);
SGSubsystem *get_subsystem (const char * name) const;
virtual void add_subsystem (const char * name,
template<class T>
T* get_subsystem() const
{
return dynamic_cast<T*>(get_subsystem(T::subsystemName()));
}
void add_subsystem (const char * name,
SGSubsystem * subsystem,
SGSubsystemMgr::GroupType
type = SGSubsystemMgr::GENERAL,
double min_time_sec = 0);
virtual SGEventMgr *get_event_mgr () const;
template<class T>
T* add_new_subsystem (SGSubsystemMgr::GroupType
type = SGSubsystemMgr::GENERAL,
double min_time_sec = 0)
{
T* sub = new T;
add_subsystem(T::subsystemName(), sub, type, min_time_sec);
return sub;
}
virtual SGSoundMgr *get_soundmgr () const;
SGEventMgr *get_event_mgr () const;
SGSoundMgr *get_soundmgr () const;
inline double get_sim_time_sec () const { return sim_time_sec; }
inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
@ -293,9 +307,6 @@ public:
inline SGMaterialLib *get_matlib() const { return matlib; }
void set_matlib( SGMaterialLib *m );
inline FGControls *get_controls() const { return controls; }
inline void set_controls( FGControls *c ) { controls = c; }
inline FGViewMgr *get_viewmgr() const { return viewmgr; }
inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
FGViewer *get_current_view() const;
@ -337,6 +348,8 @@ public:
initial_waypoints = list;
}
FGControls *get_controls() const;
FGScenery * get_scenery () const;
void set_scenery ( FGScenery *s );