mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
Ref T709, static "ownAircraftString" and improved logging
This commit is contained in:
committed by
Mat Sutcliffe
parent
60ea80301e
commit
3260209ca5
@@ -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]()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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*
|
||||
//! @}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user