VActorData.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 "VActorData.h"
  24. #include "console/consoleTypes.h"
  25. #include "core/stream/bitStream.h"
  26. //-----------------------------------------------------------------------------
  27. IMPLEMENT_CO_DATABLOCK_V1( VActorData );
  28. //-----------------------------------------------------------------------------
  29. VActorData::VActorData( void ) :
  30. mMaxStepHeight( 1.f ),
  31. mRunSpeed( 6.f ),
  32. mSubmergeCoverage( 0.25f )
  33. {
  34. // Setup Shadowing.
  35. shadowEnable = true;
  36. shadowSize = 256;
  37. shadowProjectionDistance = 14.0f;
  38. VECTOR_SET_ASSOCIATION( mAnimationSequenceList );
  39. VECTOR_SET_ASSOCIATION( mPhysicsList );
  40. }
  41. VActorData::~VActorData( void )
  42. {
  43. // Void.
  44. }
  45. void VActorData::initPersistFields( void )
  46. {
  47. Parent::initPersistFields();
  48. addField( "MaxStepHeight", TypeF32, Offset( mMaxStepHeight, VActorData ) );
  49. addField( "RunSpeed", TypeF32, Offset( mRunSpeed, VActorData ) );
  50. addField( "SubmergeCoverage", TypeF32, Offset( mSubmergeCoverage, VActorData ) );
  51. }
  52. //-----------------------------------------------------------------------------
  53. bool VActorData::initAnimationSequenceList( const S32 &pSize, const sAnimationSequence *pTable )
  54. {
  55. if ( !mShape )
  56. {
  57. // Sanity!
  58. return false;
  59. }
  60. // Clear the List.
  61. mAnimationSequenceList.clear();
  62. // Initialise each Animation Sequence.
  63. for ( U32 i = 0; i < pSize; i++ )
  64. {
  65. // Fetch Sequence Definition.
  66. const sAnimationSequence &animSequenceDef = pTable[i];
  67. // Update Animation Details.
  68. sAnimationSequence animSequence = animSequenceDef;
  69. // Find Sequence.
  70. animSequence.Sequence = mShape->findSequence( animSequenceDef.Name );
  71. // Store.
  72. mAnimationSequenceList.push_back( animSequence );
  73. }
  74. return true;
  75. }
  76. bool VActorData::initAnimationTransitionList( const S32 &pSize, const sAnimationTransition *pTable )
  77. {
  78. if ( !mShape )
  79. {
  80. // Sanity!
  81. return false;
  82. }
  83. // Clear the List.
  84. mAnimationTransitionList.clear();
  85. // Store each Animation Transition.
  86. for ( U32 i = 0; i < pSize; i++ )
  87. {
  88. // Store.
  89. mAnimationTransitionList.push_back( pTable[i] );
  90. }
  91. return true;
  92. }
  93. bool VActorData::initPhysicsStateList( const S32 &pSize, const sPhysicsState *pTable )
  94. {
  95. // Clear the List.
  96. mPhysicsList.clear();
  97. // Initialise each Animation Sequence.
  98. for ( U32 i = 0; i < pSize; i++ )
  99. {
  100. // Store.
  101. mPhysicsList.push_back( pTable[i] );
  102. }
  103. return true;
  104. }
  105. //-----------------------------------------------------------------------------
  106. void VActorData::packData( BitStream *pStream )
  107. {
  108. Parent::packData( pStream );
  109. pStream->write( mMaxStepHeight );
  110. pStream->write( mRunSpeed );
  111. pStream->write( mSubmergeCoverage );
  112. }
  113. void VActorData::unpackData( BitStream *pStream )
  114. {
  115. Parent::unpackData( pStream );
  116. pStream->read( &mMaxStepHeight );
  117. pStream->read( &mRunSpeed );
  118. pStream->read( &mSubmergeCoverage );
  119. }
  120. //-----------------------------------------------------------------------------
  121. S32 VActorData::getAnimationSequence( const U32 &pIndex )
  122. {
  123. // Iterate over the Registered Animations.
  124. for ( tAnimationSequenceVector::iterator itr = mAnimationSequenceList.begin(); itr != mAnimationSequenceList.end(); itr++ )
  125. {
  126. // Fetch Sequence Defintion.
  127. const sAnimationSequence &animSequence = ( *itr );
  128. // Target Index?
  129. if ( animSequence.Index == pIndex )
  130. {
  131. // Return Sequence ID.
  132. return animSequence.Sequence;
  133. }
  134. }
  135. // Invalid Sequence.
  136. return -1;
  137. };