1
0
Fork 0

AIBase: Refactor

getTypeString returns string_view
object_type to strongly-typed enum
ModelSearchOrder to strongly-typed enum
This commit is contained in:
Scott Giese 2022-01-15 22:54:30 -06:00
parent 42ee4822c7
commit f198ac8d8d
30 changed files with 184 additions and 193 deletions

View file

@ -104,7 +104,7 @@ FGAIAircraft::FGAIAircraft(FGAISchedule* ref) : /* HOT must be disabled for AI A
tcasThreatNode = props->getNode("tcas/threat-level", true);
tcasRANode = props->getNode("tcas/ra-sense", true);
_searchOrder = PREFER_AI;
_searchOrder = ModelSearchOrder::PREFER_AI;
}
void FGAIAircraft::lazyInitControlsNodes()

View file

@ -21,6 +21,7 @@
#pragma once
#include <string>
#include <string_view>
#include <iostream>
#include "AIBaseAircraft.hxx"
@ -38,7 +39,7 @@ public:
FGAIAircraft(FGAISchedule *ref=0);
virtual ~FGAIAircraft();
const char* getTypeString(void) const override { return "aircraft"; }
string_view getTypeString(void) const override { return "aircraft"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
void bind() override;

View file

@ -996,7 +996,7 @@ void FGAIBallistic::report_impact(double elevation, const FGAIBase *object)
SGPropertyNode *n = props->getNode("impact", true);
if (object)
n->setStringValue("type", object->getTypeString());
n->setStringValue("type", static_cast<std::string>(object->getTypeString()));
else
n->setStringValue("type", "terrain");

View file

@ -22,6 +22,7 @@
#pragma once
#include <cmath>
#include <string_view>
#include <vector>
#include <simgear/structure/SGSharedPtr.hxx>
@ -34,10 +35,10 @@ class FGAIBallistic : public FGAIBase {
public:
FGAIBallistic(object_type ot = otBallistic);
FGAIBallistic(object_type ot = object_type::otBallistic);
virtual ~FGAIBallistic() = default;
const char* getTypeString(void) const override { return "ballistic"; }
string_view getTypeString(void) const override { return "ballistic"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override;

View file

@ -144,9 +144,9 @@ private:
ErrorContext _errorContext;
};
FGAIBase::FGAIBase(object_type ot, bool enableHot) :
replay_time(fgGetNode("sim/replay/time", true)),
model_removed( fgGetNode("/ai/models/model-removed", true) ),
FGAIBase::FGAIBase(object_type ot, bool enableHot) : replay_time(fgGetNode("sim/replay/time", true)),
model_removed(fgGetNode("/ai/models/model-removed", true)),
pos(SGGeod::fromDeg(0.0, 0.0)),
_impact_lat(0),
_impact_lon(0),
_impact_elev(0),
@ -154,7 +154,7 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
_impact_pitch(0),
_impact_roll(0),
_impact_speed(0),
_refID( _newAIModelID() ),
_refID(_newAIModelID()),
_otype(ot)
{
tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
@ -178,7 +178,6 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
_roll_offset = 0;
_yaw_offset = 0;
pos = SGGeod::fromDeg(0, 0);
speed = 0;
altitude_ft = 0;
speed_north_deg_sec = 0;
@ -285,14 +284,13 @@ void FGAIBase::readFromScenario(SGPropertyNode* scFileNode)
string searchOrder = scFileNode->getStringValue("search-order", "");
if (!searchOrder.empty()) {
if (searchOrder == "DATA_ONLY") {
_searchOrder = DATA_ONLY;
_searchOrder = ModelSearchOrder::DATA_ONLY;
} else if (searchOrder == "PREFER_AI") {
_searchOrder = PREFER_AI;
_searchOrder = ModelSearchOrder::PREFER_AI;
} else if (searchOrder == "PREFER_DATA") {
_searchOrder = PREFER_DATA;
_searchOrder = ModelSearchOrder::PREFER_DATA;
} else
SG_LOG(SG_AI, SG_WARN, "invalid model search order " << searchOrder << ". Use either DATA_ONLY, PREFER_AI or PREFER_DATA");
}
const string modelLowres = scFileNode->getStringValue("model-lowres", "");
@ -306,10 +304,10 @@ void FGAIBase::update(double dt) {
SG_UNUSED(dt);
if (replay_time->getDoubleValue() > 0)
return;
if (_otype == otStatic)
if (_otype == object_type::otStatic)
return;
if (_otype == otBallistic)
if (_otype == object_type::otBallistic)
CalculateMach();
ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.getLatitudeRad());
@ -558,7 +556,7 @@ std::vector<std::string> FGAIBase::resolveModelPath(ModelSearchOrder searchOrder
{
string_list path_list;
if (searchOrder == DATA_ONLY) {
if (searchOrder == ModelSearchOrder::DATA_ONLY) {
SG_LOG(SG_AI, SG_DEBUG, "Resolving model path: DATA only");
auto p = simgear::SGModelLib::findDataFile(model_path);
if (!p.empty()) {
@ -614,7 +612,7 @@ std::vector<std::string> FGAIBase::resolveModelPath(ModelSearchOrder searchOrder
}
}
if ((searchOrder == PREFER_AI) && !path_list.empty()) {
if ((searchOrder == ModelSearchOrder::PREFER_AI) && !path_list.empty()) {
// if we prefer AI, and we've got a valid AI path from above, then use it, we're done
_installed = true;
return path_list;
@ -657,7 +655,7 @@ bool FGAIBase::init(ModelSearchOrder searchOrder)
// set by FGAISchedule::createAIAircraft
_modeldata->captureErrorContext("traffic-aircraft-callsign");
if (_otype == otMultiplayer) {
if (_otype == object_type::otMultiplayer) {
_modeldata->addErrorContext("multiplayer", getCallSign());
}
@ -995,10 +993,8 @@ void FGAIBase::_setSubID( int s ) {
}
bool FGAIBase::setParentNode() {
if (_parent == ""){
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name
<< " parent not set ");
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name << " parent not set ");
return false;
}
@ -1011,33 +1007,30 @@ bool FGAIBase::setParentNode() {
model = _selected_ac;
} else {
model = ai->getChild(i);
//const string& path = ai->getPath();
const string name = model->getStringValue("name");
if (!model->nChildren()){
continue;
}
if (name == _parent) {
_selected_ac = model; // save selected model for last iteration
break;
}
}
if (!model)
continue;
}// end for loop
if (_selected_ac != 0){
const string name = _selected_ac->getStringValue("name");
// DEADCODE: const string name = _selected_ac->getStringValue("name");
return true;
} else {
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name
<< " parent not found: dying ");
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name << " parent not found: dying ");
setDie(true);
return false;
}
}
double FGAIBase::_getLongitude() const {

View file

@ -17,40 +17,50 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef FG_AIBASE_HXX
#define FG_AIBASE_HXX
#pragma once
#include <string>
#include <string_view>
#include <osg/ref_ptr>
#include <simgear/constants.h>
#include <simgear/scene/model/placement.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/props/tiedpropertylist.hxx>
#include <simgear/sg_inlines.h>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/tiedpropertylist.hxx>
#include <simgear/scene/model/placement.hxx>
#include <simgear/sg_inlines.h>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
namespace osg { class PagedLOD; }
namespace simgear { class BVHMaterial; }
namespace simgear {
class BVHMaterial;
}
class FGAIManager;
class FGAIFlightPlan;
class FGFX;
class FGAIModelData; // defined below
class FGAIBase : public SGReferenced {
class FGAIBase : public SGReferenced
{
public:
enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
otRocket, otStorm, otThermal, otStatic, otWingman, otGroundVehicle,
otEscort, otMultiplayer,
MAX_OBJECTS }; // Needs to be last!!!
enum class object_type {
otNull = 0,
otAircraft,
otShip,
otCarrier,
otBallistic,
otRocket,
otStorm,
otThermal,
otStatic,
otWingman,
otGroundVehicle,
otEscort,
otMultiplayer,
MAX_OBJECTS // Needs to be last!!!
};
FGAIBase(object_type ot, bool enableHot);
virtual ~FGAIBase();
@ -63,7 +73,7 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode);
enum ModelSearchOrder {
enum class 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
@ -75,41 +85,58 @@ public:
virtual void bind();
virtual void unbind();
virtual void reinit() {}
// default model radius for LOD.
virtual double getDefaultModelRadius() { return 20.0; }
void updateLOD();
void updateInterior();
void setManager(FGAIManager* mgr, SGPropertyNode* p);
void setPath( const char* model );
void setPathLowres( std::string model );
void setFallbackModelIndex(const int i );
void setSMPath( const std::string& p );
void setCallSign(const std::string& );
void setSpeed( double speed_KTAS );
void setMaxSpeed(double kts);
void setAltitude( double altitude_ft );
void setAltitudeAGL( double altitude_agl_ft );
void setHeading( double heading );
void setLatitude( double latitude );
void setLongitude( double longitude );
void setBank( double bank );
void setPitch( double newpitch );
void setRadius ( double radius );
void setXoffset( double x_offset );
void setYoffset( double y_offset );
void setZoffset( double z_offset );
void setPitchoffset( double x_offset );
void setRolloffset( double y_offset );
void setYawoffset( double z_offset );
void setServiceable ( bool serviceable );
bool getDie();
void setDie( bool die );
bool isValid() const;
void setCollisionData( bool i, double lat, double lon, double elev );
void setImpactData( bool d );
void setImpactLat( double lat );
void setImpactLon( double lon );
void setImpactElev( double e );
void setParentName(const std::string& p);
void setName(const std::string& n);
void setMaxSpeed(double kts);
bool setParentNode();
void setParentName(const std::string& p);
void calcRangeBearing(double lat, double lon, double lat2, double lon2,
double &range, double &bearing) const;
@ -117,19 +144,13 @@ public:
double calcTrueBearingDeg(double bearing, double heading);
double calcRecipBearingDeg(double bearing);
bool setParentNode();
int getID() const;
int _getSubID() const;
bool getDie();
bool isValid() const;
void setFlightPlan(std::unique_ptr<FGAIFlightPlan> f);
SGGeod getGeodPos() const;
void setGeodPos(const SGGeod& pos);
SGVec3d getCartPosAt(const SGVec3d& off) const;
SGVec3d getCartPos() const;
@ -138,10 +159,7 @@ public:
SGPropertyNode* getPositionFromNode(SGPropertyNode* scFileNode, const std::string& key, SGVec3d& position);
double getTrueHeadingDeg() const
{
return hdg;
}
double getTrueHeadingDeg() const { return hdg; }
double _getCartPosX() const;
double _getCartPosY() const;
@ -158,9 +176,9 @@ public:
void setScenarioPath(const std::string& scenarioPath);
protected:
double _elevation_m;
double _elevation_m = 0.0;
double _maxRangeInterior;
double _maxRangeInterior = 50.0;
double _x_offset;
double _y_offset;
@ -202,13 +220,13 @@ protected:
double roll; // degrees, left is negative
double pitch; // degrees, nose-down is negative
double speed; // knots true airspeed
double speed_fps; // fps true airspeed
double speed_fps = 0.0; // fps true airspeed
double altitude_ft; // feet above sea level
double vs_fps; // vertical speed
double speed_north_deg_sec;
double speed_east_deg_sec;
double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
double altitude_agl_ft;
double altitude_agl_ft = 0.0;
double ft_per_deg_lon;
double ft_per_deg_lat;
@ -237,11 +255,11 @@ protected:
std::string model_path; // Path to the 3D model
std::string model_path_lowres; // Path to optional low res 3D model
int _fallback_model_index; // Index into /sim/multiplay/fallback-models[]
int _fallback_model_index = 0; // Index into /sim/multiplay/fallback-models[]
SGModelPlacement aip;
bool delete_me;
bool invisible;
bool invisible = false;
bool no_roll;
bool serviceable;
bool _installed = false;
@ -263,7 +281,7 @@ protected:
double _impact_roll;
double _impact_speed;
ModelSearchOrder _searchOrder = DATA_ONLY;
ModelSearchOrder _searchOrder = ModelSearchOrder::DATA_ONLY;
void Transform();
void CalculateMach();
double UpdateRadar(FGAIManager* manager);
@ -292,7 +310,7 @@ private:
public:
object_type getType();
virtual const char* getTypeString(void) const { return "null"; }
virtual string_view getTypeString(void) const { return "null"; }
bool isa( object_type otype );
@ -332,7 +350,6 @@ public:
double _getXOffset() const;
double _getYOffset() const;
double _getZOffset() const;
//unsigned int _getCount() const;
bool _getServiceable() const;
bool _getFirstTime() const;
@ -366,8 +383,7 @@ public:
static bool _isNight();
const std::string& getCallSign() const
{ return _callsign; }
const std::string& getCallSign() const { return _callsign; }
ModelSearchOrder getSearchOrder() const {return _searchOrder;}
};
@ -509,5 +525,3 @@ inline void FGAIBase::setMaxSpeed(double m) {
_max_speed = m;
}
#endif // _FG_AIBASE_HXX

View file

@ -24,7 +24,7 @@ class FGAIBaseAircraft : public FGAIBase
{
public:
FGAIBaseAircraft(object_type otype = FGAIBase::otAircraft);
FGAIBaseAircraft(object_type otype = object_type::otAircraft);
void bind() override;

View file

@ -37,7 +37,7 @@
#include "AICarrier.hxx"
#include "AINotifications.hxx"
FGAICarrier::FGAICarrier() : FGAIShip(otCarrier)
FGAICarrier::FGAICarrier() : FGAIShip(object_type::otCarrier)
{
simgear::Emesary::GlobalTransmitter::instance()->Register(this);
}
@ -807,7 +807,7 @@ SGSharedPtr<FGAICarrier> FGAICarrier::findCarrierByNameOrPennant(const std::stri
}
for (const auto& aiObject : aiManager->get_ai_list()) {
if (aiObject->isa(FGAIBase::otCarrier)) {
if (aiObject->isa(object_type::otCarrier)) {
SGSharedPtr<FGAICarrier> c = static_cast<FGAICarrier*>(aiObject.get());
if ((c->_sign == namePennant) || (c->_getName() == namePennant)) {
return c;

View file

@ -22,6 +22,7 @@
#include <list>
#include <string>
#include <string_view>
#include <simgear/compiler.h>
#include <simgear/emesary/Emesary.hxx>
@ -40,6 +41,7 @@ public:
FGAICarrier();
virtual ~FGAICarrier();
string_view getTypeString(void) const override { return "carrier"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
void setSign(const std::string&);
@ -65,8 +67,6 @@ public:
bool init(ModelSearchOrder searchOrder) override;
const char* getTypeString(void) const override { return "carrier"; }
bool getParkPosition(const std::string& id, SGGeod& geodPos, double& hdng, SGVec3d& uvw);
/**
@ -102,6 +102,7 @@ private:
: name(n), offset(off), heading_deg(heading)
{
}
std::string name;
SGVec3d offset;
double heading_deg;

View file

@ -22,6 +22,7 @@
#include <list>
#include <string>
#include <string_view>
#include <simgear/compiler.h>
@ -38,7 +39,7 @@ public:
FGAIEscort();
virtual ~FGAIEscort() = default;
const char* getTypeString(void) const override { return "escort"; }
string_view getTypeString(void) const override { return "escort"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override;
@ -96,4 +97,3 @@ private:
bool _patrol = false;
bool _stn_deg_true = false;
};

View file

@ -21,6 +21,7 @@
#pragma once
#include <cmath>
#include <string_view>
#include <vector>
#include <simgear/structure/SGSharedPtr.hxx>
@ -36,7 +37,7 @@ public:
FGAIGroundVehicle();
virtual ~FGAIGroundVehicle() = default;
const char* getTypeString(void) const override { return "groundvehicle"; }
string_view getTypeString(void) const override { return "groundvehicle"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override;

View file

@ -399,7 +399,7 @@ FGAIManager::update(double dt)
// entire subsystem.
for (FGAIBase* base : ai_list) {
try {
if (base->isa(FGAIBase::otThermal)) {
if (base->isa(FGAIBase::object_type::otThermal)) {
processThermal(dt, static_cast<FGAIThermal*>(base));
} else {
base->update(dt);
@ -425,7 +425,7 @@ FGAIManager::updateLOD(SGPropertyNode* node)
void
FGAIManager::attach(const SGSharedPtr<FGAIBase> &model)
{
const char* typeString = model->getTypeString();
string_view typeString = model->getTypeString();
SGPropertyNode* root = globals->get_props()->getNode("ai/models", true);
SGPropertyNode* p;
int i;
@ -433,7 +433,7 @@ FGAIManager::attach(const SGSharedPtr<FGAIBase> &model)
// find free index in the property tree, if we have
// more than 10000 mp-aircrafts in the property tree we should optimize the mp-server
for (i = 0; i < 10000; i++) {
p = root->getNode(typeString, i, false);
p = root->getNode(static_cast<std::string>(typeString), i, false);
if (!p || !p->getBoolValue("valid", false))
break;
@ -443,7 +443,7 @@ FGAIManager::attach(const SGSharedPtr<FGAIBase> &model)
}
}
p = root->getNode(typeString, i, true);
p = root->getNode(static_cast<std::string>(typeString), i, true);
model->setManager(this, p);
ai_list.push_back(model);
@ -720,11 +720,11 @@ FGAIManager::calcCollision(double alt, double lat, double lon, double fuse_range
while (ai_list_itr != end) {
double tgt_alt = (*ai_list_itr)->_getAltitude();
int type = (*ai_list_itr)->getType();
tgt_ht[type] += fuse_range;
FGAIBase::object_type type = (*ai_list_itr)->getType();
tgt_ht[static_cast<int>(type)] += fuse_range;
if (fabs(tgt_alt - alt) > tgt_ht[type] || type == FGAIBase::otBallistic
|| type == FGAIBase::otStorm || type == FGAIBase::otThermal ) {
if (fabs(tgt_alt - alt) > tgt_ht[static_cast<int>(type)] || type == FGAIBase::object_type::otBallistic
|| type == FGAIBase::object_type::otStorm || type == FGAIBase::object_type::otThermal ) {
//SG_LOG(SG_AI, SG_DEBUG, "AIManager: skipping "
// << fabs(tgt_alt - alt)
// << " "
@ -747,11 +747,11 @@ FGAIManager::calcCollision(double alt, double lat, double lon, double fuse_range
// << " alt " << tgt_alt
// );
tgt_length[type] += fuse_range;
tgt_length[static_cast<int>(type)] += fuse_range;
if (range < tgt_length[type]){
if (range < tgt_length[static_cast<int>(type)]){
SG_LOG(SG_AI, SG_DEBUG, "AIManager: HIT! "
<< " type " << type
<< " type " << static_cast<int>(type)
<< " ID " << id
<< " range " << range
<< " alt " << tgt_alt

View file

@ -39,37 +39,14 @@ using std::string;
// #define SG_DEBUG SG_ALERT
FGAIMultiplayer::FGAIMultiplayer() :
FGAIBase(otMultiplayer, fgGetBool("/sim/multiplay/hot", false))
FGAIMultiplayer::FGAIMultiplayer() : FGAIBase(object_type::otMultiplayer, fgGetBool("/sim/multiplay/hot", false)),
m_simple_time_enabled(fgGetNode("/sim/time/simple-time/enabled", true)),
m_sim_replay_replay_state(fgGetNode("/sim/replay/replay-state", true)),
m_sim_replay_time(fgGetNode("/sim/replay/time", true)),
mLogRawSpeedMultiplayer(fgGetNode("/sim/replay/log-raw-speed-multiplayer", true))
{
no_roll = false;
mTimeOffsetSet = false;
mAllowExtrapolation = true;
mLagAdjustSystemSpeed = 10;
mLastTimestamp = 0;
lastUpdateTime = 0;
playerLag = 0.03;
compensateLag = 1;
realTime = false;
lastTime=0.0;
lagPpsAveraged = 1.0;
rawLag = 0.0;
rawLagMod = 0.0;
lagModAveraged = 0.0;
_searchOrder = PREFER_DATA;
m_simple_time_enabled = fgGetNode("/sim/time/simple-time/enabled", true);
m_sim_replay_replay_state = fgGetNode("/sim/replay/replay-state", true);
m_sim_replay_time = fgGetNode("/sim/replay/time", true);
m_simple_time_first_time = true;
m_simple_time_compensation = 0.0;
m_simple_time_recent_packet_time = 0;
mLogRawSpeedMultiplayer = fgGetNode("/sim/replay/log-raw-speed-multiplayer", true);
}
FGAIMultiplayer::~FGAIMultiplayer() {
_searchOrder = ModelSearchOrder::PREFER_DATA;
}
bool FGAIMultiplayer::init(ModelSearchOrder searchOrder)
@ -161,9 +138,7 @@ void FGAIMultiplayer::FGAIMultiplayerInterpolate(
ecLinearVel = interpolate((float)tau, prevIt->second.linearVel, nextIt->second.linearVel);
speed = norm(ecLinearVel) * SG_METER_TO_NM * 3600.0;
if (prevIt->second.properties.size()
== nextIt->second.properties.size())
{
if (prevIt->second.properties.size() == nextIt->second.properties.size()) {
std::vector<FGPropertyData*>::const_iterator prevPropIt;
std::vector<FGPropertyData*>::const_iterator prevPropItEnd;
std::vector<FGPropertyData*>::const_iterator nextPropIt;
@ -929,12 +904,14 @@ FGAIMultiplayer::addMotionInfo(FGExternalMotionData& motionInfo,
}
#if 0
void
FGAIMultiplayer::setDoubleProperty(const std::string& prop, double val)
{
SGPropertyNode* pNode = props->getChild(prop.c_str(), true);
pNode->setDoubleValue(val);
}
#endif
void FGAIMultiplayer::clearMotionInfo()
{

View file

@ -18,26 +18,31 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef _FG_AIMultiplayer_HXX
#define _FG_AIMultiplayer_HXX
#pragma once
#include <map>
#include <string>
#include <string_view>
#include <MultiPlayer/mpmessages.hxx>
#include "AIBase.hxx"
class FGAIMultiplayer : public FGAIBase {
public:
FGAIMultiplayer();
virtual ~FGAIMultiplayer();
virtual ~FGAIMultiplayer() = default;
string_view getTypeString(void) const override { return "multiplayer"; }
bool init(ModelSearchOrder searchOrder) override;
void bind() override;
void update(double dt) override;
void addMotionInfo(FGExternalMotionData& motionInfo, long stamp);
#if 0
void setDoubleProperty(const std::string& prop, double val);
#endif
long getLastTimestamp(void) const
{
@ -98,11 +103,6 @@ public:
void clearMotionInfo();
const char* getTypeString(void) const override
{
return "multiplayer";
}
private:
// Automatic sorting of motion data according to its timestamp
@ -141,26 +141,28 @@ private:
SGVec3f& ecLinearVel
);
bool mTimeOffsetSet;
bool realTime;
int compensateLag;
double playerLag;
double mTimeOffset;
double lastUpdateTime;
double lastTime;
double lagPpsAveraged;
double rawLag, rawLagMod, lagModAveraged;
bool mTimeOffsetSet = false;
bool realTime = false;
int compensateLag = 1;
double playerLag = 0.03;
double mTimeOffset = 0.0;
double lastUpdateTime = 0.0;
double lastTime = 0.0;
double lagPpsAveraged = 1.0;
double rawLag = 0.0;
double rawLagMod = 0.0;
double lagModAveraged = 0.0;
/// Properties which are for now exposed for testing
bool mAllowExtrapolation;
double mLagAdjustSystemSpeed;
bool mAllowExtrapolation = true;
double mLagAdjustSystemSpeed = 10.0;
long mLastTimestamp;
long mLastTimestamp = 0;
// Properties for tankers
SGPropertyNode_ptr refuel_node;
bool isTanker;
bool contact; // set if this tanker is within fuelling range
bool isTanker = false;
bool contact = false; // set if this tanker is within fuelling range
// velocities/u,v,wbody-fps
SGPropertyNode_ptr _uBodyNode;
@ -174,11 +176,11 @@ private:
SGPropertyNode_ptr m_sim_replay_replay_state;
SGPropertyNode_ptr m_sim_replay_time;
bool m_simple_time_first_time;
double m_simple_time_offset;
double m_simple_time_offset_smoothed;
double m_simple_time_compensation;
double m_simple_time_recent_packet_time;
bool m_simple_time_first_time = true;
double m_simple_time_offset = 0.0;
double m_simple_time_offset_smoothed = 0.0;
double m_simple_time_compensation = 0.0;
double m_simple_time_recent_packet_time = 0.0;
SGPropertyNode_ptr m_node_simple_time_latest;
SGPropertyNode_ptr m_node_simple_time_offset;
@ -203,5 +205,3 @@ private:
SGPropertyNode_ptr m_node_log_multiplayer;
};
#endif // _FG_AIMultiplayer_HXX

View file

@ -793,7 +793,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
setWPPos();
object_type type = getType();
if (type != 10) // TODO: magic number
if (type != object_type::otGroundVehicle) // is this correct???
AccelTo(prev->getSpeed());
_curr_alt = curr->getAltitude();

View file

@ -21,6 +21,8 @@
#pragma once
#include <string_view>
#include <simgear/scene/material/mat.hxx>
#include "AIBase.hxx"
@ -34,7 +36,7 @@ public:
FGAIShip(object_type ot = object_type::otShip);
virtual ~FGAIShip() = default;
const char* getTypeString(void) const override { return "ship"; }
string_view getTypeString(void) const override { return "ship"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override;

View file

@ -27,8 +27,8 @@
#include "AIStatic.hxx"
FGAIStatic::FGAIStatic() : FGAIBase(otStatic, false) {
_searchOrder = DATA_ONLY;
FGAIStatic::FGAIStatic() : FGAIBase(object_type::otStatic, false) {
_searchOrder = ModelSearchOrder::DATA_ONLY;
}
@ -36,4 +36,3 @@ void FGAIStatic::update(double dt) {
FGAIBase::update(dt);
Transform();
}

View file

@ -20,6 +20,8 @@
#pragma once
#include <string_view>
#include "AIManager.hxx"
#include "AIBase.hxx"
@ -31,6 +33,6 @@ public:
FGAIStatic();
virtual ~FGAIStatic() = default;
const char* getTypeString(void) const override { return "static"; }
string_view getTypeString(void) const override { return "static"; }
void update(double dt) override;
};

View file

@ -27,12 +27,10 @@
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
using std::string;
#include "AIStorm.hxx"
FGAIStorm::FGAIStorm() : FGAIBase(otStorm, false)
FGAIStorm::FGAIStorm() : FGAIBase(object_type::otStorm, false)
{
delay = 3.6;
subflashes = 1;
@ -142,4 +140,3 @@ void FGAIStorm::Run(double dt) {
turb_rate_node->setDoubleValue(0.5);
}
}

View file

@ -21,6 +21,7 @@
#pragma once
#include <string>
#include <string_view>
#include "AIManager.hxx"
#include "AIBase.hxx"
@ -32,7 +33,7 @@ public:
FGAIStorm();
virtual ~FGAIStorm() = default;
const char* getTypeString(void) const override { return "thunderstorm"; }
string_view getTypeString(void) const override { return "thunderstorm"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
void update(double dt) override;

View file

@ -21,7 +21,7 @@
#include <Main/globals.hxx>
FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::string& modelString) : FGAIBaseAircraft(otStatic)
FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::string& modelString) : FGAIBaseAircraft(object_type::otStatic)
{
std::size_t pos = modelString.find("/Aircraft/"); // Only supporting AI models from FGDATA/AI/Aircraft for now
if(pos != std::string::npos)
@ -30,7 +30,7 @@ FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::str
model_path.append("INVALID_PATH");
setCallSign(callsign);
_searchOrder = PREFER_AI;
_searchOrder = ModelSearchOrder::PREFER_AI;
}
void FGAISwiftAircraft::updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos)
@ -92,4 +92,3 @@ void FGAISwiftAircraft::initProps()
m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true);
m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true);
}

View file

@ -20,6 +20,7 @@
#pragma once
#include <string>
#include <string_view>
#include <utility>
#include "AIBaseAircraft.hxx"
@ -72,10 +73,10 @@ public:
FGAISwiftAircraft(const std::string& callsign, const std::string& modelString);
virtual ~FGAISwiftAircraft() = default;
const char* getTypeString() const override { return "swift"; }
string_view getTypeString() const override { return "swift"; }
void update(double dt) override;
void updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos);
void update(double dt) override;
double getGroundElevation(const SGGeod& pos) const;
void initProps();
void setPlaneSurface(const AircraftSurfaces& surfaces);
@ -88,4 +89,3 @@ private:
SGPropertyNode_ptr m_transponderCModeNode;
SGPropertyNode_ptr m_transponderIdentNode;
};

View file

@ -21,6 +21,8 @@
#pragma once
#include <string_view>
#include "AIAircraft.hxx"
/**
@ -38,7 +40,7 @@ public:
FGAITanker(FGAISchedule* ref = 0);
virtual ~FGAITanker() = default;
const char* getTypeString(void) const override { return "tanker"; }
string_view getTypeString(void) const override { return "tanker"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
void bind() override;

View file

@ -27,12 +27,10 @@
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
using std::string;
#include "AIThermal.hxx"
FGAIThermal::FGAIThermal() : FGAIBase(otThermal, false)
FGAIThermal::FGAIThermal() : FGAIBase(object_type::otThermal, false)
{
altitude_agl_ft = 0.0;
max_strength = 6.0;
@ -359,4 +357,3 @@ strength = Vup;
range = dist_center;
}

View file

@ -22,8 +22,10 @@
#pragma once
#include "AIManager.hxx"
#include <string_view>
#include "AIBase.hxx"
#include "AIManager.hxx"
#include <string>
@ -34,7 +36,7 @@ public:
FGAIThermal();
virtual ~FGAIThermal() = default;
const char* getTypeString(void) const override { return "thermal"; }
string_view getTypeString(void) const override { return "thermal"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override;

View file

@ -27,7 +27,7 @@
#include "AIWingman.hxx"
FGAIWingman::FGAIWingman() : FGAIBallistic(otWingman),
FGAIWingman::FGAIWingman() : FGAIBallistic(object_type::otWingman),
_formate_to_ac(true),
_break(false),
_join(false),

View file

@ -19,6 +19,8 @@
#pragma once
#include <string_view>
#include <simgear/sg_inlines.h>
#include "AIBallistic.hxx"
@ -31,7 +33,7 @@ public:
FGAIWingman();
virtual ~FGAIWingman() = default;
const char* getTypeString(void) const override { return "wingman"; }
string_view getTypeString(void) const override { return "wingman"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override;

View file

@ -134,7 +134,7 @@ void FGSubmodelMgr::update(double dt)
FGAIBase::object_type object_type =(*sm_list_itr)->getType();
// Continue if object is not ballistic
if (object_type != FGAIBase::otBallistic) {
if (object_type != FGAIBase::object_type::otBallistic) {
continue;
}

View file

@ -224,7 +224,7 @@ void FDMShell::update(double dt)
if (_ai_wake_enabled->getBoolValue()) {
for (FGAIBase* base : _ai_mgr->get_ai_list()) {
try {
if (base->isa(FGAIBase::otAircraft) ) {
if (base->isa(FGAIBase::object_type::otAircraft) ) {
SGVec3d pos = _impl->getCartPosition();
const SGSharedPtr<FGAIAircraft> aircraft = dynamic_cast<FGAIAircraft*>(base);
double range = _ai_mgr->calcRangeFt(pos, aircraft)*SG_FEET_TO_METER;

View file

@ -115,7 +115,7 @@ void AIManagerTests::testAircraftWaypoints()
auto ai = aim->addObject(aircraftDefinition);
CPPUNIT_ASSERT(ai);
CPPUNIT_ASSERT_EQUAL(FGAIBase::otAircraft, ai->getType());
CPPUNIT_ASSERT_EQUAL(FGAIBase::object_type::otAircraft, ai->getType());
CPPUNIT_ASSERT_EQUAL(std::string{"aircraft"}, std::string{ai->getTypeString()});
auto aiAircraft = static_cast<FGAIAircraft*>(ai.get());