Skip to content

Commit

Permalink
Merge pull request #187 from TwinFan/Next
Browse files Browse the repository at this point in the history
v2.03
  • Loading branch information
TwinFan authored May 16, 2020
2 parents 10794b7 + 216eecc commit 1b925fe
Show file tree
Hide file tree
Showing 32 changed files with 685 additions and 408 deletions.
2 changes: 1 addition & 1 deletion Include/ACInfoWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TFACSearchEditWidget : public TFTextFieldWidget
TFACSearchEditWidget (XPWidgetID _me = NULL, const char* szKey = NULL);

// Find my aircraft
const LTFlightData* SearchFlightData (const std::string ac_key);
const LTFlightData* SearchFlightData (std::string ac_key);
void SetAcKey (const LTFlightData::FDKeyTy& _key);

// Get the found aircraft
Expand Down
14 changes: 10 additions & 4 deletions 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.02f;
constexpr float VERSION_NR = 2.03f;
constexpr bool VERSION_BETA = true;
extern float verXPlaneOrg; // version on X-Plane.org
extern int verDateXPlaneOrg; // and its date
Expand Down Expand Up @@ -105,6 +105,7 @@ constexpr double MDL_TIRE_SLOW_TIME = 5.0; ///< [s] time till tires stop rotati
constexpr double MDL_TIRE_MAX_RPM = 2000; ///< [rpm] max tire rotation speed
constexpr double MDL_TIRE_CF_M = 3.2; ///< [m] tire circumfence (3.2m for a 40-inch tire)
constexpr double MDL_GEAR_DEFL_TIME = 0.5; ///< [s] time for gear deflection (one direction...up down is twice this value)
constexpr double MDL_CAR_MAX_TAXI = 80.0; ///< [kn] Maximum allowed taxi speed for ground vehicles (before they turn into planes)

constexpr int COLOR_YELLOW = 0xFFFF00;
constexpr int COLOR_RED = 0xFF0000;
Expand Down Expand Up @@ -145,9 +146,10 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new

