XPMP2
X-Plane multiplayer library 2 - using instancing
Namespaces | Macros | Typedefs | Functions | Variables
CSLModels.cpp File Reference

Managing CSL Models, including matching and loading. More...

#include "XPMP2.h"

Namespaces

 XPMP2
 

Macros

#define WARN_ASYNC_LOAD_ONGOING   "Async load operation ongoing while object is being destroyed for %s"
 
#define WARN_REF_CNT   "Reference counter is %u while object is being destroyed for %s"
 
#define WARN_REF_CNT_ZERO   "Reference counter already 0, can't be decreaed, for %s"
 
#define DEBUG_OBJ_LOADING   "Async load starting for %s from %s"
 
#define DEBUG_OBJ_LOADED   "Async load succeeded for %s from %s"
 
#define DEBUG_OBJ_UNLOADED   "Object %s / %s unloaded"
 
#define ERR_OBJ_OBJ_NOT_FOUND   "Async load for %s: CSLObj in CSLModel object not found!"
 
#define ERR_OBJ_NOT_FOUND   "Async load for %s: CSLModel object not found!"
 
#define ERR_OBJ_NOT_LOADED   "Async load FAILED for %s from %s"
 
#define XSB_AIRCRAFT_TXT   "xsb_aircraft.txt"
 The file holding package information. More...
 
#define DEBUG_XSBACTXT_READ   "Processing %s"
 
#define INFO_XSBACTXT_DONE   "Read %3d aircraft %s from %s"
 
#define WARN_XSBACTXT_IGNORED   "Ignored %d aircraft %s due to outdated format (OBJECT or AIRCRAFT) from %s"
 
#define INFO_TOTAL_NUM_MODELS   "Total number of known models now is %lu"
 
#define WARN_NO_XSBACTXT_FOUND   "No xsb_aircraft.txt found"
 
#define WARN_DUP_PKG_NAME   "Package name (EXPORT_NAME) '%s' in folder '%s' is already in use by '%s'"
 
#define WARN_DUP_MODEL   "Duplicate model '%s', additional definitions ignored, originally defined in line %d of %s"
 
#define WARN_OBJ8_ONLY   "Line %d: Only supported format is OBJ8, ignoring model definition %s"
 
#define WARN_PKG_DPDCY_FAILED   "Line %d: Dependent package '%s' not known! May lead to follow-up issues when proessing this package."
 
#define WARN_DIFF_TYPE   "Line %d: Different aircraft type (%s instead of %s) for model '%s' ignored, rest processed"
 
#define ERR_TOO_FEW_PARAM   "Line %d: %s expects at least %d parameters"
 
#define ERR_PKG_NAME_INVALID   "Line %d: Package path invalid: %s"
 
#define ERR_PKG_UNKNOWN   "Line %d: Package '%s' unknown in package path %s"
 
#define ERR_OBJ_FILE_NOT_FOUND   "Line %d: The file '%s' could not be found at %s"
 
#define ERR_COULD_NOT_OPEN   "Could not open '%s' for reading!"
 
#define WARN_IGNORED_COMMANDS   "Following commands ignored: "
 
#define WARN_OBJ8_ONLY_VERTOFS   "Version is '%s', unsupported for reading vertical offset, file %s"
 
#define ERR_MATCH_NO_MODELS   "MATCH ABORTED - There is not any single CSL model available!"
 
#define DEBUG_MATCH_INPUT   "MATCH INPUT: Type=%s (WTC=%s,Class=%s,Related=%d), Airline=%s (relOp=%d), Livery=%s"
 
#define DEBUG_MATCH_FOUND   "MATCH FOUND: Type=%s (WTC=%s,Class=%s,Related=%d), Airline=%s (relOp=%d), Livery=%s / Quality = %d -> %s"
 
#define DEBUG_MATCH_NOTFOUND   "MATCH ERROR: Using a RANDOM model: %s %s %s - model %s"
 

Typedefs

typedef std::map< std::string, int > XPMP2::mapStrIntTy
 a map of a text and a counter More...
 

Functions

std::string XPMP2::CSLModelGetKeyStr (int _related, const std::string &_type, const std::string &_id)
 compiles the string used as key in the CSL model map More...
 
std::string XPMP2::CSLModelsConvPackagePath (const std::string &pkgPath, int lnNr, bool bPkgOptional=false)
 Turn a relative package path into a full path. More...
 
void XPMP2::CSLModelsAdd (CSLModel &_csl)
 Adds a readily defined CSL model to all the necessary maps. More...
 
