AIAircraft: cache controls propertes
Avoid a per-update() lookup of the AI controls properties. As part of this, bypass updatePrimaryTargetValues for the user aircraft, where it doesn’t make sense.
This commit is contained in:
parent
14b7b5d3a1
commit
cf160cc925
3 changed files with 59 additions and 26 deletions
|
@ -114,6 +114,16 @@ FGAIAircraft::FGAIAircraft(FGAISchedule* ref) : /* HOT must be disabled for AI A
|
||||||
_searchOrder = PREFER_AI;
|
_searchOrder = PREFER_AI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FGAIAircraft::lazyInitControlsNodes()
|
||||||
|
{
|
||||||
|
_controlsLateralModeNode = props->getNode("controls/flight/lateral-mode", true);
|
||||||
|
_controlsVerticalModeNode = props->getNode("controls/flight/vertical-mode", true);
|
||||||
|
_controlsTargetHeadingNode = props->getNode("controls/flight/target-hdg", true);
|
||||||
|
_controlsTargetRollNode = props->getNode("controls/flight/target-roll", true);
|
||||||
|
_controlsTargetAltitude = props->getNode("controls/flight/target-alt", true);
|
||||||
|
_controlsTargetPitch = props->getNode("controls/flight/target-pitch", true);
|
||||||
|
_controlsTargetSpeed = props->getNode("controls/flight/target-spd", true);
|
||||||
|
}
|
||||||
|
|
||||||
FGAIAircraft::~FGAIAircraft()
|
FGAIAircraft::~FGAIAircraft()
|
||||||
{
|
{
|
||||||
|
@ -175,12 +185,23 @@ void FGAIAircraft::setPerformance(const std::string& acType, const std::string&
|
||||||
|
|
||||||
void FGAIAircraft::Run(double dt)
|
void FGAIAircraft::Run(double dt)
|
||||||
{
|
{
|
||||||
|
// We currently have one situation in which an AIAircraft object is used that is not attached to the
|
||||||
|
// AI manager. In this particular case, the AIAircraft is used to shadow the user's aircraft's behavior in the AI world.
|
||||||
|
// Since we perhaps don't want a radar entry of our own aircraft, the following conditional should probably be adequate
|
||||||
|
// enough
|
||||||
|
const bool isUserAircraft = (manager == nullptr);
|
||||||
|
|
||||||
bool outOfSight = false,
|
bool outOfSight = false,
|
||||||
flightplanActive = true;
|
flightplanActive = true;
|
||||||
|
|
||||||
|
// user aircraft speed, heading and position are synchronzied in
|
||||||
|
// FGAIManager::fetchUserState()
|
||||||
|
if (!isUserAircraft) {
|
||||||
updatePrimaryTargetValues(dt, flightplanActive, outOfSight); // target hdg, alt, speed
|
updatePrimaryTargetValues(dt, flightplanActive, outOfSight); // target hdg, alt, speed
|
||||||
if (outOfSight) {
|
if (outOfSight) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!flightplanActive) {
|
if (!flightplanActive) {
|
||||||
groundTargetSpeed = 0;
|
groundTargetSpeed = 0;
|
||||||
|
@ -192,11 +213,8 @@ void FGAIAircraft::setPerformance(const std::string& acType, const std::string&
|
||||||
|
|
||||||
updateModelProperties(dt);
|
updateModelProperties(dt);
|
||||||
|
|
||||||
// We currently have one situation in which an AIAircraft object is used that is not attached to the
|
|
||||||
// AI manager. In this particular case, the AIAircraft is used to shadow the user's aircraft's behavior in the AI world.
|
if (!isUserAircraft) {
|
||||||
// Since we perhaps don't want a radar entry of our own aircraft, the following conditional should probably be adequate
|
|
||||||
// enough
|
|
||||||
if (manager){
|
|
||||||
UpdateRadar(manager);
|
UpdateRadar(manager);
|
||||||
invisible = !manager->isVisible(pos);
|
invisible = !manager->isVisible(pos);
|
||||||
}
|
}
|
||||||
|
@ -993,29 +1011,31 @@ void FGAIAircraft::updatePrimaryTargetValues(double dt, bool& flightplanActive,
|
||||||
// from control properties. These default to the initial
|
// from control properties. These default to the initial
|
||||||
// settings in the config file, but can be changed "on the
|
// settings in the config file, but can be changed "on the
|
||||||
// fly".
|
// fly".
|
||||||
const string& lat_mode = props->getStringValue("controls/flight/lateral-mode");
|
|
||||||
|
if (!_controlsLateralModeNode) {
|
||||||
|
lazyInitControlsNodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const string& lat_mode = _controlsLateralModeNode->getStringValue();
|
||||||
if ( lat_mode == "roll" ) {
|
if ( lat_mode == "roll" ) {
|
||||||
double angle
|
const double angle = _controlsTargetRollNode->getDoubleValue();
|
||||||
= props->getDoubleValue("controls/flight/target-roll" );
|
|
||||||
RollTo( angle );
|
RollTo( angle );
|
||||||
} else {
|
} else {
|
||||||
double angle
|
const double angle = _controlsTargetHeadingNode->getDoubleValue();
|
||||||
= props->getDoubleValue("controls/flight/target-hdg" );
|
|
||||||
TurnTo( angle );
|
TurnTo( angle );
|
||||||
}
|
}
|
||||||
|
|
||||||
string lon_mode
|
string vert_mode = _controlsVerticalModeNode->getStringValue();
|
||||||
= props->getStringValue("controls/flight/vertical-mode");
|
if (vert_mode == "alt") {
|
||||||
if ( lon_mode == "alt" ) {
|
const double alt = _controlsTargetAltitude->getDoubleValue();
|
||||||
double alt = props->getDoubleValue("controls/flight/target-alt" );
|
|
||||||
ClimbTo( alt );
|
ClimbTo( alt );
|
||||||
} else {
|
} else {
|
||||||
double angle
|
const double angle = _controlsTargetPitch->getDoubleValue();
|
||||||
= props->getDoubleValue("controls/flight/target-pitch" );
|
|
||||||
PitchTo( angle );
|
PitchTo( angle );
|
||||||
}
|
}
|
||||||
|
|
||||||
AccelTo( props->getDoubleValue("controls/flight/target-spd" ) );
|
AccelTo(_controlsTargetSpeed->getDoubleValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,8 @@ private:
|
||||||
|
|
||||||
double sign(double x);
|
double sign(double x);
|
||||||
|
|
||||||
|
void lazyInitControlsNodes();
|
||||||
|
|
||||||
std::string acType;
|
std::string acType;
|
||||||
std::string company;
|
std::string company;
|
||||||
std::string transponderCode;
|
std::string transponderCode;
|
||||||
|
@ -188,6 +190,15 @@ private:
|
||||||
std::string startWptName;
|
std::string startWptName;
|
||||||
std::string finalWptName;
|
std::string finalWptName;
|
||||||
} trackCache;
|
} trackCache;
|
||||||
|
|
||||||
|
// these are init-ed on first se by lazyInitControlsNodes()
|
||||||
|
SGPropertyNode_ptr _controlsLateralModeNode,
|
||||||
|
_controlsVerticalModeNode,
|
||||||
|
_controlsTargetHeadingNode,
|
||||||
|
_controlsTargetRollNode,
|
||||||
|
_controlsTargetAltitude,
|
||||||
|
_controlsTargetPitch,
|
||||||
|
_controlsTargetSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _FG_AIAircraft_HXX
|
#endif // _FG_AIAircraft_HXX
|
||||||
|
|
|
@ -763,6 +763,8 @@ void FGAIBase::bind() {
|
||||||
|
|
||||||
props->setStringValue("sim/model/path", model_path);
|
props->setStringValue("sim/model/path", model_path);
|
||||||
|
|
||||||
|
// note: AIAircraft creates real SGPropertyNodes for these, we don't do
|
||||||
|
// that here because it would bloat AIBase slightly
|
||||||
props->setBoolValue("controls/glide-path", true);
|
props->setBoolValue("controls/glide-path", true);
|
||||||
|
|
||||||
props->setStringValue("controls/flight/lateral-mode", "roll");
|
props->setStringValue("controls/flight/lateral-mode", "roll");
|
||||||
|
|
Loading…
Reference in a new issue