VHumanoidActor.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. #include "VHumanoidActor.h"
  24. #include "core/stream/bitStream.h"
  25. //-----------------------------------------------------------------------------
  26. IMPLEMENT_CO_NETOBJECT_V1( VHumanoidActor );
  27. //-----------------------------------------------------------------------------
  28. VHumanoidActor::VHumanoidActor( void )
  29. {
  30. // Void.
  31. }
  32. VHumanoidActor::~VHumanoidActor( void )
  33. {
  34. // Void.
  35. }
  36. //-----------------------------------------------------------------------------
  37. //
  38. // Initialisation Methods.
  39. //
  40. //-----------------------------------------------------------------------------
  41. //-----------------------------------------------------------------------------
  42. //
  43. // VHumanoidActor::onNewDataBlock( pDataBlock );
  44. //
  45. // ...
  46. //
  47. //-----------------------------------------------------------------------------
  48. bool VHumanoidActor::onNewDataBlock( GameBaseData *pDataBlock, bool pReload )
  49. {
  50. // Store DataBlock Reference.
  51. mDataBlock = dynamic_cast<VHumanoidActorData*>( pDataBlock );
  52. // Valid Data?
  53. if ( !mDataBlock || !Parent::onNewDataBlock( pDataBlock, pReload ) )
  54. {
  55. // Invalid Data.
  56. return false;
  57. }
  58. // Initialise the Controllers.
  59. if ( !initAnimationController() || !initPhysicsController() )
  60. {
  61. // Invalid.
  62. return false;
  63. }
  64. // Initialise the Base Animation Thread.
  65. mAnimationController.initBaseAnimation( VHumanoidActorData::k_IdleAnimation, 0.f, 1.f );
  66. // Initialise the Arm Animation Thread.
  67. mAnimationController.initArmAnimation( VHumanoidActorData::k_ArmsUpDownAnimation, 0.5f, 1.f );
  68. /*
  69. // Initialise Head Threads.
  70. initAnimationSequence( VHumanoidActorData::k_HeadHorizontalAnimation, mHeadAnimation.HThread, 0.5f );
  71. initAnimationSequence( VHumanoidActorData::k_HeadVerticalAnimation, mHeadAnimation.VThread, 0.5f );
  72. */
  73. // Valid Data.
  74. return true;
  75. }
  76. //-----------------------------------------------------------------------------
  77. //
  78. // Update Methods.
  79. //
  80. //-----------------------------------------------------------------------------
  81. //-----------------------------------------------------------------------------
  82. //
  83. // VHumanoidActor::processTick( pMove );
  84. //
  85. // ...
  86. //
  87. //-----------------------------------------------------------------------------
  88. void VHumanoidActor::processTick( const Move *pMove )
  89. {
  90. // Parent Call.
  91. Parent::processTick( pMove );
  92. // Update Physics.
  93. mPhysicsController.update( TickSec, pMove );
  94. // Update Container.
  95. updateContainer();
  96. }
  97. //-----------------------------------------------------------------------------
  98. //
  99. // VHumanoidActor::interpolateTick( pDelta );
  100. //
  101. // ...
  102. //
  103. //-----------------------------------------------------------------------------
  104. void VHumanoidActor::interpolateTick( F32 pDelta )
  105. {
  106. // Parent Call.
  107. Parent::interpolateTick( pDelta );
  108. // Update Physics.
  109. mPhysicsController.interpolateTick( pDelta );
  110. }
  111. //-----------------------------------------------------------------------------
  112. //
  113. // VHumanoidActor::advanceTime( pDelta );
  114. //
  115. // ...
  116. //
  117. //-----------------------------------------------------------------------------
  118. void VHumanoidActor::advanceTime( F32 pDelta )
  119. {
  120. // Parent Call.
  121. Parent::advanceTime( pDelta );
  122. // Valid Animation Controller?
  123. if ( getAnimationController() )
  124. {
  125. // Update Animations.
  126. getAnimationController()->update( pDelta );
  127. }
  128. }
  129. //-----------------------------------------------------------------------------
  130. //
  131. // VHumanoidActor::packUpdate( pConnection, pMask, pStream );
  132. //
  133. // ...
  134. //
  135. //-----------------------------------------------------------------------------
  136. U32 VHumanoidActor::packUpdate( NetConnection *pConnection, U32 pMask, BitStream *pStream )
  137. {
  138. // Parent Call.
  139. U32 retMask = Parent::packUpdate( pConnection, pMask, pStream );
  140. // Physics Controller?
  141. if ( pStream->writeFlag( pMask & PhysicsMask ) )
  142. {
  143. // Pack Physics.
  144. retMask &= mPhysicsController.packUpdate( pConnection, pMask, pStream );
  145. }
  146. return retMask;
  147. }
  148. //-----------------------------------------------------------------------------
  149. //
  150. // VHumanoidActor::unpackUpdate( pConnection, pStream );
  151. //
  152. // ...
  153. //
  154. //-----------------------------------------------------------------------------
  155. void VHumanoidActor::unpackUpdate( NetConnection *pConnection, BitStream *pStream )
  156. {
  157. // Parent Call.
  158. Parent::unpackUpdate( pConnection, pStream );
  159. // Physics Controller?
  160. if ( pStream->readFlag() )
  161. {
  162. // Unpack Physics.
  163. mPhysicsController.unpackUpdate( pConnection, pStream );
  164. }
  165. }
  166. //-----------------------------------------------------------------------------
  167. //
  168. // Animation Methods.
  169. //
  170. //-----------------------------------------------------------------------------
  171. //-----------------------------------------------------------------------------
  172. //
  173. // VHumanoidActor::initAnimationController();
  174. //
  175. // ...
  176. //
  177. //-----------------------------------------------------------------------------
  178. bool VHumanoidActor::initAnimationController( void )
  179. {
  180. // Reference Object.
  181. mAnimationController.setObject( this );
  182. // Initialise.
  183. return mAnimationController.initAnimationTable();
  184. }
  185. //-----------------------------------------------------------------------------
  186. //
  187. // VHumanoidActor::getAnimationController();
  188. //
  189. // ...
  190. //
  191. //-----------------------------------------------------------------------------
  192. VActorAnimationController *VHumanoidActor::getAnimationController( void )
  193. {
  194. return &mAnimationController;
  195. }
  196. //-----------------------------------------------------------------------------
  197. //
  198. // VHumanoidActor::initPhysicsController();
  199. //
  200. // ...
  201. //
  202. //-----------------------------------------------------------------------------
  203. bool VHumanoidActor::initPhysicsController( void )
  204. {
  205. // Initialise.
  206. return mPhysicsController.initPhysicsController( this );
  207. }
  208. //-----------------------------------------------------------------------------
  209. //
  210. // VHumanoidActor::getAnimationController();
  211. //
  212. // ...
  213. //
  214. //-----------------------------------------------------------------------------
  215. VActorPhysicsController *VHumanoidActor::getPhysicsController( void )
  216. {
  217. return &mPhysicsController;
  218. }