Torque3D Documentation / _generateds / VActorStateTable.h

VActorStateTable.h

Engine/source/Verve/VActor/VActorStateTable.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Verve
  4// Copyright (C) 2014 - Violent Tulip
  5//
  6// Permission is hereby granted, free of charge, to any person obtaining a copy
  7// of this software and associated documentation files (the "Software"), to
  8// deal in the Software without restriction, including without limitation the
  9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10// sell copies of the Software, and to permit persons to whom the Software is
 11// furnished to do so, subject to the following conditions:
 12//
 13// The above copyright notice and this permission notice shall be included in
 14// all copies or substantial portions of the Software.
 15//
 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 22// IN THE SOFTWARE.
 23//-----------------------------------------------------------------------------
 24#ifndef _VT_VACTORSTATETABLE_H_
 25#define _VT_VACTORSTATETABLE_H_
 26
 27#ifndef _TVECTOR_H
 28#include "core/util/tVector.h"
 29#endif
 30
 31//-----------------------------------------------------------------------------
 32class VActor;
 33class VActorStateTable;
 34//-----------------------------------------------------------------------------
 35
 36class VActorState
 37{
 38public:
 39
 40    VActorState( void ) { };
 41    virtual ~VActorState( void ) { };
 42
 43    virtual void         enter( VActor *pObject )   = 0;
 44    virtual bool         execute( VActor *pObject ) = 0;
 45    virtual void         exit( VActor *pObject )    = 0;
 46};
 47
 48//-----------------------------------------------------------------------------
 49
 50class VActorStateTable
 51{
 52public:
 53
 54    struct sStateRef
 55    {
 56        VActorState   *State;
 57        F32            Priority;
 58    };
 59
 60    typedef Vector<sStateRef>            tStateVector;
 61    typedef tStateVector::iterator       tStateIterator;
 62    typedef tStateVector::const_iterator tStateConstIterator;
 63
 64protected:
 65
 66    tStateVector          mStateVector;
 67
 68    VActor               *mObject;
 69
 70    VActorState          *mLastState;
 71    VActorState          *mCurrentState;
 72
 73public:
 74
 75    VActorStateTable( void ) :
 76        mObject( NULL ),
 77        mLastState( NULL ),
 78        mCurrentState( NULL )
 79    {
 80        VECTOR_SET_ASSOCIATION( mStateVector );
 81    };
 82
 83    virtual ~VActorStateTable( void )
 84    {
 85        // Clear Table.
 86        clear();
 87    };
 88
 89    void                   registerState( VActorState *pState, const F32 &pPriority = 0.5f );
 90
 91    virtual void           enter( void ) { };
 92    virtual VActorState   *execute( void );
 93    virtual void           exit( void )  { };
 94
 95    //-------------------------------------------------------------------------
 96    //
 97    // Gets
 98    //
 99    //-------------------------------------------------------------------------
100
101    inline VActor         *getObject( void )       { return mObject; };
102
103    bool                   isRegisteredState( VActorState *pState );
104
105    inline VActorState    *getCurrentState( void ) { return mCurrentState; };
106    inline VActorState    *getLastState( void )    { return mLastState; };
107
108    //-------------------------------------------------------------------------
109    //
110    // Sets
111    //
112    //-------------------------------------------------------------------------
113
114    void                   clear( void );
115    void                   sort( void );
116
117    inline void            setObject( VActor *pObject ) { mObject = pObject; };
118    void                   setState( VActorState *pState );
119
120    //-------------------------------------------------------------------------
121    //
122    // Accessors
123    //
124    //-------------------------------------------------------------------------
125
126    tStateConstIterator    begin( void ) const { return mStateVector.begin(); };
127    tStateConstIterator    end( void )   const { return mStateVector.end(); };
128    S32                    size( void )  const { return mStateVector.size(); };
129
130protected:
131
132    static S32 QSORT_CALLBACK _onSortCallback( const VActorStateTable::sStateRef *pA, const VActorStateTable::sStateRef *pB );
133};
134
135#endif // _VT_VACTORSTATETABLE_H_
136