1
0
Fork 0

[swift] Code cleanup

This commit is contained in:
Lars Toenning 2020-01-30 09:20:44 +01:00 committed by James Turner
parent 182df4e6ae
commit f4b60ccd90
8 changed files with 30 additions and 38 deletions

View file

@ -42,7 +42,7 @@
#include <Scripting/NasalSys.hxx> #include <Scripting/NasalSys.hxx>
#include <Sound/fg_fx.hxx> #include <Sound/fg_fx.hxx>
FGSwiftAircraft::FGSwiftAircraft(std::string callsign, std::string modelpath, SGPropertyNode* p) FGSwiftAircraft::FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode* p)
{ {
using namespace simgear; using namespace simgear;
_model = SGModelLib::loadModel(modelpath); _model = SGModelLib::loadModel(modelpath);
@ -112,7 +112,7 @@ double FGSwiftAircraft::getFudgeFactor()
return 0; return 0;
} }
inline bool FGSwiftAircraft::operator<(std::string extCallsign) inline bool FGSwiftAircraft::operator<(const std::string& extCallsign)
{ {
return _model->getName().compare(extCallsign); return _model->getName().compare(extCallsign);
} }

View file

@ -41,7 +41,7 @@ class PagedLOD;
class FGSwiftAircraft class FGSwiftAircraft
{ {
public: public:
FGSwiftAircraft(std::string callsign, std::string modelpath, SGPropertyNode* p); FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode* p);
bool updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed); bool updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed);
~FGSwiftAircraft(); ~FGSwiftAircraft();
std::string getName() { return _model->getName(); }; std::string getName() { return _model->getName(); };
@ -55,6 +55,6 @@ private:
SGPropertyNode* props; SGPropertyNode* props;
osg::ref_ptr<osg::Node> _model; osg::ref_ptr<osg::Node> _model;
SGModelPlacement aip; SGModelPlacement aip;
inline bool operator<(std::string extCallsign); inline bool operator<(const std::string& extCallsign);
}; };
#endif #endif

View file

