AudioComponent.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. //========================================================================
  3. // AudioComponent.cpp : A component for attaching sounds to an actor
  4. //
  5. // Part of the GameCode4 Application
  6. //
  7. // GameCode4 is the sample application that encapsulates much of the source code
  8. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  9. // "Rez" Graham, published by Charles River Media.
  10. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  11. //
  12. // If this source code has found it's way to you, and you think it has helped you
  13. // in any way, do the authors a favor and buy a new copy of the book - there are
  14. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  15. // by clicking here:
  16. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  17. //
  18. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  19. //
  20. // The source code is managed and maintained through Google Code:
  21. // http://code.google.com/p/gamecode4/
  22. //
  23. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  24. //
  25. // This program is free software; you can redistribute it and/or
  26. // modify it under the terms of the GNU Lesser GPL v3
  27. // as published by the Free Software Foundation.
  28. //
  29. // This program is distributed in the hope that it will be useful,
  30. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  32. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  33. //
  34. // You should have received a copy of the GNU Lesser GPL v3
  35. // along with this program; if not, write to the Free Software
  36. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  37. //
  38. //========================================================================
  39. #include "../Unix/GameCodeStd.h"
  40. #include "AudioComponent.h"
  41. #include "../Utilities/String.h"
  42. // #include "../Audio/SoundProcess.h"
  43. // #include "../MainLoop/ProcessManager.h"
  44. #include "../UserInterface/HumanView.h"
  45. const char* AudioComponent::g_Name = "AudioComponent";
  46. AudioComponent::AudioComponent()
  47. {
  48. m_audioResource = "";
  49. m_looping = false;
  50. m_fadeInTime = 0.0f;
  51. m_volume = 100;
  52. }
  53. bool AudioComponent::VInit(TiXmlElement* pData)
  54. {
  55. TiXmlElement* pTexture = pData->FirstChildElement("Sound");
  56. if (pTexture)
  57. {
  58. m_audioResource = pTexture->FirstChild()->Value();
  59. }
  60. TiXmlElement* pLooping = pData->FirstChildElement("Looping");
  61. if (pLooping)
  62. {
  63. std::string value = pLooping->FirstChild()->Value();
  64. m_looping = (value == "0") ? false : true;
  65. }
  66. TiXmlElement* pFadeIn = pData->FirstChildElement("FadeIn");
  67. if (pFadeIn)
  68. {
  69. std::string value = pFadeIn->FirstChild()->Value();
  70. m_fadeInTime = (float)atof(value.c_str());
  71. }
  72. TiXmlElement* pVolume = pData->FirstChildElement("Volume");
  73. if (pVolume)
  74. {
  75. std::string value = pVolume->FirstChild()->Value();
  76. m_volume = atoi(value.c_str());
  77. }
  78. return true;
  79. }
  80. TiXmlElement* AudioComponent::VGenerateXml(void)
  81. {
  82. TiXmlElement* pBaseElement = GCC_NEW TiXmlElement(VGetName());
  83. TiXmlElement* pSoundNode = GCC_NEW TiXmlElement("Sound");
  84. TiXmlText* pSoundText = GCC_NEW TiXmlText(m_audioResource.c_str());
  85. pSoundNode->LinkEndChild(pSoundText);
  86. pBaseElement->LinkEndChild(pSoundNode);
  87. TiXmlElement* pLoopingNode = GCC_NEW TiXmlElement("Looping");
  88. TiXmlText* pLoopingText = GCC_NEW TiXmlText(m_looping ? "1" : "0" );
  89. pLoopingNode->LinkEndChild(pLoopingText);
  90. pBaseElement->LinkEndChild(pLoopingNode);
  91. TiXmlElement* pFadeInNode = GCC_NEW TiXmlElement("FadeIn");
  92. TiXmlText* pFadeInText = GCC_NEW TiXmlText( ToStr(m_fadeInTime).c_str());
  93. pFadeInNode->LinkEndChild(pFadeInText);
  94. pBaseElement->LinkEndChild(pFadeInNode);
  95. TiXmlElement* pVolumeNode = GCC_NEW TiXmlElement("Volume");
  96. TiXmlText* pVolumeText = GCC_NEW TiXmlText( ToStr(m_volume).c_str());
  97. pVolumeNode->LinkEndChild(pVolumeText);
  98. pBaseElement->LinkEndChild(pVolumeNode);
  99. return pBaseElement;
  100. }
  101. void AudioComponent::VPostInit()
  102. {
  103. // TODO(munnellg) - implement
  104. }