![]() |
VR-Link API Documentation for DIS
|
This file serves an an example of how to re-configure VR-Link to interpret FOM attributes and parameters differently.
Specifically, after calling the configVrl function defined below on a DtExerciseConn, a VR-Link-based application will assume that the "Position" atttribute of the "BaseEntity" object class (and its subclasses) should be encoded in outgoing messages and interpreted in incoming messages as three doubles in the order: Z, Y, X, rather than the standard X, Y, Z. The same will be true for the "FiringLocation" parameter of the "WeaponFire" interaction.
To demonstrate modifying the FOM to replace existing attributes or parameters, you can edit the .fed file to replace "Position" and "FiringLocation" with different attribute and parameter names, such as "ReversePosition" and "ReverseFiringLocation". If you do this, you will need to replace the names in this file as well (in the calls to addAttributeEncoder, addAttributeDecoder, addParameterEncoder and addParameterDecoder), so that the encoding and decoding functions will be associated with the correct parameter and attribute names.
This file is commented out and not part of the default f18. To add this functionality, compile with DtReverse defined.
/******************************************************************************* ** Copyright (c) 1992-2010 VT MAK ** All rights reserved. *******************************************************************************/ #if DtHLA #if DtReverse #include <vl/fomMapper.h> #include <vl/encFactory.h> #include <vl/decFactory.h> #include <vl/entitySR.h> #include <vl/intDecFact.h> #include <vl/intEncFact.h> #include <vl/hFireInter.h> #include <vl/exerciseConn.h> // Encoder function to be used for the "Position" attribute. void DtPosEncoder( const DtEntityStateRepository& stateRep, RTI::AttributeHandleValuePairSet* avList, RTI::AttributeHandle handle ) { DtVector loc = stateRep.location(); DtNet64Vector netVal( loc[2], loc[1], loc[0] ); avList->add( handle, (char*)&netVal, sizeof( DtNet64Vector ) ); } // Decoder function to be used for the "Position" attribute. void DtPosDecoder( DtEntityStateRepository* stateRep, const RTI::AttributeHandleValuePairSet& avlist, int pairSetIndex ) { DtNet64Vector netVal; RTI::ULong length = 0; avlist.getValue( pairSetIndex, (char*)&netVal, length ); stateRep->setLocation( DtVector( netVal[2], netVal[1], netVal[0] ) ); } // Encoder function to be used for the "FiringLocation" parameter. void DtFirePosEncoder( const DtFireInteraction& fire, RTI::ParameterHandleValuePairSet* pvList, RTI::ParameterHandle handle ) { DtVector loc = fire.location(); DtNet64Vector netVal( loc[2], loc[1], loc[0]); pvList->add( handle, (char*)&netVal, sizeof( DtNet64Vector ) ); } // Decoder function to be used for the "FiringLocation" parameter. void DtFirePosDecoder( DtFireInteraction* fire, const RTI::ParameterHandleValuePairSet& pvlist, int pairSetIndex ) { DtNet64Vector netVal; RTI::ULong length = 0; pvlist.getValue( pairSetIndex, (char*)&netVal, length ); fire->setLocation( DtVector( netVal[2], netVal[1], netVal[0] ) ); } // configVrl tells the DtExerciseConn's DtFomMapper that the functions // defined above should be used in place of the default encoding // and decoding functions for the specified attributes and parameters. void configVrl( DtExerciseConn* exConn ) { exConn->fomMapper()->stateEncoderFactory()-> addAttributeEncoder( "BaseEntity", "Position", (DtHlaStateEncoder::DtAttributeEncoder)DtPosEncoder ); exConn->fomMapper()->stateDecoderFactory()-> addAttributeDecoder( "BaseEntity", "Position", (DtHlaStateDecoder::DtAttributeDecoder)DtPosDecoder ); exConn->fomMapper()->interactionEncoderFactory()-> addParameterEncoder( "WeaponFire", "FiringLocation", (DtInteractionEncoder::DtParameterEncoder)DtFirePosEncoder ); exConn->fomMapper()->interactionDecoderFactory()-> addParameterDecoder( "WeaponFire", "FiringLocation", (DtInteractionDecoder::DtParameterDecoder)DtFirePosDecoder ); } #endif // DtReverse #endif // DtHLA