1
0
Fork 0

Generalise AI-model search ordering in AIBase

Make the policy of using models in FGData/AI more flexible, with the
option to prefer normal data sources. Keep the existing behaviour for
everything except multiplayer aircraft, where we now prefer the data
model (presumably, an installed aircraft) over the AI one.
This commit is contained in:
James Turner 2018-05-23 09:46:05 +01:00
parent 87e461bb7e
commit dc6a884928
23 changed files with 87 additions and 81 deletions

View file

@ -131,8 +131,9 @@ void FGAIBallistic::readFromScenario(SGPropertyNode* scFileNode) {
setParentName(scFileNode->getStringValue("parent")); setParentName(scFileNode->getStringValue("parent"));
} }
bool FGAIBallistic::init(bool search_in_AI_path) { bool FGAIBallistic::init(ModelSearchOrder searchOrder)
FGAIBase::init(search_in_AI_path); {
FGAIBase::init(searchOrder);
reinit(); reinit();
return true; return true;
} }

View file

@ -40,7 +40,7 @@ public:
void readFromScenario(SGPropertyNode* scFileNode); void readFromScenario(SGPropertyNode* scFileNode);
bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual void bind(); virtual void bind();
virtual void reinit(); virtual void reinit();
virtual void update(double dt); virtual void update(double dt);

View file

@ -378,7 +378,43 @@ void FGAIBase::Transform() {
} }
bool FGAIBase::init(bool search_in_AI_path) std::string FGAIBase::resolveModelPath(ModelSearchOrder searchOrder)
{
std::string aiPath;
if (searchOrder != DATA_ONLY) {
for (SGPath p : globals->get_data_paths("AI")) {
p.append(model_path);
if (p.exists()) {
aiPath = p.local8BitStr();
break;
}
} // of AI data paths iteration
}
// if we prefer AI, and it's valid, use it, we're done
if ((searchOrder == PREFER_AI) && !aiPath.empty()) {
_installed = true;
return aiPath;
}
// regular search including aircraft paths
auto p = simgear::SGModelLib::findDataFile(model_path);
if (!p.empty()) {
_installed = true;
return p;
}
// if we prefer data, but will still use AI paths, now is the time.
if ((searchOrder == PREFER_DATA) && !aiPath.empty()) {
_installed = true;
return aiPath;
}
// okay, out of options, use the default model (the blue glider)
return fgGetString("/sim/multiplay/default-model", default_model);
}
bool FGAIBase::init(ModelSearchOrder searchOrder)
{ {
if (_model.valid()) if (_model.valid())
{ {
@ -386,26 +422,8 @@ bool FGAIBase::init(bool search_in_AI_path)
return false; return false;
} }
string f; string f = resolveModelPath(searchOrder);
if(search_in_AI_path)
{
BOOST_FOREACH(SGPath p, globals->get_data_paths("AI")) {
p.append(model_path);
if (p.exists()) {
f = p.local8BitStr();
break;
}
} // of AI data paths iteration
} // of search in AI path
if (f.empty()) {
f = simgear::SGModelLib::findDataFile(model_path);
}
if(f.empty())
f = fgGetString("/sim/multiplay/default-model", default_model);
else
_installed = true;
props->addChild("type")->setStringValue("AI"); props->addChild("type")->setStringValue("AI");
_modeldata = new FGAIModelData(props); _modeldata = new FGAIModelData(props);

View file

@ -57,7 +57,13 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode); virtual void readFromScenario(SGPropertyNode* scFileNode);
virtual bool init(bool search_in_AI_path=false); enum ModelSearchOrder {
DATA_ONLY, // don't search AI/ prefix at all
PREFER_AI, // search AI first, override other paths
PREFER_DATA // search data first but fall back to AI
};
virtual bool init(ModelSearchOrder searchOrder);
virtual void initModel(); virtual void initModel();
virtual void update(double dt); virtual void update(double dt);
virtual void bind(); virtual void bind();
@ -248,6 +254,8 @@ private:
SGSharedPtr<FGFX> _fx; SGSharedPtr<FGFX> _fx;
std::string resolveModelPath(ModelSearchOrder searchOrder);
public: public:
object_type getType(); object_type getType();

View file

@ -205,8 +205,8 @@ void FGAICarrier::update(double dt) {
source = 0; source = 0;
} //end update } //end update
bool FGAICarrier::init(bool search_in_AI_path) { bool FGAICarrier::init(ModelSearchOrder searchOrder) {
if (!FGAIShip::init(search_in_AI_path)) if (!FGAIShip::init(searchOrder))
return false; return false;
_longitude_node = fgGetNode("/position/longitude-deg", true); _longitude_node = fgGetNode("/position/longitude-deg", true);

View file

@ -64,7 +64,7 @@ public:
void ReturnToBox(); void ReturnToBox();
bool OutsideBox(); bool OutsideBox();
bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual const char* getTypeString(void) const { return "carrier"; } virtual const char* getTypeString(void) const { return "carrier"; }

View file

@ -118,8 +118,8 @@ void FGAIEscort::bind() {
SGRawValuePointer<bool>(&_patrol)); SGRawValuePointer<bool>(&_patrol));
} }
bool FGAIEscort::init(bool search_in_AI_path) { bool FGAIEscort::init(ModelSearchOrder searchOrder) {
if (!FGAIShip::init(search_in_AI_path)) if (!FGAIShip::init(searchOrder))
return false; return false;
reinit(); reinit();
return true; return true;

View file

@ -40,7 +40,7 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode); virtual void readFromScenario(SGPropertyNode* scFileNode);
bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual void bind(); virtual void bind();
virtual void reinit(); virtual void reinit();
virtual void update (double dt); virtual void update (double dt);

View file

@ -121,8 +121,8 @@ void FGAIGroundVehicle::bind() {
SGRawValuePointer<double>(&_contact_x2_offset)); SGRawValuePointer<double>(&_contact_x2_offset));
} }
bool FGAIGroundVehicle::init(bool search_in_AI_path) { bool FGAIGroundVehicle::init(ModelSearchOrder searchOrder) {
if (!FGAIShip::init(search_in_AI_path)) if (!FGAIShip::init(searchOrder))
return false; return false;
reinit(); reinit();
return true; return true;

View file

@ -38,7 +38,7 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode); virtual void readFromScenario(SGPropertyNode* scFileNode);
bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual void bind(); virtual void bind();
virtual void reinit(); virtual void reinit();
virtual void update (double dt); virtual void update (double dt);

View file

@ -306,9 +306,18 @@ FGAIManager::attach(FGAIBase *model)
model->setManager(this, p); model->setManager(this, p);
ai_list.push_back(model); ai_list.push_back(model);
model->init(model->getType()==FGAIBase::otAircraft FGAIBase::ModelSearchOrder modelPolicy = FGAIBase::DATA_ONLY;
|| model->getType()==FGAIBase::otMultiplayer switch (model->getType()) {
|| model->getType()==FGAIBase::otStatic); case FGAIBase::otAircraft:
case FGAIBase::otStatic:
modelPolicy = FGAIBase::PREFER_AI;
case FGAIBase::otMultiplayer:
modelPolicy = FGAIBase::PREFER_DATA;
default:
break;
}
model->init(modelPolicy);
model->bind(); model->bind();
p->setBoolValue("valid", true); p->setBoolValue("valid", true);
} }

