VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FOM Mapper Source

This file contains the main class MyFomMapper which is created by the plugin manager.

There are several ways to configure a FOM Mapper to work with this new FOM. For example, you could allow the DtExerciseConn constructor to create an empty FOM Mapper, and then add mappings to that FOM Mapper later.

However, this example creates a subclass of DtFomMapper called MyFomMapper, whose implementation of the virtual init() function self registers all of the mappings we want. Then it can either create an instance of this class and pass it to the DtExerciseConn constructor, or create a shared library containing a function called DtCreateFomMapper() that returns a new'ed instance of MyFomMapper, and pass the name of the shared library to the DtExerciseConn constructor. This example uses the shared library option.

Regardless of how an instance of a DtFomMapper is passed to a DtExerciseConn constructor, DtExerciseConn calls init() on that FOM Mapper after reading the FED file and initializing the RTI.

The MyFomMapper class is defined in myFomMap.h and myFomMap.cxx. The code is included below. Notice that MyFomMapper is derived from DtEmptyFomMapper. Within MyFomMapper::init(), call down to the DtEmptyFomMapper::init(), which initializes the FOM Mapper with empty factories and tables. Then add your own mappings to the tables, including adding instances of our encoders and decoders to the FOM Mapper's encoder and decoder factories.


/*********************************************************************
** Copyright (c) 1998 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
#pragma once
#include <vlutil/vlConfig.h>
// Export Symbols on Windows (and do nothing on Linux)
#if DT_NEED_DLL_DECLARATIONS
#ifdef DT_DLL_FOMMAP
#undef DT_DLL_FOMMAP
#define DT_DLL_FOMMAP __declspec( dllexport )
#else
#define DT_DLL_FOMMAP __declspec( dllimport )
#endif
#else
#ifdef DT_DLL_FOMMAP
#undef DT_DLL_FOMMAP
#endif
#define DT_DLL_FOMMAP
#endif
#if DtHLA
class DT_DLL_FOMMAP MyFomMapper : public DtEmptyFomMapper
{
public:
// Default constructor - most initialization is delayed until init() is
// called.
MyFomMapper();
// Destructor
virtual ~MyFomMapper();
// Virtual function override. init actually initializes most data. It is
// called from DtExerciseConn constructor. Required.
virtual void init(DtExerciseConn* conn);
protected:
// Copy Ctor Not implemented
MyFomMapper(const MyFomMapper&orig);
MyFomMapper &operator=(const MyFomMapper &orig);
};
#endif

/*********************************************************************
** Copyright (c) 1998 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
/*********************************************************************
** $RCSfile: myFomMap.cxx,v $ $Revision: 1.2 $ $State: Exp $
*********************************************************************/
#if DtHLA
#include <vl/fom.h>
#include "myFomMap.h"
#include "shootDec.h"
#include "shootEnc.h"
#include "vehicleDec.h"
#include "vehicleEnc.h"
MyFomMapper::MyFomMapper() :
DtEmptyFomMapper()
{
// Real initialization takes place in virtual init() function,
// when a DtExerciseConn is available.
}
void MyFomMapper::init(DtExerciseConn* exConn)
{
// Call base class init. This sets myExConn, and initializes all factories
// to default or empty factories (no encoders or decoders registered, no
// mappings between FOM interaction classes and VR-Link interaction
// classes.
DtEmptyFomMapper::init(exConn);
// Add encoders and decoders for our Vehicle object class and Shoot
// interaction class. When DtEntityPublisher, DtReflectedEntity, and
// DtFireInteraction ask the FOM mapper for encoders and decoders to use,
// this FOM mapper will return clones of the encoders and decoders we're
// registering here.
DtObjClassDesc* objClass = exConn->fom()->objClassByName("Vehicle");
if (objClass)
{
stateEncoderFactory()->addEncoder(
objClass->handle(), new VehicleEncoder(exConn, objClass));
stateDecoderFactory()->addDecoder(
objClass->handle(), new VehicleDecoder(exConn, objClass));
}
DtInterClassDesc* interClass = exConn->fom()->interClassByName("Shoot");
if (interClass)
{
interactionEncoderFactory()->addEncoder(
interClass->handle(), new ShootEncoder(exConn, interClass));
interactionDecoderFactory()->addDecoder(
interClass->handle(), new ShootDecoder(exConn, interClass));
}
// Set up mappings for publishing. Indicate the FOM class to use for each
// kind of DtObjectPublisher, and each kind of DtInteraction.
setObjectClassToChoose("DtEntityPublisher", "Vehicle");
setInteractionClassToChoose("DtFireInteraction", "Shoot");
// Set up mappings for subscribing. Indicate which FOM class each kind of
// DtReflectedObjectList should subscribe to, and which FOM class each kind
// of DtInteraction's addCallback function should subscribe to.
setObjectClass("DtReflectedEntityList", "Vehicle");
setInteractionClass("DtFireInteraction", "Shoot");
// Set up mappings for creating DtInteraction instances. Indicate what
// kind of DtInteraction to create to represent each FOM interaction
// class.
interactionFactory()->addCreator("Shoot", DtFireInteraction::create);
}
MyFomMapper::~MyFomMapper()
{
}
#endif

Document ID: Generated on Mon Apr 8 04:49:21 EDT 2019 from SVN revision 197403
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)