MapAudioPlayer.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * MapAudioPlayer.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../mapView/IMapRendererObserver.h"
  12. #include "../../lib/filesystem/ResourcePath.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class ObjectInstanceID;
  15. class CArmedInstance;
  16. VCMI_LIB_NAMESPACE_END
  17. class MapAudioPlayer : public IMapObjectObserver
  18. {
  19. using MapObjectsList = std::vector<ObjectInstanceID>;
  20. boost::multi_array<MapObjectsList, 3> objects;
  21. const CArmedInstance * currentSelection = nullptr;
  22. bool playerMakingTurn = false;
  23. bool enemyMakingTurn = false;
  24. bool audioPlaying = true;
  25. void addObject(const CGObjectInstance * obj);
  26. void removeObject(const CGObjectInstance * obj);
  27. std::vector<AudioPath> getAmbientSounds(const int3 & tile);
  28. void updateAmbientSounds();
  29. void updateMusic();
  30. void update();
  31. protected:
  32. // IMapObjectObserver impl
  33. bool hasOngoingAnimations() override;
  34. void onObjectFadeIn(const CGObjectInstance * obj) override;
  35. void onObjectFadeOut(const CGObjectInstance * obj) override;
  36. void onObjectInstantAdd(const CGObjectInstance * obj) override;
  37. void onObjectInstantRemove(const CGObjectInstance * obj) override;
  38. void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  39. void onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  40. void onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  41. void onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  42. void onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override {}
  43. void onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override {}
  44. void onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override {}
  45. public:
  46. MapAudioPlayer();
  47. ~MapAudioPlayer() override;
  48. /// Called whenever current adventure map selection changes
  49. void onSelectionChanged(const CArmedInstance * newSelection);
  50. /// Called when local player starts his turn
  51. void onPlayerTurnStarted();
  52. /// Called when AI or non-local player start his turn
  53. void onEnemyTurnStarted();
  54. /// Called when local player ends his turn
  55. void onPlayerTurnEnded();
  56. /// Called when map audio should be paused, e.g. on combat or town scren access
  57. void onAudioPaused();
  58. /// Called when map audio should be resume, opposite to onPaused
  59. void onAudioResumed();
  60. };