diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index c941cd9ac..3ec758314 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -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() diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 101e70f04..58d3fc5fb 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -21,6 +21,7 @@ #pragma once #include +#include #include #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; diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index d3b69e6d8..24e15262c 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -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(object->getTypeString())); else n->setStringValue("type", "terrain"); diff --git a/src/AIModel/AIBallistic.hxx b/src/AIModel/AIBallistic.hxx index fd499b2ba..477ce49db 100644 --- a/src/AIModel/AIBallistic.hxx +++ b/src/AIModel/AIBallistic.hxx @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include @@ -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; diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 7df144ee5..40a6a2d32 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -144,18 +144,18 @@ 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) ), - _impact_lat(0), - _impact_lon(0), - _impact_elev(0), - _impact_hdg(0), - _impact_pitch(0), - _impact_roll(0), - _impact_speed(0), - _refID( _newAIModelID() ), - _otype(ot) +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), + _impact_hdg(0), + _impact_pitch(0), + _impact_roll(0), + _impact_speed(0), + _refID(_newAIModelID()), + _otype(ot) { tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0; tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs_fps = pitch = 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 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 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 { diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index a57fe84fb..167795d8e 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -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 +#include + #include #include -#include -#include -#include -#include -#include -#include - #include +#include +#include +#include +#include +#include +#include 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 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; @@ -235,13 +253,13 @@ protected: double rotation; // value used by radar display instrument double ht_diff; // value used by radar display instrument - 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[] + 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 = 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 diff --git a/src/AIModel/AIBaseAircraft.hxx b/src/AIModel/AIBaseAircraft.hxx index fa1b7fdcf..1cf8e4fee 100644 --- a/src/AIModel/AIBaseAircraft.hxx +++ b/src/AIModel/AIBaseAircraft.hxx @@ -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; diff --git a/src/AIModel/AICarrier.cxx b/src/AIModel/AICarrier.cxx index 292bfc17a..8167b8846 100644 --- a/src/AIModel/AICarrier.cxx +++ b/src/AIModel/AICarrier.cxx @@ -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::findCarrierByNameOrPennant(const std::stri } for (const auto& aiObject : aiManager->get_ai_list()) { - if (aiObject->isa(FGAIBase::otCarrier)) { + if (aiObject->isa(object_type::otCarrier)) { SGSharedPtr c = static_cast(aiObject.get()); if ((c->_sign == namePennant) || (c->_getName() == namePennant)) { return c; diff --git a/src/AIModel/AICarrier.hxx b/src/AIModel/AICarrier.hxx index 4911d3151..0e8dcf9e4 100644 --- a/src/AIModel/AICarrier.hxx +++ b/src/AIModel/AICarrier.hxx @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -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; diff --git a/src/AIModel/AIEscort.hxx b/src/AIModel/AIEscort.hxx index 07bc3bdaa..278c02632 100644 --- a/src/AIModel/AIEscort.hxx +++ b/src/AIModel/AIEscort.hxx @@ -22,6 +22,7 @@ #include #include +#include #include @@ -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; }; - diff --git a/src/AIModel/AIGroundVehicle.hxx b/src/AIModel/AIGroundVehicle.hxx index 197ba4a0f..00e03a9aa 100644 --- a/src/AIModel/AIGroundVehicle.hxx +++ b/src/AIModel/AIGroundVehicle.hxx @@ -21,6 +21,7 @@ #pragma once #include +#include #include #include @@ -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; diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 3f5271e7e..9bb14c7cb 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -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(base)); } else { base->update(dt); @@ -425,7 +425,7 @@ FGAIManager::updateLOD(SGPropertyNode* node) void FGAIManager::attach(const SGSharedPtr &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 &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(typeString), i, false); if (!p || !p->getBoolValue("valid", false)) break; @@ -443,7 +443,7 @@ FGAIManager::attach(const SGSharedPtr &model) } } - p = root->getNode(typeString, i, true); + p = root->getNode(static_cast(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(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(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) // << " " @@ -734,7 +734,7 @@ FGAIManager::calcCollision(double alt, double lat, double lon, double fuse_range continue; } - int id = (*ai_list_itr)->getID(); + int id = (*ai_list_itr)->getID(); double range = calcRangeFt(cartPos, (*ai_list_itr)); @@ -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(type)] += fuse_range; - if (range < tgt_length[type]){ + if (range < tgt_length[static_cast(type)]){ SG_LOG(SG_AI, SG_DEBUG, "AIManager: HIT! " - << " type " << type + << " type " << static_cast(type) << " ID " << id << " range " << range << " alt " << tgt_alt diff --git a/src/AIModel/AIMultiplayer.cxx b/src/AIModel/AIMultiplayer.cxx index 58b3965a8..329876b48 100644 --- a/src/AIModel/AIMultiplayer.cxx +++ b/src/AIModel/AIMultiplayer.cxx @@ -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::const_iterator prevPropIt; std::vector::const_iterator prevPropItEnd; std::vector::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() { diff --git a/src/AIModel/AIMultiplayer.hxx b/src/AIModel/AIMultiplayer.hxx index 724118fa0..0ca93718e 100644 --- a/src/AIModel/AIMultiplayer.hxx +++ b/src/AIModel/AIMultiplayer.hxx @@ -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 #include +#include #include + #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 diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index 996aa2e44..5d92874d2 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -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(); diff --git a/src/AIModel/AIShip.hxx b/src/AIModel/AIShip.hxx index 4bc75fb10..dd23caac2 100644 --- a/src/AIModel/AIShip.hxx +++ b/src/AIModel/AIShip.hxx @@ -21,6 +21,8 @@ #pragma once +#include + #include #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; diff --git a/src/AIModel/AIStatic.cxx b/src/AIModel/AIStatic.cxx index 4658fd28d..8065ef422 100644 --- a/src/AIModel/AIStatic.cxx +++ b/src/AIModel/AIStatic.cxx @@ -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(); } - diff --git a/src/AIModel/AIStatic.hxx b/src/AIModel/AIStatic.hxx index 8726cbf01..11919a309 100644 --- a/src/AIModel/AIStatic.hxx +++ b/src/AIModel/AIStatic.hxx @@ -20,6 +20,8 @@ #pragma once +#include + #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; }; diff --git a/src/AIModel/AIStorm.cxx b/src/AIModel/AIStorm.cxx index f7022e996..bc5ddf9cb 100644 --- a/src/AIModel/AIStorm.cxx +++ b/src/AIModel/AIStorm.cxx @@ -27,12 +27,10 @@ #include
#include -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); } } - diff --git a/src/AIModel/AIStorm.hxx b/src/AIModel/AIStorm.hxx index 31e67987c..00446b4ea 100644 --- a/src/AIModel/AIStorm.hxx +++ b/src/AIModel/AIStorm.hxx @@ -21,6 +21,7 @@ #pragma once #include +#include #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; diff --git a/src/AIModel/AISwiftAircraft.cpp b/src/AIModel/AISwiftAircraft.cpp index b523a39dd..1a588844f 100755 --- a/src/AIModel/AISwiftAircraft.cpp +++ b/src/AIModel/AISwiftAircraft.cpp @@ -21,7 +21,7 @@ #include
-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& 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); } - diff --git a/src/AIModel/AISwiftAircraft.h b/src/AIModel/AISwiftAircraft.h index 3e2a0d542..a689bd6e4 100644 --- a/src/AIModel/AISwiftAircraft.h +++ b/src/AIModel/AISwiftAircraft.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #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& 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; }; - diff --git a/src/AIModel/AITanker.hxx b/src/AIModel/AITanker.hxx index 6d267ba3b..f7fac661f 100644 --- a/src/AIModel/AITanker.hxx +++ b/src/AIModel/AITanker.hxx @@ -21,6 +21,8 @@ #pragma once +#include + #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; diff --git a/src/AIModel/AIThermal.cxx b/src/AIModel/AIThermal.cxx index 8d1503692..b441fee40 100644 --- a/src/AIModel/AIThermal.cxx +++ b/src/AIModel/AIThermal.cxx @@ -27,12 +27,10 @@ #include
#include -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; } - diff --git a/src/AIModel/AIThermal.hxx b/src/AIModel/AIThermal.hxx index 16a0ec5b9..913d56740 100644 --- a/src/AIModel/AIThermal.hxx +++ b/src/AIModel/AIThermal.hxx @@ -22,8 +22,10 @@ #pragma once -#include "AIManager.hxx" +#include + #include "AIBase.hxx" +#include "AIManager.hxx" #include @@ -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; diff --git a/src/AIModel/AIWingman.cxx b/src/AIModel/AIWingman.cxx index 3fd3090d5..e53e41a89 100644 --- a/src/AIModel/AIWingman.cxx +++ b/src/AIModel/AIWingman.cxx @@ -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), diff --git a/src/AIModel/AIWingman.hxx b/src/AIModel/AIWingman.hxx index 4497fb66f..3eeabdf3b 100644 --- a/src/AIModel/AIWingman.hxx +++ b/src/AIModel/AIWingman.hxx @@ -19,6 +19,8 @@ #pragma once +#include + #include #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; diff --git a/src/AIModel/submodel.cxx b/src/AIModel/submodel.cxx index ca88233d9..4b5491e82 100644 --- a/src/AIModel/submodel.cxx +++ b/src/AIModel/submodel.cxx @@ -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; } diff --git a/src/FDM/fdm_shell.cxx b/src/FDM/fdm_shell.cxx index ed5df02a8..7b34f076e 100644 --- a/src/FDM/fdm_shell.cxx +++ b/src/FDM/fdm_shell.cxx @@ -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 aircraft = dynamic_cast(base); double range = _ai_mgr->calcRangeFt(pos, aircraft)*SG_FEET_TO_METER; diff --git a/test_suite/unit_tests/AI/test_AIManager.cxx b/test_suite/unit_tests/AI/test_AIManager.cxx index d55296fd1..65ffde3e4 100644 --- a/test_suite/unit_tests/AI/test_AIManager.cxx +++ b/test_suite/unit_tests/AI/test_AIManager.cxx @@ -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(ai.get());