//MARK: Text Constants
#define LIVE_TRAFFIC "LiveTraffic"
#define LIVE_TRAFFIC_XPMP2 " LT" ///< short form for logging by XPMP2, so that log entries are aligned
#define LT_CFG_VER_NM_CONV "1.0" // version of config file format, from which to convert distances from km to nm
#define LT_CFG_VERSION "1.1" // current version of config file format
#define LT_FM_VERSION "1.1" // version of flight model file format
#define LT_FM_VERSION "2.0" // version of flight model file format
#define PLUGIN_SIGNATURE "TwinFan.plugin.LiveTraffic"
#define PLUGIN_DESCRIPTION "Create Multiplayer Aircraft based on live traffic."
#define LT_DOWNLOAD_URL "https://forums.x-plane.org/index.php?/files/file/49749-livetraffic/"
Expand All @@ -158,6 +160,7 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
#define MSG_REINIT "LiveTraffic is re-initializing itself"
#define MSG_DISABLE_MYSELF "LiveTraffic disables itself due to unhandable exceptions"
#define MSG_LT_NEW_VER_AVAIL "The new version %01.2f of LiveTraffic is available at X-Plane.com!"
#define MSG_TIMESTAMPS "Current System time is %sZ, current simulated time is %sZ"
#define MSG_AI_LOAD_ACF "Changing AI control: X-Plane is now loading AI Aircraft models..."
#define MSG_REQUESTING_LIVE_FD "Requesting live flight data online..."
#define MSG_READING_HIST_FD "Reading historic flight data..."
Expand All @@ -168,6 +171,8 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
#define MSG_ADSBEX_LIMITE "%ld / %ld requests left"
#define INFO_AC_ADDED "Added aircraft %s, operator '%s', a/c model '%s', flight model [%s], bearing %.0f, distance %.1fnm, from channel %s"
#define INFO_AC_MDL_CHANGED "Changed CSL model for aircraft %s, operator '%s': a/c model now '%s'"
#define INFO_GND_VEHICLE_APT "Vehicle %s: Decided for ground vehicle based on operator name '%s'"
#define INFO_GND_VEHICLE_CALL "Vehicle %s: Decided for ground vehicle based on call sign '%s'"
#define INFO_AC_REMOVED "Removed aircraft %s"
#define INFO_AC_ALL_REMOVED "Removed all aircraft"
#define INFO_WND_AUTO_AC "AUTO"
Expand All @@ -183,6 +188,7 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
#define CSL_DEFAULT_ICAO_TYPE "A320"
#define CSL_CAR_ICAO_TYPE "ZZZC" // fake code for a ground vehicle
#define FM_MAP_SECTION "Map"
#define FM_CAR_SECTION "GroundVehicles"
#define FM_PARENT_SEPARATOR ":"
#define CFG_CSL_SECTION "[CSLPaths]"
#define CFG_DEFAULT_AC_TYPE "DEFAULT_AC_TYPE"
Expand Down Expand Up @@ -273,7 +279,7 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
#define ERR_CH_UNKNOWN_NAME "(unknown channel)"
#define ERR_CH_INVALID "%s: Channel invalid and disabled"
#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, will be rendered with standard a/c %s"
#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_DATAREF_FIND "Could not find DataRef/CmdRef: %s"
#define ERR_DATAREF_ACCESSOR "Could not register accessor for DataRef: %s"
Expand Down Expand Up @@ -318,7 +324,7 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
#define ERR_CFG_AC_DEFAULT "A/c default ICAO type '%s' invalid, still using '%s' as default. Verify Settings > CSL!"
#define ERR_CFG_CAR_DEFAULT "Car default ICAO type '%s' invalid, still using '%s' as default. Verify Settings > CSL!"
#define ERR_CFG_TYPE_INVALID "%s, line %d: ICAO type designator '%s' unknown"
#define ERR_FM_NOT_AFTER_MAP "Remainder after [Map] section ignored"
#define ERR_FM_NOT_AFTER_MAP "Unknown section after [Map] section ignored"
#define ERR_FM_NOT_BEFORE_SEC "Lines before first section ignored"
#define ERR_FM_UNKNOWN_NAME "Unknown parameter in '%s', line %d: %s"
#define ERR_FM_UNKNOWN_SECTION "Referring to unknown model section in '%s', line %d: %s"
Expand Down
3 changes: 0 additions & 3 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ enum dataRefsLT {
DR_CFG_AUTO_START,
DR_CFG_AI_ON_REQUEST,
DR_CFG_AI_UNDER_CONTROL,
DR_CFG_AI_SKIP_NOPLANE,
DR_CFG_LABELS,
DR_CFG_LABEL_SHOWN,
DR_CFG_LABEL_COL_DYN,
Expand Down Expand Up @@ -477,7 +476,6 @@ class DataRefs
// generic config values
int bAutoStart = true; // shall display a/c right after startup?
int bAIonRequest = false;// acquire multiplayer control for TCAS on request only, not automatically?
int nAISkipAssignNoPlane = -1; ///< Skip assigning NoPlane.acf to AI planes (-1 = use defaults, 0 = force off, 1 = force on)
// which elements make up an a/c label?
LabelCfgTy labelCfg = { 0,1,0,0,0,0,0,0, 0,0,0,0,0,0 };
LabelShowCfgTy labelShown = { 1, 1, 1 }; // when to show? (default: always)
Expand Down Expand Up @@ -626,7 +624,6 @@ class DataRefs
// specific access
inline bool GetAutoStart() const { return bAutoStart != 0; }
inline bool IsAIonRequest() const { return bAIonRequest != 0; }
bool ShallAISkipAssignNoPlane() const;
static int HaveAIUnderControl(void* =NULL) { return XPMPHasControlOfAIAircraft(); }
inline LabelCfgTy GetLabelCfg() const { return labelCfg; }
inline LabelShowCfgTy GetLabelShowCfg() const { return labelShown; }
Expand Down
15 changes: 11 additions & 4 deletions Include/LTAircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ class LTAircraft : public XPCAircraft

public:
static bool ReadFlightModelFile ();
static const FlightModel& FindFlightModel (const std::string acTypeIcao);
static const FlightModel* GetFlightModel (const std::string modelName);
static const FlightModel& FindFlightModel (const std::string& acTypeIcao);
static const FlightModel* GetFlightModel (const std::string& modelName);
/// Tests if the given call sign matches typical call signs of ground vehicles
static bool MatchesCar (const std::string& _callSign);
};

