VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
DtScriptInterface Class Reference

This class is a two-way interface between the script language and its parent controller. More...

Inheritance diagram for DtScriptInterface:
Inheritance graph
[legend]

Classes

class  DtScriptFunctionReference
 Abstract object used to hold a reference to a function defined in the script langauge, to be used later to invoke that function. More...
struct  PostSetDataCallbackLessThan
 Comparison operator for DtPostSetDataCallbackSet. More...

Public Types

typedef boost::shared_ptr
< DtScriptFunctionReference
DtScriptFunctionReferencePtr
 Shared ptr to DtScriptFunctionReference.
typedef std::pair< std::string,
DtScriptFunctionReferencePtr
DtPostCallbackEntry
 Matches a set data request type with a DtScriptFunctionReferencePtr.
typedef std::set
< DtPostCallbackEntry,
PostSetDataCallbackLessThan
DtPostSetDataCallbackSet
typedef std::vector
< DtSimMessage * > 
DtSetDataMessageVector
typedef std::map
< DtPostCallbackEntry, bool
DtPostCallbackEntryPendingChanges

Public Member Functions

virtual ~DtScriptInterface ()
virtual bool invokeInit ()=0
virtual void invokeSuspend ()=0
virtual bool invokeResume ()=0
virtual void invokeTick ()=0
 This will be called by the parent to invoke the script tick.
virtual bool loadScript (bool reload=false)=0
 This will be called by the parent to let the interface know when to load the script.
virtual void invokeCheckInit ()=0
virtual bool invokeCheck ()=0
virtual void invokeShutdown ()=0
virtual void invokeDisable ()=0
 Only called for reactive tasks which can be enabled but not active.
virtual DtString type () const =0
 Script engine type.
virtual void setTaskId (int taskId)
virtual int taskId () const
virtual void setScriptId (const DtString &scriptId)
virtual const DtStringscriptId () const
virtual void setSystemName (const DtString &system)
virtual const DtStringsystemName () const
virtual void setScriptPath (const DtFilename &scriptPath)
virtual const DtFilename & scriptPath () const
virtual void setEntity (DtVrfObject *entity)
virtual DtVrfObjectentity () const
virtual void init ()
 Derived class inits may do things, so init should always be called.
virtual void setTaskVariables (const DtRwVariableBindings &variables)
virtual const
DtRwVariableBindings
taskVariables () const
virtual bool updateTaskVariables ()
virtual DtReaderWritersaveState ()=0
 Called when the scenario is saved.
virtual bool loadState (const DtReaderWriter *savedState)=0
 Called when the scenario is loaded.
virtual void processClearForReuse ()
 This function should be overridden by the inheritor to clear out any task specific variables.
virtual void setTaskStarting (bool v)
virtual bool taskStarting () const
virtual void setController (DtScriptTaskControllerInterface *controller)
virtual
DtScriptTaskControllerInterface
controller ()
virtual void processEntityDestroyed ()
 Can be overridden to perform some processing when the entity is destroyed.
virtual void invokePostSetDataCallback (DtScriptFunctionReferencePtr functionReference, DtSetDataRequestMessage *setDatRequest)=0
 Implement to invoke the function referenced by functionReference.
double getTerrainAltitude (const double lat, const double lon, bool &dataAvailable, std::string &surface) const
 Gets the terrain height at the given location.
double getGroundAltitude (const double lat, const double lon, bool &isWater, bool &dataAvailable)
 Gets the height of the ground at the given location.
void chordIntersectionDebug (const DtLocation3D &startLoc, const DtLocation3D &endLoc)
 Script function for debugging chord-terrain intersections.
bool doesChordHitTerrain (const DtLocation3D &pt1, const DtLocation3D &pt2, bool &dataAvailable) const
 Determines if the chord formed by (point1, point2) intersects the terrain.
