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:
parent
87e461bb7e
commit
dc6a884928
23 changed files with 87 additions and 81 deletions
|
@ -131,8 +131,9 @@ void FGAIBallistic::readFromScenario(SGPropertyNode* scFileNode) {
|
|||
setParentName(scFileNode->getStringValue("parent"));
|
||||
}
|
||||
|
||||
bool FGAIBallistic::init(bool search_in_AI_path) {
|
||||
FGAIBase::init(search_in_AI_path);
|
||||
bool FGAIBallistic::init(ModelSearchOrder searchOrder)
|
||||
{
|
||||
FGAIBase::init(searchOrder);
|
||||
reinit();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
|
||||
void readFromScenario(SGPropertyNode* scFileNode);
|
||||
|
||||
bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
virtual void bind();
|
||||
virtual void reinit();
|
||||
virtual void update(double dt);
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
@ -386,26 +422,8 @@ bool FGAIBase::init(bool search_in_AI_path)
|
|||
return false;
|
||||
}
|
||||
|
||||
string f;
|
||||
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);
|
||||
}
|
||||
string f = resolveModelPath(searchOrder);
|
||||
|
||||
if(f.empty())
|
||||
f = fgGetString("/sim/multiplay/default-model", default_model);
|
||||
else
|
||||
_installed = true;
|
||||
|
||||
props->addChild("type")->setStringValue("AI");
|
||||
_modeldata = new FGAIModelData(props);
|
||||
|
|
|
@ -57,7 +57,13 @@ public:
|
|||
|
||||
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 update(double dt);
|
||||
virtual void bind();
|
||||
|
@ -248,6 +254,8 @@ private:
|
|||
|
||||
SGSharedPtr<FGFX> _fx;
|
||||
|
||||
std::string resolveModelPath(ModelSearchOrder searchOrder);
|
||||
|
||||
public:
|
||||
object_type getType();
|
||||
|
||||
|
|
|
@ -205,8 +205,8 @@ void FGAICarrier::update(double dt) {
|
|||
source = 0;
|
||||
} //end update
|
||||
|
||||
bool FGAICarrier::init(bool search_in_AI_path) {
|
||||
if (!FGAIShip::init(search_in_AI_path))
|
||||
bool FGAICarrier::init(ModelSearchOrder searchOrder) {
|
||||
if (!FGAIShip::init(searchOrder))
|
||||
return false;
|
||||
|
||||
_longitude_node = fgGetNode("/position/longitude-deg", true);
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
void ReturnToBox();
|
||||
bool OutsideBox();
|
||||
|
||||
bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
|
||||
virtual const char* getTypeString(void) const { return "carrier"; }
|
||||
|
||||
|
|
|
@ -118,8 +118,8 @@ void FGAIEscort::bind() {
|
|||
SGRawValuePointer<bool>(&_patrol));
|
||||
}
|
||||
|
||||
bool FGAIEscort::init(bool search_in_AI_path) {
|
||||
if (!FGAIShip::init(search_in_AI_path))
|
||||
bool FGAIEscort::init(ModelSearchOrder searchOrder) {
|
||||
if (!FGAIShip::init(searchOrder))
|
||||
return false;
|
||||
reinit();
|
||||
return true;
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
|
||||
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
||||
|
||||
bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
virtual void bind();
|
||||
virtual void reinit();
|
||||
virtual void update (double dt);
|
||||
|
|
|
@ -121,8 +121,8 @@ void FGAIGroundVehicle::bind() {
|
|||
SGRawValuePointer<double>(&_contact_x2_offset));
|
||||
}
|
||||
|
||||
bool FGAIGroundVehicle::init(bool search_in_AI_path) {
|
||||
if (!FGAIShip::init(search_in_AI_path))
|
||||
bool FGAIGroundVehicle::init(ModelSearchOrder searchOrder) {
|
||||
if (!FGAIShip::init(searchOrder))
|
||||
return false;
|
||||
reinit();
|
||||
return true;
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
||||
|
||||
bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
virtual void bind();
|
||||
virtual void reinit();
|
||||
virtual void update (double dt);
|
||||
|
|
|
@ -306,9 +306,18 @@ FGAIManager::attach(FGAIBase *model)
|
|||
model->setManager(this, p);
|
||||
ai_list.push_back(model);
|
||||
|
||||
model->init(model->getType()==FGAIBase::otAircraft
|
||||
|| model->getType()==FGAIBase::otMultiplayer
|
||||
|| model->getType()==FGAIBase::otStatic);
|
||||
FGAIBase::ModelSearchOrder modelPolicy = FGAIBase::DATA_ONLY;
|
||||
switch (model->getType()) {
|
||||
case FGAIBase::otAircraft:
|
||||
case FGAIBase::otStatic:
|
||||
modelPolicy = FGAIBase::PREFER_AI;
|
||||
case FGAIBase::otMultiplayer:
|
||||
modelPolicy = FGAIBase::PREFER_DATA;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
model->init(modelPolicy);
|
||||
model->bind();
|
||||
p->setBoolValue("valid", true);
|
||||
}
|
||||
|
|
|
@ -56,8 +56,9 @@ FGAIMultiplayer::FGAIMultiplayer() :
|
|||
FGAIMultiplayer::~FGAIMultiplayer() {
|
||||
}
|
||||
|
||||
bool FGAIMultiplayer::init(bool search_in_AI_path) {
|
||||
props->setStringValue("sim/model/path", model_path.c_str());
|
||||
bool FGAIMultiplayer::init(ModelSearchOrder searchOrder)
|
||||
{
|
||||
props->setStringValue("sim/model/path", model_path);
|
||||
//refuel_node = fgGetNode("systems/refuel/contact", true);
|
||||
isTanker = false; // do this until this property is
|
||||
// passed over the net
|
||||
|
@ -73,7 +74,7 @@ bool FGAIMultiplayer::init(bool search_in_AI_path) {
|
|||
}
|
||||
|
||||
// load model
|
||||
bool result = FGAIBase::init(search_in_AI_path);
|
||||
bool result = FGAIBase::init(searchOrder);
|
||||
// propagate installation state (used by MP pilot list)
|
||||
props->setBoolValue("model-installed", _installed);
|
||||
return result;
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
FGAIMultiplayer();
|
||||
virtual ~FGAIMultiplayer();
|
||||
|
||||
virtual bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
virtual void bind();
|
||||
virtual void update(double dt);
|
||||
|
||||
|
|
|
@ -111,9 +111,9 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
|
|||
}
|
||||
}
|
||||
|
||||
bool FGAIShip::init(bool search_in_AI_path) {
|
||||
bool FGAIShip::init(ModelSearchOrder searchOrder) {
|
||||
reinit();
|
||||
return FGAIBase::init(search_in_AI_path);
|
||||
return FGAIBase::init(searchOrder);
|
||||
}
|
||||
|
||||
void FGAIShip::reinit()
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
||||
|
||||
virtual bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
virtual void bind();
|
||||
virtual void update(double dt);
|
||||
virtual void reinit();
|
||||
|
|
|
@ -40,19 +40,6 @@ FGAIStatic::FGAIStatic() : FGAIBase(otStatic, false) {
|
|||
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) {
|
||||
FGAIBase::update(dt);
|
||||
Transform();
|
||||
|
|
|
@ -35,9 +35,6 @@ public:
|
|||
FGAIStatic();
|
||||
~FGAIStatic();
|
||||
|
||||
virtual bool init(bool search_in_AI_path=false);
|
||||
virtual void bind();
|
||||
virtual void unbind();
|
||||
virtual void update(double dt);
|
||||
|
||||
virtual const char* getTypeString(void) const { return "static"; }
|
||||
|
|
|
@ -75,19 +75,6 @@ void FGAIStorm::readFromScenario(SGPropertyNode* scFileNode) {
|
|||
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) {
|
||||
FGAIBase::update(dt);
|
||||
Run(dt);
|
||||
|
|
|
@ -37,9 +37,6 @@ public:
|
|||
|
||||
void readFromScenario(SGPropertyNode* scFileNode);
|
||||
|
||||
virtual bool init(bool search_in_AI_path=false);
|
||||
virtual void bind();
|
||||
virtual void unbind();
|
||||
virtual void update(double dt);
|
||||
inline void setStrengthNorm( double s ) { strength_norm = s; };
|
||||
inline void setDiameter( double d ) { diameter = d; };
|
||||
|
|
|
@ -61,7 +61,7 @@ void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode) {
|
|||
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);
|
||||
setAltitude( height );
|
||||
_surface_wind_from_deg_node =
|
||||
|
@ -73,7 +73,7 @@ bool FGAIThermal::init(bool search_in_AI_path) {
|
|||
_aloft_wind_speed_node =
|
||||
fgGetNode("/environment/config/aloft/entry[2]/wind-speed-kt", true);
|
||||
do_agl_calc = 1;
|
||||
return FGAIBase::init(search_in_AI_path);
|
||||
return FGAIBase::init(searchOrder);
|
||||
}
|
||||
|
||||
void FGAIThermal::bind() {
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
void readFromScenario(SGPropertyNode* scFileNode);
|
||||
|
||||
virtual bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
virtual void bind();
|
||||
virtual void update(double dt);
|
||||
|
||||
|
|
|
@ -158,8 +158,9 @@ void FGAIWingman::bind() {
|
|||
SGRawValueMethods<FGAIBallistic,double>(*this, &FGAIBallistic::getTgtZOffset, &FGAIBallistic::setTgtZOffset));
|
||||
}
|
||||
|
||||
bool FGAIWingman::init(bool search_in_AI_path) {
|
||||
if (!FGAIBallistic::init(search_in_AI_path))
|
||||
bool FGAIWingman::init(ModelSearchOrder searchOrder)
|
||||
{
|
||||
if (!FGAIBallistic::init(searchOrder))
|
||||
return false;
|
||||
reinit();
|
||||
return true;
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
||||
|
||||
bool init(bool search_in_AI_path=false);
|
||||
bool init(ModelSearchOrder searchOrder) override;
|
||||
virtual void bind();
|
||||
virtual void reinit();
|
||||
virtual void update (double dt);
|
||||
|
|
Loading…
Add table
Reference in a new issue