AnimationValue.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "Base.h"
  2. #include "AnimationValue.h"
  3. namespace gameplay
  4. {
  5. AnimationValue::AnimationValue(unsigned int componentCount)
  6. : _componentCount(componentCount), _componentSize(componentCount * sizeof(float))
  7. {
  8. GP_ASSERT(_componentCount > 0);
  9. _value = new float[_componentCount];
  10. }
  11. AnimationValue::AnimationValue(const AnimationValue& copy)
  12. {
  13. _value = new float[copy._componentCount];
  14. _componentSize = copy._componentSize;
  15. _componentCount = copy._componentCount;
  16. memcpy(_value, copy._value, _componentSize);
  17. }
  18. AnimationValue::~AnimationValue()
  19. {
  20. SAFE_DELETE_ARRAY(_value);
  21. }
  22. AnimationValue& AnimationValue::operator=(const AnimationValue& v)
  23. {
  24. if (this != &v)
  25. {
  26. if (_value == NULL || _componentSize != v._componentSize || _componentCount != v._componentCount)
  27. {
  28. _componentSize = v._componentSize;
  29. _componentCount = v._componentCount;
  30. SAFE_DELETE_ARRAY(_value);
  31. _value = new float[v._componentCount];
  32. }
  33. memcpy(_value, v._value, _componentSize);
  34. }
  35. return *this;
  36. }
  37. float AnimationValue::getFloat(unsigned int index) const
  38. {
  39. GP_ASSERT(index < _componentCount);
  40. GP_ASSERT(_value);
  41. return _value[index];
  42. }
  43. void AnimationValue::setFloat(unsigned int index, float value)
  44. {
  45. GP_ASSERT(index < _componentCount);
  46. GP_ASSERT(_value);
  47. _value[index] = value;
  48. }
  49. void AnimationValue::getFloats(unsigned int index, float* values, unsigned int count) const
  50. {
  51. GP_ASSERT(_value && values && index < _componentCount && (index + count) <= _componentCount);
  52. memcpy(values, &_value[index], count * sizeof(float));
  53. }
  54. void AnimationValue::setFloats(unsigned int index, float* values, unsigned int count)
  55. {
  56. GP_ASSERT(_value && values && index < _componentCount && (index + count) <= _componentCount);
  57. memcpy(&_value[index], values, count * sizeof(float));
  58. }
  59. }