Kaim::SegmentCastQuery< TraverseLogic > Class Template Reference

Kaim::SegmentCastQuery< TraverseLogic > Class Template Reference

#include <segmentcastquery.h>

Class Description

template<class TraverseLogic>
class Kaim::SegmentCastQuery< TraverseLogic >

The SegmentCastQuery class casts a line segment in a given direction, and records any collisions it detects along the way.

Set up the segment by assigning a starting point (m_startPos3f), half-width (m_radius), and the direction in which it will be cast (m_normalizedDir2d). If the segment collides with a border of the NavMesh or crosses any forbidden NavTag, the collision point is recorded (m_collisionPos3f). The segment stops if it reaches the maximum distance without a collision (m_maxDist). The final valid position-at a collision point, or at maximum distance-is recorded in m_arrivalPos3f. The line segment is considered to be orthogonal to m_normalizedDir2d:

              +---->-------->--------->---------->--------------+
              |                                                 |
              |                                                 | => m_radius
              |                                                 |
              |                                                 |
m_startPos3f  X                                                 X  => m_arrivalPos3f
              |                                                 |
              |                                                 |
              |                                                 | => m_radius
              |                                                 |
              +---->-------->--------->---------->--------------+
              <- - - - - - - - - - m_maxDist - - - - - - - - - ->

Inherits Kaim::BaseSegmentCastQuery.

Public Member Functions

virtual QueryType GetType () const
 Get query type. More...
 

Public Attributes

QueryProcessStatus m_processStatus
 Modified by the query within Advance(). Do not modify. More...
 
Ptr< IOnDonem_onDone
 The optional IOnDone instance to be called. Must be set manually by the user. See IOnDone. More...
 

Protected Attributes

Vec3f m_startPos3f
 The starting position of the segment. More...
 
Vec2f m_normalizedDir2d
 A normalized vector that represents the direction in which the segment is cast. More...
 
KyFloat32 m_radius
 The half-width of the segment . More...
 
KyFloat32 m_maxDist
 Determines the maximum distance the segment will travel. More...
 
NavTrianglePtr m_startTrianglePtr
 The NavMesh triangle that corresponds to m_startPos3f. You can set it as an input or retrieve it as an output of the query. More...
 
KyFloat32 m_safetyDist
 When a collision is detected, the collision point is moved back along m_normalizedDir2d by this distance, in order to ensure that the final arrival position will lie within the valid area of the NavMesh. More...
 
PositionSpatializationRange m_positionSpatializationRange
 The altitude range around the position to use when determining m_startTrianglePtr from the m_startPos3f. More...
 
Vec3f m_collisionPos3f
 Updated during processing to indicate the position of the collision point between the segment and the NavMesh border, if a collision has been detected. More...
 
Vec3f m_arrivalPos3f
 Updated during processing to indicate the final position of the segment at the end of the cast. More...
 
NavTrianglePtr m_arrivalTrianglePtr
 Updated during processing to indicate the NavMesh triangle that corresponds to m_arrivalPos3f. More...
 
NavHalfEdgePtr m_collisionHalfEdgePtr
 Updated during processing to indicate the triangle edge that the segment collided with, if a collision is detected. More...
 
SegmentCastQueryResult m_result
 Updated during processing to indicate the result of the query. More...
 
DynamicOutputMode m_dynamicOutputMode
 Specifies the type of data stored in m_queryDynamicOutput. More...
 
Ptr< QueryDynamicOutputm_queryDynamicOutput
 A ref-counted Ptr to a QueryDynamicOutput instance, used to store the data encountered during the query process. More...
 

Functions

 SegmentCastQuery ()
 
virtual ~SegmentCastQuery ()
 

Functions to set up the query

void BindToDatabase (Database *database)
 Binds the query with the specified Database, clears all the inputs and outputs and sets all other parameters to their default value (they may be changed by calling the corresponding write accessors.) More...
 
void Initialize (const Vec3f &startPos, KyFloat32 radius, const Vec2f &normalizedDir2d, KyFloat32 maxDist)
 resets an initialized instance of this class with minimum input requirements. More...
 

write accessors for query inputs

void SetStartTrianglePtr (const NavTrianglePtr &startTrianglePtr)
 The NavMesh triangle that corresponds to m_startPos3f. More...
 
void SetQueryDynamicOutput (QueryDynamicOutput *queryDynamicOutput)
 Write accessor for m_queryDynamicOutput. More...
 

write accessors for query parameters

void SetPositionSpatializationRange (const PositionSpatializationRange &positionSpatializationRange)
 Write accessor for m_positionSpatializationRange. More...
 
void SetSafetyDist (KyFloat32 safetyDist)
 Write accessor for m_safetyDist. More...
 
void SetDynamicOutputMode (DynamicOutputMode savingMode)
 Write accessor for m_dynamicOutputMode. More...
 

Query framework functions

virtual void Advance (WorkingMemory *workingMemory)
 This function is called by the QueryQueue to process one step on the query. More...
 
void PerformQuery (WorkingMemory *workingMemory=nullptr)
 If workingMemory param is nullptr, m_database.GetWorkingMemory() will be used. More...
 

Accessors

SegmentCastQueryResult GetResult () const
 
const Vec3fGetStartPos () const
 
const Vec3fGetCollisionPos () const
 
const Vec3fGetArrivalPos () const
 
const Vec2fGetNormalizedDir2d () const
 
const NavTrianglePtrGetStartTrianglePtr () const
 
const NavTrianglePtrGetArrivalTrianglePtr () const
 
const NavHalfEdgePtrGetCollisionNavHalfEdgePtr () const
 
KyFloat32 GetRadius () const
 
KyFloat32 GetMaxDist () const
 
KyFloat32 GetSafetyDist () const
 
DynamicOutputMode GetDynamicOutputMode () const
 
QueryDynamicOutputGetQueryDynamicOutput () const
 
const PositionSpatializationRangeGetPositionSpatializationRange () const
 

For internal use only

void PerformQueryWithInputCoordPos (WorkingMemory *workingMemory)
 
void SetStartIntegerPos (const WorldIntegerPos &startIntegerPos)
 
const WorldIntegerPosGetStartIntegerPos () const
 
const WorldIntegerPosGetArrivalIntegerPos () const
 

IQuery Functions

bool CanBeInitialized () const
 In the case of a query processed in a QueryQueue, this must be tested before initializing the query, to prevent modifying the query during the process. More...
 
bool IsInAQueryQueue () const
 Returns true if the query is currently registered in a QueryQueue. More...
 
bool IsSafeToReadResult () const
 Returns true if the query has been processed, is no longer in a queue, and OnDone (if there is one) has been called. More...
 
KyUInt32 PerformQueryBlocking (WorkingMemory *workingMemory=nullptr)
 Calls Advance() untill the query is done. More...
 
void OnDone ()
 Calls m_onDone IOnDone::OnDone() if m_onDone is not null. More...
 
KyResult SendVisualDebug ()
 Sends the query to the NavigationLab. More...
 
void SetTraverseLogicUserData (void *traverseLogicUserData)
 Sets m_traverseLogicUserData for queries that have a custom TraverseLogic, useless otherwise. More...
 
void * GetTraverseLogicUserData () const
 Gets m_traverseLogicUserData. More...
 

For internal use only

static const char * GetQueryTypeName (QueryType queryType)
 
Databasem_database
 The database on which the query will be performed. Set in Initialize(), do not directly modify. More...
 
void * m_traverseLogicUserData
 This userData is typically passed by the Bot. More...
 
QueryQueuem_queue
 Updated by the QueryQueue. Do not modify. More...
 
QueryStatusInQueue m_inQueueStatus
 Used by the QueryQueue. Do not modify. More...
 
KyUInt32 m_queryInfoId
 

Mandatory initialization calls to be done by derived classes

void Initialize ()
 Should be called by the derived class prior to perform the query or to push it in a QueryQueue. More...
 

Member Function Documentation

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::Advance ( WorkingMemory *  workingMemory)
inlinevirtual

This function is called by the QueryQueue to process one step on the query.

One call to Advance should be short (< 0.1ms as too long). It's Advance() responsibility to update m_processStatus. If the query is atomic, one call to Advance() will fully perform the query and set m_processStatus to QueryDone. If the query is time-sliced, several calls to Advance() will be needed to complete the query. the first call should set m_processStatus to Kaim::QueryInProcess and the last one to Kaim::QueryDone.

Parameters
workingMemorySandbox memory used to perform queries.

Implements Kaim::IQuery.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::BindToDatabase ( Database database)
inline