const char * XPMP2::CSLModelsReadPkgId (const std::string &path)
 Scans an xsb_aircraft.txt file for EXPORT_NAME entries to fill the list of packages. More...
 
const char * XPMP2::CSLModelsFindPkgs (const std::string &_path, std::vector< std::string > &paths, int _maxDepth=5)
 Recursively scans folders to find xsb_aircraft.txt files of CSL packages. More...
 
void XPMP2::AcTxtLine_DEPENDENCY (std::vector< std::string > &tokens, int lnNr)
 Process an DEPENDENCY line of an xsb_aircraft.txt file. More...
 
void XPMP2::AcTxtLine_OBJ8_AIRCRAFT (CSLModel &csl, const std::string &ln, const std::string &xsbAircraftPath, const std::string &exportName, int lnNr)
 Process an OBJ8_AIRCRAFT line of an xsb_aircraft.txt file. More...
 
void XPMP2::AcTxtLine_OBJECT_AIRCRAFT (CSLModel &csl, const std::string &, int)
 Process an OBJECT or AIRCRAFT line of an xsb_aircraft.txt file (which are no longer supported) More...
 
void XPMP2::AcTxtLine_OBJ8 (CSLModel &csl, std::vector< std::string > &tokens, int lnNr)
 
void XPMP2::AcTxtLine_VERT_OFFSET (CSLModel &csl, std::vector< std::string > &tokens, int lnNr)
 Process an VERT_OFFSET line of an xsb_aircraft.txt file. More...
 
void XPMP2::AcTxtLine_OFFSET (CSLModel &csl, std::vector< std::string > &tokens, int lnNr)
 
void XPMP2::AcTxtLine_MATCHES (CSLModel &csl, std::vector< std::string > &tokens, int lnNr)
 Process an ICAO, AIRLINE, LIVERY, or MATCHES line of an xsb_aircraft.txt file. More...
 
int XPMP2::StrCntString (const mapStrIntTy &m, std::string &s)
 Compiles a string from a map of string->int like "(A320 x 5, A388 x 12)". More...
 
const char * XPMP2::CSLModelsProcessAcFile (const std::string &path)
 Process one xsb_aircraft.txt file for importing OBJ8 models. More...
 
void XPMP2::CSLModelsInit ()
 Initialization. More...
 
void XPMP2::CSLModelsCleanup ()
 Grace cleanup. More...
 
const char * XPMP2::CSLModelsLoad (const std::string &_path, int _maxDepth=5)
 Read the CSL Models found in the given path and below. More...
 
CSLModel * XPMP2::CSLModelById (const std::string &_cslId, mapCSLModelTy::iterator *_pOutIter=nullptr)
 Find a model by unique id. More...
 
CSLModel * XPMP2::CSLModelByKey (const std::string &_cslKey, mapCSLModelTy::iterator *_pOutIter=nullptr)
 Find a model by (even more) unique key. More...
 
CSLModel * XPMP2::CSLModelByPkgShortId (std::uint16_t _pkgHash, const std::string &_shortId)
 Find a model by package name hash and short id. More...
 
template<class IteratorT >
IteratorT XPMP2::iterRnd (IteratorT lower, IteratorT upper)
 Returns any random value in the range [cslLower; cslUpper), or upper if there is no value in that range. More...
 
bool XPMP2::CSLFindMatch (const std::string &_type, const std::string &_airline, const std::string &_livery, bool bIgnoreNoMatch, int &quality, CSLModel *&pModel)
 Tries finding a match using both aircraft and Doc8643 attributes. More...
 
int XPMP2::CSLModelMatching (const std::string &_type, const std::string &_airline, const std::string &_livery, CSLModel *&pModel)
 Find a matching model. More...
 

Variables

XPLMFlightLoopID XPMP2::gGarbageCollectionID = nullptr
 The ids of our garbage collection flight loop callback. More...
 
constexpr float XPMP2::GARBAGE_COLLECTION_PERIOD = 60.0f
 How often to call the garbage collection [s]. More...
 
constexpr float XPMP2::GARBAGE_COLLECTION_TIMEOUT = 180.0f
 Unload an unused object after how many seconds? More...
 

Detailed Description

Managing CSL Models, including matching and loading.

Author
Birger Hoppe

Macro Definition Documentation

◆ DEBUG_MATCH_FOUND

#define DEBUG_MATCH_FOUND   "MATCH FOUND: Type=%s (WTC=%s,Class=%s,Related=%d), Airline=%s (relOp=%d), Livery=%s / Quality = %d -> %s"

◆ DEBUG_MATCH_INPUT

#define DEBUG_MATCH_INPUT   "MATCH INPUT: Type=%s (WTC=%s,Class=%s,Related=%d), Airline=%s (relOp=%d), Livery=%s"

