MapAudioPlayer.h 2.7 KB

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