VR-Forces 4.0.4 Class Documentation
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.
void decodeMass(MyEntityStateRep* stateRep,
   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/encFactory.h>
#include <vl/decFactory.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.
void decodeMass(MyEntityStateRep* stateRep,
   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 Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)