XPMP2
X-Plane multiplayer library 2 - using instancing
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
XPMP2::CSLObj Class Reference

One .obj file of a CSL model (of which it can have multiple) More...

#include <CSLModels.h>

Public Member Functions

 CSLObj (const std::string &_cslKey, const std::string &_path)
 Constructor doesn't do much. More...
 
 CSLObj (CSLObj &&o)=default
 Generate standard move constructor. More...
 
CSLObjoperator= (CSLObj &&o)=default
 
 ~CSLObj ()
 Destructor makes sure the XP object is removed, too. More...
 
ObjLoadStateTy GetObjState () const
 State of the X-Plane object: Is it being loaded or available? More...
 
bool IsInvalid () const
 Is invalid? More...
 
void DetermineWhichObjToLoad ()
 Determine which file to load and if we need a copied .obj file. More...
 
float FetchVertOfsFromObjFile () const
 Read the obj file to calculate its vertical offset. More...
 
XPLMObjectRef GetAndLoadObj ()
 Load and return the underlying X-Plane objects. More...
 
void Load ()
 Starts loading the XP object. More...
 
void Unload ()
 Free up the object. More...
 
bool NeedsObjCopy () const
 Will this object require copying the .obj file upon load? More...
 

Public Attributes

std::string cslKey
 key of the CSL model this belongs to More...
 
std::string path
 full path to the (potentially copied) .obj file More...
 
std::string pathOrig
 full path to the original .obj file IF there is the need to create a copy upon load More...
 
std::string texture
 texture file if defined, to be used in the TEXTURE line of the .obj file More...
 
std::string text_lit
 texture_lit file if defined, to be used in the TEXTURE_LIT line of the .obj file More...
 

Protected Member Functions

bool TriggerCopyAndReplace ()
 Trigger a separate thread to copy the .obj file if needed. More...
 
void SetCopyResult (bool bResult)
 Update with the result of the copy operation. More...
 
bool CopyAndReplace ()
 Perform the copy-on-load functionality, replacing dataRefs and textures, expected to be called via std::async. More...
 
void Invalidate ()
 Marks the CSL Model invalid in case object loading once failed. More...
 

Static Protected Member Functions

static void SetOtherObjCopyResult (bool bResult)
 Update another CSLObj with the result of the copy operation. More...
 
static void XPObjLoadedCB (XPLMObjectRef inObject, void *inRefcon)
 callback function called when loading is done More...
 

Protected Attributes

XPLMObjectRef xpObj = NULL
 The X-Plane object reference to the loaded model as requested with XPLMLoadObjectAsync. More...
 
ObjLoadStateTy xpObjState = OLS_UNAVAIL
 State of the X-Plane object: Is it being loaded or available? More...
 

Detailed Description

One .obj file of a CSL model (of which it can have multiple)

Constructor & Destructor Documentation

◆ CSLObj() [1/2]

XPMP2::CSLObj::CSLObj ( const std::string &  _cslKey,
const std::string &  _path 
)
inline

Constructor doesn't do much.

◆ CSLObj() [2/2]

XPMP2::CSLObj::CSLObj ( CSLObj &&  o)
default

Generate standard move constructor.

◆ ~CSLObj()

XPMP2::CSLObj::~CSLObj ( )

Destructor makes sure the XP object is removed, too.

Member Function Documentation

◆ CopyAndReplace()

bool XPMP2::CSLObj::CopyAndReplace ( )
protected

Perform the copy-on-load functionality, replacing dataRefs and textures, expected to be called via std::async.

◆ DetermineWhichObjToLoad()

void XPMP2::CSLObj::DetermineWhichObjToLoad ( )

Determine which file to load and if we need a copied .obj file.

  1. Determine if we need to access a copied file at all
    1. Compute that copied file name It will include one of the texture ids if texture replacement is involved It will always end on ".xpmp2.obj"
    2. Test if that copied file already exists The actual copy operation will only be peformed upon load.

