audio_event_handler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include "../core/event_manager.h"
  3. #include <chrono>
  4. #include <memory>
  5. #include <string>
  6. #include <unordered_map>
  7. class AudioSystem;
  8. namespace Engine::Core {
  9. class World;
  10. }
  11. namespace Game::Audio {
  12. class AudioEventHandler {
  13. public:
  14. static constexpr float UNIT_SELECTION_VOLUME = 1.0F;
  15. static constexpr int UNIT_SELECTION_PRIORITY = 5;
  16. static constexpr float COMBAT_HIT_VOLUME = 0.6F;
  17. static constexpr int COMBAT_HIT_PRIORITY = 3;
  18. AudioEventHandler(Engine::Core::World *world);
  19. ~AudioEventHandler();
  20. auto initialize() -> bool;
  21. void shutdown();
  22. void loadUnitVoiceMapping(const std::string &unit_type,
  23. const std::string &sound_id);
  24. void loadAmbientMusic(Engine::Core::AmbientState state,
  25. const std::string &music_id);
  26. void setVoiceSoundCategory(bool useVoiceCategory);
  27. private:
  28. void onUnitSelected(const Engine::Core::UnitSelectedEvent &event);
  29. void
  30. onAmbientStateChanged(const Engine::Core::AmbientStateChangedEvent &event);
  31. static void onAudioTrigger(const Engine::Core::AudioTriggerEvent &event);
  32. static void onMusicTrigger(const Engine::Core::MusicTriggerEvent &event);
  33. static void onCombatHit(const Engine::Core::CombatHitEvent &event);
  34. Engine::Core::World *m_world;
  35. std::unordered_map<std::string, std::string> m_unitVoiceMap;
  36. std::unordered_map<Engine::Core::AmbientState, std::string> m_ambientMusicMap;
  37. bool m_useVoiceCategory{true};
  38. std::chrono::steady_clock::time_point m_lastSelectionSoundTime;
  39. std::string m_lastSelectionUnitType;
  40. static constexpr int SELECTION_SOUND_COOLDOWN_MS = 300;
  41. Engine::Core::ScopedEventSubscription<Engine::Core::UnitSelectedEvent>
  42. m_unitSelectedSub;
  43. Engine::Core::ScopedEventSubscription<Engine::Core::AmbientStateChangedEvent>
  44. m_ambientChangedSub;
  45. Engine::Core::ScopedEventSubscription<Engine::Core::AudioTriggerEvent>
  46. m_audioTriggerSub;
  47. Engine::Core::ScopedEventSubscription<Engine::Core::MusicTriggerEvent>
  48. m_musicTriggerSub;
  49. Engine::Core::ScopedEventSubscription<Engine::Core::CombatHitEvent>
  50. m_combatHitSub;
  51. bool m_initialized{false};
  52. };
  53. } // namespace Game::Audio