◆ DEBUG_MATCH_NOTFOUND

#define DEBUG_MATCH_NOTFOUND   "MATCH ERROR: Using a RANDOM model: %s %s %s - model %s"

◆ DEBUG_OBJ_LOADED

#define DEBUG_OBJ_LOADED   "Async load succeeded for %s from %s"

◆ DEBUG_OBJ_LOADING

#define DEBUG_OBJ_LOADING   "Async load starting for %s from %s"

◆ DEBUG_OBJ_UNLOADED

#define DEBUG_OBJ_UNLOADED   "Object %s / %s unloaded"

◆ DEBUG_XSBACTXT_READ

#define DEBUG_XSBACTXT_READ   "Processing %s"

◆ ERR_COULD_NOT_OPEN

#define ERR_COULD_NOT_OPEN   "Could not open '%s' for reading!"

◆ ERR_MATCH_NO_MODELS

#define ERR_MATCH_NO_MODELS   "MATCH ABORTED - There is not any single CSL model available!"

◆ ERR_OBJ_FILE_NOT_FOUND

#define ERR_OBJ_FILE_NOT_FOUND   "Line %d: The file '%s' could not be found at %s"

◆ ERR_OBJ_NOT_FOUND

#define ERR_OBJ_NOT_FOUND   "Async load for %s: CSLModel object not found!"

◆ ERR_OBJ_NOT_LOADED

#define ERR_OBJ_NOT_LOADED   "Async load FAILED for %s from %s"

◆ ERR_OBJ_OBJ_NOT_FOUND

#define ERR_OBJ_OBJ_NOT_FOUND   "Async load for %s: CSLObj in CSLModel object not found!"

◆ ERR_PKG_NAME_INVALID

#define ERR_PKG_NAME_INVALID   "Line %d: Package path invalid: %s"

◆ ERR_PKG_UNKNOWN

#define ERR_PKG_UNKNOWN   "Line %d: Package '%s' unknown in package path %s"

◆ ERR_TOO_FEW_PARAM

#define ERR_TOO_FEW_PARAM   "Line %d: %s expects at least %d parameters"

◆ INFO_TOTAL_NUM_MODELS

#define INFO_TOTAL_NUM_MODELS   "Total number of known models now is %lu"

◆ INFO_XSBACTXT_DONE

#define INFO_XSBACTXT_DONE   "Read %3d aircraft %s from %s"

◆ WARN_ASYNC_LOAD_ONGOING

#define WARN_ASYNC_LOAD_ONGOING   "Async load operation ongoing while object is being destroyed for %s"

◆ WARN_DIFF_TYPE

#define WARN_DIFF_TYPE   "Line %d: Different aircraft type (%s instead of %s) for model '%s' ignored, rest processed"

◆ WARN_DUP_MODEL

#define WARN_DUP_MODEL   "Duplicate model '%s', additional definitions ignored, originally defined in line %d of %s"

◆ WARN_DUP_PKG_NAME

#define WARN_DUP_PKG_NAME   "Package name (EXPORT_NAME) '%s' in folder '%s' is already in use by '%s'"

◆ WARN_IGNORED_COMMANDS

#define WARN_IGNORED_COMMANDS   "Following commands ignored: "

◆ WARN_NO_XSBACTXT_FOUND

#define WARN_NO_XSBACTXT_FOUND   "No xsb_aircraft.txt found"

◆ WARN_OBJ8_ONLY

#define WARN_OBJ8_ONLY   "Line %d: Only supported format is OBJ8, ignoring model definition %s"

◆ WARN_OBJ8_ONLY_VERTOFS

#define WARN_OBJ8_ONLY_VERTOFS   "Version is '%s', unsupported for reading vertical offset, file %s"

◆ WARN_PKG_DPDCY_FAILED

#define WARN_PKG_DPDCY_FAILED   "Line %d: Dependent package '%s' not known! May lead to follow-up issues when proessing this package."

◆ WARN_REF_CNT

#define WARN_REF_CNT   "Reference counter is %u while object is being destroyed for %s"

◆ WARN_REF_CNT_ZERO

#define WARN_REF_CNT_ZERO   "Reference counter already 0, can't be decreaed, for %s"

◆ WARN_XSBACTXT_IGNORED

#define WARN_XSBACTXT_IGNORED   "Ignored %d aircraft %s due to outdated format (OBJECT or AIRCRAFT) from %s"

◆ XSB_AIRCRAFT_TXT

#define XSB_AIRCRAFT_TXT   "xsb_aircraft.txt"

The file holding package information.