DtLocation3D findClosestPointToRoad (const DtLocation3D &point, double searchRadius, bool &dataAvailable, bool &success) const
std::string getForceName (int forceType)
bool forcesHostile (std::string force1, std::string force2)
double gaussian ()
 Returns a number drawn from a standard Gaussian distribution.
virtual void setTaskResuming (bool v)
 Flag indicating if the task is resuming from a suspended state.
virtual bool taskResuming () const
 Flag indicating if the task is resuming from a suspended state.
virtual void setIsBackgroundProces (bool isBgProc)
 Flag indicating if this task is a background process.
virtual bool isBackgroundProcess () const
 Flag indicating if this task is a background process.

Protected Member Functions

 DtScriptInterface ()
 Call the DtScriptInterfaceHandler::createScriptInterface() function to create one.
 DtScriptInterface (const DtScriptInterface &other)
DtScriptInterfaceoperator= (const DtScriptInterface &other)
virtual void scriptTaskComplete (bool success)
 This function is meant to be called by the script itself or the script object to tell the parent that the script task is complete.
virtual void scriptTaskError ()
virtual bool scriptText (DtString &text)
 Returns the script text as a string and a bool on whether the text is valid or not.
virtual bool scriptPath (DtString &path)
 Returns the path to this script.
virtual const DtReaderWritergetTaskParam (const DtString &paramName)
virtual bool getParamMetaDataType (const DtString &paramName, DtString &typeName)

Protected Attributes

int myTaskId
DtString myScriptId
DtString mySystemName
DtFilename myScriptPath
DtScriptTaskControllerInterfacemyControllerInterface
DtVrfObjectmyEntity
DtRwVariableBindings myTaskVariables
bool myTaskStarting
 Indicates that a new task is starting, and should be initialized on the next tick.
bool myTaskResuming
bool myIsBackgroundProcess
DtPostSetDataCallbackSet mySetDataCallbacks
 Callbacks registered from the scripting language.
DtSetDataMessageVector mySetDataMessages
 Stores copies of set data request messages that callbacks have been registered for.
DtPostCallbackEntryPendingChanges myPendingSetDataCallbackEntries
 If a post set data callback is added or removed while invoking callbacks add to this map instead of inserting or removing immediately.
DtSetDataMessageVector myPendingSetDataMessages
 If a set data request is executed while invoking callbacks, add it to this vector instead of mySetDataMessages.
bool myExecutingSetDataCallbacks
 Set to true when invoking post set data callbacks.
double scriptGetExerciseTime ()
 Methods that are available for any script to use.
int scriptGetApplicationId ()
 Methods that are available for any script to use.
double scriptGetSimulationTime ()
 Methods that are available for any script to use.
double scriptGetTimeMultiplier ()
 Methods that are available for any script to use.
double scriptGetTimeOfDay ()
 Methods that are available for any script to use.
double scriptGetWindSpeed ()
 Returns wind speed in meters/second.
double scriptGetWindDirection ()
 Returns wind direction in radians.
DtScriptVrfObject scriptGetVrfObjectByName (const std::string name)
 Methods that are available for any script to use.
void printError (const std::string message)
 Methods that are available for any script to use.
void printErrorTranslatableStream (const DtTranslatableStream &message)
 Methods that are available for any script to use.
void printWarn (const std::string message)
 Methods that are available for any script to use.
void printWarnTranslatableStream (const DtTranslatableStream &message)
 Methods that are available for any script to use.
void printInfo (const std::string message)
 Methods that are available for any script to use.
void printInfoTranslatableStream (const DtTranslatableStream &message)
 Methods that are available for any script to use.
void printVerbose (const std::string message)
 Methods that are available for any script to use.
void printVerboseTranslatableStream (const DtTranslatableStream &message)
 Methods that are available for any script to use.
void printDebug (const std::string message)
 Methods that are available for any script to use.
void printDebugTranslatableStream (const DtTranslatableStream &message)
 Methods that are available for any script to use.
