1
0
Fork 0

[swift] Fix coding style

This commit is contained in:
Lars Toenning 2020-07-18 18:55:37 +02:00 committed by James Turner
parent d78b19546a
commit cdacea1315
5 changed files with 93 additions and 62 deletions

View file

@ -65,27 +65,24 @@ double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const
return std::numeric_limits<double>::quiet_NaN(); return std::numeric_limits<double>::quiet_NaN();
} }
void FGAISwiftAircraft::setPlaneSurface(double gear, double flaps, double spoilers, double speedBrake, double slats, void FGAISwiftAircraft::setPlaneSurface(const AircraftSurfaces& surfaces)
double wingSweeps, double thrust, double elevator, double rudder, double aileron,
bool landingLight, bool taxiLight, bool beaconLight, bool strobeLight, bool navLight,
int lightPattern)
{ {
m_gearNode->setDoubleValue(gear); m_gearNode->setDoubleValue(surfaces.gear);
m_flapsIdentNode->setDoubleValue(flaps); m_flapsIdentNode->setDoubleValue(surfaces.flaps);
m_spoilerNode->setDoubleValue(spoilers); m_spoilerNode->setDoubleValue(surfaces.spoilers);
m_speedBrakeNode->setDoubleValue(speedBrake); m_speedBrakeNode->setDoubleValue(surfaces.spoilers);
m_landLightNode->setBoolValue(landingLight); m_landLightNode->setBoolValue(surfaces.landingLight);
m_taxiLightNode->setBoolValue(taxiLight); m_taxiLightNode->setBoolValue(surfaces.taxiLight);
m_beaconLightNode->setBoolValue(beaconLight); m_beaconLightNode->setBoolValue(surfaces.beaconLight);
m_strobeLightNode->setBoolValue(strobeLight); m_strobeLightNode->setBoolValue(surfaces.strobeLight);
m_navLightNode->setBoolValue(navLight); 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_transponderCodeNode->setIntValue(transponder.code);
m_transponderCModeNode->setBoolValue(modeC); m_transponderCModeNode->setBoolValue(transponder.modeC);
m_transponderIdentNode->setBoolValue(ident); m_transponderIdentNode->setBoolValue(transponder.ident);
} }
void FGAISwiftAircraft::initProps() void FGAISwiftAircraft::initProps()
@ -95,22 +92,16 @@ void FGAISwiftAircraft::initProps()
m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true); m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true);
m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true); m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true);
m_gearNode = _getProps()->getNode("controls/gear/gear-down", true); m_gearNode = _getProps()->getNode("swift/gear/gear-down", true);
m_flapsIdentNode = _getProps()->getNode("controls/flight/flaps", true); m_flapsIdentNode = _getProps()->getNode("swift/flight/flaps", true);
m_spoilerNode = _getProps()->getNode("controls/flight/spoilers", true); m_spoilerNode = _getProps()->getNode("swift/flight/spoilers", true);
m_speedBrakeNode = _getProps()->getNode("controls/flight/speedbrake", true); m_speedBrakeNode = _getProps()->getNode("swift/flight/speedbrake", true);
m_landLightNode = _getProps()->getNode("controls/lighting/landing-lights", true);
// Untie NavLight property for explicit control (tied within FGAIBase) m_landLightNode = _getProps()->getNode("swift/lighting/landing-lights", true);
m_navLightNode = _getProps()->getNode("controls/lighting/nav-lights", true); m_navLightNode = _getProps()->getNode("swift/lighting/nav-lights", true);
if(m_navLightNode) m_taxiLightNode = _getProps()->getNode("swift/lighting/taxi-light", true);
{ m_beaconLightNode = _getProps()->getNode("swift/lighting/beacon", true);
m_navLightNode->untie(); m_strobeLightNode = _getProps()->getNode("swift/lighting/strobe", true);
}
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);
} }
FGAISwiftAircraft::~FGAISwiftAircraft() = default; FGAISwiftAircraft::~FGAISwiftAircraft() = default;

View file

