SequenceTrack.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "SequenceTrack.h"
  10. //////////////////////////////////////////////////////////////////////////
  11. /// @deprecated Serialization for Sequence Tracks in Component Entity Sequences now occur through AZ::SerializeContext and the Sequence Component
  12. void CSequenceTrack::SerializeKey(ISequenceKey& key, XmlNodeRef& keyNode, bool bLoading)
  13. {
  14. if (bLoading)
  15. {
  16. const char* szSelection;
  17. szSelection = keyNode->getAttr("node");
  18. key.szSelection = szSelection;
  19. AZ::u64 id64;
  20. if (keyNode->getAttr("sequenceEntityId", id64))
  21. {
  22. key.sequenceEntityId = AZ::EntityId(id64);
  23. }
  24. if (!keyNode->getAttr("overridetimes", key.bOverrideTimes))
  25. {
  26. key.bOverrideTimes = false;
  27. }
  28. if (key.bOverrideTimes == true)
  29. {
  30. if (!keyNode->getAttr("starttime", key.fStartTime))
  31. {
  32. key.fStartTime = 0.0f;
  33. }
  34. if (!keyNode->getAttr("endtime", key.fEndTime))
  35. {
  36. key.fEndTime = 0.0f;
  37. }
  38. }
  39. else
  40. {
  41. key.fStartTime = 0.0f;
  42. key.fEndTime = 0.0f;
  43. }
  44. }
  45. else
  46. {
  47. keyNode->setAttr("node", key.szSelection.c_str());
  48. AZ::u64 id64 = static_cast<AZ::u64>(key.sequenceEntityId);
  49. keyNode->setAttr("sequenceEntityId", id64);
  50. if (key.bOverrideTimes == true)
  51. {
  52. keyNode->setAttr("overridetimes", key.bOverrideTimes);
  53. keyNode->setAttr("starttime", key.fStartTime);
  54. keyNode->setAttr("endtime", key.fEndTime);
  55. }
  56. }
  57. }
  58. //////////////////////////////////////////////////////////////////////////
  59. void CSequenceTrack::GetKeyInfo(int key, const char*& description, float& duration)
  60. {
  61. assert(key >= 0 && key < (int)m_keys.size());
  62. CheckValid();
  63. description = 0;
  64. duration = m_keys[key].fDuration;
  65. IAnimSequence* sequence = gEnv->pMovieSystem->FindSequence(m_keys[key].sequenceEntityId);
  66. if (sequence)
  67. {
  68. description = sequence->GetName();
  69. }
  70. }
  71. //////////////////////////////////////////////////////////////////////////
  72. static bool SequencTrackVersionConverter(
  73. AZ::SerializeContext& serializeContext,
  74. AZ::SerializeContext::DataElementNode& rootElement)
  75. {
  76. if (rootElement.GetVersion() < 3)
  77. {
  78. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  79. }
  80. return true;
  81. }
  82. template<>
  83. inline void TAnimTrack<ISequenceKey>::Reflect(AZ::ReflectContext* context)
  84. {
  85. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  86. {
  87. serializeContext->Class<TAnimTrack<ISequenceKey>, IAnimTrack>()
  88. ->Version(3, &SequencTrackVersionConverter)
  89. ->Field("Flags", &TAnimTrack<ISequenceKey>::m_flags)
  90. ->Field("Range", &TAnimTrack<ISequenceKey>::m_timeRange)
  91. ->Field("ParamType", &TAnimTrack<ISequenceKey>::m_nParamType)
  92. ->Field("Keys", &TAnimTrack<ISequenceKey>::m_keys)
  93. ->Field("Id", &TAnimTrack<ISequenceKey>::m_id);
  94. }
  95. }
  96. //////////////////////////////////////////////////////////////////////////
  97. void CSequenceTrack::Reflect(AZ::ReflectContext* context)
  98. {
  99. TAnimTrack<ISequenceKey>::Reflect(context);
  100. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  101. {
  102. serializeContext->Class<CSequenceTrack, TAnimTrack<ISequenceKey> >()
  103. ->Version(1);
  104. }
  105. }