From 0605c2d139893f04adb44930a6a25b6f061ba433 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 8 Aug 2019 20:11:15 +0200 Subject: [PATCH] Ref T709, static "ownAircraftString" and improved logging --- src/xswiftbus/plugin.cpp | 2 +- src/xswiftbus/traffic.cpp | 23 ++++++++++++++--------- src/xswiftbus/traffic.h | 2 +- src/xswiftbus/utils.h | 3 +++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/xswiftbus/plugin.cpp b/src/xswiftbus/plugin.cpp index 14137a1b4..584da5c23 100644 --- a/src/xswiftbus/plugin.cpp +++ b/src/xswiftbus/plugin.cpp @@ -53,7 +53,7 @@ namespace XSwiftBus m_planeViewSubMenu = m_menu.subMenu("Follow Plane View"); m_planeViewOwnAircraftMenuItem = m_planeViewSubMenu.item("Own Aircraft", [this] { - m_traffic->setFollowedAircraft(m_traffic->ownAircraftString()); + m_traffic->setFollowedAircraft(CTraffic::ownAircraftString()); }); /*m_dbusThread = std::thread([this]() diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 710e49ec7..ffcfe8396 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -170,7 +170,7 @@ namespace XSwiftBus void CTraffic::switchToFollowPlaneView(const std::string &callsign) { - if (this->ownAircraftString() != callsign && !this->containsCallsign(callsign)) + if (CTraffic::ownAircraftString() != callsign && !this->containsCallsign(callsign)) { INFO_LOG("Cannot switch to follow " + callsign); return; @@ -502,12 +502,7 @@ namespace XSwiftBus void CTraffic::setFollowedAircraft(const std::string &callsign) { - if (callsign != ownAircraftString()) - { - auto planeIt = m_planesByCallsign.find(callsign); - if (planeIt == m_planesByCallsign.end()) { return; } - } - switchToFollowPlaneView(callsign); + this->switchToFollowPlaneView(callsign); } void CTraffic::dbusDisconnectedHandler() @@ -895,6 +890,8 @@ namespace XSwiftBus int CTraffic::orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon) { + constexpr bool DEBUG = true; + // DEBUG_LOG_C("Follow aircraft entry", DEBUG); if (isLosingControl == 1) { // do NOT use refcon here, might be invalid @@ -927,6 +924,7 @@ namespace XSwiftBus // fixme: In a future update, change the orbit only while right mouse button is pressed. XPLMGetScreenSize(&w, &h); XPLMGetMouseLocation(&x, &y); + if (DEBUG) { DEBUG_LOG("Follow aircraft coordinates w,h,x,y: " + std::to_string(w) + " " + std::to_string(h) + " " + std::to_string(x) + " " + std::to_string(y)); } // avoid follow aircraft in too small windows // int cannot be NaN @@ -960,7 +958,7 @@ namespace XSwiftBus double lx = 0, ly = 0, lz = 0; // normally init not needed, just to avoid any issues static const double kFtToMeters = 0.3048; - if (traffic->m_followPlaneViewCallsign == traffic->ownAircraftString()) + if (traffic->m_followPlaneViewCallsign == CTraffic::ownAircraftString()) { lx = traffic->m_ownAircraftPositionX.get(); ly = traffic->m_ownAircraftPositionY.get(); @@ -1026,7 +1024,11 @@ namespace XSwiftBus } // Return 1 to indicate we want to keep controlling the camera. - // INFO_LOG("Follow aircraft " + traffic->m_followPlaneViewCallsign); + if (DEBUG) + { + DEBUG_LOG("Camera: " + pos2String(cameraPosition)); + DEBUG_LOG("Follow aircraft " + traffic->m_followPlaneViewCallsign); + } return 1; } @@ -1156,8 +1158,11 @@ namespace XSwiftBus std::string CTraffic::pos2String(const XPLMCameraPosition_t *camPos) { + if (!camPos) { return "camera position invalid"; } return "x, y, z: " + std::to_string(camPos->x) + "/" + std::to_string(camPos->y) + "/" + std::to_string(camPos->z) + + " zoom: " + + std::to_string(camPos->zoom) + " prh: " + std::to_string(camPos->pitch) + "/" + std::to_string(camPos->roll) + "/" + std::to_string(camPos->heading); } diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index 275fb08b1..1f9298d04 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -126,7 +126,7 @@ namespace XSwiftBus int process(); //! Returns the own aircraft string to be used as callsign for setFollowedAircraft() - std::string ownAircraftString() const { return "ownAircraft"; } + static const std::string &ownAircraftString() { static const std::string o = "ownAircraft"; return o; } protected: //! Handler diff --git a/src/xswiftbus/utils.h b/src/xswiftbus/utils.h index 674fda55e..c635455ea 100644 --- a/src/xswiftbus/utils.h +++ b/src/xswiftbus/utils.h @@ -41,10 +41,13 @@ namespace XSwiftBus //! Logger convenience macros //! @{ + // *INDENT-OFF* #define DEBUG_LOG(msg) Logger::print(__FILE__, __LINE__, Logger::DebugMsg, msg) + #define DEBUG_LOG_C(msg, doLog) if (doLog) { Logger::print(__FILE__, __LINE__, Logger::DebugMsg, msg); } #define INFO_LOG(msg) Logger::print(__FILE__, __LINE__, Logger::InfoMsg, msg) #define WARNING_LOG(msg) Logger::print(__FILE__, __LINE__, Logger::WarningMsg, msg) #define ERROR_LOG(msg) Logger::print(__FILE__, __LINE__, Logger::ErrorMsg, msg) + // *INDENT-ON* //! @} }