2001-01-05 17:37:59 +00:00
|
|
|
|
#include "fgfs.hxx"
|
|
|
|
|
|
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
2003-01-16 15:11:04 +00:00
|
|
|
|
#include <simgear/misc/exception.hxx>
|
2001-01-05 17:37:59 +00:00
|
|
|
|
|
|
|
|
|
#include "globals.hxx"
|
2002-05-11 16:28:50 +00:00
|
|
|
|
#include "fg_props.hxx"
|
2001-01-05 17:37:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGSubsystem
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2002-05-11 16:28:50 +00:00
|
|
|
|
FGSubsystem::FGSubsystem ()
|
|
|
|
|
: _suspended(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
FGSubsystem::~FGSubsystem ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-06 18:57:31 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystem::init ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-15 14:58:08 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystem::reinit ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-06 18:57:31 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystem::bind ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystem::unbind ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-11 16:28:50 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystem::suspend ()
|
|
|
|
|
{
|
|
|
|
|
_suspended = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystem::suspend (bool suspended)
|
|
|
|
|
{
|
|
|
|
|
_suspended = suspended;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystem::resume ()
|
|
|
|
|
{
|
|
|
|
|
_suspended = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
FGSubsystem::is_suspended () const
|
|
|
|
|
{
|
|
|
|
|
if (!_freeze_master_node.valid())
|
|
|
|
|
_freeze_master_node = fgGetNode("/sim/freeze/master", true);
|
|
|
|
|
return _suspended || _freeze_master_node->getBoolValue();
|
|
|
|
|
}
|
2001-01-05 17:37:59 +00:00
|
|
|
|
|
2002-10-03 21:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGSubsystemGroup.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FGSubsystemGroup::FGSubsystemGroup ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGSubsystemGroup::~FGSubsystemGroup ()
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2002-10-03 21:20:56 +00:00
|
|
|
|
delete _members[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::init ()
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2002-10-03 21:20:56 +00:00
|
|
|
|
_members[i]->subsystem->init();
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 15:11:04 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::reinit ()
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2003-01-16 15:11:04 +00:00
|
|
|
|
_members[i]->subsystem->reinit();
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 21:20:56 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::bind ()
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2002-10-03 21:20:56 +00:00
|
|
|
|
_members[i]->subsystem->bind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::unbind ()
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2002-10-03 21:20:56 +00:00
|
|
|
|
_members[i]->subsystem->unbind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::update (double delta_time_sec)
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2003-03-01 21:29:16 +00:00
|
|
|
|
_members[i]->update(delta_time_sec); // indirect call
|
2002-10-03 21:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 15:11:04 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::suspend ()
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2003-01-16 15:11:04 +00:00
|
|
|
|
_members[i]->subsystem->suspend();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::resume ()
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++)
|
2003-01-16 15:11:04 +00:00
|
|
|
|
_members[i]->subsystem->resume();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
FGSubsystemGroup::is_suspended () const
|
|
|
|
|
{
|
2003-03-01 21:29:16 +00:00
|
|
|
|
return false;
|
2003-01-16 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 21:20:56 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::set_subsystem (const string &name, FGSubsystem * subsystem,
|
|
|
|
|
double min_step_sec)
|
|
|
|
|
{
|
|
|
|
|
Member * member = get_member(name, true);
|
|
|
|
|
if (member->subsystem != 0)
|
|
|
|
|
delete member->subsystem;
|
|
|
|
|
member->name = name;
|
|
|
|
|
member->subsystem = subsystem;
|
|
|
|
|
member->min_step_sec = min_step_sec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGSubsystem *
|
|
|
|
|
FGSubsystemGroup::get_subsystem (const string &name)
|
|
|
|
|
{
|
|
|
|
|
Member * member = get_member(name);
|
|
|
|
|
if (member != 0)
|
|
|
|
|
return member->subsystem;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::remove_subsystem (const string &name)
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++) {
|
2002-10-03 21:20:56 +00:00
|
|
|
|
if (name == _members[i]->name) {
|
|
|
|
|
_members.erase(_members.begin() + i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
FGSubsystemGroup::has_subsystem (const string &name) const
|
|
|
|
|
{
|
|
|
|
|
return (((FGSubsystemGroup *)this)->get_member(name) != 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGSubsystemGroup::Member *
|
|
|
|
|
FGSubsystemGroup::get_member (const string &name, bool create)
|
|
|
|
|
{
|
2003-03-19 17:46:52 +00:00
|
|
|
|
for (unsigned int i = 0; i < _members.size(); i++) {
|
2002-10-03 21:20:56 +00:00
|
|
|
|
if (_members[i]->name == name)
|
|
|
|
|
return _members[i];
|
|
|
|
|
}
|
|
|
|
|
if (create) {
|
|
|
|
|
Member * member = new Member;
|
|
|
|
|
_members.push_back(member);
|
|
|
|
|
return member;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGSubsystemGroup::Member
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FGSubsystemGroup::Member::Member ()
|
|
|
|
|
: name(""),
|
|
|
|
|
subsystem(0),
|
|
|
|
|
min_step_sec(0),
|
|
|
|
|
elapsed_sec(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGSubsystemGroup::Member::Member (const Member &)
|
|
|
|
|
{
|
|
|
|
|
Member();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGSubsystemGroup::Member::~Member ()
|
|
|
|
|
{
|
|
|
|
|
// FIXME: causes a crash
|
|
|
|
|
// delete subsystem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemGroup::Member::update (double delta_time_sec)
|
|
|
|
|
{
|
|
|
|
|
elapsed_sec += delta_time_sec;
|
|
|
|
|
if (elapsed_sec >= min_step_sec) {
|
2003-03-01 21:29:16 +00:00
|
|
|
|
if (!subsystem->is_suspended()) {
|
2003-03-09 03:22:12 +00:00
|
|
|
|
subsystem->update(elapsed_sec);
|
|
|
|
|
elapsed_sec = 0;
|
2003-03-01 21:29:16 +00:00
|
|
|
|
}
|
2002-10-03 21:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGSubsystemMgr.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FGSubsystemMgr::FGSubsystemMgr ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGSubsystemMgr::~FGSubsystemMgr ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemMgr::init ()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_GROUPS; i++)
|
|
|
|
|
_groups[i].init();
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 15:11:04 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystemMgr::reinit ()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_GROUPS; i++)
|
|
|
|
|
_groups[i].reinit();
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 21:20:56 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystemMgr::bind ()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_GROUPS; i++)
|
|
|
|
|
_groups[i].bind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemMgr::unbind ()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_GROUPS; i++)
|
|
|
|
|
_groups[i].unbind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemMgr::update (double delta_time_sec)
|
|
|
|
|
{
|
2003-03-01 21:29:16 +00:00
|
|
|
|
for (int i = 0; i < MAX_GROUPS; i++) {
|
|
|
|
|
_groups[i].update(delta_time_sec);
|
2002-10-03 21:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 15:11:04 +00:00
|
|
|
|
void
|
|
|
|
|
FGSubsystemMgr::suspend ()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_GROUPS; i++)
|
|
|
|
|
_groups[i].suspend();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGSubsystemMgr::resume ()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_GROUPS; i++)
|
|
|
|
|
_groups[i].resume();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
FGSubsystemMgr::is_suspended () const
|
|
|
|
|
{
|
2003-03-01 21:29:16 +00:00
|
|
|
|
return false;
|
2003-01-16 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 21:20:56 +00:00
|
|
|
|
void
|
2003-01-16 16:01:26 +00:00
|
|
|
|
FGSubsystemMgr::add (const char * name, FGSubsystem * subsystem,
|
|
|
|
|
GroupType group, double min_time_sec)
|
2002-10-03 21:20:56 +00:00
|
|
|
|
{
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_INFO, "Adding subsystem " << name);
|
|
|
|
|
get_group(group)->set_subsystem(name, subsystem, min_time_sec);
|
2003-01-16 15:11:04 +00:00
|
|
|
|
|
|
|
|
|
if (_subsystem_map.find(name) != _subsystem_map.end()) {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Adding duplicate subsystem " << name);
|
|
|
|
|
throw sg_exception("duplicate subsystem");
|
|
|
|
|
}
|
|
|
|
|
_subsystem_map[name] = subsystem;
|
2002-10-03 21:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGSubsystemGroup *
|
|
|
|
|
FGSubsystemMgr::get_group (GroupType group)
|
|
|
|
|
{
|
|
|
|
|
return &(_groups[group]);
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 15:11:04 +00:00
|
|
|
|
FGSubsystem *
|
|
|
|
|
FGSubsystemMgr::get_subsystem (const string &name)
|
|
|
|
|
{
|
|
|
|
|
map<string,FGSubsystem *>::iterator s =_subsystem_map.find(name);
|
|
|
|
|
|
|
|
|
|
if (s == _subsystem_map.end())
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return s->second;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
// end of fgfs.cxx
|