VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vehicle Object Encoder

vehicleEnc encodes vehicle objects.


/*********************************************************************
** Copyright (c) 1998 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
#if DtHLA
#ifndef VehicleEncoder_H_
#define VehicleEncoder_H_
#include "myFomMap.h"
#define DtDECLARE_TEST_ATTR_CHECKER(attrName) \
DtDECLARE_ATTR_CHECKER(DtEntityStateRepository, attrName)
#define DtDECLARE_TEST_ATTR_ENCODER(attrName) \
DtDECLARE_ATTR_ENCODER(DtEntityStateRepository, attrName)
class DT_DLL_FOMMAP VehicleEncoder : public DtHlaStateEncoder
{
public:
// default constructor
VehicleEncoder(DtExerciseConn* exConn, DtObjClassDesc* classDesc);
// destructor
virtual ~VehicleEncoder();
protected:
// Individual attribute encoding functions - one for each attribute.
// This macro expands to look like this:
// static void encodeVehicleType(const DtEntityStateRepository& rep,
// RTI::AttributeHandleValuePairSet* attrs,
// RTI::AttributeHandle attrHandle)
DtDECLARE_TEST_ATTR_ENCODER(VehicleType);
DtDECLARE_TEST_ATTR_ENCODER(GeocLoc);
// Individual attribute checking functions - one for each attribute.
// This macro expands to look like this:
// static bool needNumber(const DtEntityStateRepository& rep,
// const DtEntityStateRepository& asSeenByRemote);
DtDECLARE_TEST_ATTR_CHECKER(VehicleType);
DtDECLARE_TEST_ATTR_CHECKER(GeocLoc);
};
#endif
#endif

/*********************************************************************
** Copyright (c) 1998 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
/*********************************************************************
** $RCSfile: vehicleEnc.cxx,v $ $Revision: 1.4 $ $State: Exp $
*********************************************************************/
#if DtHLA
#include "vehicleEnc.h"
VehicleEncoder::VehicleEncoder(
DtExerciseConn* exConn,
DtObjClassDesc* classDesc) :
DtHlaStateEncoder(exConn, classDesc)
{
// Register the individual encoding and checking functions for Vehicle's
// attributes with the object. The encoding functions have names like
// encodeGeocLoc, while checking functions have names like needGeocLoc.
// The macros expands to look like this:
// addEncoder("VehicleType", (DtAttributeEncoder) encodeVehicleType);
// addChecker("VehicleType", (DtAttributeChecker) needVehicleType);
DtADD_ATTR_ENCODER(VehicleType);
DtADD_ATTR_ENCODER(GeocLoc);
DtADD_ATTR_CHECKER(VehicleType);
DtADD_ATTR_CHECKER(GeocLoc);
}
VehicleEncoder::~VehicleEncoder()
{
}
// Encoding and checking functions
// Macros can help with definitions of simple encoding and checking functions,
// as in in examples/extend/testObj/testEnc.cxx but here we do not rely on
// them.
bool VehicleEncoder::needVehicleType(
const DtEntityStateRepository& stateRep,
const DtEntityStateRepository& asSeenByRemote)
{
return (bool) !(stateRep.entityType() == asSeenByRemote.entityType());
}
bool VehicleEncoder::needGeocLoc(
const DtEntityStateRepository& stateRep,
const DtEntityStateRepository& asSeenByRemote)
{
return (bool) !(stateRep.location() == asSeenByRemote.location());
}
void VehicleEncoder::encodeVehicleType(const DtEntityStateRepository& rep,
RTI::AttributeHandleValuePairSet* attrs,
RTI::AttributeHandle attrHandle)
{
// Get value using inspector
DtEntityType type = rep.entityType();
// Convert to FOM representation:
DtNetInt32 netVal = 0;
if (type == DtEntityType(1, 1, 225, 1, 1, 0, 0))
{
// M1A1
netVal = 0;
}
else if (type == DtEntityType(1, 1, 222, 1, 2, 0, 0))
{
// T72
netVal = 1;
}
// Add to ahvps
attrs->add(attrHandle, (char*) &netVal, sizeof(netVal));
}
void VehicleEncoder::encodeGeocLoc(const DtEntityStateRepository& rep,
RTI::AttributeHandleValuePairSet* attrs,
RTI::AttributeHandle attrHandle)
{
// Get the value from the inspector function, convert to FOM representation
// (in this case, a trivial conversion), and add it to the phvps.
DtVector vec = rep.location();
DtNet64Vector netVal(vec);
// Add to ahvps
attrs->add(attrHandle, (char*) &netVal, sizeof(netVal));
}
#endif

Document ID: Generated on Mon Jun 22 21:18:40 EDT 2020 from SVN revision 213785
Copyright © 2005-2018 MAK Technologies. All Rights Reserved (www.mak.com)