VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FOM Mapper Encoder/Decoder

These routines will be used to encode and decode the new mass member for transport over the network


Header file:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: configFomMap.h,v $ $Revision: 1.4 $ $State: Exp $
*******************************************************************************/
#ifndef configFomMapper_H_
#define configFomMapper_H_ 1
#if DtHLA
#include <vl/fomMapper.h>
#include "myEsr.h"
//This function registers new encoding, decoding, and checking functions with
//a FOM Mapper for the new attribute of the "BaseEntity" object class called
//"Mass".
void configFomMapper(DtFomMapper* mapper);
//The encoding, decoding and checking functions that configFomMapper
//registers:
//Encoding function to be used for the "Mass" attribute.
void encodeMass(const MyEntityStateRep& stateRep,
RTI::AttributeHandleValuePairSet* avList,
RTI::AttributeHandle handle);
//Decoding function to be used for the "Mass" attribute.
const RTI::AttributeHandleValuePairSet& avlist,
int pairSetIndex);
//Checking function to be used for the "Mass" attribute (checks whether
//update condition has been met).
bool needMass(
const MyEntityStateRep& stateRep,
const MyEntityStateRep& asSeenByRemote);
#endif
#endif

Implementation:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: configFomMap.cxx,v $ $Revision: 1.4 $ $State: Exp $
*******************************************************************************/
#if DtHLA
#include "configFomMap.h"
#include <vl/stateEncoderFactory.h>
#include <vl/stateDecoderFactory.h>
void configFomMapper(DtFomMapper* mapper)
{
//Add your encoding function for the "Mass" attribute to the prototype
//encoders for BaseEntity and all of its subclasses.
mapper->stateEncoderFactory()->addAttributeEncoder(
"BaseEntity.PhysicalEntity", "Mass",
(DtHlaStateEncoder::DtAttributeEncoder) encodeMass, true);
//Add your decoding function for the "Mass" attribute to the prototype
//decoders for BaseEntity and all of its subclasses.
mapper->stateDecoderFactory()->addAttributeDecoder(
"BaseEntity.PhysicalEntity", "Mass",
(DtHlaStateDecoder::DtAttributeDecoder) decodeMass, true);
//Add your checking function for the "Mass" attribute to the prototype
//encoders for BaseEntity and all of its subclasses.
mapper->stateEncoderFactory()->addAttributeChecker(
"BaseEntity.PhysicalEntity", "Mass",
(DtHlaStateEncoder::DtAttributeChecker) needMass, true);
}
//Define the new encoding, decoding and checking functions that we register
//with the FOM Mapper. By using VR-Link's "Net" types in out functions, byte
//swapping occurs automatically when necessary.
//Encoding function to be used for the "Mass" attribute.
void encodeMass(const MyEntityStateRep& stateRep,
RTI::AttributeHandleValuePairSet* avList,
RTI::AttributeHandle handle)
{
//Get the value using stateRep's mass(), and add it to the avList.
double mass = stateRep.mass();
DtNetFloat64 netVal(mass);
avList->add(handle, (char*) &netVal, sizeof(DtNetFloat64));
}
//Decoding function to be used for the "Mass" attribute.
const RTI::AttributeHandleValuePairSet& avlist,
int pairSetIndex)
{
//Get the value from the avList, and pass it to stateRep's setMass().
DtNetFloat64 netVal;
RTI::ULong length = 0;
avlist.getValue(pairSetIndex, (char* )&netVal, length);
stateRep->setMass((double) netVal);
}
//Checking function to be used for the "Mass" attribute (checks whether
//update condition has been met).
bool needMass(
const MyEntityStateRep& stateRep,
const MyEntityStateRep& asSeenByRemote)
{
//Just compare the masses in the two state repositories.
return (bool) (stateRep.mass() != asSeenByRemote.mass());
}
#endif

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)