CaptureTrack.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "CaptureTrack.h"
  10. //////////////////////////////////////////////////////////////////////////
  11. void CCaptureTrack::SerializeKey(ICaptureKey& key, XmlNodeRef& keyNode, bool bLoading)
  12. {
  13. if (bLoading)
  14. {
  15. const char* desc;
  16. keyNode->getAttr("time", key.time);
  17. keyNode->getAttr("flags", key.flags);
  18. keyNode->getAttr("duration", key.duration);
  19. keyNode->getAttr("timeStep", key.timeStep);
  20. desc = keyNode->getAttr("folder");
  21. key.folder = desc;
  22. keyNode->getAttr("once", key.once);
  23. desc = keyNode->getAttr("prefix");
  24. if (desc)
  25. {
  26. key.prefix = desc;
  27. }
  28. }
  29. else
  30. {
  31. keyNode->setAttr("time", key.time);
  32. keyNode->setAttr("flags", key.flags);
  33. keyNode->setAttr("duration", key.duration);
  34. keyNode->setAttr("timeStep", key.timeStep);
  35. keyNode->setAttr("folder", key.folder.c_str());
  36. keyNode->setAttr("once", key.once);
  37. keyNode->setAttr("prefix", key.prefix.c_str());
  38. }
  39. }
  40. //////////////////////////////////////////////////////////////////////////
  41. void CCaptureTrack::GetKeyInfo(int key, const char*& description, float& duration)
  42. {
  43. assert(key >= 0 && key < (int)m_keys.size());
  44. static char buffer[256];
  45. CheckValid();
  46. duration = m_keys[key].once ? 0 : m_keys[key].duration;
  47. char prefix[64] = "Frame";
  48. if (!m_keys[key].prefix.empty())
  49. {
  50. azstrcpy(prefix, AZ_ARRAY_SIZE(prefix), m_keys[key].prefix.c_str());
  51. }
  52. description = buffer;
  53. if (!m_keys[key].folder.empty())
  54. {
  55. sprintf_s(buffer, "[%s], %.3f, %s", prefix, m_keys[key].timeStep, m_keys[key].folder.c_str());
  56. }
  57. else
  58. {
  59. sprintf_s(buffer, "[%s], %.3f", prefix, m_keys[key].timeStep);
  60. }
  61. }
  62. //////////////////////////////////////////////////////////////////////////
  63. static bool CaptureTrackVersionConverter(
  64. AZ::SerializeContext& serializeContext,
  65. AZ::SerializeContext::DataElementNode& rootElement)
  66. {
  67. if (rootElement.GetVersion() < 3)
  68. {
  69. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  70. }
  71. return true;
  72. }
  73. template<>
  74. inline void TAnimTrack<ICaptureKey>::Reflect(AZ::ReflectContext* context)
  75. {
  76. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  77. {
  78. serializeContext->Class<TAnimTrack<ICaptureKey>, IAnimTrack>()
  79. ->Version(3, &CaptureTrackVersionConverter)
  80. ->Field("Flags", &TAnimTrack<ICaptureKey>::m_flags)
  81. ->Field("Range", &TAnimTrack<ICaptureKey>::m_timeRange)
  82. ->Field("ParamType", &TAnimTrack<ICaptureKey>::m_nParamType)
  83. ->Field("Keys", &TAnimTrack<ICaptureKey>::m_keys)
  84. ->Field("Id", &TAnimTrack<ICaptureKey>::m_id);
  85. }
  86. }
  87. //////////////////////////////////////////////////////////////////////////
  88. void CCaptureTrack::Reflect(AZ::ReflectContext* context)
  89. {
  90. TAnimTrack<ICaptureKey>::Reflect(context);
  91. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  92. {
  93. serializeContext->Class<CCaptureTrack, TAnimTrack<ICaptureKey>>()
  94. ->Version(1);
  95. }
  96. }