AudioSystemGemSystemComponent.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzFramework/API/ApplicationAPI.h>
  11. #include <IAudioSystem.h>
  12. #if defined(AUDIO_SYSTEM_EDITOR)
  13. #include <AzCore/std/smart_ptr/unique_ptr.h>
  14. #include <Include/IPlugin.h>
  15. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  16. #include <Atom/RPI.Public/ViewportContextBus.h>
  17. #endif // AUDIO_SYSTEM_EDITOR
  18. namespace AudioSystemGem
  19. {
  20. class AudioSystemGemSystemComponent
  21. : public AZ::Component
  22. , protected AzFramework::LevelSystemLifecycleNotificationBus::Handler
  23. , protected AzFramework::ApplicationLifecycleEvents::Bus::Handler
  24. , protected Audio::Gem::SystemRequestBus::Handler
  25. #if defined(AUDIO_SYSTEM_EDITOR)
  26. , private AzToolsFramework::EditorEvents::Bus::Handler
  27. , public AZ::RPI::ViewportContextNotificationBus::Handler
  28. #endif // AUDIO_SYSTEM_EDITOR
  29. {
  30. public:
  31. AZ_COMPONENT(AudioSystemGemSystemComponent, "{55095EE9-38E6-485F-8314-DF35CDFECC6B}", AZ::Component);
  32. static void Reflect(AZ::ReflectContext* context);
  33. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  34. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  35. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  36. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  37. AudioSystemGemSystemComponent();
  38. ~AudioSystemGemSystemComponent() override;
  39. protected:
  40. ////////////////////////////////////////////////////////////////////////
  41. // AZ::Component interface implementation
  42. void Init() override;
  43. void Activate() override;
  44. void Deactivate() override;
  45. ////////////////////////////////////////////////////////////////////////
  46. ////////////////////////////////////////////////////////////////////////
  47. // Audio::Gem::SystemRequestBus interface implementation
  48. bool Initialize() override;
  49. void Release() override;
  50. ////////////////////////////////////////////////////////////////////////
  51. ////////////////////////////////////////////////////////////////////////
  52. // AzFramework::LevelSystemLifecycleNotifications interface implementation
  53. void OnLoadingStart(const char* levelName) override;
  54. void OnUnloadComplete(const char* levelName) override;
  55. ////////////////////////////////////////////////////////////////////////
  56. ////////////////////////////////////////////////////////////////////////
  57. // AzFramework::ApplicationLifecycleEvents interface implementation
  58. void OnApplicationConstrained(Event /*lastEvent*/) override;
  59. void OnApplicationUnconstrained(Event /*lastEvent*/) override;
  60. ////////////////////////////////////////////////////////////////////////
  61. #if defined(AUDIO_SYSTEM_EDITOR)
  62. ////////////////////////////////////////////////////////////////////////
  63. // AzToolsFramework::EditorEvents::Bus interface implementation
  64. void NotifyRegisterViews() override;
  65. void NotifyIEditorAvailable(IEditor*) override;
  66. ////////////////////////////////////////////////////////////////////////
  67. ////////////////////////////////////////////////////////////////////////
  68. // AZ::RPI::ViewportContextNotificationBus::Handler interface implementation
  69. void OnViewportDefaultViewChanged(AZ::RPI::ViewPtr view) override;
  70. ////////////////////////////////////////////////////////////////////////
  71. #endif // AUDIO_SYSTEM_EDITOR
  72. private:
  73. ////////////////////////////////////////////////////////////////////////
  74. void CreateAudioSystem();
  75. void PrepareAudioSystem();
  76. /// This is here to express ownership
  77. AZStd::unique_ptr<Audio::IAudioSystem> m_audioSystem;
  78. #if defined(AUDIO_SYSTEM_EDITOR)
  79. AZStd::unique_ptr<IPlugin> m_editorPlugin;
  80. AZ::RPI::MatrixChangedEvent::Handler m_cameraTransformHandler;
  81. #endif // AUDIO_SYSTEM_EDITOR
  82. };
  83. } // namespace AudioSystemGem