VPathObject.h 8.4 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_VPATHOBJECT_H_
  24. #define _VT_VPATHOBJECT_H_
  25. #ifndef _GAMEBASE_H_
  26. #include "T3D/gameBase/gameBase.h"
  27. #endif
  28. #ifndef _VNETSTATE_H_
  29. #include "VNetState.h"
  30. #endif
  31. #ifndef _MOVEMANAGER_H_
  32. #include "T3D/gameBase/moveManager.h"
  33. #endif
  34. //-----------------------------------------------------------------------------
  35. class VPath;
  36. class NetConnection;
  37. struct VPathObject
  38. {
  39. public:
  40. enum eState
  41. {
  42. k_StateUpdateObject = BIT( 0 ),
  43. k_StateUpdateMount = BIT( 1 ),
  44. k_StateUpdatePosition = BIT( 2 ),
  45. k_StateUpdateState = BIT( 3 ),
  46. k_StateAttach = BIT( 4 ),
  47. k_StateDetach = BIT( 5 ),
  48. k_StateUpdate = ( k_StateUpdateObject | k_StateUpdateMount | k_StateUpdatePosition | k_StateUpdateState ),
  49. k_StateInit = ( k_StateAttach | k_StateUpdate ),
  50. };
  51. enum eOrientationType
  52. {
  53. k_OrientationFree,
  54. k_OrientationInterpolate,
  55. k_OrientationToPath,
  56. k_OrientationToObject,
  57. k_OrientationToPoint,
  58. k_OrientationTypeSize,
  59. };
  60. struct sOrientation
  61. {
  62. eOrientationType Type;
  63. // k_OrientationToObject
  64. SceneObject *Object;
  65. // k_OrientationToPoint
  66. Point3F Point;
  67. };
  68. struct sDelta
  69. {
  70. Point3F Position[2];
  71. VectorF Orientation[2];
  72. };
  73. protected:
  74. bool mActive;
  75. U32 mLastTime;
  76. F32 mLastDelta;
  77. SceneObject *mObject;
  78. VNetState mNetState;
  79. sDelta mDelta;
  80. F32 mTimeInterp;
  81. F32 mPathInterp;
  82. Point3F mPosition;
  83. Point3F mOffset;
  84. sOrientation mOrientationMode;
  85. VectorF mOrientation;
  86. bool mForward;
  87. F32 mSpeed;
  88. S32 mSourceNode;
  89. S32 mDestinationNode;
  90. S32 mStartNode;
  91. S32 mEndNode;
  92. public:
  93. VPathObject( void );
  94. ~VPathObject( void );
  95. // Network Methods.
  96. U32 packUpdate( NetConnection *pConnection, BitStream *pStream );
  97. void unpackUpdate( NetConnection *pConnection, BitStream *pStream );
  98. //-------------------------------------------------------------------------
  99. //
  100. // Gets
  101. //
  102. //-------------------------------------------------------------------------
  103. inline const bool &isActive( void ) { return mActive; };
  104. inline SceneObject *getObject( void ) { return mObject; };
  105. inline const F32 &getTimeInterp( void ) { return mTimeInterp; };
  106. inline const F32 &getPathInterp( void ) { return mPathInterp; };
  107. inline const Point3F &getPosition( void ) { return mPosition; };
  108. inline const Point3F &getOffset( void ) { return mOffset; };
  109. inline const VectorF &getOrientation( void ) { return mOrientation; };
  110. inline const sOrientation &getOrientationMode( void ) { return mOrientationMode; };
  111. inline const bool &isForward( void ) { return mForward; };
  112. inline const F32 &getSpeed( void ) { return mSpeed; };
  113. inline const S32 &getSourceNode( void ) { return mSourceNode; };
  114. inline const S32 &getDestinationNode( void ) { return mDestinationNode; };
  115. inline const S32 &getStartNode( void ) { return mStartNode; };
  116. inline const S32 &getEndNode( void ) { return mEndNode; };
  117. Point3F getWorldPosition( void );
  118. Point3F getRenderWorldPosition( const F32 &pDelta );
  119. MatrixF getTransform( void );
  120. MatrixF getRenderTransform( const F32 &pDelta );
  121. inline F32 getTimeDelta( const bool &pUpdate = true )
  122. {
  123. if ( !pUpdate )
  124. {
  125. return mLastDelta;
  126. }
  127. // Calculate Delta.
  128. const S32 time = Sim::getCurrentTime();
  129. const F32 delta = ( time - mLastTime ) / 1000.f;
  130. // Store Time.
  131. mLastTime = time;
  132. mLastDelta = delta;
  133. // Return Delta.
  134. return delta;
  135. };
  136. inline void resetTime( void )
  137. {
  138. mLastTime = Sim::getCurrentTime();
  139. };
  140. //-------------------------------------------------------------------------
  141. //
  142. // Sets
  143. //
  144. //-------------------------------------------------------------------------
  145. void setActive( const bool &pActive );
  146. void setObject( SceneObject *pObject );
  147. void setTimeInterp( const F32 &pInterp );
  148. void setPathInterp( const F32 &pInterp );
  149. void setPosition( const Point3F &pPosition );
  150. void setOffset( const Point3F &pOffset );
  151. void setOrientation( const VectorF &pOrientation );
  152. void setOrientationMode( const eOrientationType &pType );
  153. void setOrientationMode( const eOrientationType &pType, SceneObject *pObject );
  154. void setOrientationMode( const eOrientationType &pType, const Point3F &pPoint );
  155. void setForward( const bool &pForward );
  156. void setSpeed( const F32 &pSpeed );
  157. void setNode( const S32 &pSourceNodeIndex, const S32 &pDestinationNodeIndex );
  158. void setStartNode( const S32 &pNodeIndex );
  159. void setEndNode( const S32 &pNodeIndex );
  160. // Delta Methods.
  161. void resetDelta( void );
  162. void resetDelta( const Point3F &pPosition, const VectorF &pOrientation );
  163. void popDelta( void );
  164. void pushDelta( const Point3F &pPosition, const VectorF &pOrientation );
  165. Point3F getPositionDelta( const F32 &pInterp );
  166. VectorF getOrientationDelta( const F32 &pInterp );
  167. // Net State Methods.
  168. inline VNetStateInfo *getState( NetConnection *pConnection ) { return mNetState.getState( pConnection ); };
  169. inline void setMaskBits( const U32 &pMask ) { mNetState.setMaskBits( pMask ); };
  170. inline void clearMaskBits( const U32 &pMask ) { mNetState.clearMaskBits( pMask ); };
  171. inline bool isConnection( NetConnection *pConnection ) { return mNetState.isConnection( pConnection ); };
  172. inline void addConnection( NetConnection *pConnection ) { mNetState.addConnection( pConnection ); };
  173. inline void clearConnection( NetConnection *pConnection ) { mNetState.clearConnection( pConnection ); };
  174. // Enum Methods.
  175. static eOrientationType getOrientationTypeEnum( const char *pLabel );
  176. static StringTableEntry getOrientationTypeLabel( const eOrientationType &pType );
  177. };
  178. //-----------------------------------------------------------------------------
  179. // Define Types.
  180. typedef VPathObject::eOrientationType VPathObjectOrientationType;
  181. // Declare Enum Types.
  182. DefineEnumType( VPathObjectOrientationType );
  183. //-----------------------------------------------------------------------------
  184. #endif // _VT_VPATHOBJECT_H_