MapAudioPlayer.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. public:
  42. MapAudioPlayer();
  43. ~MapAudioPlayer() override;
  44. /// Called whenever current adventure map selection changes
  45. void onSelectionChanged(const CArmedInstance * newSelection);
  46. /// Called when local player starts his turn
  47. void onPlayerTurnStarted();
  48. /// Called when AI or non-local player start his turn
  49. void onEnemyTurnStarted();
  50. /// Called when local player ends his turn
  51. void onPlayerTurnEnded();
  52. /// Called when map audio should be paused, e.g. on combat or town scren access
  53. void onAudioPaused();
  54. /// Called when map audio should be resume, opposite to onPaused
  55. void onAudioResumed();
  56. };