1
0
Fork 0

Minor code fixes

This commit is contained in:
Lars Toenning 2020-03-04 12:42:37 +01:00 committed by James Turner
parent aca625eda2
commit e2135369ce
8 changed files with 69 additions and 65 deletions

View file

@ -42,7 +42,7 @@
#include <Scripting/NasalSys.hxx>
#include <Sound/fg_fx.hxx>
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<double>::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;
}

View file

@ -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<osg::Node> _model;
SGModelPlacement aip;
inline bool operator<(const std::string& extCallsign);

View file

@ -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<std::string, FGSwiftAircraft*>(callsign, curAircraft));
return true;
}
@ -79,9 +79,13 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& 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<double>::quiet_NaN();
}

View file

@ -36,6 +36,6 @@ public:
std::vector<double>& elevationsM, std::vector<double>& 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

View file

@ -82,7 +82,7 @@ void CPlugin::startServer()
float CPlugin::startServerDeferred(float, float, int, void* refcon)
{
auto* plugin = static_cast<CPlugin*>(refcon);
auto plugin = static_cast<CPlugin*>(refcon);
if (!plugin->m_isRunning) {
plugin->startServer();
plugin->m_isRunning = true;

View file

@ -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

View file

@ -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<CTraffic*>(self);
auto traffic = static_cast<CTraffic*>(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);

View file

@ -99,7 +99,7 @@ private:
bool m_emitSimFrame = true;
FGSwiftAircraftManager* acm;
std::unique_ptr<FGSwiftAircraftManager> acm;
static void planeLoaded(void* id, bool succeeded, void* self);
};