VController.h

Engine/source/Verve/Core/VController.h

More...

Classes:

Public Typedefs

VEventIterator 
VEventVector 
VGroupIterator 
VGroupVector 
VTrackIterator 
VTrackVector 

Detailed Description

Public Typedefs

typedef VEventVector::iterator VEventIterator 
typedef VectorPtr< VEvent * > VEventVector 
typedef VGroupVector::iterator VGroupIterator 
typedef VectorPtr< VGroup * > VGroupVector 
typedef VTrackVector::iterator VTrackIterator 
typedef VectorPtr< VTrack * > VTrackVector 
  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_VCONTROLLER_H_
 25#define _VT_VCONTROLLER_H_
 26
 27#ifndef _VT_VERVECONFIG_H_
 28#include "Verve/VerveConfig.h"
 29#endif
 30
 31#ifndef _PLATFORM_H_
 32#include "platform/platform.h"
 33#endif
 34
 35#ifndef _PROCESSLIST_H_
 36#include "T3D/gameBase/processList.h"
 37#endif
 38
 39#ifndef _ITICKABLE_H_
 40#include "core/iTickable.h"
 41#endif
 42
 43#ifndef _VT_VPERSISTENCE_H_
 44#include "Verve/Core/Persistence/VPersistence.h"
 45#endif
 46
 47#ifndef _VT_VTREENODE_H_
 48#include "Verve/Core/VTreeNode.h"
 49#endif
 50
 51#ifndef _VT_VDATATABLE_H_
 52#include "Verve/Core/VDataTable.h"
 53#endif
 54
 55#ifndef _VT_TORQUE_CAMERA_H_
 56#include "Verve/Torque/TCamera.h"
 57#endif
 58
 59//-----------------------------------------------------------------------------
 60class VObject;
 61
 62class VTrack;
 63class VEvent;
 64class VGroup;
 65
 66class VDirectorGroup;
 67class VDirectorTrack;
 68
 69typedef VectorPtr<VTrack*>        VTrackVector;
 70typedef VTrackVector::iterator    VTrackIterator;
 71
 72typedef VectorPtr<VEvent*>        VEventVector;
 73typedef VEventVector::iterator    VEventIterator;
 74
 75typedef VectorPtr<VGroup*>        VGroupVector;
 76typedef VGroupVector::iterator    VGroupIterator;
 77//-----------------------------------------------------------------------------
 78
 79class VController : public SimObject,
 80                    public virtual ITickable,
 81                    public VTreeNode
 82{
 83    typedef SimObject Parent;
 84
 85public:
 86
 87    enum eControllerStatus
 88    {
 89        k_StatusInit    = BIT( 0 ),
 90
 91        k_StatusPlaying = BIT( 1 ),
 92        k_StatusPaused  = BIT( 2 ),
 93        k_StatusStopped = BIT( 3 ),
 94    };
 95
 96    enum eControllerEventType
 97    {
 98        k_EventInit,
 99        k_EventReset,
100
101        k_EventPlay,
102        k_EventPause,
103        k_EventStop,
104
105        k_EventLoop,
106    };
107
108    enum eControllerJumpType
109    {
110        k_JumpTime,
111        k_JumpDelta,
112
113        k_JumpInvalid,
114    };
115
116    typedef Signal<void( const S32 &pTime, const S32 &pDelta )> ControllerUpdateSignal;
117    typedef Signal<bool( eControllerEventType )> ControllerEventSignal;
118
119private:
120
121    // Data.
122
123    VDataTable                mDataTable;
124
125    // Event Signal.
126
127    ControllerUpdateSignal    mControllerUpdateSignal;
128    ControllerEventSignal     mControllerEventSignal;
129
130    // Properties.
131
132    S32                       mStatus;
133
134    S32                       mTime;
135    U32                       mLastTime;
136    S32                       mDuration;
137    F32                       mTimeScale;
138
139    bool                      mLoop;
140    bool                      mLoopBackwards;
141    S32                       mLoopCount;
142    S32                       mLoopIndex;
143    S32                       mLoopDelay;
144    S32                       mLoopDelayTime;
145
146    eControllerJumpType       mJump;
147    S32                       mJumpTime;
148
149    bool                      mResetOnCompletion;
150
151public:
152
153    VController();
154    ~VController();
155
156    static  void    initPersistFields( void );
157
158    // ITickable.
159
160    void            interpolateTick( F32 pDelta ) { };
161    void            advanceTime( F32 pDelta ) { };
162    void            processTick( void );
163    void            onPostTick( void );
164
165    // Controller.
166
167    void            reset( void );
168    void            reset( const S32 &pTime );
169
170    void            play( void );
171    void            play( const S32 &pTime );
172
173    void            pause( void );
174    void            stop( const bool &pReset = true );
175
176    void            jump( void );
177    void            jump( const eControllerJumpType &pType, const S32 &pDelta );
178
179    void            updateStatus( const S32 &pStatus );
180
181    // Reference.
182
183    VGroup *getObject( const String &pLabel );
184    template <class T> inline bool getObject( const String &pLabel, T *&pObject )
185    {
186        // Reference Group.
187        pObject = dynamic_cast<T*>( getObject( pLabel ) );
188
189        // Valid?
190        return ( pObject != NULL );
191    }
192
193    bool            getDataValue( const String &pFieldName, String &pValue );
194    void            clearData( void );
195    void            clearData( const S32 &pIndex );
196    void            clearData( const String &pFieldName );
197
198    void            sort( void );
199
200    // Saving.
201
202    bool            writeDataTable( TiXmlElement *pElement );
203
204    // Reading.
205
206    bool            readDataTable( TiXmlElement *pElement );
207
208    // Console Declaration.
209
210    DECLARE_CONOBJECT( VController );
211
212public:
213
214    inline VDataTable               &getDataTable( void )                   { return mDataTable;                     };
215
216    inline ControllerUpdateSignal   &getControllerUpdateSignal( void )      { return mControllerUpdateSignal;        };
217    inline ControllerEventSignal    &getControllerEventSignal( void )       { return mControllerEventSignal;         };
218    void                             postEvent( const eControllerEventType &pEvent );
219
220    VDirectorGroup                  *getDirectorGroup( void );
221    VDirectorTrack                  *getDirectorTrack( void );
222
223    inline void                      setTime( const S32 &pTime )            { mTime = pTime;                         };
224    inline void                      setDuration( const S32 &pDuration )    { mDuration = pDuration;                 };
225    void                             setTimeScale( const F32 &pTimeScale );
226
227    inline bool                      isLooping( void )                      { return mLoop;                          };
228    inline bool                      isPlaying( void )                      { return ( mStatus & k_StatusPlaying );  };
229    inline bool                      isPaused( void )                       { return ( mStatus & k_StatusPaused );   };
230    inline bool                      isStopped( void )                      { return ( mStatus & k_StatusStopped );  };
231    inline bool                      isPlayingForward( void )               { return ( mTimeScale > 0.f );           };
232
233    inline S32                       getTime( void )                        { return mTime;                          };
234    inline S32                       getDuration( void )                    { return mDuration;                      };
235    inline F32                       getTimeScale( void )                   { return mTimeScale;                     };
236    inline S32                       getLoopDelayTime( void )               { return mLoopDelayTime;                 };
237
238protected:
239
240    static bool     setTime( void *pObject, const char *pArray, const char *pData )      { static_cast<VController*>( pObject )->setTime( dAtoi( pData ) );      return false; };
241    static bool     setDuration( void *pObject, const char *pArray, const char *pData )  { static_cast<VController*>( pObject )->setDuration( dAtoi( pData ) );  return false; };
242    static bool     setTimeScale( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setTimeScale( dAtof( pData ) ); return false; };
243};
244
245//-----------------------------------------------------------------------------
246
247#endif // _VT_VCONTROLLER_H_
248