From cdacea131509cff1c0c4d368d3e3ef7716aa2b05 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Sat, 18 Jul 2020 18:55:37 +0200 Subject: [PATCH] [swift] Fix coding style --- src/AIModel/AISwiftAircraft.cpp | 55 +++++++++------------- src/AIModel/AISwiftAircraft.h | 49 +++++++++++++++++-- src/Network/Swift/SwiftAircraftManager.cpp | 23 ++++----- src/Network/Swift/SwiftAircraftManager.h | 9 +--- src/Network/Swift/traffic.cpp | 19 ++++++-- 5 files changed, 93 insertions(+), 62 deletions(-) diff --git a/src/AIModel/AISwiftAircraft.cpp b/src/AIModel/AISwiftAircraft.cpp index 1ae7461e1..5b94fb2dc 100644 --- a/src/AIModel/AISwiftAircraft.cpp +++ b/src/AIModel/AISwiftAircraft.cpp @@ -65,27 +65,24 @@ double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const return std::numeric_limits::quiet_NaN(); } -void FGAISwiftAircraft::setPlaneSurface(double gear, double flaps, double spoilers, double speedBrake, double slats, - double wingSweeps, double thrust, double elevator, double rudder, double aileron, - bool landingLight, bool taxiLight, bool beaconLight, bool strobeLight, bool navLight, - int lightPattern) +void FGAISwiftAircraft::setPlaneSurface(const AircraftSurfaces& surfaces) { - m_gearNode->setDoubleValue(gear); - m_flapsIdentNode->setDoubleValue(flaps); - m_spoilerNode->setDoubleValue(spoilers); - m_speedBrakeNode->setDoubleValue(speedBrake); - m_landLightNode->setBoolValue(landingLight); - m_taxiLightNode->setBoolValue(taxiLight); - m_beaconLightNode->setBoolValue(beaconLight); - m_strobeLightNode->setBoolValue(strobeLight); - m_navLightNode->setBoolValue(navLight); + m_gearNode->setDoubleValue(surfaces.gear); + m_flapsIdentNode->setDoubleValue(surfaces.flaps); + m_spoilerNode->setDoubleValue(surfaces.spoilers); + m_speedBrakeNode->setDoubleValue(surfaces.spoilers); + m_landLightNode->setBoolValue(surfaces.landingLight); + m_taxiLightNode->setBoolValue(surfaces.taxiLight); + m_beaconLightNode->setBoolValue(surfaces.beaconLight); + m_strobeLightNode->setBoolValue(surfaces.strobeLight); + m_navLightNode->setBoolValue(surfaces.navLight); } -void FGAISwiftAircraft::setPlaneTransponder(int code, bool modeC, bool ident) +void FGAISwiftAircraft::setPlaneTransponder(const AircraftTransponder& transponder) { - m_transponderCodeNode->setIntValue(code); - m_transponderCModeNode->setBoolValue(modeC); - m_transponderIdentNode->setBoolValue(ident); + m_transponderCodeNode->setIntValue(transponder.code); + m_transponderCModeNode->setBoolValue(transponder.modeC); + m_transponderIdentNode->setBoolValue(transponder.ident); } void FGAISwiftAircraft::initProps() @@ -95,22 +92,16 @@ void FGAISwiftAircraft::initProps() m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true); m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true); - m_gearNode = _getProps()->getNode("controls/gear/gear-down", true); - m_flapsIdentNode = _getProps()->getNode("controls/flight/flaps", true); - m_spoilerNode = _getProps()->getNode("controls/flight/spoilers", true); - m_speedBrakeNode = _getProps()->getNode("controls/flight/speedbrake", true); - m_landLightNode = _getProps()->getNode("controls/lighting/landing-lights", true); + m_gearNode = _getProps()->getNode("swift/gear/gear-down", true); + m_flapsIdentNode = _getProps()->getNode("swift/flight/flaps", true); + m_spoilerNode = _getProps()->getNode("swift/flight/spoilers", true); + m_speedBrakeNode = _getProps()->getNode("swift/flight/speedbrake", true); - // Untie NavLight property for explicit control (tied within FGAIBase) - m_navLightNode = _getProps()->getNode("controls/lighting/nav-lights", true); - if(m_navLightNode) - { - m_navLightNode->untie(); - } - - m_taxiLightNode = _getProps()->getNode("controls/lighting/taxi-light", true); - m_beaconLightNode = _getProps()->getNode("controls/lighting/beacon", true); - m_strobeLightNode = _getProps()->getNode("controls/lighting/strobe", true); + m_landLightNode = _getProps()->getNode("swift/lighting/landing-lights", true); + m_navLightNode = _getProps()->getNode("swift/lighting/nav-lights", true); + m_taxiLightNode = _getProps()->getNode("swift/lighting/taxi-light", true); + m_beaconLightNode = _getProps()->getNode("swift/lighting/beacon", true); + m_strobeLightNode = _getProps()->getNode("swift/lighting/strobe", true); } FGAISwiftAircraft::~FGAISwiftAircraft() = default; diff --git a/src/AIModel/AISwiftAircraft.h b/src/AIModel/AISwiftAircraft.h index a313219ee..998ce0351 100644 --- a/src/AIModel/AISwiftAircraft.h +++ b/src/AIModel/AISwiftAircraft.h @@ -23,9 +23,51 @@ #include "AIBase.hxx" #include +#include using charPtr = const char*; +struct AircraftTransponder +{ + AircraftTransponder(std::string callsign, int code, bool modeC, bool ident) + : callsign(std::move(callsign)), code(code), modeC(modeC), ident(ident) + {} + + std::string callsign; + int code; + bool modeC; + bool ident; +}; + +struct AircraftSurfaces +{ + AircraftSurfaces(std::string callsign, double gear, double flaps, double spoilers, double speedBrake, double slats, double wingSweeps, + double thrust, double elevator, double rudder, double aileron, bool landingLight, bool taxiLight, bool beaconLight, + bool strobeLight, bool navLight, int lightPattern) + : callsign(std::move(callsign)), gear(gear), flaps(flaps), spoilers(spoilers), speedBrake(speedBrake), slats(slats), wingSweeps(wingSweeps), + thrust(thrust), elevator(elevator), rudder(rudder), aileron(aileron), landingLight(landingLight), taxiLight(taxiLight), beaconLight(beaconLight), + strobeLight(strobeLight), navLight(navLight), lightPattern(lightPattern){} + + std::string callsign; + double gear; + double flaps; + double spoilers; + double speedBrake; + double slats; + double wingSweeps; + double thrust; + double elevator; + double rudder; + double aileron; + bool landingLight; + bool taxiLight; + bool beaconLight; + bool strobeLight; + bool navLight; + int lightPattern; +}; + + class FGAISwiftAircraft : public FGAIBase { @@ -36,11 +78,8 @@ public: void update(double dt) override; double getGroundElevation(const SGGeod& pos) const; void initProps(); - void setPlaneSurface(double gear, double flaps, double spoilers, double speedBrake, double slats, - double wingSweeps, double thrust, double elevator, double rudder, double aileron, - bool landingLight, bool taxiLight, bool beaconLight, bool strobeLight, bool navLight, - int lightPattern); - void setPlaneTransponder(int code, bool modeC, bool ident); + void setPlaneSurface(const AircraftSurfaces& surfaces); + void setPlaneTransponder(const AircraftTransponder& transponder); const char* getTypeString() const override { return "swift"; } diff --git a/src/Network/Swift/SwiftAircraftManager.cpp b/src/Network/Swift/SwiftAircraftManager.cpp index 07b217f72..c2bdde941 100644 --- a/src/Network/Swift/SwiftAircraftManager.cpp +++ b/src/Network/Swift/SwiftAircraftManager.cpp @@ -126,33 +126,26 @@ double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsig return std::numeric_limits::quiet_NaN(); } -void FGSwiftAircraftManager::setPlanesTransponders(std::vector callsigns, std::vector codes, std::vector modeCs, std::vector idents) +void FGSwiftAircraftManager::setPlanesTransponders(const std::vector& transponders) { - for (long unsigned int i = 0; i < callsigns.size(); i++) + for (const auto & transponder : transponders) { - auto it = aircraftByCallsign.find(callsigns.at(i)); + auto it = aircraftByCallsign.find(transponder.callsign); if(it != aircraftByCallsign.end()) { - it->second->setPlaneTransponder(codes.at(i), modeCs.at(i), idents.at(i)); + it->second->setPlaneTransponder(transponder); } } } -void FGSwiftAircraftManager::setPlanesSurfaces(std::vector callsigns, std::vector gears, std::vector flaps, - std::vector spoilers ,std::vector speedBrakes, std::vector slats, - std::vector wingSweeps, std::vector thrusts, std::vector elevators, - std::vector rudders, std::vector ailerons, std::vector landLights, - std::vector taxiLights, std::vector beaconLights, std::vector strobeLights, - std::vector navLights, std::vector lightPatterns) +void FGSwiftAircraftManager::setPlanesSurfaces(const std::vector& surfaces) { - for (long unsigned int i = 0; i < callsigns.size(); i++) + for (const auto & surface : surfaces) { - auto it = aircraftByCallsign.find(callsigns.at(i)); + auto it = aircraftByCallsign.find(surface.callsign); if(it != aircraftByCallsign.end()) { - it->second->setPlaneSurface(gears.at(i), flaps.at(i), spoilers.at(i), speedBrakes.at(i), slats.at(i), wingSweeps.at(i), thrusts.at(i), elevators.at(i), - rudders.at(i), ailerons.at(i), landLights.at(i), taxiLights.at(i), beaconLights.at(i), strobeLights.at(i), navLights.at(i), - lightPatterns.at(i)); + it->second->setPlaneSurface(surface); } } } diff --git a/src/Network/Swift/SwiftAircraftManager.h b/src/Network/Swift/SwiftAircraftManager.h index deb7cb674..6ebb9e273 100644 --- a/src/Network/Swift/SwiftAircraftManager.h +++ b/src/Network/Swift/SwiftAircraftManager.h @@ -38,15 +38,10 @@ public: std::vector& elevationsM, std::vector& verticalOffsets) const; void removePlane(const std::string& callsign); void removeAllPlanes(); - void setPlanesTransponders(std::vector callsigns, std::vector codes, std::vector modeCs, std::vector idents); + void setPlanesTransponders(const std::vector& transponders); double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const; bool isInitialized() const; - void setPlanesSurfaces(std::vector callsigns, std::vector gears, std::vector flaps, - std::vector spoilers ,std::vector speedBrakes, std::vector slats, - std::vector wingSweeps, std::vector thrusts, std::vector elevators, - std::vector rudders, std::vector ailerons, std::vector landLights, - std::vector taxiLights, std::vector beaconLights, std::vector strobeLights, - std::vector navLights, std::vector lightPatterns); + void setPlanesSurfaces(const std::vector& surfaces); private: std::unordered_map aircraftByCallsign; diff --git a/src/Network/Swift/traffic.cpp b/src/Network/Swift/traffic.cpp index cc208a7f5..ecfe4b749 100644 --- a/src/Network/Swift/traffic.cpp +++ b/src/Network/Swift/traffic.cpp @@ -241,9 +241,15 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) message.getArgument(codes); message.getArgument(modeCs); message.getArgument(idents); + std::vector transponders; + transponders.reserve(callsigns.size()); + for(long unsigned int i = 0; i < callsigns.size(); i++) + { + transponders.emplace_back(callsigns.at(i), codes.at(i), modeCs.at(i), idents.at(i)); + } queueDBusCall([ = ]() { - acm->setPlanesTransponders(callsigns, codes, modeCs, idents); + acm->setPlanesTransponders(transponders); }); } else if (message.getMethodName() == "setPlanesSurfaces") { @@ -283,10 +289,17 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) message.getArgument(strobeLights); message.getArgument(navLights); message.getArgument(lightPatterns); + std::vector surfaces; + surfaces.reserve(callsigns.size()); + for(long unsigned int i = 0; i < callsigns.size(); i++) + { + surfaces.emplace_back(callsigns.at(i), gears.at(i), flaps.at(i), spoilers.at(i), speedBrakes.at(i), slats.at(i), + wingSweeps.at(i), thrusts.at(i), elevators.at(i), rudders.at(i), ailerons.at(i), + landLights.at(i), taxiLights.at(i), beaconLights.at(i), strobeLights.at(i), navLights.at(i), lightPatterns.at(i)); + } queueDBusCall([ = ]() { - acm->setPlanesSurfaces(callsigns, gears, flaps, spoilers, speedBrakes, slats, wingSweeps, thrusts, elevators, - rudders, ailerons, landLights, taxiLights, beaconLights, strobeLights, navLights, lightPatterns); + acm->setPlanesSurfaces(surfaces); }); } else { // Unknown message. Tell DBus that we cannot handle it