@ -20,16 +20,15 @@
#include "SwiftAircraftManager.h" #include "SwiftAircraftManager.h"
#include "SwiftAircraft.h" #include "SwiftAircraft.h"
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <utility>
FGSwiftAircraftManager::FGSwiftAircraftManager() FGSwiftAircraftManager::FGSwiftAircraftManager()
{ = default;
}
FGSwiftAircraftManager::~FGSwiftAircraftManager() FGSwiftAircraftManager::~FGSwiftAircraftManager()
{ = default;
}
bool FGSwiftAircraftManager::addPlane(std::string callsign, std::string modelString) bool FGSwiftAircraftManager::addPlane(const std::string& callsign, std::string modelString)
{ {
if (aircraftByCallsign.find(callsign) != aircraftByCallsign.end()) if (aircraftByCallsign.find(callsign) != aircraftByCallsign.end())
return false; return false;
@ -46,14 +45,14 @@ bool FGSwiftAircraftManager::addPlane(std::string callsign, std::string modelStr
} }
p = root->getNode(typeString,i,true); p = root->getNode(typeString,i,true);
p->setIntValue("id",i); p->setIntValue("id",i);
FGSwiftAircraft* curAircraft = new FGSwiftAircraft(callsign, modelString, p); auto* curAircraft = new FGSwiftAircraft(callsign, std::move(modelString), p);
aircraftByCallsign.insert(std::pair<std::string, FGSwiftAircraft*>(callsign, curAircraft)); aircraftByCallsign.insert(std::pair<std::string, FGSwiftAircraft*>(callsign, curAircraft));
return true; return true;
} }
void FGSwiftAircraftManager::updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds) void FGSwiftAircraftManager::updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds)
{ {
for (int i = 0; i < callsigns.size(); i++) { for (long unsigned int i = 0; i < callsigns.size(); i++) {
auto it = aircraftByCallsign.find(callsigns.at(i)); auto it = aircraftByCallsign.find(callsigns.at(i));
if (it != aircraftByCallsign.end()) { if (it != aircraftByCallsign.end()) {
it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i)); it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i));
@ -71,15 +70,15 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& cal
elevationsM.clear(); elevationsM.clear();
verticalOffsets.clear(); verticalOffsets.clear();
for (int i = 0; i < requestedCallsigns.size(); i++) { for (const auto & requestedCallsign : requestedCallsigns) {
auto it = aircraftByCallsign.find(requestedCallsigns.at(i)); auto it = aircraftByCallsign.find(requestedCallsign);
if (it != aircraftByCallsign.end()) { if (it != aircraftByCallsign.end()) {
double latDeg = it->second->getLatDeg(); double latDeg = it->second->getLatDeg();
double lonDeg = it->second->getLongDeg(); double lonDeg = it->second->getLongDeg();
double groundElevation = it->second->getGroundElevation(); double groundElevation = it->second->getGroundElevation();
double fudgeFactor = it->second->getFudgeFactor(); double fudgeFactor = it->second->getFudgeFactor();
(void)fudgeFactor;
callsigns.push_back(requestedCallsigns.at(i)); callsigns.push_back(requestedCallsign);
latitudesDeg.push_back(latDeg); latitudesDeg.push_back(latDeg);
longitudesDeg.push_back(lonDeg); longitudesDeg.push_back(lonDeg);
elevationsM.push_back(groundElevation); elevationsM.push_back(groundElevation);
@ -89,7 +88,7 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& cal
} }
void FGSwiftAircraftManager::removePlane(std::string callsign) void FGSwiftAircraftManager::removePlane(const std::string& callsign)
{ {
auto it = aircraftByCallsign.find(callsign); auto it = aircraftByCallsign.find(callsign);
if (it != aircraftByCallsign.end()) { if (it != aircraftByCallsign.end()) {

View file

@ -29,11 +29,11 @@ public:
FGSwiftAircraftManager(); FGSwiftAircraftManager();
~FGSwiftAircraftManager(); ~FGSwiftAircraftManager();
std::map<std::string, FGSwiftAircraft*> aircraftByCallsign; std::map<std::string, FGSwiftAircraft*> aircraftByCallsign;
bool addPlane(std::string callsign, std::string modelString); bool addPlane(const std::string& callsign, std::string modelString);
void updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds); void updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds);
void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg, void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg,
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const; std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
void removePlane(std::string callsign); void removePlane(const std::string& callsign);
void removeAllPlanes(); void removeAllPlanes();
}; };
#endif #endif

View file

@ -19,17 +19,9 @@
#include "service.h" #include "service.h"
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <algorithm>
#include <iostream> #include <iostream>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/io/raw_socket.hxx>
#include <simgear/misc/stdint.hxx>
#include <simgear/props/props.hxx>
#include <simgear/structure/commands.hxx> #include <simgear/structure/commands.hxx>
#include <simgear/structure/event_mgr.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/timing/timestamp.hxx>
#define FGSWIFTBUS_API_VERSION 1; #define FGSWIFTBUS_API_VERSION 1;
@ -169,22 +161,22 @@ bool CService::getAllWheelsOnGround() const
int CService::getCom1Active() const int CService::getCom1Active() const
{ {
return com1ActiveNode->getDoubleValue() * 1000; return (int)com1ActiveNode->getDoubleValue() * 1000;
} }
int CService::getCom1Standby() const int CService::getCom1Standby() const
{ {
return com1StandbyNode->getDoubleValue() * 1000; return (int)com1StandbyNode->getDoubleValue() * 1000;
} }
int CService::getCom2Active() const int CService::getCom2Active() const
{ {
return com2ActiveNode->getDoubleValue() * 1000; return (int)com2ActiveNode->getDoubleValue() * 1000;
} }
int CService::getCom2Standby() const int CService::getCom2Standby() const
{ {
return com2StandbyNode->getDoubleValue() * 1000; return (int)com2StandbyNode->getDoubleValue() * 1000;
} }
int CService::getTransponderCode() const int CService::getTransponderCode() const

View file

@ -51,7 +51,8 @@ bool SwiftConnection::startServer(const SGPropertyNode* arg, SGPropertyNode* roo
bool SwiftConnection::stopServer(const SGPropertyNode* arg, SGPropertyNode* root) bool SwiftConnection::stopServer(const SGPropertyNode* arg, SGPropertyNode* root)
{ {
SwiftConnection::plug->~CPlugin(); delete SwiftConnection::plug;
SwiftConnection::plug = nullptr;
fgSetBool("/sim/swift/serverRunning", false); fgSetBool("/sim/swift/serverRunning", false);
serverRunning = false; serverRunning = false;
return true; return true;
@ -68,9 +69,9 @@ SwiftConnection::~SwiftConnection()
shutdown(); shutdown();
} }
void SwiftConnection::init(void) void SwiftConnection::init()
{ {
if (initialized == false) { if (!initialized) {
globals->get_commands()->addCommand("swiftStart", this, &SwiftConnection::startServer); globals->get_commands()->addCommand("swiftStart", this, &SwiftConnection::startServer);
globals->get_commands()->addCommand("swiftStop", this, &SwiftConnection::stopServer); globals->get_commands()->addCommand("swiftStop", this, &SwiftConnection::stopServer);
fgSetBool("/sim/swift/available", true); fgSetBool("/sim/swift/available", true);
@ -81,14 +82,14 @@ void SwiftConnection::init(void)
void SwiftConnection::update(double delta_time_sec) void SwiftConnection::update(double delta_time_sec)
{ {
if (serverRunning == true) { if (serverRunning) {
SwiftConnection::plug->fastLoop(); SwiftConnection::plug->fastLoop();
} }
} }
void SwiftConnection::shutdown(void) void SwiftConnection::shutdown()
{ {
if (initialized == true) { if (initialized) {
globals->get_commands()->removeCommand("swiftStart"); globals->get_commands()->removeCommand("swiftStart");
globals->get_commands()->removeCommand("swiftStop"); globals->get_commands()->removeCommand("swiftStop");
fgSetBool("/sim/swift/available", false); fgSetBool("/sim/swift/available", false);

View file

@ -52,7 +52,7 @@ public:
bool startServer(const SGPropertyNode* arg, SGPropertyNode* root); bool startServer(const SGPropertyNode* arg, SGPropertyNode* root);
bool stopServer(const SGPropertyNode* arg, SGPropertyNode* root); bool stopServer(const SGPropertyNode* arg, SGPropertyNode* root);
FGSwiftBus::CPlugin* plug; FGSwiftBus::CPlugin* plug{};
private: private:
bool serverRunning = false; bool serverRunning = false;

View file

@ -209,7 +209,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
queueDBusCall([=]() { queueDBusCall([=]() {
std::vector<SGGeod> positions; std::vector<SGGeod> positions;
std::vector<SGVec3d> orientations; std::vector<SGVec3d> orientations;
for (int i = 0; i < latitudes.size(); i++) { for (long unsigned int i = 0; i < latitudes.size(); i++) {
SGGeod newPos; SGGeod newPos;
newPos.setLatitudeDeg(latitudes.at(i)); newPos.setLatitudeDeg(latitudes.at(i));
newPos.setLongitudeDeg(longitudes.at(i)); newPos.setLongitudeDeg(longitudes.at(i));