VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Entity State Repository

The DtEntityStateRepWithTemperature is a new class that replaces the default VR-Link entity state repository in order to add storage for the new temperature attribute. In order to encode the temperature to an HLA attribute, new encoder, decoder, and checker functions are also required to be registered with VR-Link. Note that this example does not support publishing the new attribute to DIS. However this could be achieved using the VR-Link API to encode the temperature into a new attribute record in DIS 7. See the VR-Link API for more details. Additionally, VR-Forces state properties can also be used to easily add and publish new attributes for both HLA and DIS. Please see the addStateProperty example for more details.


State Repository Header file:

/*******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
#if DtHLA
#include <stdio.h>
#include <vl/entityPublisher.h>
#include <vl/reflectedEntityList.h>
// Because this example adds a concept that did not already exist in VR-Link's
// DtEntityStateRepository class, we create this subclass of that adds the concept of temperature.
{
public:
{
}
{
}
// Set/Get the value of temperature
virtual void setTemperature(double temp);
virtual double temperature() const;
// Virtual function override: print the state rep's data.
virtual void printData() const;
public:
// Create a DtEntityStateRepWithTemperature. Caller is responsible for deletion.
// Copy shallow (false) or deep (true).
virtual DtStateRepository* clone(bool copy = false) const override;
protected:
};
// Inline functions
{
myTemperature = temp;
}
{
return myTemperature;
}
{
DtEntityStateRepository::printData();
printf("Temperature: %lf\n", temperature());
}
{
}
{
if (copy)
{
}
else
{
}
}
{
public:
{
DtWarn << "Constructing" << std::endl;
}
{
DtWarn << "Destructing" << std::endl;
}
protected:
{
DtEntityPublisher::setStateRepCreator((DtEntityPublisher::DtStateRepCreator)
}
{
DtReflectedEntity::setStateRepCreator((DtReflectedEntity::DtStateRepCreator)
}
};
#endif

Header file for encoder, decoder, and checker functions as well as FOM mapper configuration:

/*******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
#if DtHLA
#include <vl/fomMapper.h>
// This function registers new encoding, decoding, and checking functions with
// a FOM Mapper for the new attribute of the "BaseEntity" object class called
// "Temperature".
void configFomMapper(DtFomMapper* mapper);
// The encoding, decoding and checking functions that configFomMapper registers:
//Encoding function to be used for the "Temperature" attribute.
RTI::AttributeHandleValuePairSet* avList,
RTI::AttributeHandle handle);
//Decoding function to be used for the "Temperature" attribute.
const RTI::AttributeHandleValuePairSet& avlist,
int pairSetIndex);
//Checking function to be used for the "Temperature" attribute (checks whether
//update condition has been met).
const DtEntityStateRepWithTemperature& asSeenByRemote);
#endif

Implementation for encoder, decoder, and checker functions as well as FOM mapper configuration:

/*******************************************************************************
** Copyright(c) 2021 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#if DtHLA
#include <vl/stateEncoderFactory.h>
#include <vl/stateDecoderFactory.h>
void configFomMapper(DtFomMapper* mapper)
{
// Add your encoding function for the "Temperature" attribute to the prototype
// encoders for BaseEntity and all of its subclasses.
mapper->stateEncoderFactory()->addAttributeEncoder(
"BaseEntity.PhysicalEntity", "Temperature",
(DtHlaStateEncoder::DtAttributeEncoder) encodeTemperature, true);
// Add your decoding function for the "Temperature" attribute to the prototype
// decoders for BaseEntity and all of its subclasses.
mapper->stateDecoderFactory()->addAttributeDecoder(
"BaseEntity.PhysicalEntity", "Temperature",
(DtHlaStateDecoder::DtAttributeDecoder) decodeTemperature, true);
// Add your checking function for the "Temperature" attribute to the prototype
// encoders for BaseEntity and all of its subclasses.
mapper->stateEncoderFactory()->addAttributeChecker(
"BaseEntity.PhysicalEntity", "Temperature",
(DtHlaStateEncoder::DtAttributeChecker) needTemperature, 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 "Temperature" attribute.
RTI::AttributeHandleValuePairSet* avList,
RTI::AttributeHandle handle)
{
// Get the value using stateRep's temperature(), and add it to the avList.
double temperature = stateRep.temperature();
DtNetFloat64 netVal(temperature);
avList->add(handle, (char*)&netVal, sizeof(DtNetFloat64));
}
// Decoding function to be used for the "Temperature" attribute.
const RTI::AttributeHandleValuePairSet& avlist,
int pairSetIndex)
{
// Get the value from the avList, and pass it to stateRep's setTemperature().
DtNetFloat64 netVal;
RTI::ULong length = 0;
avlist.getValue(pairSetIndex, (char*)&netVal, length);
stateRep->setTemperature((double)netVal);
}
// Checking function to be used for the "Temperature" attribute (checks whether
// update condition has been met).
const DtEntityStateRepWithTemperature& asSeenByRemote)
{
// Just compare the Temperatures in the two state repositories.
return (bool)(stateRep.temperature() != asSeenByRemote.temperature());
}
#endif

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)