/* * 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 #include #include #include #include namespace Blast { //! Blast family implementation that listens to events from the TkFamily and manages BlastActors for a destructible //! object. class BlastFamilyImpl : public BlastFamily , public Nv::Blast::TkEventListener { public: AZ_CLASS_ALLOCATOR(BlastFamilyImpl, AZ::SystemAllocator, 0); //! Constructor for the BlastPxFamily //! @param desc Creation descriptor for the family based on the Blast library's ExtPxFamily. BlastFamilyImpl(const BlastFamilyDesc& desc); ~BlastFamilyImpl(); // BlastFamily interface bool Spawn(const AZ::Transform& transform) override; void Despawn() override; void HandleEvents(const Nv::Blast::TkEvent* events, uint32_t eventCount) override; void DestroyActor(BlastActor* blastActor) override; ActorTracker& GetActorTracker() override; const Nv::Blast::TkFamily* GetTkFamily() const override; Nv::Blast::TkFamily* GetTkFamily() override; const Nv::Blast::ExtPxAsset& GetPxAsset() const override; const BlastActorConfiguration& GetActorConfiguration() const override; void FillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, float renderScale) override; //! TkEventListener interface. void receive(const Nv::Blast::TkEvent* events, uint32_t eventCount) override; private: void CreateActors(const AZStd::vector& tkActors); void DestroyActors(const AZStd::unordered_set& actors); void DispatchActorCreated(const BlastActor& actor); void DispatchActorDestroyed(const BlastActor& actor); AZStd::vector CalculateInitialActors(const AZ::Transform& transform); void HandleSplitEvent( const Nv::Blast::TkSplitEvent* splitEvent, AZStd::vector& newActors, AZStd::unordered_set& actorsToDelete); // Calculates actor description for an actor that has a parent. BlastActorDesc CalculateActorDesc( Physics::WorldBody* parentBody, bool parentStatic, AZ::Transform parentTransform, Nv::Blast::TkActor* tkActor); // Calculates actor description for an actor that does not have a parent. BlastActorDesc CalculateActorDesc(const AZ::Transform& transform, Nv::Blast::TkActor* tkActor); void FillDebugRenderHealthGraph( DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, Nv::Blast::TkActor& actor); void FillDebugRenderAccelerator(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode); const BlastAsset& m_asset; ActorTracker m_actorTracker; physx::unique_ptr m_tkFamily; AZStd::shared_ptr m_actorFactory; AZStd::shared_ptr m_entityProvider; BlastListener* m_listener; const Physics::MaterialId m_physicsMaterialId; const BlastMaterial m_blastMaterial; const BlastActorConfiguration& m_actorConfiguration; AZ::Transform m_initialTransform; bool m_isSpawned; }; } // namespace Blast