@ -23,9 +23,51 @@
#include "AIBase.hxx" #include "AIBase.hxx"
#include <string> #include <string>
#include <utility>
using charPtr = const char*; 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 class FGAISwiftAircraft : public FGAIBase
{ {
@ -36,11 +78,8 @@ public:
void update(double dt) override; void update(double dt) override;
double getGroundElevation(const SGGeod& pos) const; double getGroundElevation(const SGGeod& pos) const;
void initProps(); void initProps();
void setPlaneSurface(double gear, double flaps, double spoilers, double speedBrake, double slats, void setPlaneSurface(const AircraftSurfaces& surfaces);
double wingSweeps, double thrust, double elevator, double rudder, double aileron, void setPlaneTransponder(const AircraftTransponder& transponder);
bool landingLight, bool taxiLight, bool beaconLight, bool strobeLight, bool navLight,
int lightPattern);
void setPlaneTransponder(int code, bool modeC, bool ident);
const char* getTypeString() const override { return "swift"; } const char* getTypeString() const override { return "swift"; }

View file

@ -126,33 +126,26 @@ double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsig
return std::numeric_limits<double>::quiet_NaN(); return std::numeric_limits<double>::quiet_NaN();
} }
void FGSwiftAircraftManager::setPlanesTransponders(std::vector<std::string> callsigns, std::vector<int> codes, std::vector<bool> modeCs, std::vector<bool> idents) void FGSwiftAircraftManager::setPlanesTransponders(const std::vector<AircraftTransponder>& 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()) 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<std::string> callsigns, std::vector<double> gears, std::vector<double> flaps, void FGSwiftAircraftManager::setPlanesSurfaces(const std::vector<AircraftSurfaces>& surfaces)
std::vector<double> spoilers ,std::vector<double> speedBrakes, std::vector<double> slats,
std::vector<double> wingSweeps, std::vector<double> thrusts, std::vector<double> elevators,
std::vector<double> rudders, std::vector<double> ailerons, std::vector<bool> landLights,
std::vector<bool> taxiLights, std::vector<bool> beaconLights, std::vector<bool> strobeLights,
std::vector<bool> navLights, std::vector<int> lightPatterns)
{ {
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()) 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), it->second->setPlaneSurface(surface);
rudders.at(i), ailerons.at(i), landLights.at(i), taxiLights.at(i), beaconLights.at(i), strobeLights.at(i), navLights.at(i),
lightPatterns.at(i));
} }
} }
} }

View file

@ -38,15 +38,10 @@ public:
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const; std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
void removePlane(const std::string& callsign); void removePlane(const std::string& callsign);
void removeAllPlanes(); void removeAllPlanes();
void setPlanesTransponders(std::vector<std::string> callsigns, std::vector<int> codes, std::vector<bool> modeCs, std::vector<bool> idents); void setPlanesTransponders(const std::vector<AircraftTransponder>& transponders);
double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const; double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const;
bool isInitialized() const; bool isInitialized() const;
void setPlanesSurfaces(std::vector<std::string> callsigns, std::vector<double> gears, std::vector<double> flaps, void setPlanesSurfaces(const std::vector<AircraftSurfaces>& surfaces);
std::vector<double> spoilers ,std::vector<double> speedBrakes, std::vector<double> slats,
std::vector<double> wingSweeps, std::vector<double> thrusts, std::vector<double> elevators,
std::vector<double> rudders, std::vector<double> ailerons, std::vector<bool> landLights,
std::vector<bool> taxiLights, std::vector<bool> beaconLights, std::vector<bool> strobeLights,
std::vector<bool> navLights, std::vector<int> lightPatterns);
private: private:
std::unordered_map<std::string, FGAISwiftAircraft*> aircraftByCallsign; std::unordered_map<std::string, FGAISwiftAircraft*> aircraftByCallsign;

View file

@ -241,9 +241,15 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(codes); message.getArgument(codes);
message.getArgument(modeCs); message.getArgument(modeCs);
message.getArgument(idents); message.getArgument(idents);
std::vector<AircraftTransponder> 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([ = ]() queueDBusCall([ = ]()
{ {
acm->setPlanesTransponders(callsigns, codes, modeCs, idents); acm->setPlanesTransponders(transponders);
}); });
} else if (message.getMethodName() == "setPlanesSurfaces") } else if (message.getMethodName() == "setPlanesSurfaces")
{ {
@ -283,10 +289,17 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(strobeLights); message.getArgument(strobeLights);
message.getArgument(navLights); message.getArgument(navLights);
message.getArgument(lightPatterns); message.getArgument(lightPatterns);
std::vector<AircraftSurfaces> 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([ = ]() queueDBusCall([ = ]()
{ {
acm->setPlanesSurfaces(callsigns, gears, flaps, spoilers, speedBrakes, slats, wingSweeps, thrusts, elevators, acm->setPlanesSurfaces(surfaces);
rudders, ailerons, landLights, taxiLights, beaconLights, strobeLights, navLights, lightPatterns);
}); });
} else { } else {
// Unknown message. Tell DBus that we cannot handle it // Unknown message. Tell DBus that we cannot handle it