bool entityTypeMatches (const std::string &, const std::string &)
 Methods that are available for any script to use.
void setTickPeriod (double)
 Tick management. Will store information in PSR of controller only.
void setRespondToNewSensorContacts (bool)
 Set tick on new sensor contact.
virtual void addPostSetDataCallback (const std::string &setDataType, DtScriptFunctionReferencePtr functionReference)
 Adds a callback to be invoked after the specified type of set data request is executed.
virtual void removePostSetDataCallback (const std::string &setDataType, DtScriptFunctionReferencePtr functionReference)
 Remove a callback invoked after the specified type of set data request is executed.
virtual void clearPostSetDataCallbacks ()
 Clear all post-set data request callbacks.
virtual void processPostSetData (DtSimMessage *msg)
 Methods that are available for any script to use.
static void postSetDataCallback (DtSimMessage *msg, void *usr)
 Callback registered to the set data manager.
virtual void processPostTick ()
 Invokes any post-set data request callbacks for set data requests executed this tick.
static void postTickCallback (void *usr)
 Invokes any post-set data request callbacks for set data requests executed this tick.

Detailed Description

This class is a two-way interface between the script language and its parent controller.

There are functions that either the parent controller will call on the script interface (such as tick() ) and there will be functions the script interface will call on the parent controller to inform the parent of status updates and for data access.

Member Typedef Documentation

Shared ptr to DtScriptFunctionReference.

Matches a set data request type with a DtScriptFunctionReferencePtr.

Constructor & Destructor Documentation

DtScriptInterface::DtScriptInterface ( )
protected

Call the DtScriptInterfaceHandler::createScriptInterface() function to create one.

DtScriptInterface::DtScriptInterface ( const DtScriptInterface other)
protected
virtual DtScriptInterface::~DtScriptInterface ( )
virtual

Member Function Documentation

DtScriptInterface& DtScriptInterface::operator= ( const DtScriptInterface other)
protected
virtual bool DtScriptInterface::invokeInit ( )
pure virtual

Implemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::invokeSuspend ( )
pure virtual

Implemented in DtLuaScriptInterfaceImpl.

virtual bool DtScriptInterface::invokeResume ( )
pure virtual

Implemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::invokeTick ( )
pure virtual

This will be called by the parent to invoke the script tick.

Implemented in DtLuaScriptInterfaceImpl.

virtual bool DtScriptInterface::loadScript ( bool  reload = false)
pure virtual

This will be called by the parent to let the interface know when to load the script.

Implemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::invokeCheckInit ( )
pure virtual

Implemented in DtLuaScriptInterfaceImpl.

virtual bool DtScriptInterface::invokeCheck ( )
pure virtual

Implemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::invokeShutdown ( )
pure virtual

Implemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::invokeDisable ( )
pure virtual

Only called for reactive tasks which can be enabled but not active.

When the task is completely disabled, this should be invoked.

Implemented in DtLuaScriptInterfaceImpl.

virtual DtString DtScriptInterface::type ( ) const
pure virtual

Script engine type.

Implemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::setTaskId ( int  taskId)
inlinevirtual
virtual int DtScriptInterface::taskId ( ) const
inlinevirtual
virtual void DtScriptInterface::setScriptId ( const DtString scriptId)
inlinevirtual
virtual const DtString& DtScriptInterface::scriptId ( ) const
inlinevirtual
virtual void DtScriptInterface::setSystemName ( const DtString system)
inlinevirtual
virtual const DtString& DtScriptInterface::systemName ( ) const
inlinevirtual
virtual void DtScriptInterface::setScriptPath ( const DtFilename &  scriptPath)
inlinevirtual
virtual const DtFilename& DtScriptInterface::scriptPath ( ) const
inlinevirtual
virtual void DtScriptInterface::setEntity ( DtVrfObject entity)
inlinevirtual
virtual DtVrfObject* DtScriptInterface::entity ( ) const
inlinevirtual
virtual void DtScriptInterface::init ( void  )
inlinevirtual

