MapAudioPlayer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. VCMI_LIB_NAMESPACE_BEGIN
  13. class ObjectInstanceID;
  14. class CArmedInstance;
  15. VCMI_LIB_NAMESPACE_END
  16. class MapAudioPlayer : public IMapObjectObserver
  17. {
  18. using MapObjectsList = std::vector<ObjectInstanceID>;
  19. boost::multi_array<MapObjectsList, 3> objects;
  20. const CArmedInstance * currentSelection = nullptr;
  21. bool playerMakingTurn = false;
  22. bool enemyMakingTurn = false;
  23. bool audioPlaying = true;
  24. void addObject(const CGObjectInstance * obj);
  25. void removeObject(const CGObjectInstance * obj);
  26. std::vector<std::string> getAmbientSounds(const int3 & tile);
  27. void updateAmbientSounds();
  28. void updateMusic();
  29. void update();
  30. protected:
  31. // IMapObjectObserver impl
  32. bool hasOngoingAnimations() override;
  33. void onObjectFadeIn(const CGObjectInstance * obj) override;
  34. void onObjectFadeOut(const CGObjectInstance * obj) override;
  35. void onObjectInstantAdd(const CGObjectInstance * obj) override;
  36. void onObjectInstantRemove(const CGObjectInstance * obj) override;
  37. void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  38. void onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  39. void onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  40. void onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  41. void onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override {}
  42. void onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override {}
  43. void onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override {}
  44. public:
  45. MapAudioPlayer();
  46. ~MapAudioPlayer() override;
  47. /// Called whenever current adventure map selection changes
  48. void onSelectionChanged(const CArmedInstance * newSelection);
  49. /// Called when local player starts his turn
  50. void onPlayerTurnStarted();
  51. /// Called when AI or non-local player start his turn
  52. void onEnemyTurnStarted();
  53. /// Called when local player ends his turn
  54. void onPlayerTurnEnded();
  55. /// Called when map audio should be paused, e.g. on combat or town scren access
  56. void onAudioPaused();
  57. /// Called when map audio should be resume, opposite to onPaused
  58. void onAudioResumed();
  59. };