Skip to content

Commit

Permalink
Added ai_for_tcas, label_shown (in/external/VR), lnd_lights_taxi,...
Browse files Browse the repository at this point in the history
...and debug fixings for CSL model matching (a/c, op, livery) as basis for full functionality and settings UI to come.
  • Loading branch information
TwinFan committed Jan 25, 2019
1 parent a7a05de commit 9cb2fc4
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 45 deletions.
31 changes: 28 additions & 3 deletions Src/DataRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ const char* DATA_REFS_XP[CNT_DATAREFS_XP] = {
"sim/time/local_date_days",
"sim/time/use_system_time",
"sim/time/zulu_time_sec",
"sim/graphics/view/view_is_external",
"sim/graphics/VR/enabled",
};

//
Expand Down Expand Up @@ -216,7 +218,9 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[] = {
{"livetraffic/sim/time", DataRefs::LTGetSimDateTime, DataRefs::LTSetSimDateTime, (void*)2, false },
{"livetraffic/cfg/aircrafts_displayed", DataRefs::LTGetInt, DataRefs::LTSetAircraftsDisplayed, GET_VAR, false },
{"livetraffic/cfg/auto_start", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/ai_for_tcas", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/labels", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/label_shown", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/label_col_dyn", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/label_color", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/log_level", DataRefs::LTGetInt, DataRefs::LTSetLogLevel, GET_VAR, true },
Expand All @@ -228,6 +232,7 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[] = {
{"livetraffic/cfg/fd_refresh_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/fd_buf_period", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/ac_outdated_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/lnd_lights_taxi", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/adsb_exchange/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/channel/adsb_exchange/historic", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/channel/open_sky/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
Expand All @@ -249,7 +254,9 @@ void* DataRefs::getVarAddr (dataRefsLT dr)
switch (dr) {
case DR_CFG_AIRCRAFTS_DISPLAYED: return &bShowingAircrafts;
case DR_CFG_AUTO_START: return &bAutoStart;
case DR_CFG_LABELS: return &labelCfg.i;
case DR_CFG_AI_FOR_TCAS: return &bAIforTCAS;
case DR_CFG_LABELS: return &labelCfg;
case DR_CFG_LABEL_SHOWN: return &labelShown;
case DR_CFG_LABEL_COL_DYN: return &bLabelColDynamic;
case DR_CFG_LABEL_COLOR: return &labelColor;
case DR_CFG_LOG_LEVEL: return &iLogLevel;
Expand All @@ -261,6 +268,7 @@ void* DataRefs::getVarAddr (dataRefsLT dr)
case DR_CFG_FD_REFRESH_INTVL: return &fdRefreshIntvl;
case DR_CFG_FD_BUF_PERIOD: return &fdBufPeriod;
case DR_CFG_AC_OUTDATED_INTVL: return &acOutdatedIntvl;
case DR_CFG_LND_LIGHTS_TAXI: return &bLndLightsTaxi;

case DR_DBG_AC_FILTER: return &uDebugAcFilter;
case DR_DBG_AC_POS: return &bDebugAcPos;
Expand Down Expand Up @@ -435,7 +443,14 @@ bool DataRefs::Init ()
for ( int i=0; i < CNT_DATAREFS_XP; i++ )
{
if ( (adrXP[i] = XPLMFindDataRef (DATA_REFS_XP[i])) == NULL )
{ LOG_MSG(logFATAL,ERR_DATAREF_FIND,DATA_REFS_XP[i]); return false; }
{
// for XP10 compatibility we accept if we don't find "VR/enabled",
// all else stays an error
if (i != DR_VR_ENABLED) {
LOG_MSG(logFATAL,ERR_DATAREF_FIND,DATA_REFS_XP[i]);
return false;
}
}
}

// register all LiveTraffic-provided dataRefs
Expand Down Expand Up @@ -945,7 +960,7 @@ bool DataRefs::SetCfgValue (void* p, int val)
}

// Tell XPMP if we need labels
if (labelCfg.i > 0)
if (ShallDrawLabels())
XPMPEnableAircraftLabels();
else
XPMPDisableAircraftLabels();
Expand Down Expand Up @@ -1441,3 +1456,13 @@ double DataRefs::GetViewHeading()
XPLMReadCameraPosition(&camPos);
return camPos.heading;
}

bool DataRefs::ShallDrawLabels() const
{
// user doesn't want labels in VR but is in VR mode? -> no labels
if (!labelShown.bVR && IsVREnabled())
return false;

// now depends on internal or external view
return IsViewExternal() ? labelShown.bExternal : labelShown.bInternal;
}
51 changes: 43 additions & 8 deletions Src/Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ enum dataRefsXP {
DR_LOCAL_DATE_DAYS,
DR_USE_SYSTEM_TIME,
DR_ZULU_TIME_SEC,
DR_VIEW_EXTERNAL,
DR_VR_ENABLED,
CNT_DATAREFS_XP // always last, number of elements
};

Expand Down Expand Up @@ -127,7 +129,9 @@ enum dataRefsLT {
DR_SIM_TIME,
DR_CFG_AIRCRAFTS_DISPLAYED,
DR_CFG_AUTO_START,
DR_CFG_AI_FOR_TCAS,
DR_CFG_LABELS,
DR_CFG_LABEL_SHOWN,
DR_CFG_LABEL_COL_DYN,
DR_CFG_LABEL_COLOR,
DR_CFG_LOG_LEVEL,
Expand All @@ -139,6 +143,7 @@ enum dataRefsLT {
DR_CFG_FD_REFRESH_INTVL,
DR_CFG_FD_BUF_PERIOD,
DR_CFG_AC_OUTDATED_INTVL,
DR_CFG_LND_LIGHTS_TAXI,
DR_CHANNEL_ADSB_EXCHANGE_ONLINE,
DR_CHANNEL_ADSB_EXCHANGE_HISTORIC,
DR_CHANNEL_OPEN_SKY_ONLINE,
Expand Down Expand Up @@ -238,13 +243,28 @@ class DataRefs
bHeightAGL : 1,
bSpeed : 1, // default
bVSI : 1;

// this is a bit ugly but avoids a wrapper union with an int
inline int GetInt() const { return *reinterpret_cast<const int*>(this); }
inline void SetInt(int i) { *reinterpret_cast<int*>(this) = i; }
inline bool operator != (const LabelCfgTy& o) const
{ return GetInt() != o.GetInt(); }
};

union LabelCfgUTy {
LabelCfgTy b;
int i;
};
// when to show a/c labels?
struct LabelShowCfgTy {
unsigned
bExternal : 1, // external/outside views
bInternal : 1, // internal/cockpit views
bVR : 1; // VR views

// this is a bit ugly but avoids a wrapper union with an int
inline int GetInt() const { return *reinterpret_cast<const int*>(this); }
inline void SetInt(int i) { *reinterpret_cast<int*>(this) = i; }
inline bool operator != (const LabelCfgTy& o) const
{ return GetInt() != o.GetInt(); }
};

struct CSLPathCfgTy { // represents a line in the [CSLPath] section of LiveTrafic.prg
bool bEnabled = false;
std::string path;
Expand Down Expand Up @@ -284,8 +304,10 @@ class DataRefs

// generic config values
int bAutoStart = true; // shall display a/c right after startup?
int bAIforTCAS = true; // acquire multiplayer control for TCAS? (false might enhance interperability with other multiplayer clients)
// which elements make up an a/c label?
LabelCfgUTy labelCfg = { {1,1,0,0,0,0,0,0, 0,0,1,0,1,0} };
LabelCfgTy labelCfg = { 1,1,0,0,0,0,0,0, 0,0,1,0,1,0 };
LabelShowCfgTy labelShown = { 1, 1, 1 }; // when to show? (default: always)
bool bLabelColDynamic = false; // dynamic label color?
int labelColor = COLOR_YELLOW; // label color, by default yellow
int maxNumAc = 50; // how many aircrafts to create at most?
Expand All @@ -295,6 +317,7 @@ class DataRefs
int fdRefreshIntvl = 20; // how often to fetch new flight data
int fdBufPeriod = 90; // seconds to buffer before simulating aircrafts
int acOutdatedIntvl = 50; // a/c considered outdated if latest flight data more older than this compare to 'now'
int bLndLightsTaxi = false; // keep landing lights on while taxiing? (to be able to see the a/c as there is no taxi light functionality)

vecCSLPaths vCSLPaths; // list of paths to search for CSL packages

Expand All @@ -309,6 +332,12 @@ class DataRefs
int cntAc = 0; // number of a/c being displayed
std::string keyAc; // key (transpIcao) for a/c whose data is returned
const LTAircraft* pAc = nullptr; // ptr to that a/c

//MARK: Debug helpers (public)
public:
std::string cslFixAcIcaoType; // set of fixed values to use for...
std::string cslFixOpIcao; // ...newly created aircrafts for...
std::string cslFixLivery; // ...CSL model package testing

//MARK: Constructor
public:
Expand All @@ -329,7 +358,9 @@ class DataRefs
inline int GetLocalDateDays() const { return XPLMGetDatai(adrXP[DR_LOCAL_DATE_DAYS]); }
inline bool GetUseSystemTime() const { return XPLMGetDatai(adrXP[DR_USE_SYSTEM_TIME]) != 0; }
inline float GetZuluTimeSec() const { return XPLMGetDataf(adrXP[DR_ZULU_TIME_SEC]); }

inline bool IsViewExternal() const { return XPLMGetDatai(adrXP[DR_VIEW_EXTERNAL]) != 0; }
inline bool IsVREnabled() const { return adrXP[DR_VR_ENABLED] ? XPLMGetDatai(adrXP[DR_VR_ENABLED]) != 0 : false; } // for XP10 compatibility we accept not having this dataRef

inline void SetLocalDateDays(int days) { XPLMSetDatai(adrXP[DR_LOCAL_DATE_DAYS], days); }
inline void SetUseSystemTime(bool bSys) { XPLMSetDatai(adrXP[DR_USE_SYSTEM_TIME], (int)bSys); }
inline void SetZuluTimeSec(float sec) { XPLMSetDataf(adrXP[DR_ZULU_TIME_SEC], sec); }
Expand Down Expand Up @@ -377,7 +408,9 @@ class DataRefs
static void LTSetCfgValue(void* p, int val);
bool SetCfgValue(void* p, int val);
inline bool GetAutoStart() const { return bAutoStart != 0; }
inline LabelCfgUTy GetLabelCfg() const { return labelCfg; }
inline bool GetAIforTCAS() const { return bAIforTCAS != 0; }
inline LabelCfgTy GetLabelCfg() const { return labelCfg; }
inline LabelShowCfgTy GetLabelShowCfg() const { return labelShown; }
inline bool IsLabelColorDynamic() const { return bLabelColDynamic; }
inline int GetLabelColor() const { return labelColor; }
void GetLabelColor (float outColor[4]) const;
Expand All @@ -390,7 +423,8 @@ class DataRefs
inline int GetFdRefreshIntvl() const { return fdRefreshIntvl; }
inline int GetFdBufPeriod() const { return fdBufPeriod; }
inline int GetAcOutdatedIntvl() const { return acOutdatedIntvl; }

inline bool GetLndLightsTaxi() const { return bLndLightsTaxi != 0; }

const vecCSLPaths& GetCSLPaths() const { return vCSLPaths; }
vecCSLPaths& GetCSLPaths() { return vCSLPaths; }
void SaveCSLPath(int idx, const CSLPathCfgTy path);
Expand Down Expand Up @@ -454,6 +488,7 @@ class DataRefs
static double GetViewHeading();
static inline boundingBoxTy GetBoundingBox(double dist) // bounding box around current view pos
{ return boundingBoxTy(GetViewPos(), dist); }
bool ShallDrawLabels() const;
};

extern DataRefs::dataRefDefinitionT DATA_REFS_LT[CNT_DATAREFS_LT];
Expand Down
2 changes: 1 addition & 1 deletion Src/Include/LTFlightData.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class LTFlightData
int sig; // signal level

std::string labelStat; // static part of the a/c label
DataRefs::LabelCfgUTy labelCfg = { {0,0,0,0,0,0,0,0,0,0,0,0,0} }; // the configuration the label was saved for
DataRefs::LabelCfgTy labelCfg = { 0,0,0,0,0,0,0,0,0,0,0,0,0 }; // the configuration the label was saved for

protected:
// DYNAMIC DATA (protected, access will be mutex-controlled for thread-safety)
Expand Down
13 changes: 8 additions & 5 deletions Src/LTAircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,12 @@ std::string LTAircraft::FlightPhase2String (FlightPhase phase)
// Constructor: create an aircraft from Flight Data
LTAircraft::LTAircraft(LTFlightData& inFd) :
// Base class -> this registers with XPMP API for actual display in XP!
XPCAircraft(inFd.WaitForSafeCopyStat().acTypeIcao.c_str(), // repeated calls to WaitForSafeCopyStat look inefficient
inFd.WaitForSafeCopyStat().opIcao.c_str(), // ...but if the lock is held by the calling function already then these are quick recursive calls
inFd.WaitForSafeCopyStat().reg.c_str()), // Using registration as livery indicator, allows for different liveries per actual airframe
// repeated calls to WaitForSafeCopyStat look inefficient, but if the lock is held by the calling function already then these are quick recursive calls
// Using registration as livery indicator, allows for different liveries per actual airframe
// Debug options to set fixed type/op/livery take precedence
XPCAircraft(str_first_non_empty({dataRefs.cslFixAcIcaoType, inFd.WaitForSafeCopyStat().acTypeIcao}).c_str(),
str_first_non_empty({dataRefs.cslFixOpIcao, inFd.WaitForSafeCopyStat().opIcao}).c_str(),
str_first_non_empty({dataRefs.cslFixLivery, inFd.WaitForSafeCopyStat().reg}).c_str()),
// class members
fd(inFd),
mdl(FlightModel::FindFlightModel(inFd.WaitForSafeCopyStat().acTypeIcao)), // find matching flight model
Expand Down Expand Up @@ -1471,7 +1474,7 @@ void LTAircraft::CalcFlightModel (const positionTy& /*from*/, const positionTy&
// some assumption to begin with...
surfaces.thrust = 0.1f;
surfaces.lights.timeOffset = (unsigned int)rand();
surfaces.lights.landLights = 0;
surfaces.lights.landLights = dataRefs.GetLndLightsTaxi() ? 1 : 0;
surfaces.lights.bcnLights = 1;
surfaces.lights.strbLights = 0;
surfaces.lights.navLights = 1;
Expand Down Expand Up @@ -1587,7 +1590,7 @@ void LTAircraft::CalcFlightModel (const positionTy& /*from*/, const positionTy&
flaps.up();
surfaces.spoilerRatio = surfaces.speedBrakeRatio = 0.0;
surfaces.thrust = 0.1f;
surfaces.lights.landLights = 0;
surfaces.lights.landLights = dataRefs.GetLndLightsTaxi() ? 1 : 0;
surfaces.lights.strbLights = 0;
}

Expand Down
22 changes: 11 additions & 11 deletions Src/LTFlightData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,18 @@ void LTFlightData::UpdateStaticLabel()
std::lock_guard<std::recursive_mutex> lock (dataAccessMutex);

// the configuration: which parts to include in the label?
const DataRefs::LabelCfgUTy cfg = dataRefs.GetLabelCfg();
const DataRefs::LabelCfgTy cfg = dataRefs.GetLabelCfg();

// add parts as per config
labelStat.clear();
ADD_LABEL(cfg.b.bIcaoType, statData.acTypeIcao);
ADD_LABEL(cfg.b.bAnyAcId, statData.acId(key()));
ADD_LABEL(cfg.b.bTranspCode, key());
ADD_LABEL(cfg.b.bReg, statData.reg);
ADD_LABEL(cfg.b.bIcaoOp, statData.opIcao);
ADD_LABEL(cfg.b.bCallSign, statData.call);
ADD_LABEL(cfg.b.bFlightNo, statData.flight);
ADD_LABEL(cfg.b.bRoute, statData.route());
ADD_LABEL(cfg.bIcaoType, statData.acTypeIcao);
ADD_LABEL(cfg.bAnyAcId, statData.acId(key()));
ADD_LABEL(cfg.bTranspCode, key());
ADD_LABEL(cfg.bReg, statData.reg);
ADD_LABEL(cfg.bIcaoOp, statData.opIcao);
ADD_LABEL(cfg.bCallSign, statData.call);
ADD_LABEL(cfg.bFlightNo, statData.flight);
ADD_LABEL(cfg.bRoute, statData.route());

// this is the config we did the label for
labelCfg = cfg;
Expand All @@ -336,7 +336,7 @@ std::string LTFlightData::ComposeLabel() const
std::lock_guard<std::recursive_mutex> lock (dataAccessMutex);

// the configuration: which parts to include in the label?
const DataRefs::LabelCfgTy cfg = dataRefs.GetLabelCfg().b;
const DataRefs::LabelCfgTy cfg = dataRefs.GetLabelCfg();
std::string label(labelStat); // copy static parts

// only possible if we have an aircraft
Expand Down Expand Up @@ -1691,7 +1691,7 @@ bool LTFlightData::AircraftMaintenance ( double simTime )
return true;

// do we need to recalc the static part of the a/c label due to config change?
if (dataRefs.GetLabelCfg().i != labelCfg.i)
if (dataRefs.GetLabelCfg() != labelCfg)
UpdateStaticLabel();

// doesn't yet have an associated aircraft but two positions?
Expand Down
Loading

1 comment on commit 9cb2fc4

@TwinFan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prepares for #76, #75, #69

Please sign in to comment.