VHumanoidActorData.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "VHumanoidActorData.h"
  24. #include "VHumanoidAnimationStates.h"
  25. #include "VHumanoidPhysicsStates.h"
  26. //-----------------------------------------------------------------------------
  27. // Animation Table.
  28. //-----------------------------------------------------------------------------
  29. static VActorData::sAnimationSequence animSequenceLookup[] =
  30. {
  31. // State Based Animations.
  32. { VHumanoidActorData::k_IdleAnimation, "root", 0.0f, ActorAnimationStateInstance( HumanoidIdle ) },
  33. { VHumanoidActorData::k_WalkForwardAnimation, "walk", 0.1f, ActorAnimationStateInstance( HumanoidWalkForward ) },
  34. { VHumanoidActorData::k_WalkBackwardAnimation, "walkback", 0.1f, ActorAnimationStateInstance( HumanoidWalkBackward ) },
  35. { VHumanoidActorData::k_RunForwardAnimation, "run", 0.1f, ActorAnimationStateInstance( HumanoidRunForward ) },
  36. { VHumanoidActorData::k_RunBackwardAnimation, "runback", 0.1f, ActorAnimationStateInstance( HumanoidRunBackward ) },
  37. { VHumanoidActorData::k_SwimIdleAnimation, "swimroot", 1.0f, ActorAnimationStateInstance( HumanoidSwimIdle ) },
  38. { VHumanoidActorData::k_SwimForwardAnimation, "swim", 1.0f, ActorAnimationStateInstance( HumanoidSwimForward ) },
  39. { VHumanoidActorData::k_SwimBackwardAnimation, "swimback", 1.0f, ActorAnimationStateInstance( HumanoidSwimBackward ) },
  40. // Support Animations.
  41. { VHumanoidActorData::k_HeadHorizontalAnimation, "headside" },
  42. { VHumanoidActorData::k_HeadVerticalAnimation, "head" },
  43. { VHumanoidActorData::k_ArmsUpDownAnimation, "look" },
  44. };
  45. //-----------------------------------------------------------------------------
  46. // Physics Table.
  47. //-----------------------------------------------------------------------------
  48. static VActorData::sPhysicsState physStateLookup[] =
  49. {
  50. { VHumanoidActorData::k_OnGroundPhysics, 0.f, ActorPhysicsStateInstance( HumanoidOnGround ) },
  51. { VHumanoidActorData::k_InAirPhysics, 0.f, ActorPhysicsStateInstance( HumanoidInAir ) },
  52. { VHumanoidActorData::k_InWaterPhysics, 0.f, ActorPhysicsStateInstance( HumanoidInWater ) },
  53. };
  54. //-----------------------------------------------------------------------------
  55. IMPLEMENT_CO_DATABLOCK_V1( VHumanoidActorData );
  56. //-----------------------------------------------------------------------------
  57. VHumanoidActorData::VHumanoidActorData( void )
  58. {
  59. // Void.
  60. };
  61. bool VHumanoidActorData::preload( bool pServer, String &pErrorStr )
  62. {
  63. if ( !Parent::preload( pServer, pErrorStr ) )
  64. {
  65. return false;
  66. }
  67. // Initialise Animation List.
  68. if ( !initAnimationSequenceList( sizeof( animSequenceLookup ) / sizeof( VActorData::sAnimationSequence ), &animSequenceLookup[0] ) )
  69. {
  70. Con::errorf( "VHumanoidActorData::preload() - Failed to Initialise Actor Animations." );
  71. return false;
  72. }
  73. // Initialise Physics State List.
  74. if ( !initPhysicsStateList( sizeof( physStateLookup ) / sizeof( VActorData::sPhysicsState ), &physStateLookup[0] ) )
  75. {
  76. Con::errorf( "VHumanoidActorData::preload() - Failed to Initialise Actor Physics States." );
  77. return false;
  78. }
  79. // Valid Load.
  80. return true;
  81. }