VController.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #ifndef _VT_VCONTROLLER_H_
  24. #define _VT_VCONTROLLER_H_
  25. #ifndef _VT_VERVECONFIG_H_
  26. #include "Verve/VerveConfig.h"
  27. #endif
  28. #ifndef _PLATFORM_H_
  29. #include "platform/platform.h"
  30. #endif
  31. #ifndef _PROCESSLIST_H_
  32. #include "T3D/gameBase/processList.h"
  33. #endif
  34. #ifndef _ITICKABLE_H_
  35. #include "core/iTickable.h"
  36. #endif
  37. #ifndef _VT_VPERSISTENCE_H_
  38. #include "Verve/Core/Persistence/VPersistence.h"
  39. #endif
  40. #ifndef _VT_VTREENODE_H_
  41. #include "Verve/Core/VTreeNode.h"
  42. #endif
  43. #ifndef _VT_VDATATABLE_H_
  44. #include "Verve/Core/VDataTable.h"
  45. #endif
  46. #ifndef _VT_TORQUE_CAMERA_H_
  47. #include "Verve/Torque/TCamera.h"
  48. #endif
  49. //-----------------------------------------------------------------------------
  50. class VObject;
  51. class VTrack;
  52. class VEvent;
  53. class VGroup;
  54. class VDirectorGroup;
  55. class VDirectorTrack;
  56. typedef VectorPtr<VTrack*> VTrackVector;
  57. typedef VTrackVector::iterator VTrackIterator;
  58. typedef VectorPtr<VEvent*> VEventVector;
  59. typedef VEventVector::iterator VEventIterator;
  60. typedef VectorPtr<VGroup*> VGroupVector;
  61. typedef VGroupVector::iterator VGroupIterator;
  62. //-----------------------------------------------------------------------------
  63. class VController : public SimObject,
  64. public virtual ITickable,
  65. public VTreeNode
  66. {
  67. typedef SimObject Parent;
  68. public:
  69. enum eControllerStatus
  70. {
  71. k_StatusInit = BIT( 0 ),
  72. k_StatusPlaying = BIT( 1 ),
  73. k_StatusPaused = BIT( 2 ),
  74. k_StatusStopped = BIT( 3 ),
  75. };
  76. enum eControllerEventType
  77. {
  78. k_EventInit,
  79. k_EventReset,
  80. k_EventPlay,
  81. k_EventPause,
  82. k_EventStop,
  83. k_EventLoop,
  84. };
  85. enum eControllerJumpType
  86. {
  87. k_JumpTime,
  88. k_JumpDelta,
  89. k_JumpInvalid,
  90. };
  91. typedef Signal<void( const S32 &pTime, const S32 &pDelta )> ControllerUpdateSignal;
  92. typedef Signal<bool( eControllerEventType )> ControllerEventSignal;
  93. private:
  94. // Data.
  95. VDataTable mDataTable;
  96. // Event Signal.
  97. ControllerUpdateSignal mControllerUpdateSignal;
  98. ControllerEventSignal mControllerEventSignal;
  99. // Properties.
  100. S32 mStatus;
  101. S32 mTime;
  102. U32 mLastTime;
  103. S32 mDuration;
  104. F32 mTimeScale;
  105. bool mLoop;
  106. bool mLoopBackwards;
  107. S32 mLoopCount;
  108. S32 mLoopIndex;
  109. S32 mLoopDelay;
  110. S32 mLoopDelayTime;
  111. eControllerJumpType mJump;
  112. S32 mJumpTime;
  113. bool mResetOnCompletion;
  114. public:
  115. VController();
  116. ~VController();
  117. static void initPersistFields( void );
  118. // ITickable.
  119. void interpolateTick( F32 pDelta ) { };
  120. void advanceTime( F32 pDelta ) { };
  121. void processTick( void );
  122. void onPostTick( void );
  123. // Controller.
  124. void reset( void );
  125. void reset( const S32 &pTime );
  126. void play( void );
  127. void play( const S32 &pTime );
  128. void pause( void );
  129. void stop( const bool &pReset = true );
  130. void jump( void );
  131. void jump( const eControllerJumpType &pType, const S32 &pDelta );
  132. void updateStatus( const S32 &pStatus );
  133. // Reference.
  134. VGroup *getObject( const String &pLabel );
  135. template <class T> inline bool getObject( const String &pLabel, T *&pObject )
  136. {
  137. // Reference Group.
  138. pObject = dynamic_cast<T*>( getObject( pLabel ) );
  139. // Valid?
  140. return ( pObject != NULL );
  141. }
  142. bool getDataValue( const String &pFieldName, String &pValue );
  143. void clearData( void );
  144. void clearData( const S32 &pIndex );
  145. void clearData( const String &pFieldName );
  146. void sort( void );
  147. // Saving.
  148. bool writeDataTable( tinyxml2::XMLElement *pElement );
  149. // Reading.
  150. bool readDataTable( tinyxml2::XMLElement *pElement );
  151. // Console Declaration.
  152. DECLARE_CONOBJECT( VController );
  153. public:
  154. inline VDataTable &getDataTable( void ) { return mDataTable; };
  155. inline ControllerUpdateSignal &getControllerUpdateSignal( void ) { return mControllerUpdateSignal; };
  156. inline ControllerEventSignal &getControllerEventSignal( void ) { return mControllerEventSignal; };
  157. void postEvent( const eControllerEventType &pEvent );
  158. VDirectorGroup *getDirectorGroup( void );
  159. VDirectorTrack *getDirectorTrack( void );
  160. inline void setTime( const S32 &pTime ) { mTime = pTime; };
  161. inline void setDuration( const S32 &pDuration ) { mDuration = pDuration; };
  162. void setTimeScale( const F32 &pTimeScale );
  163. inline bool isLooping( void ) { return mLoop; };
  164. inline bool isPlaying( void ) { return ( mStatus & k_StatusPlaying ); };
  165. inline bool isPaused( void ) { return ( mStatus & k_StatusPaused ); };
  166. inline bool isStopped( void ) { return ( mStatus & k_StatusStopped ); };
  167. inline bool isPlayingForward( void ) { return ( mTimeScale > 0.f ); };
  168. inline S32 getTime( void ) { return mTime; };
  169. inline S32 getDuration( void ) { return mDuration; };
  170. inline F32 getTimeScale( void ) { return mTimeScale; };
  171. inline S32 getLoopDelayTime( void ) { return mLoopDelayTime; };
  172. protected:
  173. static bool setTime( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setTime( dAtoi( pData ) ); return false; };
  174. static bool setDuration( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setDuration( dAtoi( pData ) ); return false; };
  175. static bool setTimeScale( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setTimeScale( dAtof( pData ) ); return false; };
  176. };
  177. //-----------------------------------------------------------------------------
  178. #endif // _VT_VCONTROLLER_H_