Derived class inits may do things, so init should always be called.

Reimplemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::setTaskVariables ( const DtRwVariableBindings variables)
inlinevirtual
virtual const DtRwVariableBindings& DtScriptInterface::taskVariables ( ) const
inlinevirtual
virtual bool DtScriptInterface::updateTaskVariables ( )
virtual
virtual DtReaderWriter* DtScriptInterface::saveState ( )
pure virtual

Called when the scenario is saved.

The stateState pointer may not be valid, in which case something went wrong with saving

Implemented in DtLuaScriptInterfaceImpl.

virtual bool DtScriptInterface::loadState ( const DtReaderWriter savedState)
pure virtual

Called when the scenario is loaded.

The load state pointer may not be valid, which does not indicate that the scenario loaded incorrectly, but that the data for this particular script interface was either corrupt or did not exist.

Implemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::processClearForReuse ( )
virtual

This function should be overridden by the inheritor to clear out any task specific variables.

This version should probably be called last if you override it rather than first to take care of things before these things get cleared. Note: This function should only be used when a script interface is being reused between different controllers/vrfObjects (to keep from having to delete and recreate the script interface).

Reimplemented in DtLuaScriptInterfaceImpl.

virtual void DtScriptInterface::setTaskStarting ( bool  v)
virtual
virtual bool DtScriptInterface::taskStarting ( ) const
virtual
virtual void DtScriptInterface::setTaskResuming ( bool  v)
virtual

Flag indicating if the task is resuming from a suspended state.

virtual bool DtScriptInterface::taskResuming ( ) const
virtual

Flag indicating if the task is resuming from a suspended state.

virtual void DtScriptInterface::setIsBackgroundProces ( bool  isBgProc)
virtual

Flag indicating if this task is a background process.

virtual bool DtScriptInterface::isBackgroundProcess ( ) const
virtual

Flag indicating if this task is a background process.

virtual void DtScriptInterface::setController ( DtScriptTaskControllerInterface controller)
inlinevirtual
virtual DtScriptTaskControllerInterface* DtScriptInterface::controller ( )
inlinevirtual
virtual void DtScriptInterface::processEntityDestroyed ( )
inlinevirtual

Can be overridden to perform some processing when the entity is destroyed.

Reimplemented in DtLuaScriptInterfaceImpl.

double DtScriptInterface::scriptGetExerciseTime ( )

Methods that are available for any script to use.

int DtScriptInterface::scriptGetApplicationId ( )

Methods that are available for any script to use.

double DtScriptInterface::scriptGetSimulationTime ( )

Methods that are available for any script to use.

double DtScriptInterface::scriptGetTimeMultiplier ( )

Methods that are available for any script to use.

double DtScriptInterface::scriptGetTimeOfDay ( )

Methods that are available for any script to use.

double DtScriptInterface::scriptGetWindSpeed ( )

Returns wind speed in meters/second.

double DtScriptInterface::scriptGetWindDirection ( )

Returns wind direction in radians.

DtScriptVrfObject DtScriptInterface::scriptGetVrfObjectByName ( const std::string  name)

Methods that are available for any script to use.

void DtScriptInterface::printError ( const std::string  message)

Methods that are available for any script to use.

void DtScriptInterface::printErrorTranslatableStream ( const DtTranslatableStream message)

Methods that are available for any script to use.

void DtScriptInterface::printWarn ( const std::string  message)

Methods that are available for any script to use.

void DtScriptInterface::printWarnTranslatableStream ( const DtTranslatableStream message)

Methods that are available for any script to use.

void DtScriptInterface::printInfo ( const std::string  message)

Methods that are available for any script to use.

void DtScriptInterface::printInfoTranslatableStream ( const DtTranslatableStream message)

Methods that are available for any script to use.

void DtScriptInterface::printVerbose ( const std::string  message)

Methods that are available for any script to use.

