VActor.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 "VActor.h"
  24. //-----------------------------------------------------------------------------
  25. IMPLEMENT_CO_NETOBJECT_V1( VActor );
  26. //-----------------------------------------------------------------------------
  27. VActor::VActor( void ) :
  28. mDataBlock( NULL )
  29. {
  30. // Void.
  31. }
  32. VActor::~VActor( void )
  33. {
  34. // Void.
  35. }
  36. //-----------------------------------------------------------------------------
  37. //
  38. // Initialisation Methods.
  39. //
  40. //-----------------------------------------------------------------------------
  41. //-----------------------------------------------------------------------------
  42. //
  43. // VActor::onAdd();
  44. //
  45. // ...
  46. //
  47. //-----------------------------------------------------------------------------
  48. bool VActor::onAdd( void )
  49. {
  50. if ( !Parent::onAdd() || !mDataBlock )
  51. {
  52. return false;
  53. }
  54. // Add to Scene.
  55. addToScene();
  56. if ( isServerObject() )
  57. {
  58. // Script Callback.
  59. scriptOnAdd();
  60. }
  61. return true;
  62. }
  63. //-----------------------------------------------------------------------------
  64. //
  65. // VActor::onRemove();
  66. //
  67. // ...
  68. //
  69. //-----------------------------------------------------------------------------
  70. void VActor::onRemove( void )
  71. {
  72. // Script Callback.
  73. scriptOnRemove();
  74. // Remove From Scene.
  75. removeFromScene();
  76. Parent::onRemove();
  77. }
  78. //-----------------------------------------------------------------------------
  79. //
  80. // VActor::onNewDataBlock( pDataBlock );
  81. //
  82. // ...
  83. //
  84. //-----------------------------------------------------------------------------
  85. bool VActor::onNewDataBlock( GameBaseData *pDataBlock, bool pReload )
  86. {
  87. // Store DataBlock Reference.
  88. mDataBlock = dynamic_cast<VActorData*>( pDataBlock );
  89. if ( !mDataBlock )
  90. {
  91. // Invalid Data.
  92. return false;
  93. }
  94. // Parent Call.
  95. return Parent::onNewDataBlock( pDataBlock, pReload );
  96. }
  97. //-----------------------------------------------------------------------------
  98. //
  99. // Update Methods.
  100. //
  101. //-----------------------------------------------------------------------------
  102. //-----------------------------------------------------------------------------
  103. //
  104. // VActor::processTick( pMove );
  105. //
  106. // ...
  107. //
  108. //-----------------------------------------------------------------------------
  109. void VActor::processTick( const Move *pMove )
  110. {
  111. // Parent Call.
  112. Parent::processTick( pMove );
  113. // Triggers?
  114. if ( pMove && mDamageState == Enabled )
  115. {
  116. // Handle each Image Trigger.
  117. const U32 imageCount = getMin( ShapeBase::MaxMountedImages, MaxTriggerKeys );
  118. for ( U32 i = 0; i < imageCount; i++ )
  119. {
  120. setImageTriggerState( i, pMove->trigger[i] );
  121. }
  122. }
  123. }
  124. //-----------------------------------------------------------------------------
  125. //
  126. // VActor::packUpdate( pConnection, pMask, pStream );
  127. //
  128. // ...
  129. //
  130. //-----------------------------------------------------------------------------
  131. U32 VActor::packUpdate( NetConnection *pConnection, U32 pMask, BitStream *pStream )
  132. {
  133. // Parent Call.
  134. return Parent::packUpdate( pConnection, pMask, pStream );
  135. }
  136. //-----------------------------------------------------------------------------
  137. //
  138. // VActor::unpackUpdate( pConnection, pStream );
  139. //
  140. // ...
  141. //
  142. //-----------------------------------------------------------------------------
  143. void VActor::unpackUpdate( NetConnection *pConnection, BitStream *pStream )
  144. {
  145. // Parent Call.
  146. Parent::unpackUpdate( pConnection, pStream );
  147. }
  148. //-----------------------------------------------------------------------------
  149. //
  150. // Physics Methods.
  151. //
  152. //-----------------------------------------------------------------------------
  153. //-----------------------------------------------------------------------------
  154. //
  155. // VActor::setTransform( pMatrix );
  156. //
  157. // ...
  158. //
  159. //-----------------------------------------------------------------------------
  160. void VActor::setTransform( const MatrixF &pMatrix )
  161. {
  162. Parent::setTransform( pMatrix );
  163. // Server Object?
  164. if ( isServerObject() )
  165. {
  166. // Move Object.
  167. setMaskBits( MoveMask );
  168. }
  169. }
  170. //-----------------------------------------------------------------------------
  171. //
  172. // VActor::onMount( pObject, pNode );
  173. //
  174. // ...
  175. //
  176. //-----------------------------------------------------------------------------
  177. void VActor::onMount( SceneObject *pObject, S32 pNode )
  178. {
  179. // Parent Call.
  180. Parent::onMount( pObject, pNode );
  181. // Post Event.
  182. mEventSignal.trigger( k_MountEvent );
  183. }
  184. //-----------------------------------------------------------------------------
  185. //
  186. // VActor::onUnmount( pObject, pNode );
  187. //
  188. // ...
  189. //
  190. //-----------------------------------------------------------------------------
  191. void VActor::onUnmount( SceneObject *pObject, S32 pNode )
  192. {
  193. // Parent Call.
  194. Parent::onUnmount( pObject, pNode );
  195. // Post Event.
  196. mEventSignal.trigger( k_UnmountEvent );
  197. }