Templated subsystem handling
- remove explicit FGControls var from globals, as part of work towards unit-testing infrastructure.
This commit is contained in:
parent
6446d67431
commit
d7a680e848
5 changed files with 34 additions and 18 deletions
|
@ -78,7 +78,6 @@ FGControls::FGControls() :
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_all();
|
reset_all();
|
||||||
globals->set_controls( this );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,9 +161,8 @@ void FGControls::reset_all()
|
||||||
|
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
FGControls::~FGControls() {
|
FGControls::~FGControls()
|
||||||
if (globals)
|
{
|
||||||
globals->set_controls( NULL );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -639,6 +639,7 @@ public:
|
||||||
// controls/autoflight/autopilot[n]/
|
// controls/autoflight/autopilot[n]/
|
||||||
void set_autopilot_engage( int ap, bool val );
|
void set_autopilot_engage( int ap, bool val );
|
||||||
|
|
||||||
|
static const char* subsystemName() { return "controls"; }
|
||||||
private:
|
private:
|
||||||
inline void do_autocoordination() {
|
inline void do_autocoordination() {
|
||||||
// check for autocoordination
|
// check for autocoordination
|
||||||
|
|
|
@ -849,7 +849,7 @@ void fgCreateSubsystems(bool duringReset) {
|
||||||
// Initialize the controls subsystem.
|
// Initialize the controls subsystem.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
globals->add_subsystem("controls", new FGControls, SGSubsystemMgr::GENERAL);
|
globals->add_new_subsystem<FGControls>(SGSubsystemMgr::GENERAL);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Initialize the input subsystem.
|
// Initialize the input subsystem.
|
||||||
|
|
|
@ -160,7 +160,6 @@ FGGlobals::FGGlobals() :
|
||||||
time_params( NULL ),
|
time_params( NULL ),
|
||||||
ephem( NULL ),
|
ephem( NULL ),
|
||||||
route_mgr( NULL ),
|
route_mgr( NULL ),
|
||||||
controls( NULL ),
|
|
||||||
viewmgr( NULL ),
|
viewmgr( NULL ),
|
||||||
commands( SGCommandMgr::instance() ),
|
commands( SGCommandMgr::instance() ),
|
||||||
channel_options_list( NULL ),
|
channel_options_list( NULL ),
|
||||||
|
@ -509,7 +508,7 @@ FGGlobals::get_subsystem_mgr () const
|
||||||
}
|
}
|
||||||
|
|
||||||
SGSubsystem *
|
SGSubsystem *
|
||||||
FGGlobals::get_subsystem (const char * name)
|
FGGlobals::get_subsystem (const char * name) const
|
||||||
{
|
{
|
||||||
if (!subsystem_mgr) {
|
if (!subsystem_mgr) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -751,6 +750,11 @@ void FGGlobals::set_matlib( SGMaterialLib *m )
|
||||||
matlib = m;
|
matlib = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FGControls *FGGlobals::get_controls() const
|
||||||
|
{
|
||||||
|
return get_subsystem<FGControls>();
|
||||||
|
}
|
||||||
|
|
||||||
FGSampleQueue* FGGlobals::get_chatter_queue() const
|
FGSampleQueue* FGGlobals::get_chatter_queue() const
|
||||||
{
|
{
|
||||||
return _chatter_queue;
|
return _chatter_queue;
|
||||||
|
|
|
@ -123,9 +123,6 @@ private:
|
||||||
// Global autopilot "route"
|
// Global autopilot "route"
|
||||||
FGRouteMgr *route_mgr;
|
FGRouteMgr *route_mgr;
|
||||||
|
|
||||||
// control input state
|
|
||||||
FGControls *controls;
|
|
||||||
|
|
||||||
// viewer manager
|
// viewer manager
|
||||||
FGViewMgr *viewmgr;
|
FGViewMgr *viewmgr;
|
||||||
|
|
||||||
|
@ -180,19 +177,36 @@ public:
|
||||||
virtual FGRenderer *get_renderer () const;
|
virtual FGRenderer *get_renderer () const;
|
||||||
void set_renderer(FGRenderer* render);
|
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,
|
SGSubsystem * subsystem,
|
||||||
SGSubsystemMgr::GroupType
|
SGSubsystemMgr::GroupType
|
||||||
type = SGSubsystemMgr::GENERAL,
|
type = SGSubsystemMgr::GENERAL,
|
||||||
double min_time_sec = 0);
|
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 double get_sim_time_sec () const { return sim_time_sec; }
|
||||||
inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
|
inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
|
||||||
|
@ -293,9 +307,6 @@ public:
|
||||||
inline SGMaterialLib *get_matlib() const { return matlib; }
|
inline SGMaterialLib *get_matlib() const { return matlib; }
|
||||||
void set_matlib( SGMaterialLib *m );
|
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 FGViewMgr *get_viewmgr() const { return viewmgr; }
|
||||||
inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
|
inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
|
||||||
FGViewer *get_current_view() const;
|
FGViewer *get_current_view() const;
|
||||||
|
@ -337,6 +348,8 @@ public:
|
||||||
initial_waypoints = list;
|
initial_waypoints = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FGControls *get_controls() const;
|
||||||
|
|
||||||
FGScenery * get_scenery () const;
|
FGScenery * get_scenery () const;
|
||||||
void set_scenery ( FGScenery *s );
|
void set_scenery ( FGScenery *s );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue