![]() |
VR-Forces Developer's Guide
|
This subclass of the DtGroundVehicleSetController registers for the new DtSetSpeedAndHeadingRequest and sets the appropriate values into the VRF state repository.
Header file:
/*******************************************************************************
** Copyright (c) 2006 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
#include "vrfmodel/groundVehicleSetController.h"
#include "vrfobjcore/simRadio.h"
namespace vrfAddSetExample
{
//\brief MyLocalEntitySetController is a controller that handles new
//DtSetSpeedAndHeadingRequest. It replaces the existing DtLocalEntitySetController
//
//Uses Descriptor Type: DtComponentDescriptor
class MyGroundVehicleSetController : public DtGroundVehicleSetController
{
public:
//\copydoc DtSimComponent(const DtString&,DtLocalObject*,DtSimulationServices*,
//DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
MyGroundVehicleSetController(const DtString& name,
DtLocalObject* owner,
DtSimulationServices* simManager,
DtComponentDescriptor* desc = 0,
DtReaderWriterRegistry* parentRegistry = 0);
//destructor
virtual ~MyGroundVehicleSetController() override;
virtual void processSetSpeedAndHeading(DtSimMessage * msg);
static void setSpeedAndHeadingCallback(DtSimMessage * msg, void * usrData);
//\copydoc DtSimComponent(const DtString&,DtLocalObject*,DtSimulationServices*,
//DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
//\return New instance of this class.
static DtSimComponent * creator(const DtString& name,
DtLocalObject* owner,
DtSimulationServices* simManager,
DtComponentDescriptor* desc = 0,
DtReaderWriterRegistry* parentRegistry = 0);
private:
//Default constructor; should not be called. Here because the compiler
//will generate an unprotected one otherwise.
MyGroundVehicleSetController();
//copy constructor
MyGroundVehicleSetController(const MyGroundVehicleSetController& orig);
//assignment operator
const MyGroundVehicleSetController & operator=(const
MyGroundVehicleSetController& orig);
protected:
//Overrides this so it can register its interest in the set commands.
virtual void setRadio(DtSimRadio * radio) override;
};
}
Implementation:
/*******************************************************************************
** Copyright (c) 2014 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//
//File: myLclEntSetCtlr.cxx
//
//Class: MyGroundVehicleSetController
//
#include "myGndVehSetCtlr.h"
#include "vrfobjcore/simComponentTypes.h"
#include "vrfobjcore/simRadio.h"
#include "vrftasks/setDataTypes.h"
#include "vrfobjcore/setDataManager.h"
#include "vrfobjcore/vrfMovingObjectStateRepository.h"
#include "vrfmsgs/setDataRequestMessage.h"
#include "setSpeedAndHeading.h"
namespace vrfAddSetExample
{
//constructor
MyGroundVehicleSetController::MyGroundVehicleSetController(
const DtString& name,
DtLocalObject* owner,
DtSimulationServices* simManager,
DtComponentDescriptor* desc,
DtReaderWriterRegistry* parentRegistry) :
DtGroundVehicleSetController(name, owner, simManager, desc, parentRegistry)
{
}
//destructor
MyGroundVehicleSetController::~MyGroundVehicleSetController()
{
entity()->setDataManager()->removeSetDataCallback(
DtSetSpeedAndHeadingType, setSpeedAndHeadingCallback, (void*)this);
}
void MyGroundVehicleSetController::processSetSpeedAndHeading(DtSimMessage* msg)
{
DtSetDataRequestMessage* drMsg = static_cast<DtSetDataRequestMessage*>(msg);
DtSetSpeedAndHeadingRequest* req =
static_cast<DtSetSpeedAndHeadingRequest*>(drMsg->setDataRequest());
DtVrfMovingObjectStateRepository* movingSR = localStateRepository()->as<DtVrfMovingObjectStateRepository>();
if (movingSR)
{
movingSR->setOrderedSpeed(req->speed());
}
//Make sure that the required terrain data is available. In most cases
//rotating an entity would not cause its support points to be on different
//pages but this is an important measure to insure that no blocking terrain
//calls are made.
bool dataAvailable = false;
entity()->internalState()->place(req->heading(), &dataAvailable, true);
if (dataAvailable)
{
objectConsoleInfo() << "Setting heading: " << req->heading() <<
" and speed: " << req->speed() << std::endl;
setHeading(req->heading());
}
else
{
//Queue the set heading request for processing by
//DtGroundVehicleSetController::tick once the terrain data is available.
myProcessState->setPendingSetHeadingRequest(true);
myProcessState->setPendingSetHeading(req->heading());
}
}
void MyGroundVehicleSetController::setSpeedAndHeadingCallback(DtSimMessage* msg, void* usrData)
{
((MyGroundVehicleSetController *)usrData)->processSetSpeedAndHeading(msg);
}
//overrides this so it can register its interest in the set commands
void MyGroundVehicleSetController::setRadio(DtSimRadio* radio)
{
DtGroundVehicleSetController::setRadio(radio);
entity()->setDataManager()->addSetDataProcessorCallback(
DtSetSpeedAndHeadingType, setSpeedAndHeadingCallback, (void*)this);
}
DtSimComponent* MyGroundVehicleSetController::creator(const DtString& name, DtLocalObject* owner,
DtSimulationServices* simManager, DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry)
{
return new MyGroundVehicleSetController(name, owner, simManager, desc,
parentRegistry);
}
}