123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- //-----------------------------------------------------------------------------
- // Verve
- // Copyright (C) 2014 - Violent Tulip
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #ifndef _VT_VCONTROLLER_H_
- #define _VT_VCONTROLLER_H_
- #ifndef _VT_VERVECONFIG_H_
- #include "Verve/VerveConfig.h"
- #endif
- #ifndef _PLATFORM_H_
- #include "platform/platform.h"
- #endif
- #ifndef _PROCESSLIST_H_
- #include "T3D/gameBase/processList.h"
- #endif
- #ifndef _ITICKABLE_H_
- #include "core/iTickable.h"
- #endif
- #ifndef _VT_VPERSISTENCE_H_
- #include "Verve/Core/Persistence/VPersistence.h"
- #endif
- #ifndef _VT_VTREENODE_H_
- #include "Verve/Core/VTreeNode.h"
- #endif
- #ifndef _VT_VDATATABLE_H_
- #include "Verve/Core/VDataTable.h"
- #endif
- #ifndef _VT_TORQUE_CAMERA_H_
- #include "Verve/Torque/TCamera.h"
- #endif
- //-----------------------------------------------------------------------------
- class VObject;
- class VTrack;
- class VEvent;
- class VGroup;
- class VDirectorGroup;
- class VDirectorTrack;
- typedef VectorPtr<VTrack*> VTrackVector;
- typedef VTrackVector::iterator VTrackIterator;
- typedef VectorPtr<VEvent*> VEventVector;
- typedef VEventVector::iterator VEventIterator;
- typedef VectorPtr<VGroup*> VGroupVector;
- typedef VGroupVector::iterator VGroupIterator;
- //-----------------------------------------------------------------------------
- class VController : public SimObject,
- public virtual ITickable,
- public VTreeNode
- {
- typedef SimObject Parent;
- public:
- enum eControllerStatus
- {
- k_StatusInit = BIT( 0 ),
- k_StatusPlaying = BIT( 1 ),
- k_StatusPaused = BIT( 2 ),
- k_StatusStopped = BIT( 3 ),
- };
- enum eControllerEventType
- {
- k_EventInit,
- k_EventReset,
- k_EventPlay,
- k_EventPause,
- k_EventStop,
- k_EventLoop,
- };
- enum eControllerJumpType
- {
- k_JumpTime,
- k_JumpDelta,
- k_JumpInvalid,
- };
- typedef Signal<void( const S32 &pTime, const S32 &pDelta )> ControllerUpdateSignal;
- typedef Signal<bool( eControllerEventType )> ControllerEventSignal;
- private:
- // Data.
- VDataTable mDataTable;
- // Event Signal.
- ControllerUpdateSignal mControllerUpdateSignal;
- ControllerEventSignal mControllerEventSignal;
- // Properties.
- S32 mStatus;
- S32 mTime;
- U32 mLastTime;
- S32 mDuration;
- F32 mTimeScale;
- bool mLoop;
- bool mLoopBackwards;
- S32 mLoopCount;
- S32 mLoopIndex;
- S32 mLoopDelay;
- S32 mLoopDelayTime;
- eControllerJumpType mJump;
- S32 mJumpTime;
- bool mResetOnCompletion;
- public:
- VController();
- ~VController();
- static void initPersistFields( void );
- // ITickable.
- void interpolateTick( F32 pDelta ) { };
- void advanceTime( F32 pDelta ) { };
- void processTick( void );
- void onPostTick( void );
- // Controller.
- void reset( void );
- void reset( const S32 &pTime );
- void play( void );
- void play( const S32 &pTime );
- void pause( void );
- void stop( const bool &pReset = true );
- void jump( void );
- void jump( const eControllerJumpType &pType, const S32 &pDelta );
- void updateStatus( const S32 &pStatus );
- // Reference.
- VGroup *getObject( const String &pLabel );
- template <class T> inline bool getObject( const String &pLabel, T *&pObject )
- {
- // Reference Group.
- pObject = dynamic_cast<T*>( getObject( pLabel ) );
- // Valid?
- return ( pObject != NULL );
- }
- bool getDataValue( const String &pFieldName, String &pValue );
- void clearData( void );
- void clearData( const S32 &pIndex );
- void clearData( const String &pFieldName );
- void sort( void );
- // Saving.
- bool writeDataTable( tinyxml2::XMLElement *pElement );
- // Reading.
- bool readDataTable( tinyxml2::XMLElement *pElement );
- // Console Declaration.
- DECLARE_CONOBJECT( VController );
- public:
- inline VDataTable &getDataTable( void ) { return mDataTable; };
- inline ControllerUpdateSignal &getControllerUpdateSignal( void ) { return mControllerUpdateSignal; };
- inline ControllerEventSignal &getControllerEventSignal( void ) { return mControllerEventSignal; };
- void postEvent( const eControllerEventType &pEvent );
- VDirectorGroup *getDirectorGroup( void );
- VDirectorTrack *getDirectorTrack( void );
- inline void setTime( const S32 &pTime ) { mTime = pTime; };
- inline void setDuration( const S32 &pDuration ) { mDuration = pDuration; };
- void setTimeScale( const F32 &pTimeScale );
- inline bool isLooping( void ) { return mLoop; };
- inline bool isPlaying( void ) { return ( mStatus & k_StatusPlaying ); };
- inline bool isPaused( void ) { return ( mStatus & k_StatusPaused ); };
- inline bool isStopped( void ) { return ( mStatus & k_StatusStopped ); };
- inline bool isPlayingForward( void ) { return ( mTimeScale > 0.f ); };
- inline S32 getTime( void ) { return mTime; };
- inline S32 getDuration( void ) { return mDuration; };
- inline F32 getTimeScale( void ) { return mTimeScale; };
- inline S32 getLoopDelayTime( void ) { return mLoopDelayTime; };
- protected:
- static bool setTime( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setTime( dAtoi( pData ) ); return false; };
- static bool setDuration( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setDuration( dAtoi( pData ) ); return false; };
- static bool setTimeScale( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setTimeScale( dAtof( pData ) ); return false; };
- };
- //-----------------------------------------------------------------------------
- #endif // _VT_VCONTROLLER_H_
|