Skip to content

Commit

Permalink
Merge pull request #205 from TwinFan/Next
Browse files Browse the repository at this point in the history
v2.40
  • Loading branch information
TwinFan authored Dec 23, 2020
2 parents bba4912 + 439a3ff commit 43a3d4c
Show file tree
Hide file tree
Showing 33 changed files with 10,372 additions and 2,061 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.localized
.image
.vs/
.vscode/

# Build directories
build/
Expand Down
8,160 changes: 8,160 additions & 0 deletions Data/RealTraffic/KPTK_20201128.csv

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//
// MARK: Version Information (CHANGE VERSION HERE)
//
constexpr float VERSION_NR = 2.30f;
constexpr float VERSION_NR = 2.40f;
constexpr bool VERSION_BETA = false;
extern float verXPlaneOrg; // version on X-Plane.org
extern int verDateXPlaneOrg; // and its date
Expand Down Expand Up @@ -307,6 +307,7 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
#define ERR_CH_MAX_ERR_INV "%s: Channel invalid and disabled after too many errors"
#define ERR_NO_AC_TYPE "Tracking data for '%s' (man '%s', mdl '%s') lacks ICAO a/c type code, can't derive type -> will be rendered with standard a/c %s"
#define ERR_NO_AC_TYPE_BUT_MDL "Tracking data for '%s' (man '%s', mdl '%s') lacks ICAO a/c type code, but derived %s from mdl text"
#define ERR_SHARED_DATAREF "Could not created shared dataRef for livetraffic/camera/..., 3rd party camera plugins will not be able to take over camera view automatically"
#define ERR_DATAREF_FIND "Could not find DataRef/CmdRef: %s"
#define ERR_DATAREF_ACCESSOR "Could not register accessor for DataRef: %s"
#define ERR_CREATE_COMMAND "Could not create command %s"
Expand Down
5 changes: 0 additions & 5 deletions Include/CoordCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,6 @@ struct positionTy {
v{dLat, dLon, dAlt_m, dTS, dHead, dPitch, dRoll},
f{fPhase,false,grnd,uCoord,uAngle,SPOS_NONE,false}
{}
positionTy(const XPMPPlanePosition_t& x) :
positionTy (x.lat, x.lon, x.elevation * M_per_FT,
NAN, x.heading, x.pitch, x.roll) {}
positionTy ( const XPLMProbeInfo_t& probe ) :
positionTy ( probe.locationZ, probe.locationX, probe.locationY ) { f.unitCoord=UNIT_LOCAL; }
positionTy ( const ptTy& _pt) :
Expand All @@ -373,8 +370,6 @@ struct positionTy {

// typecase to ptTy
operator ptTy() const { return ptTy(lon(),lat()); }
// typecast to what XPMP API needs
operator XPMPPlanePosition_t() const;
// standard string for any output purposes
static const char* GrndE2String (onGrndE grnd);
std::string dbgTxt() const;
Expand Down
15 changes: 13 additions & 2 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ enum dataRefsXP {
DR_VIEW_EXTERNAL,
DR_VIEW_TYPE,
DR_MODERN_DRIVER, // sim/graphics/view/using_modern_driver: boolean: Vulkan/Metal in use?

DR_CAMERA_TCAS_IDX, ///< Shared data ref created by us: If LiveTraffic's camera is on, then on which aircraft? Here: TCAS index
DR_CAMERA_AC_ID, ///< Shared data ref created by us: If LiveTraffic's camera is on, then on which aircraft? Here: aircraft id (usually ICAO hex code)

DR_PLANE_LAT, // user's plane
DR_PLANE_LON,
DR_PLANE_ELEV,
Expand Down Expand Up @@ -320,7 +324,7 @@ enum dataRefsLT {

DR_SIM_DATE,
DR_SIM_TIME,

DR_LT_VER, ///< LiveTraffic's version number, like 201 for v2.01
DR_LT_VER_DATE, ///< LiveTraffic's version date, like 20200430 for 30-APR-2020

Expand Down Expand Up @@ -360,6 +364,7 @@ enum dataRefsLT {
DR_CFG_HIDE_NEARBY_AIR,
DR_CFG_COPY_OBJ_FILES,
DR_CFG_REMOTE_SUPPORT,
DR_CFG_EXTERNAL_CAMERA,
DR_CFG_LAST_CHECK_NEW_VER,

// debug options
Expand Down Expand Up @@ -559,7 +564,7 @@ class DataRefs

//MARK: DataRefs
protected:
XPLMDataRef adrXP[CNT_DATAREFS_XP]; // array of XP data refs to read from
XPLMDataRef adrXP[CNT_DATAREFS_XP]; ///< array of XP data refs to read from and shared dataRefs to provide
XPLMDataRef adrLT[CNT_DATAREFS_LT]; // array of data refs LiveTraffic provides
public:
XPLMCommandRef cmdXP[CNT_CMDREFS_XP]; // array of command refs
Expand Down Expand Up @@ -621,6 +626,7 @@ class DataRefs
int hideNearbyAir = 0; // [m] hide a/c if closer than this to user's aircraft in the air
int cpyObjFiles = 1; ///< copy `.obj` files for replacing dataRefs and textures
int remoteSupport = 0; ///< support XPMP2 Remote Client? (3-way: -1 off, 0 auto, 1 on)
bool bUseExternalCamera = false; ///< Do not activate LiveTraffic's camera view when hitting the camera button (intended for a 3rd party camera plugin to activate instead based on reading livetraffic/camera/... dataRefs or using LTAPI)

// channel config options
int ognUseRequRepl = 0; ///< OGN: Use Request/Reply instead of TCP receiver
Expand Down Expand Up @@ -688,6 +694,7 @@ class DataRefs
public:
DataRefs ( logLevelTy initLogLevel ); // Constructor doesn't do much
bool Init(); // Init DataRefs, return "OK?"
void InformDataRefEditors(); ///< tell DRE and DRT our dataRefs
void Stop(); // unregister what's needed

protected:
Expand Down Expand Up @@ -740,6 +747,9 @@ class DataRefs
static int LTGetAcInfoI(void* p);
static float LTGetAcInfoF(void* p);

void SetCameraAc(const LTAircraft* pCamAc); ///< sets the data of the shared datarefs to point to `ac` as the current aircraft under the camera
static void ClearCameraAc(void*); ///< shared dataRef callback: Whenever someone else writes to the shared dataRef we clear our a/c camera information

// seconds since epoch including fractionals
double GetSimTime() const { return lastSimTime; }
/// Current sim time as a human readable string, including 10th of seconds
Expand Down Expand Up @@ -810,6 +820,7 @@ class DataRefs
hideNearbyGnd > 0 || hideNearbyAir > 0; }
bool ShallCpyObjFiles () const { return cpyObjFiles != 0; }
int GetRemoteSupport () const { return remoteSupport; }
bool ShallUseExternalCamera () const { return bUseExternalCamera; }

bool NeedNewVerCheck () const;
void SetLastCheckedNewVerNow ();
Expand Down
25 changes: 8 additions & 17 deletions Include/LTAircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include <string>
#include "XPLMScenery.h"
#include "XPCAircraft.h"
#include "XPMPAircraft.h"
#include "CoordCalc.h"
#include "LTFlightData.h"

Expand Down Expand Up @@ -203,7 +203,7 @@ struct BezierCurve
// Represents an aircraft as displayed in XP by use of the
// XP Multiplayer Lib
//
class LTAircraft : public XPCAircraft
class LTAircraft : public XPMP2::Aircraft
{
public:
class FlightModel {
Expand Down Expand Up @@ -282,9 +282,6 @@ class LTAircraft : public XPCAircraft
// as basis for calculating ppos per frame
dequePositionTy posList;

XPMPPlaneSurfaces_t surfaces;
XPMPPlaneRadar_t radar;
char szLabelAc[sizeof(XPMPPlanePosition_t::label)]; // label at the a/c
std::string labelInternal; // internal label, e.g. for error messages
protected:
// this is "ppos", the present simulated position,
Expand Down Expand Up @@ -330,8 +327,6 @@ class LTAircraft : public XPCAircraft
// visibility
bool bSetVisible = true; // manually set visible?
bool bAutoVisible = true; // visibility handled automatically?
int aiPrio = 0; ///< prio for AI slotting (libxplanemp)
int multiIdx = 0; ///< plane's multiplayer index if reported via sim/multiplayer/position dataRefs, 0 otherwise

/// Nearest airport
std::string nearestAirport;
Expand All @@ -340,16 +335,14 @@ class LTAircraft : public XPCAircraft

public:
LTAircraft(LTFlightData& fd);
virtual ~LTAircraft();
~LTAircraft() override;

// key for maps
inline const std::string& key() const { return fd.key().key; }
// labels to pin to aircraft on the screes
inline const std::string label() const { return szLabelAc; }
void LabelUpdate();
/// @brief Return a value for dataRef .../tcas/target/flight_id
/// @returns "Any Id"
virtual std::string GetFlightId() const;
std::string GetFlightId() const override;
// stringify e.g. for debugging info purposes
operator std::string() const;
// current position
Expand Down Expand Up @@ -397,13 +390,14 @@ class LTAircraft : public XPCAircraft
inline void SetSendNewInfoData () { bSendNewInfoData = true; }
// Visibility
inline bool IsAutoVisible() const { return bAutoVisible; }
virtual void SetVisible (bool _bVisible); // define visibility, overrides auto
void SetVisible (bool _bVisible) override; // define visibility, overrides auto
bool SetAutoVisible (bool b); // returns bVisible after auto setting
// external camera view
void ToggleCameraView(); // start an external view on this a/c
void CalcCameraViewPos();
inline bool IsInCameraView() const { return pExtViewAc == this; }
static bool IsCameraViewOn() { return pExtViewAc != NULL; }
static void SetCameraAcExternally (LTAircraft* pCamAc) { pExtViewAc = pCamAc; }

protected:
void CalcLabelInternal (const LTFlightData::FDStaticData& statDat);
Expand Down Expand Up @@ -443,11 +437,8 @@ class LTAircraft : public XPCAircraft
void * inRefcon);

protected:
// XPMP Aircraft Updates (callbacks)
virtual XPMPPlaneCallbackResult GetPlanePosition(XPMPPlanePosition_t* outPosition);
virtual XPMPPlaneCallbackResult GetPlaneSurfaces(XPMPPlaneSurfaces_t* outSurfaces);
virtual XPMPPlaneCallbackResult GetPlaneRadar(XPMPPlaneRadar_t* outRadar);
virtual XPMPPlaneCallbackResult GetInfoTexts(XPMPInfoTexts_t * outInfoTexts);
/// XPMP Aircraft Updates
void UpdatePosition (float, int cycle) override;
};

#endif /* LTAircraft_h */
1 change: 1 addition & 0 deletions Include/LTChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern std::mutex FDThreadSynchMutex; // supports wake-up and stop sync
extern std::condition_variable FDThreadSynchCV;
// stop all threads?
extern volatile bool bFDMainStop;
extern std::chrono::time_point<std::chrono::steady_clock> gNextWakeup; ///< when to wake up next for network requests

//
//MARK: Flight Data Connection (abstract base class)
Expand Down
11 changes: 6 additions & 5 deletions Include/LTFlightData.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class LTFlightData
std::string opIcao; // XPMP API: "Airline" BER

protected:
bool bInit = false; // has been initialized?
/// Has this static data object already been filled from a proper master data channel?
bool bFilledFromMasterCh = false;

public:
FDStaticData() {}
Expand All @@ -137,7 +138,7 @@ class LTFlightData
FDStaticData& operator=(FDStaticData&&) = default;
/// @brief Merges data, i.e. copy only filled fields from 'other'
/// @return Have matching-relevant fields now changed?
bool merge (const FDStaticData& other);
bool merge (const FDStaticData& other, bool bIsMasterChData);
// returns flight, call sign, registration, or provieded _default (e.g. transp hex code)
std::string acId (const std::string _default) const;
// route (this is "originAp-destAp", but considers empty txt)
Expand All @@ -149,8 +150,8 @@ class LTFlightData
{ return opIcao.empty() ? call.substr(0,3) : opIcao; }
/// is this a ground vehicle?
bool isGrndVehicle() const;
// has been initialized at least once?
bool isInit() const { return bInit; }
/// has been initialized from a proper master data channel?
bool hasMasterChData() const { return bFilledFromMasterCh; }
};

// KEY (protected, can be set only once, no mutex-control)
Expand Down Expand Up @@ -354,7 +355,7 @@ class LTFlightData
inline int GetRcvr() const { return rcvr; }

// access static data
void UpdateData ( const FDStaticData& inStat );
void UpdateData ( const FDStaticData& inStat, bool bIsMasterChData = false );
bool TryGetSafeCopy ( FDStaticData& outStat ) const;
FDStaticData WaitForSafeCopyStat() const;
inline const FDStaticData& GetUnsafeStat() const { return statData; } // no lock, potentially inconsistent!
Expand Down
1 change: 1 addition & 0 deletions Include/LTOpenSky.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ constexpr double OPSKY_WAIT_BETWEEN = 0.5; // seconds to pause between
#define OPSKY_MD_AC_TYPE_ICAO "typecode"
#define OPSKY_MD_CAT_DESCR "categoryDescription"
#define OPSKY_MD_TEXT_VEHICLE "Surface Vehicle"
constexpr size_t OPSKY_MD_TEXT_VEHICLE_LEN = 20; ///< length after which category description might contain useful text in case of a Surface Vehicle
#define OPSKY_MD_TEXT_NO_CAT "No ADS-B Emitter Category Information"
#define OPSKY_MD_MDL_UNKNOWN "[?]"

Expand Down
4 changes: 4 additions & 0 deletions Include/LiveTraffic.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ constexpr bool between( const T& v, const T& lo, const T& hi )
// comparing 2 doubles for near-equality
bool dequal ( const double d1, const double d2 );

/// Convert NAN to zero, otherwise pass `d`
inline double nanToZero (double d)
{ return std::isnan(d) ? 0.0 : d; }

/// @brief random long between too given values invlusive
/// @see https://stackoverflow.com/a/7560171
inline long randoml (long min, long max)
Expand Down
Loading

0 comments on commit 43a3d4c

Please sign in to comment.