Binds the query with the specified Database, clears all the inputs and outputs and sets all other parameters to their default value (they may be changed by calling the corresponding write accessors.)

Parameters
databaseA pointer to the Database on which the query must be performed.
bool Kaim::IQuery::CanBeInitialized ( ) const
inlineinherited

In the case of a query processed in a QueryQueue, this must be tested before initializing the query, to prevent modifying the query during the process.

void* Kaim::IQuery::GetTraverseLogicUserData ( ) const
inlineinherited
virtual QueryType Kaim::BaseSegmentCastQuery::GetType ( ) const
inlinevirtualinherited

Get query type.

Implements Kaim::IQuery.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::Initialize ( const Vec3f startPos,
KyFloat32  radius,
const Vec2f normalizedDir2d,
KyFloat32  maxDist 
)
inline

resets an initialized instance of this class with minimum input requirements.

Clears all the output, and let all other parameters unchanged. They may be changed by calling the corresponding write accessors.

Parameters
startPosSets the value of m_startPos3f.
radiusSets the value of m_radius.
normalizedDir2dSets the value of m_normalizedDir2d.
maxDistSets the value of m_maxDist.
void Kaim::IQuery::Initialize ( )
inlineinherited

Should be called by the derived class prior to perform the query or to push it in a QueryQueue.

BindToDatabase() must have been called once before. It sets m_processStatus to QueryNotStarted. The query can be pending or in-progress in a query queue, then calling Initialize() is an error. CanBeInitialized() can be called to test this.

bool Kaim::IQuery::IsInAQueryQueue ( ) const
inlineinherited

Returns true if the query is currently registered in a QueryQueue.

If true, you must not push it again in QueryQueue (even the same one). If false, you must not try to cancel it from the QueryQueue.

bool Kaim::IQuery::IsSafeToReadResult ( ) const
inlineinherited

Returns true if the query has been processed, is no longer in a queue, and OnDone (if there is one) has been called.

If true, it's guaranteed to be safe to read the results of this query. Will return false if the Query has been cancelled or has not yet been processed.

void Kaim::IQuery::OnDone ( )
inlineinherited

Calls m_onDone IOnDone::OnDone() if m_onDone is not null.

Called automatically by the QueryQueue during the World::Update() (in the FlushQueries() step) when this query has been completed. OnDone() is not called if the query is canceled. Note that the member m_onDone is reset to nullptr at the end of this function.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::PerformQuery ( WorkingMemory *  workingMemory = nullptr)
inline

If workingMemory param is nullptr, m_database.GetWorkingMemory() will be used.

KyUInt32 Kaim::IQuery::PerformQueryBlocking ( WorkingMemory *  workingMemory = nullptr)
inherited

Calls Advance() untill the query is done.

Parameters
workingMemorySandbox memory used to perform queries. If not set, m_database.GetWorkingMemory() will be used.
Returns
the number of call to Advance() (timesliced iterations) it took to perform the query.
KyResult Kaim::IQuery::SendVisualDebug ( )
inherited

Sends the query to the NavigationLab.

Currently the implementation transform the query using a DisplayList, and the display list is shown only at the frame SendVisualDebug is called.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::SetDynamicOutputMode ( DynamicOutputMode  savingMode)
inline

Write accessor for m_dynamicOutputMode.

Call this method after BindToDatabase during which member m_dynamicOutputMode is set to its default value.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::SetPositionSpatializationRange ( const PositionSpatializationRange positionSpatializationRange)
inline

Write accessor for m_positionSpatializationRange.

Call this method after BindToDatabase(), during which m_positionSpatializationRange is set to its default value.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::SetQueryDynamicOutput ( QueryDynamicOutput queryDynamicOutput)
inline

Write accessor for m_queryDynamicOutput.

Call this method after Initialize(), during which m_queryDynamicOutput is set to nullptr.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::SetSafetyDist ( KyFloat32  safetyDist)
inline

Write accessor for m_safetyDist.

Call this method after BindToDatabase(), during which m_safetyDist is set to its default value.

template<class TLogic >
void Kaim::SegmentCastQuery< TLogic >::SetStartTrianglePtr ( const NavTrianglePtr startTrianglePtr)
inline

The NavMesh triangle that corresponds to m_startPos3f.