void DtScriptInterface::printVerboseTranslatableStream ( const DtTranslatableStream message)

Methods that are available for any script to use.

void DtScriptInterface::printDebug ( const std::string  message)

Methods that are available for any script to use.

void DtScriptInterface::printDebugTranslatableStream ( const DtTranslatableStream message)

Methods that are available for any script to use.

bool DtScriptInterface::entityTypeMatches ( const std::string &  ,
const std::string &   
)

Methods that are available for any script to use.

void DtScriptInterface::setTickPeriod ( double  )

Tick management. Will store information in PSR of controller only.

void DtScriptInterface::setRespondToNewSensorContacts ( bool  )

Set tick on new sensor contact.

Will cause a script to set its next tick time to current sim time when new sensor information is available - either a new sensor contact or a contact reaching a higher CID level.

virtual void DtScriptInterface::addPostSetDataCallback ( const std::string &  setDataType,
DtScriptFunctionReferencePtr  functionReference 
)
virtual

Adds a callback to be invoked after the specified type of set data request is executed.

virtual void DtScriptInterface::removePostSetDataCallback ( const std::string &  setDataType,
DtScriptFunctionReferencePtr  functionReference 
)
virtual

Remove a callback invoked after the specified type of set data request is executed.

virtual void DtScriptInterface::clearPostSetDataCallbacks ( )
virtual

Clear all post-set data request callbacks.

This will remove set data request callbacks that would be invoked this tick.

static void DtScriptInterface::postSetDataCallback ( DtSimMessage msg,
void *  usr 
)
static

Callback registered to the set data manager.

This callback will clone the DtSimMessage and add a post tick entry to the sim manager to invoke any lua callback functions registered for the specific set data request type.

virtual void DtScriptInterface::processPostSetData ( DtSimMessage msg)
virtual

Methods that are available for any script to use.

static void DtScriptInterface::postTickCallback ( void *  usr)
static

Invokes any post-set data request callbacks for set data requests executed this tick.

Removes itself as a post-tick entry on the DtSimManager, so it is only invoked when there is work to do.

virtual void DtScriptInterface::processPostTick ( )
virtual

Invokes any post-set data request callbacks for set data requests executed this tick.

Removes itself as a post-tick entry on the DtSimManager, so it is only invoked when there is work to do.

virtual void DtScriptInterface::invokePostSetDataCallback ( DtScriptFunctionReferencePtr  functionReference,
DtSetDataRequestMessage setDatRequest 
)
pure virtual

Implement to invoke the function referenced by functionReference.

setDatRequest contains the information to be set. If a script interface implementation will not make use of post-set data request callbacks, this can be a no-op.

Implemented in DtLuaScriptInterfaceImpl.

double DtScriptInterface::getTerrainAltitude ( const double  lat,
const double  lon,
bool dataAvailable,
std::string &  surface 
) const

Gets the terrain height at the given location.

This function always makes a non-blocking call to the terrain interface (see documentation for DtTerrainInterface), even if dataAvailable is null; if dataAvailable is not null, then it is filled in with the result from the terrainInterface call indicating whether the altitude data is valid.

Note that in the Lua interface, dataAvailable and surface are pure_out_values, meaning that the arguments are not included in the function call, but are provided as additional return values of the function. E.g. use: height, valid, surfaceType = getTerrainAltitude(lat, lon)

double DtScriptInterface::getGroundAltitude ( const double  lat,
const double  lon,
bool isWater,
bool dataAvailable 
)

Gets the height of the ground at the given location.

If this point on the terrain is ground, then the value will be the same as that returned by getTerrainAltitude. However, if the terrain is water, then this function will return the altitude of the sea floor instead of the altitude of the water surface. This function always makes a non-blocking call to the terrain interface (see documentation for DtTerrainInterface), even if dataAvailable is null; if dataAvailable is not null, then it is filled in with the result from the terrainInterface call indicating whether the altitude data is valid.

