[swift] Add parts support
This commit is contained in:
parent
3893754537
commit
d78b19546a
6 changed files with 180 additions and 4 deletions
|
@ -32,6 +32,7 @@ FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::str
|
|||
setCallSign(callsign);
|
||||
_searchOrder = PREFER_AI;
|
||||
}
|
||||
|
||||
void FGAISwiftAircraft::updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos)
|
||||
{
|
||||
m_initPos = initPos;
|
||||
|
@ -50,6 +51,7 @@ void FGAISwiftAircraft::update(double dt)
|
|||
FGAIBase::update(dt);
|
||||
Transform();
|
||||
}
|
||||
|
||||
double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const
|
||||
{
|
||||
if(!m_initPos) { return std::numeric_limits<double>::quiet_NaN(); }
|
||||
|
@ -62,4 +64,53 @@ double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const
|
|||
return alt;
|
||||
return std::numeric_limits<double>::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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void FGAISwiftAircraft::setPlaneTransponder(int code, bool modeC, bool ident)
|
||||
{
|
||||
m_transponderCodeNode->setIntValue(code);
|
||||
m_transponderCModeNode->setBoolValue(modeC);
|
||||
m_transponderIdentNode->setBoolValue(ident);
|
||||
}
|
||||
|
||||
void FGAISwiftAircraft::initProps()
|
||||
{
|
||||
// Setup node properties
|
||||
m_transponderCodeNode = _getProps()->getNode("swift/transponder/code", true);
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
FGAISwiftAircraft::~FGAISwiftAircraft() = default;
|
||||
|
|
|
@ -35,11 +35,39 @@ public:
|
|||
void updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos);
|
||||
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);
|
||||
|
||||
const char* getTypeString() const override { return "swift"; }
|
||||
|
||||
private:
|
||||
bool m_initPos = false;
|
||||
// Property Nodes for transponder and parts
|
||||
SGPropertyNode_ptr m_transponderCodeNode;
|
||||
SGPropertyNode_ptr m_transponderCModeNode;
|
||||
SGPropertyNode_ptr m_transponderIdentNode;
|
||||
|
||||
SGPropertyNode_ptr m_gearNode;
|
||||
SGPropertyNode_ptr m_flapsIdentNode;
|
||||
SGPropertyNode_ptr m_spoilerNode;
|
||||
SGPropertyNode_ptr m_speedBrakeNode;
|
||||
//SGPropertyNode_ptr m_slatsNode;
|
||||
//SGPropertyNode_ptr m_wingSweepNode;
|
||||
//SGPropertyNode_ptr m_thrustNode;
|
||||
//SGPropertyNode_ptr m_elevatorNode;
|
||||
//SGPropertyNode_ptr m_rudderNode;
|
||||
//SGPropertyNode_ptr m_aileronNode;
|
||||
SGPropertyNode_ptr m_landLightNode;
|
||||
SGPropertyNode_ptr m_taxiLightNode;
|
||||
SGPropertyNode_ptr m_beaconLightNode;
|
||||
SGPropertyNode_ptr m_strobeLightNode;
|
||||
SGPropertyNode_ptr m_navLightNode;
|
||||
//SGPropertyNode_ptr m_lightPatternNode;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ bool FGSwiftAircraftManager::addPlane(const std::string& callsign, const std::st
|
|||
this->removePlane(callsign); // Remove plane if already exists e.g. when rematching is done.
|
||||
auto curAircraft = new FGAISwiftAircraft(callsign, modelString);
|
||||
globals->get_subsystem<FGAIManager>()->attach(curAircraft);
|
||||
// Init props after prop-root is assigned
|
||||
curAircraft->initProps();
|
||||
|
||||
aircraftByCallsign.insert(std::pair<std::string, FGAISwiftAircraft*>(callsign, curAircraft));
|
||||
return true;
|
||||
|
@ -123,3 +125,34 @@ double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsig
|
|||
// Aircraft not found in list
|
||||
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)
|
||||
{
|
||||
for (long unsigned int i = 0; i < callsigns.size(); i++)
|
||||
{
|
||||
auto it = aircraftByCallsign.find(callsigns.at(i));
|
||||
if(it != aircraftByCallsign.end())
|
||||
{
|
||||
it->second->setPlaneTransponder(codes.at(i), modeCs.at(i), idents.at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FGSwiftAircraftManager::setPlanesSurfaces(std::vector<std::string> callsigns, std::vector<double> gears, std::vector<double> flaps,
|
||||
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++)
|
||||
{
|
||||
auto it = aircraftByCallsign.find(callsigns.at(i));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,15 @@ public:
|
|||
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
|
||||
void removePlane(const std::string& callsign);
|
||||
void removeAllPlanes();
|
||||
void setPlanesTransponders(std::vector<std::string> callsigns, std::vector<int> codes, std::vector<bool> modeCs, std::vector<bool> idents);
|
||||
double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const;
|
||||
bool isInitialized() const;
|
||||
void setPlanesSurfaces(std::vector<std::string> callsigns, std::vector<double> gears, std::vector<double> flaps,
|
||||
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:
|
||||
std::unordered_map<std::string, FGAISwiftAircraft*> aircraftByCallsign;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/structure/commands.hxx>
|
||||
|
||||
#define FGSWIFTBUS_API_VERSION 1;
|
||||
#define FGSWIFTBUS_API_VERSION 2;
|
||||
|
||||
namespace FGSwiftBus {
|
||||
|
||||
|
|
|
@ -94,7 +94,6 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
|
|||
const std::string sender = message.getSender();
|
||||
const dbus_uint32_t serial = message.getSerial();
|
||||
const bool wantsReply = message.wantsReply();
|
||||
std::string test = message.getMethodName();
|
||||
|
||||
if (message.getInterfaceName() == DBUS_INTERFACE_INTROSPECTABLE) {
|
||||
if (message.getMethodName() == "Introspect") {
|
||||
|
@ -206,8 +205,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
|
|||
reply.appendArgument(verticalOffsets);
|
||||
sendDBusMessage(reply);
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "getElevationAtPosition")
|
||||
} else if (message.getMethodName() == "getElevationAtPosition")
|
||||
{
|
||||
std::string callsign;
|
||||
double latitudeDeg;
|
||||
|
@ -231,6 +229,65 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
|
|||
reply.appendArgument(elevation);
|
||||
sendDBusMessage(reply);
|
||||
});
|
||||
} else if (message.getMethodName() == "setPlanesTransponders")
|
||||
{
|
||||
maybeSendEmptyDBusReply(wantsReply, sender, serial);
|
||||
std::vector<std::string> callsigns;
|
||||
std::vector<int> codes;
|
||||
std::vector<bool> modeCs;
|
||||
std::vector<bool> idents;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(callsigns);
|
||||
message.getArgument(codes);
|
||||
message.getArgument(modeCs);
|
||||
message.getArgument(idents);
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
acm->setPlanesTransponders(callsigns, codes, modeCs, idents);
|
||||
});
|
||||
} else if (message.getMethodName() == "setPlanesSurfaces")
|
||||
{
|
||||
maybeSendEmptyDBusReply(wantsReply, sender, serial);
|
||||
std::vector<std::string> callsigns;
|
||||
std::vector<double> gears;
|
||||
std::vector<double> flaps;
|
||||
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;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(callsigns);
|
||||
message.getArgument(gears);
|
||||
message.getArgument(flaps);
|
||||
message.getArgument(spoilers);
|
||||
message.getArgument(speedBrakes);
|
||||
message.getArgument(slats);
|
||||
message.getArgument(wingSweeps);
|
||||
message.getArgument(thrusts);
|
||||
message.getArgument(elevators);
|
||||
message.getArgument(rudders);
|
||||
message.getArgument(ailerons);
|
||||
message.getArgument(landLights);
|
||||
message.getArgument(taxiLights);
|
||||
message.getArgument(beaconLights);
|
||||
message.getArgument(strobeLights);
|
||||
message.getArgument(navLights);
|
||||
message.getArgument(lightPatterns);
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
acm->setPlanesSurfaces(callsigns, gears, flaps, spoilers, speedBrakes, slats, wingSweeps, thrusts, elevators,
|
||||
rudders, ailerons, landLights, taxiLights, beaconLights, strobeLights, navLights, lightPatterns);
|
||||
});
|
||||
} else {
|
||||
// Unknown message. Tell DBus that we cannot handle it
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
|
|
Loading…
Reference in a new issue