1
0
Fork 0

Remove persistent references to AI mananger and its objects from the submodel-manager.

This commit is contained in:
James Turner 2010-10-28 15:10:37 +01:00
parent e9f4106bc1
commit 0147f78d20
2 changed files with 30 additions and 37 deletions

View file

@ -43,6 +43,11 @@ FGSubmodelMgr::~FGSubmodelMgr()
{ {
} }
FGAIManager* FGSubmodelMgr::aiManager()
{
return (FGAIManager*)globals->get_subsystem("ai_model");
}
void FGSubmodelMgr::init() void FGSubmodelMgr::init()
{ {
index = 0; index = 0;
@ -74,8 +79,6 @@ void FGSubmodelMgr::init()
_contrail_trigger = fgGetNode("ai/submodels/contrails", true); _contrail_trigger = fgGetNode("ai/submodels/contrails", true);
_contrail_trigger->setBoolValue(false); _contrail_trigger->setBoolValue(false);
ai = (FGAIManager*)globals->get_subsystem("ai_model");
load(); load();
} }
@ -116,9 +119,9 @@ void FGSubmodelMgr::update(double dt)
_expiry = false; _expiry = false;
// check if the submodel hit an object or terrain // check if the submodel hit an object or terrain
sm_list = ai->get_ai_list(); FGAIManager::ai_list_type sm_list(aiManager()->get_ai_list());
sm_list_iterator sm_list_itr = sm_list.begin(); FGAIManager::ai_list_iterator sm_list_itr = sm_list.begin(),
sm_list_iterator end = sm_list.end(); end = sm_list.end();
for (; sm_list_itr != end; ++sm_list_itr) { for (; sm_list_itr != end; ++sm_list_itr) {
FGAIBase::object_type object_type =(*sm_list_itr)->getType(); FGAIBase::object_type object_type =(*sm_list_itr)->getType();
@ -300,7 +303,8 @@ bool FGSubmodelMgr::release(submodel *sm, double dt)
ballist->setParentNodes(_selected_ac); ballist->setParentNodes(_selected_ac);
ballist->setContentsNode(sm->contents_node); ballist->setContentsNode(sm->contents_node);
ballist->setWeight(sm->weight); ballist->setWeight(sm->weight);
ai->attach(ballist);
aiManager()->attach(ballist);
if (sm->count > 0) if (sm->count > 0)
sm->count--; sm->count--;
@ -383,8 +387,6 @@ void FGSubmodelMgr::transform(submodel *sm)
} else { } else {
// set the data for a submodel tied to an AI Object // set the data for a submodel tied to an AI Object
//cout << " set the data for a submodel tied to an AI Object " << id << endl; //cout << " set the data for a submodel tied to an AI Object " << id << endl;
sm_list_iterator sm_list_itr = sm_list.begin();
sm_list_iterator end = sm_list.end();
setParentNode(id); setParentNode(id);
} }
@ -477,15 +479,15 @@ void FGSubmodelMgr::loadAI()
{ {
SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading AI submodels "); SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading AI submodels ");
sm_list = ai->get_ai_list(); FGAIManager::ai_list_type sm_list(aiManager()->get_ai_list());
if (sm_list.empty()) { if (sm_list.empty()) {
SG_LOG(SG_GENERAL, SG_ALERT, "Submodels: Unable to read AI submodel list"); SG_LOG(SG_GENERAL, SG_ALERT, "Submodels: Unable to read AI submodel list");
return; return;
} }
sm_list_iterator sm_list_itr = sm_list.begin(); FGAIManager::ai_list_iterator sm_list_itr = sm_list.begin(),
sm_list_iterator end = sm_list.end(); end = sm_list.end();
while (sm_list_itr != end) { while (sm_list_itr != end) {
string path = (*sm_list_itr)->_getSMPath(); string path = (*sm_list_itr)->_getSMPath();

View file

@ -13,17 +13,13 @@
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <AIModel/AIBase.hxx> #include <simgear/math/SGMath.hxx>
#include <vector> #include <vector>
#include <string> #include <string>
#include <Main/fg_props.hxx>
using std::vector;
using std::string;
using std::list;
class FGAIBase; class FGAIBase;
class FGAIManager;
class FGSubmodelMgr : public SGSubsystem, public SGPropertyChangeListener class FGSubmodelMgr : public SGSubsystem, public SGPropertyChangeListener
{ {
@ -37,8 +33,8 @@ public:
SGPropertyNode_ptr submodel_node; SGPropertyNode_ptr submodel_node;
SGPropertyNode_ptr speed_node; SGPropertyNode_ptr speed_node;
string name; std::string name;
string model; std::string model;
double speed; double speed;
bool slaved; bool slaved;
bool repeat; bool repeat;
@ -68,13 +64,13 @@ public:
bool collision; bool collision;
bool expiry; bool expiry;
bool impact; bool impact;
string impact_report; std::string impact_report;
double fuse_range; double fuse_range;
string submodel; std::string submodel;
int sub_id; int sub_id;
bool force_stabilised; bool force_stabilised;
bool ext_force; bool ext_force;
string force_path; std::string force_path;
} submodel; } submodel;
typedef struct { typedef struct {
@ -112,7 +108,7 @@ public:
private: private:
typedef vector <submodel*> submodel_vector_type; typedef std::vector <submodel*> submodel_vector_type;
typedef submodel_vector_type::iterator submodel_vector_iterator; typedef submodel_vector_type::iterator submodel_vector_iterator;
submodel_vector_type submodels; submodel_vector_type submodels;
@ -186,22 +182,17 @@ private:
SGPropertyNode_ptr _path_node; SGPropertyNode_ptr _path_node;
SGPropertyNode_ptr _selected_ac; SGPropertyNode_ptr _selected_ac;
FGAIManager* ai;
IC_struct IC; IC_struct IC;
// A list of pointers to AI objects /**
typedef list <SGSharedPtr<FGAIBase> > sm_list_type; * Helper to retrieve the AI manager, if it currently exists
typedef sm_list_type::iterator sm_list_iterator; */
typedef sm_list_type::const_iterator sm_list_const_iterator; FGAIManager* aiManager();
sm_list_type sm_list;
void loadAI(); void loadAI();
void loadSubmodels(); void loadSubmodels();
void setData(int id, string& path, bool serviceable); void setData(int id, std::string& path, bool serviceable);
void setSubData(int id, string& path, bool serviceable); void setSubData(int id, std::string& path, bool serviceable);
void valueChanged (SGPropertyNode *); void valueChanged (SGPropertyNode *);
void transform(submodel *); void transform(submodel *);
void setParentNode(int parent_id); void setParentNode(int parent_id);