/* * 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 #include #include #include #include #include #include #include #include #include #include namespace PhysX { class PhysXCpuDispatcher; } namespace Blast { class BlastSystemComponent : public AZ::Component , BlastSystemRequestBus::Handler , public AZ::Interface::Registrar , public AZ::TickBus::Handler , private CrySystemEventBus::Handler , private AZ::Data::AssetBus::MultiHandler { public: AZ_COMPONENT(BlastSystemComponent, "{9705144A-FF10-45CE-AA3D-3E1F43872429}"); BlastSystemComponent() = default; BlastSystemComponent(const BlastSystemComponent&) = delete; BlastSystemComponent& operator=(const BlastSystemComponent&) = delete; static void Reflect(AZ::ReflectContext* context); static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); // AZ::Component interface implementation void Init() override; void Activate() override; void Deactivate() override; // AZTickBus interface implementation void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; // AZ::Data::AssetBus interface implementation void OnAssetReloaded(AZ::Data::Asset asset) override; // Blast configuration methods void LoadConfiguration(); void SaveConfiguration(); void CheckoutConfiguration(); // CrySystemEventBus interface implementation void OnCrySystemInitialized(ISystem&, const SSystemInitParams&) override; void OnCryEditorInitialized() override; // Getters for physx/NvBlast structures Nv::Blast::TkFramework* GetTkFramework() const override; Nv::Blast::ExtSerialization* GetExtSerialization() const override; Nv::Blast::TkGroup* GetTkGroup() override; void AddDamageDesc(AZStd::unique_ptr desc) override; void AddDamageDesc(AZStd::unique_ptr desc) override; void AddDamageDesc(AZStd::unique_ptr desc) override; void AddDamageDesc(AZStd::unique_ptr desc) override; void AddDamageDesc(AZStd::unique_ptr desc) override; void AddProgramParams(AZStd::unique_ptr program) override; const BlastGlobalConfiguration& GetGlobalConfiguration() const override; void SetGlobalConfiguration(const BlastGlobalConfiguration& materialLibrary) override; void SetDebugRenderMode(DebugRenderMode debugRenderMode) override; protected: void InitPhysics(); void DeactivatePhysics(); void RegisterCommands(); // Internal helper functions & classes class AZBlastAllocatorCallback : public Nv::Blast::AllocatorCallback { public: void* allocate( size_t size, const char* typeName, [[maybe_unused]] const char* filename, [[maybe_unused]] int line) override { return azmalloc_4(size, 0, AZ::SystemAllocator, typeName); } void deallocate(void* ptr) override { azfree(ptr); } }; class AZBlastProfilerCallback : public Nv::Blast::ProfilerCallback { public: void zoneStart(const char* eventName) override; void zoneEnd() override; }; struct BlastGroup { physx::unique_ptr m_tkGroup; physx::unique_ptr m_extGroupTaskManager; }; AZBlastAllocatorCallback m_blastAllocatorCallback; AZBlastProfilerCallback m_blastProfilerCallback; AZStd::vector m_groups; // Container for asset types that need to be registered AZStd::vector> m_assetHandlers; // Blast framework & physics singletons, in order of initialization physx::unique_ptr m_tkFramework; physx::unique_ptr m_extSerialization; physx::unique_ptr m_defaultTaskManager; PhysX::PhysXCpuDispatcher* m_dispatcher; // Library for blast materials and other global configurations BlastGlobalConfiguration m_configuration; // Storage for damage info that gets simulated. AZStd::vector> m_radialDamageDescs; AZStd::vector> m_capsuleDamageDescs; AZStd::vector> m_shearDamageDescs; AZStd::vector> m_triangleDamageDescs; AZStd::vector> m_impactDamageDescs; AZStd::vector> m_programParams; bool m_registered; DebugRenderMode m_debugRenderMode; }; } // namespace Blast