EventTrack.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include "EventTrack.h"
  10. #include "TrackEventTrack.h"
  11. CEventTrack::CEventTrack()
  12. : CEventTrack(nullptr)
  13. {
  14. }
  15. CEventTrack::CEventTrack(IAnimStringTable* pStrings)
  16. : m_pStrings(pStrings)
  17. {
  18. }
  19. //////////////////////////////////////////////////////////////////////////
  20. void CEventTrack::SerializeKey(IEventKey& key, XmlNodeRef& keyNode, bool bLoading)
  21. {
  22. if (bLoading)
  23. {
  24. const char* str;
  25. str = keyNode->getAttr("event");
  26. key.event = m_pStrings->Add(str);
  27. str = keyNode->getAttr("eventValue");
  28. key.eventValue = m_pStrings->Add(str);
  29. str = keyNode->getAttr("anim");
  30. key.animation = m_pStrings->Add(str);
  31. key.duration = 0;
  32. keyNode->getAttr("length", key.duration);
  33. }
  34. else
  35. {
  36. if (strlen(key.event.c_str()) > 0)
  37. {
  38. keyNode->setAttr("event", key.event.c_str());
  39. }
  40. if (strlen(key.eventValue.c_str()) > 0)
  41. {
  42. keyNode->setAttr("eventValue", key.eventValue.c_str());
  43. }
  44. if (strlen(key.animation.c_str()) > 0)
  45. {
  46. keyNode->setAttr("anim", key.animation.c_str());
  47. }
  48. if (key.duration > 0)
  49. {
  50. keyNode->setAttr("length", key.duration);
  51. }
  52. }
  53. }
  54. void CEventTrack::GetKeyInfo(int key, const char*& description, float& duration)
  55. {
  56. static char desc[128];
  57. assert(key >= 0 && key < (int)m_keys.size());
  58. CheckValid();
  59. description = 0;
  60. duration = 0;
  61. azstrcpy(desc, AZ_ARRAY_SIZE(desc), m_keys[key].event.c_str());
  62. if (!m_keys[key].eventValue.empty())
  63. {
  64. azstrcat(desc, AZ_ARRAY_SIZE(desc), ", ");
  65. azstrcat(desc, AZ_ARRAY_SIZE(desc), m_keys[key].eventValue.c_str());
  66. }
  67. description = desc;
  68. }
  69. void CEventTrack::SetKey(int index, IKey* key)
  70. {
  71. IEventKey* pEvKey = static_cast<IEventKey*>(key);
  72. // Intern string values
  73. pEvKey->event = m_pStrings->Add(pEvKey->event.c_str());
  74. pEvKey->eventValue = m_pStrings->Add(pEvKey->eventValue.c_str());
  75. pEvKey->animation = m_pStrings->Add(pEvKey->animation.c_str());
  76. TAnimTrack<IEventKey>::SetKey(index, pEvKey);
  77. }
  78. //////////////////////////////////////////////////////////////////////////
  79. void CEventTrack::InitPostLoad(IAnimSequence* sequence)
  80. {
  81. m_pStrings = sequence->GetTrackEventStringTable();
  82. }
  83. //////////////////////////////////////////////////////////////////////////
  84. void CEventTrack::Reflect(AZ::ReflectContext* context)
  85. {
  86. // Note the template base class TAnimTrack<IEventKey>::Reflect() is reflected by CTrackEventTrack::Reflect()
  87. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  88. {
  89. serializeContext->Class<CEventTrack, TAnimTrack<IEventKey>>()
  90. ->Version(1);
  91. }
  92. }