Skip to content

Commit 9cb2fc4

Browse files
committed
Added ai_for_tcas, label_shown (in/external/VR), lnd_lights_taxi,...
...and debug fixings for CSL model matching (a/c, op, livery) as basis for full functionality and settings UI to come.
1 parent a7a05de commit 9cb2fc4

File tree

6 files changed

+115
-45
lines changed

6 files changed

+115
-45
lines changed

Src/DataRefs.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const char* DATA_REFS_XP[CNT_DATAREFS_XP] = {
179179
"sim/time/local_date_days",
180180
"sim/time/use_system_time",
181181
"sim/time/zulu_time_sec",
182+
"sim/graphics/view/view_is_external",
183+
"sim/graphics/VR/enabled",
182184
};
183185

184186
//
@@ -216,7 +218,9 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[] = {
216218
{"livetraffic/sim/time", DataRefs::LTGetSimDateTime, DataRefs::LTSetSimDateTime, (void*)2, false },
217219
{"livetraffic/cfg/aircrafts_displayed", DataRefs::LTGetInt, DataRefs::LTSetAircraftsDisplayed, GET_VAR, false },
218220
{"livetraffic/cfg/auto_start", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
221+
{"livetraffic/cfg/ai_for_tcas", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
219222
{"livetraffic/cfg/labels", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
223+
{"livetraffic/cfg/label_shown", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
220224
{"livetraffic/cfg/label_col_dyn", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
221225
{"livetraffic/cfg/label_color", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
222226
{"livetraffic/cfg/log_level", DataRefs::LTGetInt, DataRefs::LTSetLogLevel, GET_VAR, true },
@@ -228,6 +232,7 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[] = {
228232
{"livetraffic/cfg/fd_refresh_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
229233
{"livetraffic/cfg/fd_buf_period", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
230234
{"livetraffic/cfg/ac_outdated_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
235+
{"livetraffic/cfg/lnd_lights_taxi", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
231236
{"livetraffic/channel/adsb_exchange/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
232237
{"livetraffic/channel/adsb_exchange/historic", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
233238
{"livetraffic/channel/open_sky/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
@@ -249,7 +254,9 @@ void* DataRefs::getVarAddr (dataRefsLT dr)
249254
switch (dr) {
250255
case DR_CFG_AIRCRAFTS_DISPLAYED: return &bShowingAircrafts;
251256
case DR_CFG_AUTO_START: return &bAutoStart;
252-
case DR_CFG_LABELS: return &labelCfg.i;
257+
case DR_CFG_AI_FOR_TCAS: return &bAIforTCAS;
258+
case DR_CFG_LABELS: return &labelCfg;
259+
case DR_CFG_LABEL_SHOWN: return &labelShown;
253260
case DR_CFG_LABEL_COL_DYN: return &bLabelColDynamic;
254261
case DR_CFG_LABEL_COLOR: return &labelColor;
255262
case DR_CFG_LOG_LEVEL: return &iLogLevel;
@@ -261,6 +268,7 @@ void* DataRefs::getVarAddr (dataRefsLT dr)
261268
case DR_CFG_FD_REFRESH_INTVL: return &fdRefreshIntvl;
262269
case DR_CFG_FD_BUF_PERIOD: return &fdBufPeriod;
263270
case DR_CFG_AC_OUTDATED_INTVL: return &acOutdatedIntvl;
271+
case DR_CFG_LND_LIGHTS_TAXI: return &bLndLightsTaxi;
264272

265273
case DR_DBG_AC_FILTER: return &uDebugAcFilter;
266274
case DR_DBG_AC_POS: return &bDebugAcPos;
@@ -435,7 +443,14 @@ bool DataRefs::Init ()
435443
for ( int i=0; i < CNT_DATAREFS_XP; i++ )
436444
{
437445
if ( (adrXP[i] = XPLMFindDataRef (DATA_REFS_XP[i])) == NULL )
438-
{ LOG_MSG(logFATAL,ERR_DATAREF_FIND,DATA_REFS_XP[i]); return false; }
446+
{
447+
// for XP10 compatibility we accept if we don't find "VR/enabled",
448+
// all else stays an error
449+
if (i != DR_VR_ENABLED) {
450+
LOG_MSG(logFATAL,ERR_DATAREF_FIND,DATA_REFS_XP[i]);
451+
return false;
452+
}
453+
}
439454
}
440455

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

947962
// Tell XPMP if we need labels
948-
if (labelCfg.i > 0)
963+
if (ShallDrawLabels())
949964
XPMPEnableAircraftLabels();
950965
else
951966
XPMPDisableAircraftLabels();
@@ -1441,3 +1456,13 @@ double DataRefs::GetViewHeading()
14411456
XPLMReadCameraPosition(&camPos);
14421457
return camPos.heading;
14431458
}
1459+
1460+
bool DataRefs::ShallDrawLabels() const
1461+
{
1462+
// user doesn't want labels in VR but is in VR mode? -> no labels
1463+
if (!labelShown.bVR && IsVREnabled())
1464+
return false;
1465+
1466+
// now depends on internal or external view
1467+
return IsViewExternal() ? labelShown.bExternal : labelShown.bInternal;
1468+
}

Src/Include/DataRefs.h

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ enum dataRefsXP {
9595
DR_LOCAL_DATE_DAYS,
9696
DR_USE_SYSTEM_TIME,
9797
DR_ZULU_TIME_SEC,
98+
DR_VIEW_EXTERNAL,
99+
DR_VR_ENABLED,
98100
CNT_DATAREFS_XP // always last, number of elements
99101
};
100102

@@ -127,7 +129,9 @@ enum dataRefsLT {
127129
DR_SIM_TIME,
128130
DR_CFG_AIRCRAFTS_DISPLAYED,
129131
DR_CFG_AUTO_START,
132+
DR_CFG_AI_FOR_TCAS,
130133
DR_CFG_LABELS,
134+
DR_CFG_LABEL_SHOWN,
131135
DR_CFG_LABEL_COL_DYN,
132136
DR_CFG_LABEL_COLOR,
133137
DR_CFG_LOG_LEVEL,
@@ -139,6 +143,7 @@ enum dataRefsLT {
139143
DR_CFG_FD_REFRESH_INTVL,
140144
DR_CFG_FD_BUF_PERIOD,
141145
DR_CFG_AC_OUTDATED_INTVL,
146+
DR_CFG_LND_LIGHTS_TAXI,
142147
DR_CHANNEL_ADSB_EXCHANGE_ONLINE,
143148
DR_CHANNEL_ADSB_EXCHANGE_HISTORIC,
144149
DR_CHANNEL_OPEN_SKY_ONLINE,
@@ -238,13 +243,28 @@ class DataRefs
238243
bHeightAGL : 1,
239244
bSpeed : 1, // default
240245
bVSI : 1;
246+
247+
// this is a bit ugly but avoids a wrapper union with an int
248+
inline int GetInt() const { return *reinterpret_cast<const int*>(this); }
249+
inline void SetInt(int i) { *reinterpret_cast<int*>(this) = i; }
250+
inline bool operator != (const LabelCfgTy& o) const
251+
{ return GetInt() != o.GetInt(); }
241252
};
242253

243-
union LabelCfgUTy {
244-
LabelCfgTy b;
245-
int i;
246-
};
254+
// when to show a/c labels?
255+
struct LabelShowCfgTy {
256+
unsigned
257+
bExternal : 1, // external/outside views
258+
bInternal : 1, // internal/cockpit views
259+
bVR : 1; // VR views
247260

261+
// this is a bit ugly but avoids a wrapper union with an int
262+
inline int GetInt() const { return *reinterpret_cast<const int*>(this); }
263+
inline void SetInt(int i) { *reinterpret_cast<int*>(this) = i; }
264+
inline bool operator != (const LabelCfgTy& o) const
265+
{ return GetInt() != o.GetInt(); }
266+
};
267+
248268
struct CSLPathCfgTy { // represents a line in the [CSLPath] section of LiveTrafic.prg
249269
bool bEnabled = false;
250270
std::string path;
@@ -284,8 +304,10 @@ class DataRefs
284304

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

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

@@ -309,6 +332,12 @@ class DataRefs
309332
int cntAc = 0; // number of a/c being displayed
310333
std::string keyAc; // key (transpIcao) for a/c whose data is returned
311334
const LTAircraft* pAc = nullptr; // ptr to that a/c
335+
336+
//MARK: Debug helpers (public)
337+
public:
338+
std::string cslFixAcIcaoType; // set of fixed values to use for...
339+
std::string cslFixOpIcao; // ...newly created aircrafts for...
340+
std::string cslFixLivery; // ...CSL model package testing
312341

313342
//MARK: Constructor
314343
public:
@@ -329,7 +358,9 @@ class DataRefs
329358
inline int GetLocalDateDays() const { return XPLMGetDatai(adrXP[DR_LOCAL_DATE_DAYS]); }
330359
inline bool GetUseSystemTime() const { return XPLMGetDatai(adrXP[DR_USE_SYSTEM_TIME]) != 0; }
331360
inline float GetZuluTimeSec() const { return XPLMGetDataf(adrXP[DR_ZULU_TIME_SEC]); }
332-
361+
inline bool IsViewExternal() const { return XPLMGetDatai(adrXP[DR_VIEW_EXTERNAL]) != 0; }
362+
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
363+
333364
inline void SetLocalDateDays(int days) { XPLMSetDatai(adrXP[DR_LOCAL_DATE_DAYS], days); }
334365
inline void SetUseSystemTime(bool bSys) { XPLMSetDatai(adrXP[DR_USE_SYSTEM_TIME], (int)bSys); }
335366
inline void SetZuluTimeSec(float sec) { XPLMSetDataf(adrXP[DR_ZULU_TIME_SEC], sec); }
@@ -377,7 +408,9 @@ class DataRefs
377408
static void LTSetCfgValue(void* p, int val);
378409
bool SetCfgValue(void* p, int val);
379410
inline bool GetAutoStart() const { return bAutoStart != 0; }
380-
inline LabelCfgUTy GetLabelCfg() const { return labelCfg; }
411+
inline bool GetAIforTCAS() const { return bAIforTCAS != 0; }
412+
inline LabelCfgTy GetLabelCfg() const { return labelCfg; }
413+
inline LabelShowCfgTy GetLabelShowCfg() const { return labelShown; }
381414
inline bool IsLabelColorDynamic() const { return bLabelColDynamic; }
382415
inline int GetLabelColor() const { return labelColor; }
383416
void GetLabelColor (float outColor[4]) const;
@@ -390,7 +423,8 @@ class DataRefs
390423
inline int GetFdRefreshIntvl() const { return fdRefreshIntvl; }
391424
inline int GetFdBufPeriod() const { return fdBufPeriod; }
392425
inline int GetAcOutdatedIntvl() const { return acOutdatedIntvl; }
393-
426+
inline bool GetLndLightsTaxi() const { return bLndLightsTaxi != 0; }
427+
394428
const vecCSLPaths& GetCSLPaths() const { return vCSLPaths; }
395429
vecCSLPaths& GetCSLPaths() { return vCSLPaths; }
396430
void SaveCSLPath(int idx, const CSLPathCfgTy path);
@@ -454,6 +488,7 @@ class DataRefs
454488
static double GetViewHeading();
455489
static inline boundingBoxTy GetBoundingBox(double dist) // bounding box around current view pos
456490
{ return boundingBoxTy(GetViewPos(), dist); }
491+
bool ShallDrawLabels() const;
457492
};
458493

459494
extern DataRefs::dataRefDefinitionT DATA_REFS_LT[CNT_DATAREFS_LT];

Src/Include/LTFlightData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class LTFlightData
159159
int sig; // signal level
160160

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

164164
protected:
165165
// DYNAMIC DATA (protected, access will be mutex-controlled for thread-safety)

Src/LTAircraft.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,12 @@ std::string LTAircraft::FlightPhase2String (FlightPhase phase)
826826
// Constructor: create an aircraft from Flight Data
827827
LTAircraft::LTAircraft(LTFlightData& inFd) :
828828
// Base class -> this registers with XPMP API for actual display in XP!
829-
XPCAircraft(inFd.WaitForSafeCopyStat().acTypeIcao.c_str(), // repeated calls to WaitForSafeCopyStat look inefficient
830-
inFd.WaitForSafeCopyStat().opIcao.c_str(), // ...but if the lock is held by the calling function already then these are quick recursive calls
831-
inFd.WaitForSafeCopyStat().reg.c_str()), // Using registration as livery indicator, allows for different liveries per actual airframe
829+
// repeated calls to WaitForSafeCopyStat look inefficient, but if the lock is held by the calling function already then these are quick recursive calls
830+
// Using registration as livery indicator, allows for different liveries per actual airframe
831+
// Debug options to set fixed type/op/livery take precedence
832+
XPCAircraft(str_first_non_empty({dataRefs.cslFixAcIcaoType, inFd.WaitForSafeCopyStat().acTypeIcao}).c_str(),
833+
str_first_non_empty({dataRefs.cslFixOpIcao, inFd.WaitForSafeCopyStat().opIcao}).c_str(),
834+
str_first_non_empty({dataRefs.cslFixLivery, inFd.WaitForSafeCopyStat().reg}).c_str()),
832835
// class members
833836
fd(inFd),
834837
mdl(FlightModel::FindFlightModel(inFd.WaitForSafeCopyStat().acTypeIcao)), // find matching flight model
@@ -1471,7 +1474,7 @@ void LTAircraft::CalcFlightModel (const positionTy& /*from*/, const positionTy&
14711474
// some assumption to begin with...
14721475
surfaces.thrust = 0.1f;
14731476
surfaces.lights.timeOffset = (unsigned int)rand();
1474-
surfaces.lights.landLights = 0;
1477+
surfaces.lights.landLights = dataRefs.GetLndLightsTaxi() ? 1 : 0;
14751478
surfaces.lights.bcnLights = 1;
14761479
surfaces.lights.strbLights = 0;
14771480
surfaces.lights.navLights = 1;
@@ -1587,7 +1590,7 @@ void LTAircraft::CalcFlightModel (const positionTy& /*from*/, const positionTy&
15871590
flaps.up();
15881591
surfaces.spoilerRatio = surfaces.speedBrakeRatio = 0.0;
15891592
surfaces.thrust = 0.1f;
1590-
surfaces.lights.landLights = 0;
1593+
surfaces.lights.landLights = dataRefs.GetLndLightsTaxi() ? 1 : 0;
15911594
surfaces.lights.strbLights = 0;
15921595
}
15931596

Src/LTFlightData.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,18 @@ void LTFlightData::UpdateStaticLabel()
306306
std::lock_guard<std::recursive_mutex> lock (dataAccessMutex);
307307

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

311311
// add parts as per config
312312
labelStat.clear();
313-
ADD_LABEL(cfg.b.bIcaoType, statData.acTypeIcao);
314-
ADD_LABEL(cfg.b.bAnyAcId, statData.acId(key()));
315-
ADD_LABEL(cfg.b.bTranspCode, key());
316-
ADD_LABEL(cfg.b.bReg, statData.reg);
317-
ADD_LABEL(cfg.b.bIcaoOp, statData.opIcao);
318-
ADD_LABEL(cfg.b.bCallSign, statData.call);
319-
ADD_LABEL(cfg.b.bFlightNo, statData.flight);
320-
ADD_LABEL(cfg.b.bRoute, statData.route());
313+
ADD_LABEL(cfg.bIcaoType, statData.acTypeIcao);
314+
ADD_LABEL(cfg.bAnyAcId, statData.acId(key()));
315+
ADD_LABEL(cfg.bTranspCode, key());
316+
ADD_LABEL(cfg.bReg, statData.reg);
317+
ADD_LABEL(cfg.bIcaoOp, statData.opIcao);
318+
ADD_LABEL(cfg.bCallSign, statData.call);
319+
ADD_LABEL(cfg.bFlightNo, statData.flight);
320+
ADD_LABEL(cfg.bRoute, statData.route());
321321

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

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

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

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

16971697
// doesn't yet have an associated aircraft but two positions?

0 commit comments

Comments
 (0)