VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Derived Move To Controller

This subclass of the DtGroundMoveToControllerComponent will give up on the movement task after a certain amount of simulation time


Header file:

/*******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//
//File: DerivedMoveToController.h
//
//Class: DerivedMoveToController
//
#pragma once
//
//Class Description: DerivedMoveToController
//
//The purpose of this class is to demonstrate how to check for and handle
//a situation in which an entity is unable to carry out a given task behavior.
//In this particular example, it extends the DtGroundMoveToControllerComponent
//with the ability to determine when it should 'give up' trying to reach its
//waypoint. The criteria for determining it should give up trying to complete
//its task is that it should stop trying after 10 seconds. At that point, it
//sends a task complete report, indicating it has finished (although it may be
//no where near its destination).
//
//There are 2 required member functions that this class overrides to implement
//the 'give up' behavior:
//
//decideToGiveUpTask() : This is the function that looks at the current
//situation and decides if it should give up. It will be automatically called
//immediately following the entity's tick().
//
//giveUpTask() : This gets called when the decideToGiveUpTask() returns true.
//In this example, it calls taskComplete(), which results in a task complete
//report being sent and the controller put into a non-tasked state.
{
public:
//constructor
DtLocalObject* owner,
DtSimulationServices* simManager,
DtComponentDescriptor* desc = NULL,
DtReaderWriterRegistry* parentRegistry = NULL);
//destructor
//Override to initialize myTimeToGiveUp member to current time plus 10 seconds.
//We'll check this in decideToGiveUp(). Note that this function is only
//overridden for this particular time-based criteria for giving up. You would
//not in general have to override this to add a 'decide to give up' capability
//to a controller.
virtual void processMoveToTask(DtSimMessage * msg);
//Creates and returns a new DerivedMoveToController
static DtSimComponent* creator(const DtString& name,
DtLocalObject* owner,
DtSimulationServices* simManager,
DtComponentDescriptor* desc = NULL,
DtReaderWriterRegistry* parentRegistry = NULL);
protected:
//Override to see if we should give up after 10 seconds (checks current
//simulation time against myTimeToGiveUp).
virtual bool decideToGiveUpTask() const;
//Calls taskComplete(). This will result in a DtTaskComplete report being
//sent to whomever issued the task.
virtual void giveUpTask();
private:
//Default constructor; should not be called. Here because the compiler
//will generate an unprotected one otherwise.
//copy constructor; shallow; does not copy the ports.
orig);
//assignment operator; see comments on copy constructor!
protected:
//This is the time we decide we want to give up when the entity
//is executing a task.
};

Implementation:

/*******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
const DtString& name,
DtLocalObject* owner,
DtSimulationServices* simServices,
DtReaderWriterRegistry* parentRegistry) :
DtGroundMoveToControllerComponent(name, owner, simServices, desc,
parentRegistry)
{
}
{
}
const DtString& name,
DtLocalObject* owner,
DtSimulationServices* simServices,
DtReaderWriterRegistry* parentRegistry)
{
return new DerivedMoveToController(name, owner, simServices, desc, parentRegistry);
}
{
//Initialize time to give up to 10 seconds from now.
objectConsoleInfo() << entity()->objectName().string() <<
" - Setting time to give up for move-to task to " << myTimeToGiveUp <<
std::endl;
}
{
DtTime currentSimTime = simulationServices()->simTime();
if( currentSimTime > myTimeToGiveUp)
{
objectConsoleInfo() << entity()->objectName().string() <<
" - Giving up move to task at time " << currentSimTime << std::endl;
return true;
}
else
{
return false;
}
}
{
objectConsoleInfo() << entity()->objectName().string() <<
" - Gave up on move to task. Calling taskComplete()." << std::endl;
}

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)