[swift] Code cleanup
This commit is contained in:
parent
f823e033f1
commit
7b9940f1b1
7 changed files with 14 additions and 83 deletions
|
@ -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/)
|
||||
// Written by Lars Toenning <dev@ltoenning.de> started on April 2020.
|
||||
|
|
|
@ -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/)
|
||||
// Written by Lars Toenning <dev@ltoenning.de> started on April 2020.
|
||||
|
|
|
@ -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/)
|
||||
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>
|
||||
|
@ -22,13 +22,12 @@
|
|||
#include <utility>
|
||||
|
||||
FGSwiftAircraftManager::FGSwiftAircraftManager()
|
||||
{
|
||||
}
|
||||
= default;
|
||||
|
||||
FGSwiftAircraftManager::~FGSwiftAircraftManager()
|
||||
= 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.
|
||||
auto curAircraft = new FGAISwiftAircraft(callsign, modelString);
|
||||
|
|
|
@ -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/)
|
||||
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>
|
||||
|
@ -32,7 +32,7 @@ class FGSwiftAircraftManager
|
|||
public:
|
||||
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 getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg,
|
||||
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// swift_conection.hxx
|
||||
// swift_connection.hxx
|
||||
//
|
||||
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
|
||||
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>
|
||||
|
|
|
@ -25,10 +25,6 @@
|
|||
#include "traffic.h"
|
||||
#include "SwiftAircraftManager.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
@ -60,25 +56,8 @@ const std::string& CTraffic::ObjectPath()
|
|||
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()
|
||||
{
|
||||
m_initialized = true;
|
||||
|
||||
m_enabled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -96,24 +75,11 @@ void CTraffic::emitPlaneAdded(const std::string& callsign)
|
|||
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()
|
||||
{
|
||||
acm->removeAllPlanes();
|
||||
}
|
||||
|
||||
void CTraffic::removeAllPlanes()
|
||||
{
|
||||
acm->removeAllPlanes();
|
||||
}
|
||||
|
||||
void CTraffic::dbusDisconnectedHandler()
|
||||
{
|
||||
acm->removeAllPlanes();
|
||||
|
@ -278,14 +244,6 @@ int CTraffic::process()
|
|||
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
|
||||
|
||||
//! \endcond
|
||||
|
|
|
@ -54,9 +54,6 @@ public:
|
|||
//! Initialize the multiplayer planes rendering and return true if successful
|
||||
bool initialize();
|
||||
|
||||
//! Remove all traffic aircraft
|
||||
void removeAllPlanes();
|
||||
|
||||
//! Perform generic processing
|
||||
int process();
|
||||
|
||||
|
@ -68,40 +65,17 @@ protected:
|
|||
DBusHandlerResult dbusMessageHandler(const CDBusMessage& message) override;
|
||||
|
||||
private:
|
||||
bool m_initialized = false;
|
||||
bool m_enabled = false;
|
||||
|
||||
void emitPlaneAdded(const std::string& callsign);
|
||||
void emitPlaneAddingFailed(const std::string& callsign);
|
||||
void cleanup();
|
||||
|
||||
struct Plane {
|
||||
void* id = nullptr;
|
||||
std::string callsign;
|
||||
std::string aircraftIcao;
|
||||
std::string airlineIcao;
|
||||
std::string livery;
|
||||
std::string modelName;
|
||||
bool hasSurfaces = false;
|
||||
bool hasXpdr = false;
|
||||
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;
|
||||
|
||||
|
||||
std::unique_ptr<FGSwiftAircraftManager> acm;
|
||||
|
||||
static void planeLoaded(void* id, bool succeeded, void* self);
|
||||
};
|
||||
} // namespace FGSwiftBus
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue