VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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.
*******************************************************************************/

#pragma once

#include "vrfmodel/localEntitySetController.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&,DtLocalObject*,DtSimulationServices*,
      //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
   MyLocalEntitySetController(const DtString& name, 
      DtLocalObject* owner,
      DtSimulationServices* 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&,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.
   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);
   };
}

Implementation:

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

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

#include "myLclEntSetCtlr.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
   MyLocalEntitySetController::MyLocalEntitySetController(
   const DtString& name, 
   DtLocalObject* owner,
      DtSimulationServices* 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 = 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
      //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, 
   DtLocalObject* owner,
      DtSimulationServices* simManager,
   DtComponentDescriptor* desc, 
   DtReaderWriterRegistry* parentRegistry)
   {
   return new MyLocalEntitySetController(name, owner, simManager, desc,
      parentRegistry);
   }
}

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)