1
0
Fork 0

[swift] Code cleanup

This commit is contained in:
Lars Toenning 2020-05-11 09:21:26 +02:00 committed by James Turner
parent f823e033f1
commit 7b9940f1b1
7 changed files with 14 additions and 83 deletions

View file

@ -1,4 +1,4 @@
// AISwiftAircraft.cpp - Derived AIBase class for swift aircrafts // AISwiftAircraft.cpp - Derived AIBase class for swift aircraft
// //
// Copyright (C) 2020 - swift Project Community / Contributors (http://swift-project.org/) // Copyright (C) 2020 - swift Project Community / Contributors (http://swift-project.org/)
// Written by Lars Toenning <dev@ltoenning.de> started on April 2020. // Written by Lars Toenning <dev@ltoenning.de> started on April 2020.

View file

@ -1,4 +1,4 @@
// AISwiftAircraft.h - Derived AIBase class for swift aircrafts // AISwiftAircraft.h - Derived AIBase class for swift aircraft
// //
// Copyright (C) 2020 - swift Project Community / Contributors (http://swift-project.org/) // Copyright (C) 2020 - swift Project Community / Contributors (http://swift-project.org/)
// Written by Lars Toenning <dev@ltoenning.de> started on April 2020. // Written by Lars Toenning <dev@ltoenning.de> started on April 2020.

View file

@ -1,4 +1,4 @@
// SwiftAircraftManager.cpp - Manager class for aircrafts generated by swift // SwiftAircraftManager.cpp - Manager class for aircraft generated by swift
// //
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/) // Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de> // Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>
@ -22,13 +22,12 @@
#include <utility> #include <utility>
FGSwiftAircraftManager::FGSwiftAircraftManager() FGSwiftAircraftManager::FGSwiftAircraftManager()
{ = default;
}
FGSwiftAircraftManager::~FGSwiftAircraftManager() FGSwiftAircraftManager::~FGSwiftAircraftManager()
= default; = default;
bool FGSwiftAircraftManager::addPlane(const std::string& callsign, std::string modelString) bool FGSwiftAircraftManager::addPlane(const std::string& callsign, const std::string& modelString)
{ {
this->removePlane(callsign); // Remove plane if already exists e.g. when rematching is done. this->removePlane(callsign); // Remove plane if already exists e.g. when rematching is done.
auto curAircraft = new FGAISwiftAircraft(callsign, modelString); auto curAircraft = new FGAISwiftAircraft(callsign, modelString);

View file

@ -1,4 +1,4 @@
// SwiftAircraftManager.h - Manger class for aircrafts generated for swift // SwiftAircraftManager.h - Manger class for aircraft generated for swift
// //
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/) // Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de> // Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>
@ -32,7 +32,7 @@ class FGSwiftAircraftManager
public: public:
FGSwiftAircraftManager(); FGSwiftAircraftManager();
~FGSwiftAircraftManager(); ~FGSwiftAircraftManager();
bool addPlane(const std::string& callsign, std::string modelString); bool addPlane(const std::string& callsign, const std::string& modelString);
void updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds); void updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds);
void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg, void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg,
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const; std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;

View file

@ -1,4 +1,4 @@
// swift_conection.hxx // swift_connection.hxx
// //
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/) // Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de> // Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>

View file