View file

@ -56,8 +56,9 @@ FGAIMultiplayer::FGAIMultiplayer() :
FGAIMultiplayer::~FGAIMultiplayer() { FGAIMultiplayer::~FGAIMultiplayer() {
} }
bool FGAIMultiplayer::init(bool search_in_AI_path) { bool FGAIMultiplayer::init(ModelSearchOrder searchOrder)
props->setStringValue("sim/model/path", model_path.c_str()); {
props->setStringValue("sim/model/path", model_path);
//refuel_node = fgGetNode("systems/refuel/contact", true); //refuel_node = fgGetNode("systems/refuel/contact", true);
isTanker = false; // do this until this property is isTanker = false; // do this until this property is
// passed over the net // passed over the net
@ -73,7 +74,7 @@ bool FGAIMultiplayer::init(bool search_in_AI_path) {
} }
// load model // load model
bool result = FGAIBase::init(search_in_AI_path); bool result = FGAIBase::init(searchOrder);
// propagate installation state (used by MP pilot list) // propagate installation state (used by MP pilot list)
props->setBoolValue("model-installed", _installed); props->setBoolValue("model-installed", _installed);
return result; return result;

View file

@ -32,7 +32,7 @@ public:
FGAIMultiplayer(); FGAIMultiplayer();
virtual ~FGAIMultiplayer(); virtual ~FGAIMultiplayer();
virtual bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual void bind(); virtual void bind();
virtual void update(double dt); virtual void update(double dt);

View file

@ -111,9 +111,9 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
} }
} }
bool FGAIShip::init(bool search_in_AI_path) { bool FGAIShip::init(ModelSearchOrder searchOrder) {
reinit(); reinit();
return FGAIBase::init(search_in_AI_path); return FGAIBase::init(searchOrder);
} }
void FGAIShip::reinit() void FGAIShip::reinit()

View file

@ -37,7 +37,7 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode); virtual void readFromScenario(SGPropertyNode* scFileNode);
virtual bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual void bind(); virtual void bind();
virtual void update(double dt); virtual void update(double dt);
virtual void reinit(); virtual void reinit();

