diff --git a/src/Network/Swift/SwiftAircraft.cpp b/src/Network/Swift/SwiftAircraft.cpp index 110dbd43d..7b0d639f2 100644 --- a/src/Network/Swift/SwiftAircraft.cpp +++ b/src/Network/Swift/SwiftAircraft.cpp @@ -42,7 +42,7 @@ #include #include -FGSwiftAircraft::FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode* p) +FGSwiftAircraft::FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode_ptr p) { using namespace simgear; _model = SGModelLib::loadModel(modelpath); @@ -57,7 +57,6 @@ FGSwiftAircraft::FGSwiftAircraft(const std::string& callsign, const std::string& props->setStringValue("callsign", callsign); props->setBoolValue("valid",true); } - initPos = false; } bool FGSwiftAircraft::updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed, bool initPos) @@ -120,15 +119,15 @@ inline bool FGSwiftAircraft::operator<(const std::string& extCallsign) return _model->getName().compare(extCallsign); } -double FGSwiftAircraft::getGroundElevation(double latitudeDeg, double longitudeDeg) const +double FGSwiftAircraft::getGroundElevation(const SGGeod& pos) const { if(!initPos) { return std::numeric_limits::quiet_NaN(); } double alt = 0; - SGGeod pos; - pos.setElevationFt(30000); - pos.setLatitudeDeg(latitudeDeg); - pos.setLongitudeDeg(longitudeDeg); - globals->get_scenery()->get_elevation_m(pos,alt,0,_model.get()); + SGGeod posReq; + posReq.setElevationFt(30000); + posReq.setLatitudeDeg(pos.getLatitudeDeg()); + posReq.setLongitudeDeg(pos.getLongitudeDeg()); + globals->get_scenery()->get_elevation_m(posReq,alt,0,_model.get()); return alt; } \ No newline at end of file diff --git a/src/Network/Swift/SwiftAircraft.h b/src/Network/Swift/SwiftAircraft.h index 58484b8e1..2bad224d5 100644 --- a/src/Network/Swift/SwiftAircraft.h +++ b/src/Network/Swift/SwiftAircraft.h @@ -41,19 +41,19 @@ class PagedLOD; class FGSwiftAircraft { public: - FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode* p); + FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode_ptr p); bool updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed, bool initPos); ~FGSwiftAircraft(); std::string getName() { return _model->getName(); }; double getLatDeg() const; double getLongDeg() const; - double getGroundElevation(double, double) const; + double getGroundElevation(const SGGeod& pos) const; double getFudgeFactor() const; private: - bool initPos; + bool initPos = false; SGGeod position; - SGPropertyNode* props; + SGPropertyNode_ptr props; osg::ref_ptr _model; SGModelPlacement aip; inline bool operator<(const std::string& extCallsign); diff --git a/src/Network/Swift/SwiftAircraftManager.cpp b/src/Network/Swift/SwiftAircraftManager.cpp index eaf4e070a..8b2e6adfb 100644 --- a/src/Network/Swift/SwiftAircraftManager.cpp +++ b/src/Network/Swift/SwiftAircraftManager.cpp @@ -34,8 +34,8 @@ bool FGSwiftAircraftManager::addPlane(const std::string& callsign, std::string m return false; const char* typeString = "swift"; - SGPropertyNode* root = globals->get_props()->getNode("ai/models",true); - SGPropertyNode* p; + SGPropertyNode_ptr root = globals->get_props()->getNode("ai/models",true); + SGPropertyNode_ptr p; int i; for(i = 0; i < 10000; i++){ p = root->getNode(typeString,i,false); @@ -45,7 +45,7 @@ bool FGSwiftAircraftManager::addPlane(const std::string& callsign, std::string m } p = root->getNode(typeString,i,true); p->setIntValue("id",i); - auto* curAircraft = new FGSwiftAircraft(callsign, std::move(modelString), p); + auto curAircraft = new FGSwiftAircraft(callsign, std::move(modelString), p); aircraftByCallsign.insert(std::pair(callsign, curAircraft)); return true; } @@ -79,9 +79,13 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector& cal const FGSwiftAircraft *aircraft = it->second; assert(aircraft); - const double latDeg = aircraft->getLatDeg(); - const double lonDeg = aircraft->getLongDeg(); - double groundElevation = aircraft->getGroundElevation(latDeg, lonDeg); + + SGGeod pos; + pos.setLatitudeDeg(aircraft->getLatDeg()); + pos.setLongitudeDeg(aircraft->getLongDeg()); + const double latDeg = pos.getLatitudeDeg(); + const double lonDeg = pos.getLongitudeDeg(); + double groundElevation = aircraft->getGroundElevation(pos); double fudgeFactor = aircraft->getFudgeFactor(); (void)fudgeFactor; @@ -110,12 +114,11 @@ void FGSwiftAircraftManager::removeAllPlanes() } } -double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsign, double latitudeDeg, - double longitudeDeg, double altitudeMeters) const +double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const { auto it = aircraftByCallsign.find(callsign); if(it != aircraftByCallsign.end()){ - return it->second->getGroundElevation(latitudeDeg, longitudeDeg); + return it->second->getGroundElevation(pos); } return std::numeric_limits::quiet_NaN(); } diff --git a/src/Network/Swift/SwiftAircraftManager.h b/src/Network/Swift/SwiftAircraftManager.h index 83c99f1d6..0c1e731c2 100644 --- a/src/Network/Swift/SwiftAircraftManager.h +++ b/src/Network/Swift/SwiftAircraftManager.h @@ -36,6 +36,6 @@ public: std::vector& elevationsM, std::vector& verticalOffsets) const; void removePlane(const std::string& callsign); void removeAllPlanes(); - double getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const; + double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const; }; #endif \ No newline at end of file diff --git a/src/Network/Swift/plugin.cpp b/src/Network/Swift/plugin.cpp index f269dea6a..15a8ec6be 100644 --- a/src/Network/Swift/plugin.cpp +++ b/src/Network/Swift/plugin.cpp @@ -82,7 +82,7 @@ void CPlugin::startServer() float CPlugin::startServerDeferred(float, float, int, void* refcon) { - auto* plugin = static_cast(refcon); + auto plugin = static_cast(refcon); if (!plugin->m_isRunning) { plugin->startServer(); plugin->m_isRunning = true; diff --git a/src/Network/Swift/service.h b/src/Network/Swift/service.h index 991608f4e..d4c264eea 100644 --- a/src/Network/Swift/service.h +++ b/src/Network/Swift/service.h @@ -203,42 +203,42 @@ protected: DBusHandlerResult dbusMessageHandler(const CDBusMessage& message) override; private: - SGPropertyNode* textMessageNode; - SGPropertyNode* aircraftModelPathNode; - //SGPropertyNode* aircraftLiveryNode; - //SGPropertyNode* aircraftIcaoCodeNode; - SGPropertyNode* aircraftDescriptionNode; - SGPropertyNode* isPausedNode; - SGPropertyNode* latitudeNode; - SGPropertyNode* longitudeNode; - SGPropertyNode* altitudeMSLNode; - SGPropertyNode* heightAGLNode; - SGPropertyNode* groundSpeedNode; - SGPropertyNode* pitchNode; - SGPropertyNode* rollNode; - SGPropertyNode* trueHeadingNode; - SGPropertyNode* wheelsOnGroundNode; - SGPropertyNode* com1ActiveNode; - SGPropertyNode* com1StandbyNode; - SGPropertyNode* com2ActiveNode; - SGPropertyNode* com2StandbyNode; - SGPropertyNode* transponderCodeNode; - SGPropertyNode* transponderModeNode; - SGPropertyNode* transponderIdentNode; - SGPropertyNode* beaconLightsNode; - SGPropertyNode* landingLightsNode; - SGPropertyNode* navLightsNode; - SGPropertyNode* strobeLightsNode; - SGPropertyNode* taxiLightsNode; - SGPropertyNode* altimeterServiceableNode; - SGPropertyNode* pressAltitudeFtNode; - SGPropertyNode* flapsDeployRatioNode; - SGPropertyNode* gearDeployRatioNode; - SGPropertyNode* speedBrakeDeployRatioNode; - SGPropertyNode* groundElevation; - //SGPropertyNode* numberEnginesNode; - //SGPropertyNode* engineN1PercentageNode; - SGPropertyNode* aircraftNameNode; + SGPropertyNode_ptr textMessageNode; + SGPropertyNode_ptr aircraftModelPathNode; + //SGPropertyNode_ptr aircraftLiveryNode; + //SGPropertyNode_ptr aircraftIcaoCodeNode; + SGPropertyNode_ptr aircraftDescriptionNode; + SGPropertyNode_ptr isPausedNode; + SGPropertyNode_ptr latitudeNode; + SGPropertyNode_ptr longitudeNode; + SGPropertyNode_ptr altitudeMSLNode; + SGPropertyNode_ptr heightAGLNode; + SGPropertyNode_ptr groundSpeedNode; + SGPropertyNode_ptr pitchNode; + SGPropertyNode_ptr rollNode; + SGPropertyNode_ptr trueHeadingNode; + SGPropertyNode_ptr wheelsOnGroundNode; + SGPropertyNode_ptr com1ActiveNode; + SGPropertyNode_ptr com1StandbyNode; + SGPropertyNode_ptr com2ActiveNode; + SGPropertyNode_ptr com2StandbyNode; + SGPropertyNode_ptr transponderCodeNode; + SGPropertyNode_ptr transponderModeNode; + SGPropertyNode_ptr transponderIdentNode; + SGPropertyNode_ptr beaconLightsNode; + SGPropertyNode_ptr landingLightsNode; + SGPropertyNode_ptr navLightsNode; + SGPropertyNode_ptr strobeLightsNode; + SGPropertyNode_ptr taxiLightsNode; + SGPropertyNode_ptr altimeterServiceableNode; + SGPropertyNode_ptr pressAltitudeFtNode; + SGPropertyNode_ptr flapsDeployRatioNode; + SGPropertyNode_ptr gearDeployRatioNode; + SGPropertyNode_ptr speedBrakeDeployRatioNode; + SGPropertyNode_ptr groundElevation; + //SGPropertyNode_ptr numberEnginesNode; + //SGPropertyNode_ptr engineN1PercentageNode; + SGPropertyNode_ptr aircraftNameNode; }; } // namespace FGSwiftBus diff --git a/src/Network/Swift/traffic.cpp b/src/Network/Swift/traffic.cpp index 65aa6b267..854d2e8bf 100644 --- a/src/Network/Swift/traffic.cpp +++ b/src/Network/Swift/traffic.cpp @@ -38,15 +38,13 @@ namespace FGSwiftBus { CTraffic::CTraffic() { - acm = new FGSwiftAircraftManager(); + acm.reset(new FGSwiftAircraftManager()); SG_LOG(SG_NETWORK, SG_INFO, "FGSwiftBus Traffic started"); } CTraffic::~CTraffic() { cleanup(); - delete acm; - acm = nullptr; SG_LOG(SG_NETWORK, SG_INFO, "FGSwiftBus Traffic stopped"); } @@ -64,7 +62,7 @@ const std::string& CTraffic::ObjectPath() void CTraffic::planeLoaded(void* id, bool succeeded, void* self) { - auto* traffic = static_cast(self); + auto traffic = static_cast(self); auto planeIt = traffic->m_planesById.find(id); if (planeIt == traffic->m_planesById.end()) { return; } @@ -255,7 +253,11 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) message.getArgument(altitudeMeters); queueDBusCall([ = ]() { - double elevation = acm->getElevationAtPosition(callsign, latitudeDeg, longitudeDeg, altitudeMeters); + SGGeod pos; + pos.setLatitudeDeg(latitudeDeg); + pos.setLongitudeDeg(longitudeDeg); + pos.setElevationM(altitudeMeters); + double elevation = acm->getElevationAtPosition(callsign, pos); CDBusMessage reply = CDBusMessage::createReply(sender, serial); reply.beginArgumentWrite(); reply.appendArgument(callsign); diff --git a/src/Network/Swift/traffic.h b/src/Network/Swift/traffic.h index 711540a67..bbc040001 100644 --- a/src/Network/Swift/traffic.h +++ b/src/Network/Swift/traffic.h @@ -99,7 +99,7 @@ private: bool m_emitSimFrame = true; - FGSwiftAircraftManager* acm; + std::unique_ptr acm; static void planeLoaded(void* id, bool succeeded, void* self); };