@ -25,10 +25,6 @@
#include "traffic.h" #include "traffic.h"
#include "SwiftAircraftManager.h" #include "SwiftAircraftManager.h"
#include <algorithm> #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream> #include <iostream>
@ -60,25 +56,8 @@ const std::string& CTraffic::ObjectPath()
return s; return s;
} }
void CTraffic::planeLoaded(void* id, bool succeeded, void* self)
{
auto traffic = static_cast<CTraffic*>(self);
auto planeIt = traffic->m_planesById.find(id);
if (planeIt == traffic->m_planesById.end()) { return; }
if (succeeded) {
traffic->emitPlaneAdded(planeIt->second->callsign);
} else {
traffic->emitPlaneAddingFailed(planeIt->second->callsign);
}
}
bool CTraffic::initialize() bool CTraffic::initialize()
{ {
m_initialized = true;
m_enabled = true;
return true; return true;
} }
@ -96,24 +75,11 @@ void CTraffic::emitPlaneAdded(const std::string& callsign)
sendDBusMessage(signalPlaneAdded); sendDBusMessage(signalPlaneAdded);
} }
void CTraffic::emitPlaneAddingFailed(const std::string& callsign)
{
CDBusMessage signalPlaneAddingFailed = CDBusMessage::createSignal(FGSWIFTBUS_TRAFFIC_OBJECTPATH, FGSWIFTBUS_TRAFFIC_INTERFACENAME, "remoteAircraftAddingFailed");
signalPlaneAddingFailed.beginArgumentWrite();
signalPlaneAddingFailed.appendArgument(callsign);
sendDBusMessage(signalPlaneAddingFailed);
}
void CTraffic::cleanup() void CTraffic::cleanup()
{ {
acm->removeAllPlanes(); acm->removeAllPlanes();
} }
void CTraffic::removeAllPlanes()
{
acm->removeAllPlanes();
}
void CTraffic::dbusDisconnectedHandler() void CTraffic::dbusDisconnectedHandler()
{ {
acm->removeAllPlanes(); acm->removeAllPlanes();
@ -272,20 +238,12 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
return DBUS_HANDLER_RESULT_HANDLED; return DBUS_HANDLER_RESULT_HANDLED;
} }
int CTraffic::process() int CTraffic::process()
{ {
invokeQueuedDBusCalls(); invokeQueuedDBusCalls();
return 1; return 1;
} }
//! memcmp function which ignores the header ("size" member) and compares only the payload (the rest of the struct)
template <typename T>
int memcmpPayload(T* dst, T* src)
{
return std::memcmp(reinterpret_cast<char*>(dst) + sizeof(dst->size),
reinterpret_cast<char*>(src) + sizeof(src->size),
sizeof(*dst) - sizeof(dst->size));
}
} // namespace FGSwiftBus } // namespace FGSwiftBus
//! \endcond //! \endcond

View file

@ -54,9 +54,6 @@ public:
//! Initialize the multiplayer planes rendering and return true if successful //! Initialize the multiplayer planes rendering and return true if successful
bool initialize(); bool initialize();
//! Remove all traffic aircraft
void removeAllPlanes();
//! Perform generic processing //! Perform generic processing
int process(); int process();
@ -68,40 +65,17 @@ protected:
DBusHandlerResult dbusMessageHandler(const CDBusMessage& message) override; DBusHandlerResult dbusMessageHandler(const CDBusMessage& message) override;
private: private:
bool m_initialized = false;
bool m_enabled = false;
void emitPlaneAdded(const std::string& callsign); void emitPlaneAdded(const std::string& callsign);
void emitPlaneAddingFailed(const std::string& callsign);
void cleanup(); void cleanup();
struct Plane { struct Plane {
void* id = nullptr; void* id = nullptr;
std::string callsign; std::string callsign;
std::string aircraftIcao;
std::string airlineIcao;
std::string livery;
std::string modelName;
bool hasSurfaces = false;
bool hasXpdr = false;
char label[32]{}; char label[32]{};
float targetGearPosition = 0;
std::chrono::system_clock::time_point prevSurfacesLerpTime;
}; };
std::unordered_map<std::string, Plane*> m_planesByCallsign;
std::unordered_map<void*, Plane*> m_planesById;
std::vector<std::string> m_followPlaneViewSequence;
std::chrono::system_clock::time_point m_timestampLastSimFrame = std::chrono::system_clock::now();
std::string m_followPlaneViewCallsign;
bool m_emitSimFrame = true; bool m_emitSimFrame = true;
std::unique_ptr<FGSwiftAircraftManager> acm; std::unique_ptr<FGSwiftAircraftManager> acm;
static void planeLoaded(void* id, bool succeeded, void* self);
}; };
} // namespace FGSwiftBus } // namespace FGSwiftBus