public:
Expand Down Expand Up @@ -350,6 +352,7 @@ class LTAircraft : public XPCAircraft
#ifdef DEBUG
bool bIsSelected = false; // is selected for logging/debugging?
#endif
bool bChangeModel = false; ///< shall the model be updated at next chance?
bool bSendNewInfoData = false; ///< is there new static data to announce?
// visibility
bool bVisible = true; // is a/c visible?
Expand All @@ -368,8 +371,6 @@ class LTAircraft : public XPCAircraft
void LabelUpdate();
// stringify e.g. for debugging info purposes
operator std::string() const;
// change the model (e.g. when model-defining static data changed)
void ChangeModel (const LTFlightData::FDStaticData& statData);
// current position
inline const positionTy& GetPPos() const { return ppos; }
inline positionTy GetPPosLocal() const { return positionTy(ppos).WorldToLocal(); }
Expand Down Expand Up @@ -407,6 +408,8 @@ class LTAircraft : public XPCAircraft
// object valid? (set to false after exceptions)
inline bool IsValid() const { return bValid; }
void SetInvalid() { bValid = false; }
bool ShallUpdateModel () const { return bChangeModel; }
void SetUpdateModel () { bChangeModel = true; }
inline bool ShallSendNewInfoData () const { return bSendNewInfoData; }
inline void SetSendNewInfoData () { bSendNewInfoData = true; }
// Visibility
Expand Down Expand Up @@ -434,6 +437,10 @@ class LTAircraft : public XPCAircraft
/// Determines AI priority based on bearing to user's plane and ground status
void CalcAIPrio ();

/// @brief change the model (e.g. when model-defining static data changed)
/// @note Should be used in main thread only
void ChangeModel ();

