From 10b8cf5feae446c04f323ed150afb8a11219814c Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 5 Jun 2018 11:44:16 +0200 Subject: [PATCH] Add new command to jump to next plane in follow plane view ref T269 --- src/xswiftbus/traffic.cpp | 21 ++++++++++++++++++++- src/xswiftbus/traffic.h | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 127193f9c..32796edd7 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -44,7 +44,8 @@ namespace XSwiftBus } CTraffic::CTraffic(CDBusConnection *dbusConnection) : - CDBusObject(dbusConnection) + CDBusObject(dbusConnection), + m_planeViewNextCommand("org/swift-project/xswiftbus/follow_next_plane", "Changes plane view to follow next plane in sequence", [this] { followNextPlane(); }) { registerDBusObjectPath(XSWIFTBUS_TRAFFIC_INTERFACENAME, XSWIFTBUS_TRAFFIC_OBJECTPATH); XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this); @@ -146,6 +147,19 @@ namespace XSwiftBus XPLMControlCamera(xplm_ControlCameraUntilViewChanges, orbitPlaneFunc, this); } + void CTraffic::followNextPlane() + { + if (m_planesByCallsign.empty() || m_planeViewCallsign.empty()) { return; } + auto callsignIt = std::find(m_followPlaneViewSequence.begin(), m_followPlaneViewSequence.end(), m_planeViewCallsign); + + // If we are not at the end, increase by one + if (callsignIt != m_followPlaneViewSequence.end()) { callsignIt++; } + // If we were already at the end or reached it now, start from the beginning + if (callsignIt == m_followPlaneViewSequence.end()) { callsignIt = m_followPlaneViewSequence.begin(); } + + m_planeViewCallsign = *callsignIt; + } + int g_maxPlanes = 100; float g_drawDistance = 50.0f; @@ -239,6 +253,7 @@ namespace XSwiftBus // Create view menu item CMenuItem planeViewMenuItem = m_planeViewSubMenu.item(callsign, [this, callsign] { switchToPlaneView(callsign); }); m_planeViewMenuItems[callsign] = planeViewMenuItem; + m_followPlaneViewSequence.push_back(callsign); } } @@ -254,6 +269,9 @@ namespace XSwiftBus auto planeIt = m_planesByCallsign.find(callsign); if (planeIt == m_planesByCallsign.end()) { return; } + m_followPlaneViewSequence.erase(std::remove(m_followPlaneViewSequence.begin(), m_followPlaneViewSequence.end(), callsign), + m_followPlaneViewSequence.end()); + Plane *plane = planeIt->second; m_planesByCallsign.erase(callsign); m_planesById.erase(plane->id); @@ -280,6 +298,7 @@ namespace XSwiftBus m_planesByCallsign.clear(); m_planesById.clear(); m_planeViewMenuItems.clear(); + m_followPlaneViewSequence.clear(); } void CTraffic::setPlanesPositions(const std::vector &callsigns, std::vector latitudes, std::vector longitudes, std::vector altitudes, diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index c04618d97..4fe366319 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -13,6 +13,7 @@ //! \file #include "dbusobject.h" +#include "command.h" #include "datarefs.h" #include "terrainprobe.h" #include "menus.h" @@ -132,6 +133,7 @@ namespace XSwiftBus void emitPlaneAdded(const std::string &callsign); void emitPlaneAddingFailed(const std::string &callsign); void switchToPlaneView(const std::string &callsign); + void followNextPlane(); static int preferences(const char *section, const char *name, int def); static float preferences(const char *section, const char *name, float def); @@ -161,6 +163,7 @@ namespace XSwiftBus std::unordered_map m_planesByCallsign; std::unordered_map m_planesById; + std::vector m_followPlaneViewSequence; std::chrono::system_clock::time_point m_timestampLastSimFrame = std::chrono::system_clock::now(); CMenu m_planeViewSubMenu; @@ -170,6 +173,8 @@ namespace XSwiftBus DataRef m_worldRenderType; bool m_emitSimFrame = true; + CCommand m_planeViewNextCommand; + int getPlaneData(void *id, int dataType, void *io_data); static int getPlaneData(void *id, int dataType, void *io_data, void *self) {