If a valid NavTrianglePtr is specified, this value will be used. If no value is specified, it will be automatically computed during the query. Call this method after Initialize(), during which it is cleared.

void Kaim::IQuery::SetTraverseLogicUserData ( void *  traverseLogicUserData)
inlineinherited

Sets m_traverseLogicUserData for queries that have a custom TraverseLogic, useless otherwise.

Member Data Documentation

Vec3f Kaim::BaseSegmentCastQuery::m_arrivalPos3f
protectedinherited

Updated during processing to indicate the final position of the segment at the end of the cast.

NavTrianglePtr Kaim::BaseSegmentCastQuery::m_arrivalTrianglePtr
protectedinherited

Updated during processing to indicate the NavMesh triangle that corresponds to m_arrivalPos3f.

Due to the imprecision of floating-point calculations, this triangle may be invalid even after moving m_arrivalPos3f back from the point of collision.

NavHalfEdgePtr Kaim::BaseSegmentCastQuery::m_collisionHalfEdgePtr
protectedinherited

Updated during processing to indicate the triangle edge that the segment collided with, if a collision is detected.

Vec3f Kaim::BaseSegmentCastQuery::m_collisionPos3f
protectedinherited

Updated during processing to indicate the position of the collision point between the segment and the NavMesh border, if a collision has been detected.

Database* Kaim::IQuery::m_database
inherited

The database on which the query will be performed. Set in Initialize(), do not directly modify.

DynamicOutputMode Kaim::BaseSegmentCastQuery::m_dynamicOutputMode
protectedinherited

Specifies the type of data stored in m_queryDynamicOutput.

QueryStatusInQueue Kaim::IQuery::m_inQueueStatus
inherited

Used by the QueryQueue. Do not modify.

KyFloat32 Kaim::BaseSegmentCastQuery::m_maxDist
protectedinherited

Determines the maximum distance the segment will travel.

Vec2f Kaim::BaseSegmentCastQuery::m_normalizedDir2d
protectedinherited

A normalized vector that represents the direction in which the segment is cast.

Ptr<IOnDone> Kaim::IQuery::m_onDone
inherited

The optional IOnDone instance to be called. Must be set manually by the user. See IOnDone.

PositionSpatializationRange Kaim::BaseSegmentCastQuery::m_positionSpatializationRange
protectedinherited

The altitude range around the position to use when determining m_startTrianglePtr from the m_startPos3f.

QueryProcessStatus Kaim::IQuery::m_processStatus
inherited

Modified by the query within Advance(). Do not modify.

Before reading m_processStatus, always ensure IsInAQueryQueue() returns false.

Ptr<QueryDynamicOutput> Kaim::BaseSegmentCastQuery::m_queryDynamicOutput
protectedinherited

A ref-counted Ptr to a QueryDynamicOutput instance, used to store the data encountered during the query process.

You have to first call SetDynamicOutputMode(), after BindToDatabase() that set it to QUERY_SAVE_NOTHING by default and before processing the query, to define the data type you want to gather. You can keep the Ptr for reuse and reassign it to another query by calling SetQueryDynamicOutput() after the BindToDatabase(), but in this case, be careful: the query may swap the underlying instance when processing if the provided buffer is to short. In this case, it is more sure to always update the Ptr when the query process is over.

QueryQueue* Kaim::IQuery::m_queue
inherited

Updated by the QueryQueue. Do not modify.

KyFloat32 Kaim::BaseSegmentCastQuery::m_radius
protectedinherited

The half-width of the segment .

SegmentCastQueryResult Kaim::BaseSegmentCastQuery::m_result
protectedinherited

Updated during processing to indicate the result of the query.

KyFloat32 Kaim::BaseSegmentCastQuery::m_safetyDist
protectedinherited

When a collision is detected, the collision point is moved back along m_normalizedDir2d by this distance, in order to ensure that the final arrival position will lie within the valid area of the NavMesh.

Vec3f Kaim::BaseSegmentCastQuery::m_startPos3f
protectedinherited

The starting position of the segment.

NavTrianglePtr Kaim::BaseSegmentCastQuery::m_startTrianglePtr
protectedinherited

The NavMesh triangle that corresponds to m_startPos3f. You can set it as an input or retrieve it as an output of the query.

void* Kaim::IQuery::m_traverseLogicUserData
inherited

This userData is typically passed by the Bot.


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