protected:
// *** Camera view ***
static LTAircraft* pExtViewAc; // the a/c to show in external view, NULL if none/stop ext view
Expand Down
2 changes: 1 addition & 1 deletion Include/LTApt.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool LTAptSnap (LTFlightData& fd, dequePositionTy::iterator& posIter,
/// Cleanup
void LTAptDisable ();

#ifdef DEBUG
#ifdef APT_DUMP
/// @brief Dumps the entire taxi network into a CSV file readable by GPS Visualizer
/// @see https://www.gpsvisualizer.com/
void LTAptDump (const std::string& _aptId);
Expand Down
7 changes: 5 additions & 2 deletions Include/LTFlightData.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ class LTFlightData
FDStaticData(FDStaticData&&) = default;
FDStaticData& operator=(const FDStaticData&) = default;
FDStaticData& operator=(FDStaticData&&) = default;
// 'merge' data, i.e. copy only filled fields from 'other'
FDStaticData& operator |= (const FDStaticData& other);
/// @brief Merges data, i.e. copy only filled fields from 'other'
/// @return Have matching-relevant fields now changed?
bool merge (const FDStaticData& other);
// 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 @@ -151,6 +152,8 @@ class LTFlightData
// best guess for an airline livery: opIcao if exists, otherwise first 3 digits of call sign
inline std::string airlineCode() const
{ 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; }
};
Expand Down
Binary file added Lib/CURL/libcurl.pdb
Binary file not shown.
19 changes: 13 additions & 6 deletions Lib/XPMP2/XPMP2.framework/Versions/1.0/Headers/XPCAircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ XPCAircraft : public XPMP2::Aircraft {

public:

/// Legacy constructor creates a plane and puts it under control of XPlaneMP
XPCAircraft(const char* inICAOCode,
const char* inAirline,
const char* inLivery,
const char* inModelName = nullptr); // this new parameter is defaulted, so that old code should compile
/// @brief Legacy constructor creates a plane and puts it under control of XPlaneMP
/// @exception XPMP2::XPMP2Error Mode S id invalid or duplicate, no model found during model matching
/// @param _icaoType ICAO aircraft type designator, like 'A320', 'B738', 'C172'
/// @param _icaoAirline ICAO airline code, like 'BAW', 'DLH', can be an empty string
/// @param _livery Special livery designator, can be an empty string
/// @param _modeS_id (optional) Unique identification of the plane [0x01..0xFFFFFF], e.g. the 24bit mode S transponder code. XPMP2 assigns an arbitrary unique number of not given
/// @param _modelId (optional) specific model id to be used (no folder/package name, just the id as defined in the `OBJ8_AIRCRAFT` line)
XPCAircraft(const char* _icaoType,
const char* _icaoAirline,
const char* _livery,
XPMPPlaneID _modeS_id = 0, // new parameters are defaulted, so that old code should compile
const char* _modelId = nullptr);

/// Legacy: Called before rendering to query plane's current position, overwrite to provide your implementation
virtual XPMPPlaneCallbackResult GetPlanePosition(XPMPPlanePosition_t* outPosition) = 0;
Expand All @@ -61,7 +68,7 @@ XPCAircraft : public XPMP2::Aircraft {
{ return xpmpData_Unavailable; }

/// Just calls all 4 previous `Get...` functions and copies the provided values into `drawInfo` and `v`
virtual void UpdatePosition ();
virtual void UpdatePosition (float _elapsedSinceLastCall, int _flCounter);

};

Expand Down
65 changes: 40 additions & 25 deletions Lib/XPMP2/XPMP2.framework/Versions/1.0/Headers/XPMPAircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ enum DR_VALS {
class Aircraft {

protected:
/// Legacy: The id of the represented plane (in XPMP2, this now is an arbitrary, ever increasing number)
XPMPPlaneID mPlane = 0;
/// @brief A plane is uniquely identified by a 24bit number [0x01..0xFFFFFF]
/// @details This number is directly used as `modeS_id` n the new
/// [TCAS override](https://developer.x-plane.com/article/overriding-tcas-and-providing-traffic-information/)
/// approach.
XPMPPlaneID modeS_id = 0;

public:
std::string acIcaoType; ///< ICAO aircraft type of this plane
Expand Down Expand Up @@ -144,8 +147,8 @@ class Aircraft {

/// X-Plane instance handles for all objects making up the model
std::list<XPLMInstanceRef> listInst;
/// Which sim/multiplayer/plane-index used last?
int multiIdx = -1;
/// Which sim/cockpit2/tcas/targets-index used last?
int tcasTargetIdx = -1;

/// Timestamp of last update of camera dist/bearing
float camTimLstUpd = 0.0f;
Expand All @@ -162,31 +165,38 @@ class Aircraft {
int mapIconCol = 0; ///< map icon coordinates, column
float mapX = 0.0f; ///< temporary: map coordinates (NAN = not to be drawn)
float mapY = 0.0f; ///< temporary: map coordinates (NAN = not to be drawn)
std::string mapLabel; ///< label for map drawing

public:
/// Constructor
/// Constructor creates a new aircraft object, which will be managed and displayed
/// @exception XPMP2::XPMP2Error Mode S id invalid or duplicate, no model found during model matching
/// @param _icaoType ICAO aircraft type designator, like 'A320', 'B738', 'C172'
/// @param _icaoAirline ICAO airline code, like 'BAW', 'DLH', can be an empty string
/// @param _livery Special livery designator, can be an empty string
/// @param _modeS_id (optional) Unique identification of the plane [0x01..0xFFFFFF], e.g. the 24bit mode S transponder code. XPMP2 assigns an arbitrary unique number of not given
/// @param _modelId (optional) specific model id to be used (no folder/package name, just the id as defined in the `OBJ8_AIRCRAFT` line)
Aircraft (const std::string& _icaoType,
const std::string& _icaoAirline,
const std::string& _livery,
const std::string& _modelName = "");
XPMPPlaneID _modeS_id = 0,
const std::string& _modelId = "");
/// Destructor cleans up all resources acquired
virtual ~Aircraft();

/// return the XPMP2 plane id
XPMPPlaneID GetPlaneID () const { return mPlane; }
/// @brief return the current multiplayer-index
/// @note This is a 0-based index into our internal tables!
/// It is one less than the number used in sim/multiplayer/plane dataRefs,
/// use Aircraft::GetAIPlaneIdx() for that purpose.
int GetMultiIdx () const { return multiIdx; }
/// @brief return the plane's index in XP's sim/multiplayer/plane dataRefs
int GetAIPlaneIdx () const { return multiIdx >= 0 ? multiIdx+1 : -1; }
/// Is this plane currently also being tracked by X-Plane's AI/multiplayer, ie. will appear on TCAS?
bool IsCurrentlyShownAsAI () const { return multiIdx >= 0; }
/// Will this plane show up on TCAS / in multiplayer views? (It will if transponder is not switched off)
XPMPPlaneID GetModeS_ID () const { return modeS_id; }
/// Is this object a ground vehicle?
bool IsGroundVehicle() const;
/// @brief return the current TCAS target index (into sim/cockpit2/tcas/targets), 1-based, -1 if not used
int GetTcasTargetIdx () const { return tcasTargetIdx; }
/// Is this plane currently also being tracked as a TCAS target, ie. will appear on TCAS?
bool IsCurrentlyShownAsTcasTarget () const { return tcasTargetIdx >= 1; }
/// Is this plane currently also being tracked by X-Plane's classic AI/multiplayer?
bool IsCurrentlyShownAsAI () const { return 1 <= tcasTargetIdx && tcasTargetIdx <= 20; }
/// Is this plane to be drawn on TCAS? (It will if transponder is not switched off)
bool ShowAsAIPlane () const { return IsVisible() && acRadar.mode != xpmpTransponderMode_Standby; }
/// Reset multiplayer slot index
void ResetMultiIdx () { multiIdx = -1; }
/// Reset TCAS target slot index
void ResetTcasTargetIdx () { tcasTargetIdx = -1; }

/// (Potentially) change the plane's model after doing a new match attempt
int ChangeModel (const std::string& _icaoType,
Expand All @@ -208,7 +218,11 @@ class Aircraft {
/// @brief Called right before updating the aircraft's placement in the world
/// @details Abstract virtual function. Override in derived classes and fill
/// `drawInfo`, the `v` array of dataRefs, `label`, and `infoTexts` with current values.
virtual void UpdatePosition () = 0;
/// @see See [XPLMFlightLoop_f](https://developer.x-plane.com/sdk/XPLMProcessing/#XPLMFlightLoop_f)
/// for background on the two passed-on parameters:
/// @param _elapsedSinceLastCall The wall time since last call
/// @param _flCounter A monotonically increasing counter, bumped once per flight loop dispatch from the sim.
virtual void UpdatePosition (float _elapsedSinceLastCall, int _flCounter) = 0;
/// Distance to camera [m]
float GetCameraDist () const { return camDist; }
/// Bearing from camera [°]
Expand Down Expand Up @@ -254,12 +268,13 @@ class Aircraft {
bool CreateInstances ();
/// Destroy all instances
void DestroyInstances ();

/// Put together the map label, depends on tcasTargetIdx
virtual void ComputeMapLabel ();

// The following functions are implemented in AIMultiplayer.cpp:
/// AI/Multiplayer handling: Find next AI slot
int AISlotReserve ();
/// AI/Multiplayer handling: Clear AI slot
void AISlotClear ();
/// Define the TCAS target index in use
virtual void SetTcasTargetIdx (int _idx) { tcasTargetIdx = _idx; }
// These functions are called from AIMultiUpdate()
friend void AIMultiUpdate ();
};
Expand All @@ -271,7 +286,7 @@ Aircraft* AcFindByID (XPMPPlaneID _id);
// MARK: XPMP2 Exception class
//

/// XPMP2 Exception class, e.g. thrown if there are no CSL models when creating an Aircraft
/// XPMP2 Exception class, e.g. thrown if there are no CSL models or duplicate modeS_ids when creating an Aircraft
class XPMP2Error : public std::logic_error {
protected:
std::string fileName; ///< filename of the line of code where exception occurred
Expand Down
Loading

0 comments on commit 1b925fe

Please sign in to comment.