SoundTrack.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "SoundTrack.h"
  10. //////////////////////////////////////////////////////////////////////////
  11. void CSoundTrack::SerializeKey(ISoundKey& key, XmlNodeRef& keyNode, bool bLoading)
  12. {
  13. if (bLoading)
  14. {
  15. const char* sTemp;
  16. sTemp = keyNode->getAttr("StartTrigger");
  17. key.sStartTrigger = sTemp;
  18. sTemp = keyNode->getAttr("StopTrigger");
  19. key.sStopTrigger = sTemp;
  20. float fDuration = 0.0f;
  21. if (keyNode->getAttr("Duration", fDuration))
  22. {
  23. key.fDuration = fDuration;
  24. }
  25. keyNode->getAttr("CustomColor", key.customColor);
  26. }
  27. else
  28. {
  29. keyNode->setAttr("StartTrigger", key.sStartTrigger.c_str());
  30. keyNode->setAttr("StopTrigger", key.sStopTrigger.c_str());
  31. keyNode->setAttr("Duration", key.fDuration);
  32. keyNode->setAttr("CustomColor", key.customColor);
  33. }
  34. }
  35. //////////////////////////////////////////////////////////////////////////
  36. void CSoundTrack::GetKeyInfo(int key, const char*& description, float& duration)
  37. {
  38. assert(key >= 0 && key < (int)m_keys.size());
  39. CheckValid();
  40. description = 0;
  41. duration = m_keys[key].fDuration;
  42. if (!m_keys[key].sStartTrigger.empty())
  43. {
  44. description = m_keys[key].sStartTrigger.c_str();
  45. }
  46. }
  47. //////////////////////////////////////////////////////////////////////////
  48. static bool SoundTrackVersionConverter(
  49. AZ::SerializeContext& serializeContext,
  50. AZ::SerializeContext::DataElementNode& rootElement)
  51. {
  52. if (rootElement.GetVersion() < 3)
  53. {
  54. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  55. }
  56. return true;
  57. }
  58. template<>
  59. inline void TAnimTrack<ISoundKey>::Reflect(AZ::ReflectContext* context)
  60. {
  61. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  62. {
  63. serializeContext->Class<TAnimTrack<ISoundKey>, IAnimTrack>()
  64. ->Version(3, &SoundTrackVersionConverter)
  65. ->Field("Flags", &TAnimTrack<ISoundKey>::m_flags)
  66. ->Field("Range", &TAnimTrack<ISoundKey>::m_timeRange)
  67. ->Field("ParamType", &TAnimTrack<ISoundKey>::m_nParamType)
  68. ->Field("Keys", &TAnimTrack<ISoundKey>::m_keys)
  69. ->Field("Id", &TAnimTrack<ISoundKey>::m_id);
  70. }
  71. }
  72. //////////////////////////////////////////////////////////////////////////
  73. void CSoundTrack::Reflect(AZ::ReflectContext* context)
  74. {
  75. TAnimTrack<ISoundKey>::Reflect(context);
  76. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  77. {
  78. serializeContext->Class<CSoundTrack, TAnimTrack<ISoundKey>>()
  79. ->Version(1);
  80. }
  81. }