[swift] Pass struct to updatePlanes() instead of multiple vectors
This commit is contained in:
parent
e35c24af99
commit
2ccd9bfb30
6 changed files with 26 additions and 21 deletions
|
@ -33,7 +33,7 @@ FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::str
|
|||
_searchOrder = ModelSearchOrder::PREFER_AI;
|
||||
}
|
||||
|
||||
void FGAISwiftAircraft::updatePosition(const SGGeod &position, const SGVec3<double> &orientation, double groundspeed, bool initPos)
|
||||
void FGAISwiftAircraft::updatePosition(const SGGeod &position, const SGVec3d &orientation, double groundspeed, bool initPos)
|
||||
{
|
||||
m_initPos = initPos;
|
||||
_setLatitude(position.getLatitudeDeg());
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
string_view getTypeString() const override { return "swift"; }
|
||||
void update(double dt) override;
|
||||
|
||||
void updatePosition(const SGGeod &position, const SGVec3<double> &orientation, double groundspeed, bool initPos);
|
||||
void updatePosition(const SGGeod &position, const SGVec3d &orientation, double groundspeed, bool initPos);
|
||||
double getGroundElevation(const SGGeod& pos) const;
|
||||
void initProps();
|
||||
void setPlaneSurface(const AircraftSurfaces& surfaces);
|
||||
|
|
|
@ -37,12 +37,12 @@ bool FGSwiftAircraftManager::addPlane(const std::string& callsign, const std::st
|
|||
return true;
|
||||
}
|
||||
|
||||
void FGSwiftAircraftManager::updatePlanes(const std::vector<std::string>& callsigns, const std::vector<SGGeod>& positions, const std::vector<SGVec3d>& orientations, const std::vector<double>& groundspeeds, const std::vector<bool>& onGrounds)
|
||||
void FGSwiftAircraftManager::updatePlanes(const std::vector<SwiftPlaneUpdate>& updates)
|
||||
{
|
||||
for (long unsigned int i = 0; i < callsigns.size(); i++) {
|
||||
auto it = aircraftByCallsign.find(callsigns.at(i));
|
||||
for (auto& update : updates) {
|
||||
auto it = aircraftByCallsign.find(update.callsign);
|
||||
if (it != aircraftByCallsign.end()) {
|
||||
it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i), true);
|
||||
it->second->updatePosition(update.position, update.orientation, update.groundspeed, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,14 @@
|
|||
#ifndef FGSWIFTAIRCRAFTMANAGER_H
|
||||
#define FGSWIFTAIRCRAFTMANAGER_H
|
||||
|
||||
struct SwiftPlaneUpdate {
|
||||
std::string callsign;
|
||||
SGGeod position;
|
||||
SGVec3d orientation;
|
||||
double groundspeed;
|
||||
bool onGround;
|
||||
};
|
||||
|
||||
class FGSwiftAircraftManager
|
||||
{
|
||||
using FGAISwiftAircraftPtr = SGSharedPtr<FGAISwiftAircraft>;
|
||||
|
@ -23,7 +31,7 @@ public:
|
|||
FGSwiftAircraftManager();
|
||||
~FGSwiftAircraftManager();
|
||||
bool addPlane(const std::string& callsign, const std::string& modelString);
|
||||
void updatePlanes(const std::vector<std::string>& callsigns, const std::vector<SGGeod>& positions, const std::vector<SGVec3d>& orientations, const std::vector<double>& groundspeeds, const std::vector<bool>& onGrounds);
|
||||
void updatePlanes(const std::vector<SwiftPlaneUpdate>& updates);
|
||||
void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg,
|
||||
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
|
||||
void removePlane(const std::string& callsign);
|
||||
|
|
|
@ -161,19 +161,16 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
|
|||
message.getArgument(groundspeeds);
|
||||
message.getArgument(onGrounds);
|
||||
queueDBusCall([=]() {
|
||||
std::vector<SGGeod> positions;
|
||||
std::vector<SGVec3d> orientations;
|
||||
std::vector<SwiftPlaneUpdate> updates;
|
||||
for (long unsigned int i = 0; i < latitudes.size(); i++) {
|
||||
SGGeod newPos;
|
||||
newPos.setLatitudeDeg(latitudes.at(i));
|
||||
newPos.setLongitudeDeg(longitudes.at(i));
|
||||
newPos.setElevationFt(altitudes.at(i));
|
||||
SGVec3d vec(pitches.at(i), rolls.at(i), headings.at(i));
|
||||
|
||||
positions.push_back(newPos);
|
||||
orientations.push_back(vec);
|
||||
SGGeod pos;
|
||||
pos.setLatitudeDeg(latitudes.at(i));
|
||||
pos.setLongitudeDeg(longitudes.at(i));
|
||||
pos.setElevationFt(altitudes.at(i));
|
||||
SGVec3d orientation(pitches.at(i), rolls.at(i), headings.at(i));
|
||||
updates.push_back({callsigns.at(i), pos, orientation, groundspeeds.at(i), onGrounds.at(i)});
|
||||
}
|
||||
acm->updatePlanes(callsigns, positions, orientations, groundspeeds, onGrounds);
|
||||
acm->updatePlanes(updates);
|
||||
});
|
||||
} else if (message.getMethodName() == "getRemoteAircraftData") {
|
||||
std::vector<std::string> requestedcallsigns;
|
||||
|
|
|
@ -61,7 +61,7 @@ void SwiftAircraftManagerTest::testAircraftManager()
|
|||
position.setLongitudeDeg(6.0);
|
||||
position.setElevationM(1024);
|
||||
|
||||
acm.updatePlanes({"SAS123"}, {position}, {SGVec3d(1.0, 2.0, 3.0)}, {200}, {false});
|
||||
acm.updatePlanes({{"SAS123", position, SGVec3d(1.0, 2.0, 3.0), 200, false}});
|
||||
CPPUNIT_ASSERT_EQUAL(fgGetString("/ai/models/swift[3]/callsign"), std::string("SAS123"));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/pitch-deg"), 1.0, 0.1);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/roll-deg"), 2.0, 0.1);
|
||||
|
@ -72,7 +72,7 @@ void SwiftAircraftManagerTest::testAircraftManager()
|
|||
|
||||
position.setLatitudeDeg(20.0);
|
||||
position.setLongitudeDeg(4.0);
|
||||
acm.updatePlanes({"SAS123"}, {position}, {SGVec3d(5.0, 6.0, 7.0)}, {400}, {false});
|
||||
acm.updatePlanes({{"SAS123", position, SGVec3d(5.0, 6.0, 7.0), 400, false}});
|
||||
CPPUNIT_ASSERT_EQUAL(fgGetString("/ai/models/swift[3]/callsign"), std::string("SAS123"));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/pitch-deg"), 5.0, 0.1);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/roll-deg"), 6.0, 0.1);
|
||||
|
@ -86,7 +86,7 @@ void SwiftAircraftManagerTest::testAircraftManager()
|
|||
acm.addPlane("DAL123", "PATH_TO_MODEL");
|
||||
position.setLatitudeDeg(-20.0);
|
||||
position.setLongitudeDeg(5.0);
|
||||
acm.updatePlanes({"DAL123"}, {position}, {SGVec3d(1.0, 1.0, 1.0)}, {250}, {false});
|
||||
acm.updatePlanes({{"DAL123", position, SGVec3d(1.0, 1.0, 1.0), 250, false}});
|
||||
CPPUNIT_ASSERT_EQUAL(fgGetString("/ai/models/swift[4]/callsign"), std::string("DAL123"));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/orientation/pitch-deg"), 1.0, 0.1);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/orientation/roll-deg"), 1.0, 0.1);
|
||||
|
|
Loading…
Reference in a new issue