Note that in the Lua interface, dataAvailable and surface are pure_out_values, meaning that the arguments are not included in the function call, but are provided as additional return values of the function.

void DtScriptInterface::chordIntersectionDebug ( const DtLocation3D startLoc,
const DtLocation3D endLoc 
)

Script function for debugging chord-terrain intersections.

bool DtScriptInterface::doesChordHitTerrain ( const DtLocation3D pt1,
const DtLocation3D pt2,
bool dataAvailable 
) const

Determines if the chord formed by (point1, point2) intersects the terrain.

The ground surface and features are considered. Returns a boolean indicating whether the LOS is blocked, and provides a flag indicating if the result is valid (the terrain data was available). This function always makes a non-blocking call to the terrain interface (see documentation for DtTerrainInterface), even if dataAvailable passed in is null.

DtLocation3D DtScriptInterface::findClosestPointToRoad ( const DtLocation3D point,
double  searchRadius,
bool dataAvailable,
bool success 
) const
std::string DtScriptInterface::getForceName ( int  forceType)
bool DtScriptInterface::forcesHostile ( std::string  force1,
std::string  force2 
)
double DtScriptInterface::gaussian ( )

Returns a number drawn from a standard Gaussian distribution.

virtual void DtScriptInterface::scriptTaskComplete ( bool  success)
protectedvirtual

This function is meant to be called by the script itself or the script object to tell the parent that the script task is complete.

This call will mark this object for deletion.

virtual void DtScriptInterface::scriptTaskError ( )
protectedvirtual
virtual bool DtScriptInterface::scriptText ( DtString text)
protectedvirtual

Returns the script text as a string and a bool on whether the text is valid or not.

virtual bool DtScriptInterface::scriptPath ( DtString path)
protectedvirtual

Returns the path to this script.

virtual const DtReaderWriter* DtScriptInterface::getTaskParam ( const DtString paramName)
protectedvirtual
virtual bool DtScriptInterface::getParamMetaDataType ( const DtString paramName,
DtString typeName 
)
protectedvirtual

Member Data Documentation

int DtScriptInterface::myTaskId
protected
DtString DtScriptInterface::myScriptId
protected
DtString DtScriptInterface::mySystemName
protected
DtFilename DtScriptInterface::myScriptPath
protected
DtScriptTaskControllerInterface* DtScriptInterface::myControllerInterface
protected
DtVrfObject* DtScriptInterface::myEntity
protected
DtRwVariableBindings DtScriptInterface::myTaskVariables
protected
bool DtScriptInterface::myTaskStarting
protected

Indicates that a new task is starting, and should be initialized on the next tick.

bool DtScriptInterface::myTaskResuming
protected
bool DtScriptInterface::myIsBackgroundProcess
protected
DtPostSetDataCallbackSet DtScriptInterface::mySetDataCallbacks
protected

Callbacks registered from the scripting language.

Registration/unregistration is done using vrf:addPostSetDataCallback and vrf:removePostSetDataCallback.

DtSetDataMessageVector DtScriptInterface::mySetDataMessages
protected

Stores copies of set data request messages that callbacks have been registered for.

These are deleted after they are used in processPostTick.

DtPostCallbackEntryPendingChanges DtScriptInterface::myPendingSetDataCallbackEntries
protected

If a post set data callback is added or removed while invoking callbacks add to this map instead of inserting or removing immediately.

The map is DtPostCallbackEntry, bool where true == insert and false == remove.

DtSetDataMessageVector DtScriptInterface::myPendingSetDataMessages
protected

If a set data request is executed while invoking callbacks, add it to this vector instead of mySetDataMessages.

Messages will be moved from this to mySetDataMessages once we're done invoking callbacks. These copied messages will be processed the next time callbacks are invoked by default, the next simulation tick).

bool DtScriptInterface::myExecutingSetDataCallbacks
protected

Set to true when invoking post set data callbacks.


The documentation for this class was generated from the following file:

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)