![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 1999 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: derivedMoveToController.h,v $ $Revision: 1.5 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 // 00010 //File: DerivedMoveToController.h 00011 // 00012 //Class: DerivedMoveToController 00013 // 00014 00015 00016 #ifndef DerivedMoveToController_H_ 00017 #define DerivedMoveToController_H_ 00018 00019 00020 #include "vrfmodel/gndMvToCntlr.h" 00021 00022 // 00023 //Class Description: DerivedMoveToController 00024 // 00025 //The purpose of this class is to demonstrate how to check for and handle 00026 //a situation in which an entity is unable to carry out a given task behavior. 00027 //In this particular example, it extends the DtGroundMoveToControllerComponent 00028 //with the ability to determine when it should 'give up' trying to reach its 00029 //waypoint. The criteria for determining it should give up trying to complete 00030 //its task is that it should stop trying after 10 seconds. At that point, it 00031 //sends a task complete report, indicating it has finished (although it may be 00032 //no where near its destination). 00033 // 00034 //There are 2 required member functions that this class overrides to implement 00035 //the 'give up' behavior: 00036 // 00037 //decideToGiveUpTask() : This is the function that looks at the current 00038 //situation and decides if it should give up. It will be automatically called 00039 //immediately following the entity's tick(). 00040 // 00041 //giveUpTask() : This gets called when the decideToGiveUpTask() returns true. 00042 //In this example, it calls taskComplete(), which results in a task complete 00043 //report being sent and the controller put into a non-tasked state. 00044 00045 class DerivedMoveToController : public DtGroundMoveToControllerComponent 00046 { 00047 public: 00048 00049 //constructor 00050 DerivedMoveToController(const DtString& name, 00051 DtVrfObject* owner, 00052 DtSimManager* simManager, 00053 DtComponentDescriptor* desc = NULL, 00054 DtReaderWriterRegistry* parentRegistry = NULL); 00055 00056 //destructor 00057 virtual ~DerivedMoveToController(); 00058 00059 //Override to initialize myTimeToGiveUp member to current time plus 10 seconds. 00060 //We'll check this in decideToGiveUp(). Note that this function is only 00061 //overridden for this particular time-based criteria for giving up. You would 00062 //not in general have to override this to add a 'decide to give up' capability 00063 //to a controller. 00064 virtual void processMoveToTask(DtSimMessage * msg); 00065 00066 //Creates and returns a new DerivedMoveToController 00067 static DtSimComponent* creator(const DtString& name, 00068 DtVrfObject* owner, 00069 DtSimManager* simManager, 00070 DtComponentDescriptor* desc = NULL, 00071 DtReaderWriterRegistry* parentRegistry = NULL); 00072 00073 protected: 00074 00075 //Override to see if we should give up after 10 seconds (checks current 00076 //simulation time against myTimeToGiveUp). 00077 virtual bool decideToGiveUpTask() const; 00078 00079 //Calls taskComplete(). This will result in a DtTaskComplete report being 00080 //sent to whomever issued the task. 00081 virtual void giveUpTask(); 00082 00083 private: 00084 //Default constructor; should not be called. Here because the compiler 00085 //will generate an unprotected one otherwise. 00086 DerivedMoveToController(); 00087 00088 //copy constructor; shallow; does not copy the ports. 00089 DerivedMoveToController(const DerivedMoveToController & 00090 orig); 00091 00092 //assignment operator; see comments on copy constructor! 00093 const DerivedMoveToController & operator=(const 00094 DerivedMoveToController & orig); 00095 00096 protected: 00097 00098 //This is the time we decide we want to give up when the entity 00099 //is executing a task. 00100 DtTime myTimeToGiveUp; 00101 }; 00102 00103 #endif 00104 00105 00106