AnimationTarget.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "Base.h"
  2. #include "AnimationTarget.h"
  3. #include "Animation.h"
  4. #include "Game.h"
  5. #include <string.h>
  6. #include "Transform.h"
  7. namespace gameplay
  8. {
  9. AnimationTarget::AnimationTarget()
  10. : _targetType(SCALAR), _activeAnimationCount(0), _currentPriority(0), _animations(NULL), _reassignPriorities(false)
  11. {
  12. }
  13. AnimationTarget::~AnimationTarget()
  14. {
  15. if (_animations)
  16. {
  17. std::vector<Animation*>::iterator animationIter = _animations->begin();
  18. while (animationIter != _animations->end())
  19. {
  20. SAFE_RELEASE((*animationIter));
  21. animationIter++;
  22. }
  23. SAFE_DELETE(_animations);
  24. }
  25. }
  26. void AnimationTarget::addAnimation(Animation* animation)
  27. {
  28. if (_animations == NULL)
  29. {
  30. _animations = new std::vector<Animation*>;
  31. }
  32. _animations->push_back(animation);
  33. animation->addRef();
  34. }
  35. unsigned int AnimationTarget::getAnimationCount() const
  36. {
  37. if (_animations)
  38. return _animations->size();
  39. return 0;
  40. }
  41. Animation* AnimationTarget::getAnimation(unsigned int index) const
  42. {
  43. if (_animations)
  44. return _animations->at(index);
  45. else
  46. return 0;
  47. }
  48. Animation* AnimationTarget::getAnimation(const char* id) const
  49. {
  50. if (_animations)
  51. {
  52. std::vector<Animation*>::iterator animationIter = _animations->begin();
  53. while(animationIter != _animations->end())
  54. {
  55. if ((*animationIter)->_id.compare(id) == 0)
  56. {
  57. return *animationIter;
  58. }
  59. animationIter++;
  60. }
  61. }
  62. return NULL;
  63. }
  64. void AnimationTarget::increaseActiveAnimationCount()
  65. {
  66. ++_activeAnimationCount;
  67. }
  68. void AnimationTarget::decreaseActiveAnimationCount()
  69. {
  70. --_activeAnimationCount;
  71. _reassignPriorities = true;
  72. _currentPriority = 0;
  73. }
  74. unsigned int AnimationTarget::getPriority()
  75. {
  76. if (_reassignPriorities)
  77. {
  78. ++_currentPriority;
  79. if (_currentPriority == _activeAnimationCount)
  80. _reassignPriorities = false;
  81. return _currentPriority;
  82. }
  83. return _activeAnimationCount;
  84. }
  85. }