◆ FetchVertOfsFromObjFile()

float XPMP2::CSLObj::FetchVertOfsFromObjFile ( ) const

Read the obj file to calculate its vertical offset.

The idea behind doing this is taken from the original libxplanemp implementation, particularly XPMPMultiplayerCSLOffset.cpp: CslModelVertOffsetCalculator::findOffsetInObj8: The vertices and lines defined in the file have coordinates, their outer edges define how much the aircraft would need to be lifted to make its lowest part (typically the gear) appear on the surfaces. So it searches for min/max values of vertical (y) coordinates.

Note
I am not sure why the original code returns -max if min > 0, my understanding would be to always return -min and don't need max. But I just hope that the original author knows better and I stick to it.

◆ GetAndLoadObj()

XPLMObjectRef XPMP2::CSLObj::GetAndLoadObj ( )

Load and return the underlying X-Plane objects.

Note
Can return NULL while async load is underway!

◆ GetObjState()

ObjLoadStateTy XPMP2::CSLObj::GetObjState ( ) const
inline

State of the X-Plane object: Is it being loaded or available?

◆ Invalidate()

void XPMP2::CSLObj::Invalidate ( )
protected

Marks the CSL Model invalid in case object loading once failed.

◆ IsInvalid()

bool XPMP2::CSLObj::IsInvalid ( ) const
inline

Is invalid?

◆ Load()

void XPMP2::CSLObj::Load ( )

Starts loading the XP object.

Async load takes time. Maybe this object exists no longer when the load operaton returns. That's why we do not just pass this to the XPLMLoadObjectAsync() call, but a separate object, here a pair of copies of the id strings, by which we can try to find the object again in the callback XPObjLoadedCB().

◆ NeedsObjCopy()

bool XPMP2::CSLObj::NeedsObjCopy ( ) const
inline

Will this object require copying the .obj file upon load?

◆ operator=()

CSLObj& XPMP2::CSLObj::operator= ( CSLObj &&  o)
default

◆ SetCopyResult()

void XPMP2::CSLObj::SetCopyResult ( bool  bResult)
protected

Update with the result of the copy operation.

◆ SetOtherObjCopyResult()

void XPMP2::CSLObj::SetOtherObjCopyResult ( bool  bResult)
staticprotected

Update another CSLObj with the result of the copy operation.

◆ TriggerCopyAndReplace()

bool XPMP2::CSLObj::TriggerCopyAndReplace ( )
protected

Trigger a separate thread to copy the .obj file if needed.

Returns
true when copying has finished, false if the loading sequence needs to wait here (for the copy operation to start or finish)

◆ Unload()

void XPMP2::CSLObj::Unload ( )

Free up the object.

◆ XPObjLoadedCB()

void XPMP2::CSLObj::XPObjLoadedCB ( XPLMObjectRef  inObject,
void *  inRefcon 
)
staticprotected

callback function called when loading is done

Member Data Documentation

◆ cslKey

std::string XPMP2::CSLObj::cslKey

key of the CSL model this belongs to

◆ path

std::string XPMP2::CSLObj::path

full path to the (potentially copied) .obj file

◆ pathOrig

std::string XPMP2::CSLObj::pathOrig

full path to the original .obj file IF there is the need to create a copy upon load

◆ text_lit

std::string XPMP2::CSLObj::text_lit

texture_lit file if defined, to be used in the TEXTURE_LIT line of the .obj file

◆ texture

std::string XPMP2::CSLObj::texture

texture file if defined, to be used in the TEXTURE line of the .obj file

◆ xpObj

XPLMObjectRef XPMP2::CSLObj::xpObj = NULL
protected

The X-Plane object reference to the loaded model as requested with XPLMLoadObjectAsync.

◆ xpObjState

ObjLoadStateTy XPMP2::CSLObj::xpObjState = OLS_UNAVAIL
protected

State of the X-Plane object: Is it being loaded or available?


The documentation for this class was generated from the following files: