/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include #include namespace LmbrCentral { /*! * Audio Multi-Position Component * Used to simulate "area" sounds and consume less resources. * Example: A river sound can be created by placing a bunch of entities along the river * and adding them to this component. The positions of those entities will be sent to * audio system and treated as one sound. * Example: A hallway lined with torches. The torches are individual sources, but they * can all use the same resources via this component. * * Note: This component doesn't yet support full orientation of the entities, only position. * Note: This component doesn't yet support tracking movement of the entities. */ class AudioMultiPositionComponent : public AZ::Component , public AudioMultiPositionComponentRequestBus::Handler , private AZ::EntityBus::MultiHandler { public: //! AZ::Component interface AZ_COMPONENT(AudioMultiPositionComponent, "{CF3B3C77-746C-4EB0-83C6-FE4AAA4203B0}"); void Activate() override; void Deactivate() override; AudioMultiPositionComponent() = default; AudioMultiPositionComponent(const AZStd::vector& entities, Audio::MultiPositionBehaviorType type); //! AudioMultiPositionComponentRequestBus interface void AddEntity(const AZ::EntityId& entityId) override; void RemoveEntity(const AZ::EntityId& entityId) override; void SetBehaviorType(Audio::MultiPositionBehaviorType type) override; //! AZ::EntityBus interface void OnEntityActivated(const AZ::EntityId& entityId) override; void OnEntityDeactivated(const AZ::EntityId& entityId) override; static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { dependent.push_back(AZ_CRC("AudioTriggerService", 0xeba17b52)); } static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("AudioMultiPositionService", 0x2cc67a6e)); } static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC("AudioTriggerService", 0xeba17b52)); } static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("AudioMultiPositionService", 0x2cc67a6e)); } static void Reflect(AZ::ReflectContext* context); #if defined(AZ_TESTS_ENABLED) AZStd::size_t GetNumEntityRefs() const { return m_entityRefs.size(); } AZStd::size_t GetNumEntityPositions() const { return m_entityPositions.size(); } #endif // AZ_TESTS_ENABLED protected: //! Send the positions to the audio system. void SendMultiplePositions(); private: //! Serialized Data AZStd::vector m_entityRefs; Audio::MultiPositionBehaviorType m_behaviorType; //! Transient Data using EntityPosPair = AZStd::pair; AZStd::vector m_entityPositions; }; } // namespace LmbrCentral