View file

@ -40,19 +40,6 @@ FGAIStatic::FGAIStatic() : FGAIBase(otStatic, false) {
FGAIStatic::~FGAIStatic() { FGAIStatic::~FGAIStatic() {
} }
bool FGAIStatic::init(bool search_in_AI_path) {
return FGAIBase::init(search_in_AI_path);
}
void FGAIStatic::bind() {
FGAIBase::bind();
}
void FGAIStatic::unbind() {
FGAIBase::unbind();
}
void FGAIStatic::update(double dt) { void FGAIStatic::update(double dt) {
FGAIBase::update(dt); FGAIBase::update(dt);
Transform(); Transform();

View file

@ -35,9 +35,6 @@ public:
FGAIStatic(); FGAIStatic();
~FGAIStatic(); ~FGAIStatic();
virtual bool init(bool search_in_AI_path=false);
virtual void bind();
virtual void unbind();
virtual void update(double dt); virtual void update(double dt);
virtual const char* getTypeString(void) const { return "static"; } virtual const char* getTypeString(void) const { return "static"; }

View file

@ -75,19 +75,6 @@ void FGAIStorm::readFromScenario(SGPropertyNode* scFileNode) {
setStrengthNorm(scFileNode->getDoubleValue("strength-norm", 1.0)); setStrengthNorm(scFileNode->getDoubleValue("strength-norm", 1.0));
} }
bool FGAIStorm::init(bool search_in_AI_path) {
return FGAIBase::init(search_in_AI_path);
}
void FGAIStorm::bind() {
FGAIBase::bind();
}
void FGAIStorm::unbind() {
FGAIBase::unbind();
}
void FGAIStorm::update(double dt) { void FGAIStorm::update(double dt) {
FGAIBase::update(dt); FGAIBase::update(dt);
Run(dt); Run(dt);

View file

@ -37,9 +37,6 @@ public:
void readFromScenario(SGPropertyNode* scFileNode); void readFromScenario(SGPropertyNode* scFileNode);
virtual bool init(bool search_in_AI_path=false);
virtual void bind();
virtual void unbind();
virtual void update(double dt); virtual void update(double dt);
inline void setStrengthNorm( double s ) { strength_norm = s; }; inline void setStrengthNorm( double s ) { strength_norm = s; };
inline void setDiameter( double d ) { diameter = d; }; inline void setDiameter( double d ) { diameter = d; };

View file

@ -61,7 +61,7 @@ void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode) {
setHeight(scFileNode->getDoubleValue("height-msl", 5000.0)); setHeight(scFileNode->getDoubleValue("height-msl", 5000.0));
} }
bool FGAIThermal::init(bool search_in_AI_path) { bool FGAIThermal::init(ModelSearchOrder searchOrder) {
factor = 8.0 * max_strength / (diameter * diameter * diameter); factor = 8.0 * max_strength / (diameter * diameter * diameter);
setAltitude( height ); setAltitude( height );
_surface_wind_from_deg_node = _surface_wind_from_deg_node =
@ -73,7 +73,7 @@ bool FGAIThermal::init(bool search_in_AI_path) {
_aloft_wind_speed_node = _aloft_wind_speed_node =
fgGetNode("/environment/config/aloft/entry[2]/wind-speed-kt", true); fgGetNode("/environment/config/aloft/entry[2]/wind-speed-kt", true);
do_agl_calc = 1; do_agl_calc = 1;
return FGAIBase::init(search_in_AI_path); return FGAIBase::init(searchOrder);
} }
void FGAIThermal::bind() { void FGAIThermal::bind() {

View file

@ -38,7 +38,7 @@ public:
void readFromScenario(SGPropertyNode* scFileNode); void readFromScenario(SGPropertyNode* scFileNode);
virtual bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual void bind(); virtual void bind();
virtual void update(double dt); virtual void update(double dt);

View file

@ -158,8 +158,9 @@ void FGAIWingman::bind() {
SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtZOffset, &FGAIBallistic::setTgtZOffset)); SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtZOffset, &FGAIBallistic::setTgtZOffset));
} }
bool FGAIWingman::init(bool search_in_AI_path) { bool FGAIWingman::init(ModelSearchOrder searchOrder)
if (!FGAIBallistic::init(search_in_AI_path)) {
if (!FGAIBallistic::init(searchOrder))
return false; return false;
reinit(); reinit();
return true; return true;

View file

@ -35,7 +35,7 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode); virtual void readFromScenario(SGPropertyNode* scFileNode);
bool init(bool search_in_AI_path=false); bool init(ModelSearchOrder searchOrder) override;
virtual void bind(); virtual void bind();
virtual void reinit(); virtual void reinit();
virtual void update (double dt); virtual void update (double dt);