playsoundaction.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. ** Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: playsoundaction.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the training library "playsoundaction" interface.
  10. **
  11. ** History:
  12. */
  13. #include "pch.h"
  14. #include "PlaySoundAction.h"
  15. namespace Training
  16. {
  17. //------------------------------------------------------------------------------
  18. // class methods
  19. //------------------------------------------------------------------------------
  20. /* void */ PlaySoundAction::PlaySoundAction (SoundID soundID) :
  21. m_soundID (soundID),
  22. m_soundInstance (0),
  23. m_bHasStarted (false)
  24. {
  25. }
  26. //------------------------------------------------------------------------------
  27. /* void */ PlaySoundAction::~PlaySoundAction (void)
  28. {
  29. m_soundInstance = 0;
  30. }
  31. //------------------------------------------------------------------------------
  32. void PlaySoundAction::Execute (void)
  33. {
  34. if (m_soundID != NA)
  35. {
  36. ThingSitePrivate* pThingSite = static_cast<ThingSitePrivate*> (trekClient.GetShip ()->GetThingSite());
  37. TRef<ISoundPositionSource> pSource = pThingSite ? pThingSite->GetSoundSource () : NULL;
  38. m_soundInstance = trekClient.StartSound (m_soundID, pSource);
  39. }
  40. m_bHasStarted = true;
  41. }
  42. //------------------------------------------------------------------------------
  43. void PlaySoundAction::Stop (void)
  44. {
  45. if ((m_soundID != NA) and m_bHasStarted and (m_soundInstance->IsPlaying () == S_OK))
  46. m_soundInstance->Stop (true);
  47. }
  48. //------------------------------------------------------------------------------
  49. bool PlaySoundAction::HasStarted (void) const
  50. {
  51. return (m_bHasStarted);
  52. }
  53. //------------------------------------------------------------------------------
  54. bool PlaySoundAction::HasStopped (void) const
  55. {
  56. if (m_soundID == NA)
  57. return true;
  58. return (m_soundInstance->IsPlaying () == S_OK) ? false : true;
  59. }
  60. //------------------------------------------------------------------------------
  61. }