3
0

BoolTrack.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "BoolTrack.h"
  10. #include "Maestro/Types/AnimValueType.h"
  11. //////////////////////////////////////////////////////////////////////////
  12. CBoolTrack::CBoolTrack()
  13. : m_bDefaultValue(true)
  14. {
  15. }
  16. //////////////////////////////////////////////////////////////////////////
  17. void CBoolTrack::GetKeyInfo([[maybe_unused]] int index, const char*& description, float& duration)
  18. {
  19. description = 0;
  20. duration = 0;
  21. }
  22. //////////////////////////////////////////////////////////////////////////
  23. AnimValueType CBoolTrack::GetValueType()
  24. {
  25. return AnimValueType::Bool;
  26. }
  27. //////////////////////////////////////////////////////////////////////////
  28. void CBoolTrack::GetValue(float time, bool& value)
  29. {
  30. value = m_bDefaultValue;
  31. CheckValid();
  32. int nkeys = static_cast<int>(m_keys.size());
  33. if (nkeys < 1)
  34. {
  35. return;
  36. }
  37. int key = 0;
  38. while ((key < nkeys) && (time >= m_keys[key].time))
  39. {
  40. key++;
  41. }
  42. if (m_bDefaultValue)
  43. {
  44. value = !(key & 1); // True if even key.
  45. }
  46. else
  47. {
  48. value = (key & 1); // False if even key.
  49. }
  50. }
  51. //////////////////////////////////////////////////////////////////////////
  52. void CBoolTrack::SetValue([[maybe_unused]] float time, const bool& value, bool bDefault)
  53. {
  54. if (bDefault)
  55. {
  56. SetDefaultValue(value);
  57. }
  58. Invalidate();
  59. }
  60. //////////////////////////////////////////////////////////////////////////
  61. void CBoolTrack::SetDefaultValue(const bool bDefaultValue)
  62. {
  63. m_bDefaultValue = bDefaultValue;
  64. }
  65. /// @deprecated Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
  66. bool CBoolTrack::Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks)
  67. {
  68. bool retVal = TAnimTrack<IBoolKey>::Serialize(xmlNode, bLoading, bLoadEmptyTracks);
  69. if (bLoading)
  70. {
  71. xmlNode->getAttr("DefaultValue", m_bDefaultValue);
  72. }
  73. else
  74. {
  75. //saving
  76. xmlNode->setAttr("DefaultValue", m_bDefaultValue);
  77. }
  78. return retVal;
  79. }
  80. //////////////////////////////////////////////////////////////////////////
  81. static bool BoolTrackVersionConverter(
  82. AZ::SerializeContext& serializeContext,
  83. AZ::SerializeContext::DataElementNode& rootElement)
  84. {
  85. if (rootElement.GetVersion() < 3)
  86. {
  87. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  88. }
  89. return true;
  90. }
  91. template<>
  92. inline void TAnimTrack<IBoolKey>::Reflect(AZ::ReflectContext* context)
  93. {
  94. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  95. {
  96. serializeContext->Class<TAnimTrack<IBoolKey>, IAnimTrack>()
  97. ->Version(3, &BoolTrackVersionConverter)
  98. ->Field("Flags", &TAnimTrack<IBoolKey>::m_flags)
  99. ->Field("Range", &TAnimTrack<IBoolKey>::m_timeRange)
  100. ->Field("ParamType", &TAnimTrack<IBoolKey>::m_nParamType)
  101. ->Field("Keys", &TAnimTrack<IBoolKey>::m_keys)
  102. ->Field("Id", &TAnimTrack<IBoolKey>::m_id);
  103. }
  104. }
  105. //////////////////////////////////////////////////////////////////////////
  106. void CBoolTrack::Reflect(AZ::ReflectContext* context)
  107. {
  108. TAnimTrack<IBoolKey>::Reflect(context);
  109. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  110. {
  111. serializeContext->Class<CBoolTrack, TAnimTrack<IBoolKey>>()
  112. ->Version(1)
  113. ->Field("DefaultValue", &CBoolTrack::m_bDefaultValue);
  114. }
  115. }