VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
derivedMoveToController.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 //
7 //File: DerivedMoveToController.h
8 //
9 //Class: DerivedMoveToController
10 //
11 #pragma once
12 
14 
15 //
16 //Class Description: DerivedMoveToController
17 //
18 //The purpose of this class is to demonstrate how to check for and handle
19 //a situation in which an entity is unable to carry out a given task behavior.
20 //In this particular example, it extends the DtGroundMoveToControllerComponent
21 //with the ability to determine when it should 'give up' trying to reach its
22 //waypoint. The criteria for determining it should give up trying to complete
23 //its task is that it should stop trying after 10 seconds. At that point, it
24 //sends a task complete report, indicating it has finished (although it may be
25 //no where near its destination).
26 //
27 //There are 2 required member functions that this class overrides to implement
28 //the 'give up' behavior:
29 //
30 //decideToGiveUpTask() : This is the function that looks at the current
31 //situation and decides if it should give up. It will be automatically called
32 //immediately following the entity's tick().
33 //
34 //giveUpTask() : This gets called when the decideToGiveUpTask() returns true.
35 //In this example, it calls taskComplete(), which results in a task complete
36 //report being sent and the controller put into a non-tasked state.
37 
39 {
40 public:
41 
42  //constructor
44  DtLocalObject* owner,
46  DtComponentDescriptor* desc = NULL,
47  DtReaderWriterRegistry* parentRegistry = NULL);
48 
49  //destructor
50  virtual ~DerivedMoveToController();
51 
52  //Override to initialize myTimeToGiveUp member to current time plus 10 seconds.
53  //We'll check this in decideToGiveUp(). Note that this function is only
54  //overridden for this particular time-based criteria for giving up. You would
55  //not in general have to override this to add a 'decide to give up' capability
56  //to a controller.
57  virtual void processMoveToTask(DtSimMessage * msg);
58 
59  //Creates and returns a new DerivedMoveToController
60  static DtSimComponent* creator(const DtString& name,
61  DtLocalObject* owner,
62  DtSimulationServices* simManager,
63  DtComponentDescriptor* desc = NULL,
64  DtReaderWriterRegistry* parentRegistry = NULL);
65 
66 protected:
67 
68  //Override to see if we should give up after 10 seconds (checks current
69  //simulation time against myTimeToGiveUp).
70  virtual bool decideToGiveUpTask() const;
71 
72  //Calls taskComplete(). This will result in a DtTaskComplete report being
73  //sent to whomever issued the task.
74  virtual void giveUpTask();
75 
76 private:
77  //Default constructor; should not be called. Here because the compiler
78  //will generate an unprotected one otherwise.
80 
81  //copy constructor; shallow; does not copy the ports.
83  orig);
84 
85  //assignment operator; see comments on copy constructor!
86  const DerivedMoveToController & operator=(const
88 
89 protected:
90 
91  //This is the time we decide we want to give up when the entity
92  //is executing a task.
94 };
virtual void processMoveToTask(DtSimMessage *msg)
const DerivedMoveToController & operator=(const DerivedMoveToController &orig)
A readable, writable type whose name is the name of a component and that has a list of component name...
Definition: componentDescriptor.h:49
Definition: readerWriterRegistry.h:39
DtGroundMoveToControllerComponent is a controller that models movement to a waypoint for ground entit...
Definition: groundMoveToControllerComponent.h:37
File: simMsg.h.
Definition: simMessage.h:35
virtual ~DerivedMoveToController()
Definition: derivedMoveToController.h:38
virtual bool decideToGiveUpTask() const
Checks to see if destination is inside an obstruction. If it is, returns true. Otherwise it returns t...
Central access point of all non-object-specific the services and managers that are available for use ...
Definition: simulationServices.h:90
The DtSimComponent class is the base class for the entire simulation model component hierarchy...
Definition: simComponent.h:70
DtTime myTimeToGiveUp
Definition: derivedMoveToController.h:93
VRF4API_METHOD const DtSimulationServices * simManager() const
This is the deprecated API that can be used as a reference to migrate 4.X code to 5...
Definition: simComponent.h:566
virtual void giveUpTask()
Called when controller is tasked and decideToGiveUp() returns true. Base class implementation calls c...
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=NULL, DtReaderWriterRegistry *parentRegistry=NULL)
virtual DtSymbolString name() const
Accessor for name of this readable/writable object.
A locally simulated VRF object. Holds all internal and external data for the object, and provides access to both the current frame and next frame state data for the object. All current frame data is read-only, and next-frame data can be written to. No thread safety guarantees are made on this object during the simulation frame and it should only be accessed by the thread that is simulating the object.
Definition: localObject.h:86

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)