VR-Forces 4.1 Class Documentation
Local Entity Set Controller

This subclass of the DtLocalEntitySetController 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.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: myLclEntSetCtlr.h,v $ $Revision: 1.2 $ $State: Exp $
*******************************************************************************/

//\file myLclEntSetCtlr.h
//\brief MyLocalEntitySetController; handles new DtSetSpeedAndHeadingRequest


#ifndef MyLocalEntitySetController_H_
#define MyLocalEntitySetController_H_


#include "vrfmodel/lclEntSetCtlr.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 MyLocalEntitySetController : public DtLocalEntitySetController
   {

   public:

      //\copydoc DtSimComponent(const DtString&,DtVrfObject*,DtSimManager*,
      //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
   MyLocalEntitySetController(const DtString& name, 
      DtVrfObject* owner,
      DtSimManager* simManager, 
      DtComponentDescriptor* desc = 0,
      DtReaderWriterRegistry* parentRegistry = 0);

      //destructor
   virtual ~MyLocalEntitySetController();

   virtual void processSetSpeedAndHeading(DtSimMessage * msg);

   static void setSpeedAndHeadingCallback(DtSimMessage * msg, void * usrData);

      //\copydoc DtSimComponent(const DtString&,DtVrfObject*,DtSimManager*,
      //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
      //\return New instance of this class.
   static DtSimComponent * creator(const DtString& name, 
      DtVrfObject* owner,
      DtSimManager* simManager, 
      DtComponentDescriptor* desc = 0,
      DtReaderWriterRegistry* parentRegistry = 0);

   private:
      //Default constructor; should not be called.  Here because the compiler
      //will generate an unprotected one otherwise.
   MyLocalEntitySetController();

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

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


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


Implementation:

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

//
//File:        myLclEntSetCtlr.cxx
//
//Class:       MyLocalEntitySetController
//

#include "myLclEntSetCtlr.h"
#include "vrfcore/simMgr.h"
#include "vrfobjcore/vrfObjMgr.h"

#include "vrfobjcore/compTypes.h"
#include "vrfobjcore/simRadio.h"
#include "vrftasks/setDtaTypes.h"
#include "vrfobjcore/setDataManager.h"
#include "vrfobjcore/vrfMvObjSR.h"

#include "vrfmsgs/setDtaRqMsg.h"
#include "setSpeedAndHeading.h"

namespace vrfAddSetExample
{
   //constructor
   MyLocalEntitySetController::MyLocalEntitySetController(
   const DtString& name, 
   DtVrfObject* owner,
   DtSimManager* simManager, 
   DtComponentDescriptor* desc, 
   DtReaderWriterRegistry* parentRegistry) :
   DtLocalEntitySetController(name, owner, simManager, desc, parentRegistry)
   {
   }

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

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

   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;
   myLocalEntity->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
      //DtLocalEntitySetController::tick once the terrain data is available.
      myProcessState->setPendingSetHeadingRequest(true);
      myProcessState->setPendingSetHeading(req->heading());
   }
   }

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

   //overrides this so it can register its interest in the set commands
   void MyLocalEntitySetController::setRadio(DtSimRadio* radio)
   {
   DtLocalEntitySetController::setRadio(radio);

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

   DtSimComponent* MyLocalEntitySetController::creator(
   const DtString& name, 
   DtVrfObject* owner,
   DtSimManager* simManager, 
   DtComponentDescriptor* desc, 
   DtReaderWriterRegistry* parentRegistry)
   {
   return new MyLocalEntitySetController(name, owner, simManager, desc,
      parentRegistry);
   }
}

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)