VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Air Vehicle Set Controller

This subclass of the DtAirVehicleSetController registers for the new DtSetSpeedAndHeadingRequest and sets the appropriate values into the VRF state repository.


Header file:

/*******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/

#pragma once

#include "vrfmodel/airVehicleSetController.h"
#include "vrfobjcore/simRadio.h"

namespace vrfAddSetExample
{

   //\brief MyAirVehicleSetController is a controller that handles new
   //DtSetSpeedAndHeadingRequest.  It replaces the existing DtAirVehicleSetController
   //
   //Uses Descriptor Type: DtComponentDescriptor

   class MyAirVehicleSetController : public DtAirVehicleSetController
   {

   public:

      //\copydoc DtSimComponent(const DtString&,DtLocalObject*,DtSimulationServices*,
      //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
   MyAirVehicleSetController(const DtString& name, 
      DtLocalObject* owner,
      DtSimulationServices* simManager,
      DtComponentDescriptor* desc = 0,
      DtReaderWriterRegistry* parentRegistry = 0);

      //destructor
   virtual ~MyAirVehicleSetController();

   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.
   MyAirVehicleSetController();

      //copy constructor
   MyAirVehicleSetController(const MyAirVehicleSetController& orig);

      //assignment operator
   const MyAirVehicleSetController & operator=(const 
      MyAirVehicleSetController& orig);


   protected:
      //Overrides this so it can register its interest in the set commands.
   virtual void setRadio(DtSimRadio * radio);
   };
}

Implementation:

/*******************************************************************************
** Copyright (c) 2006 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/

//
//File:        myAirVehSetCtlr.cxx
//
//Class:       MyIndividualLifeFormSetController
//

#include "myAirVehSetCtlr.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
   MyAirVehicleSetController::MyAirVehicleSetController(
   const DtString& name, 
   DtLocalObject* owner,
      DtSimulationServices* simManager,
   DtComponentDescriptor* desc, 
   DtReaderWriterRegistry* parentRegistry) :
   DtAirVehicleSetController(name, owner, simManager, desc, parentRegistry)
   {
   }

   //destructor
   MyAirVehicleSetController::~MyAirVehicleSetController()
   {
   entity()->setDataManager()->removeSetDataCallback(DtSetSpeedAndHeadingType, 
      setSpeedAndHeadingCallback, (void *) this);
   }

   void MyAirVehicleSetController::processSetSpeedAndHeading(DtSimMessage* msg)
   {
   DtSetDataRequestMessage* drMsg = (DtSetDataRequestMessage *) msg;
   DtSetSpeedAndHeadingRequest* req = (DtSetSpeedAndHeadingRequest *)drMsg->setDataRequest();
   DtVrfMovingObjectStateRepository* movingSR = localStateRepository()->as<DtVrfMovingObjectStateRepository>();

   if (movingSR)
   {
      movingSR->setOrderedSpeed(req->speed());
   }

   entity()->internalState()->place(req->heading());
   objectConsoleInfo() << "Setting heading: " << req->heading() << " and speed: " << req->speed() << std::endl;
   }

   void MyAirVehicleSetController::setSpeedAndHeadingCallback(DtSimMessage* msg, 
   void* usrData)
   {
   ((MyAirVehicleSetController *)usrData)->processSetSpeedAndHeading(msg);
   }

   //overrides this so it can register it's interest in the set commands
   void MyAirVehicleSetController::setRadio(DtSimRadio* radio)
   {
   DtAirVehicleSetController::setRadio(radio);

   entity()->setDataManager()->addSetDataProcessorCallback(DtSetSpeedAndHeadingType, 
      setSpeedAndHeadingCallback, (void *) this);
   }

   DtSimComponent* MyAirVehicleSetController::creator(
   const DtString& name, 
   DtLocalObject* owner,
      DtSimulationServices* simManager,
   DtComponentDescriptor* desc, 
   DtReaderWriterRegistry* parentRegistry)
   {
   return new MyAirVehicleSetController(name, owner, simManager, desc,
      parentRegistry);
   }
}

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)