/* * 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 namespace NvCloth { //! Implementation of the IClothSystem interface. //! //! This class has the responsibility to initialize and tear down NvCloth library. //! It owns all Solvers, Cloths and Fabrics, and it manages their creation and destruction. //! It's also the responsible for updating (on Physics Tick) all the solvers that are not flagged as "user simulated". class SystemComponent : public AZ::Component , public CrySystemEventBus::Handler , protected IClothSystem , protected AZ::TickBus::Handler { public: AZ_COMPONENT(SystemComponent, "{89DF5C48-64AC-4B8E-9E61-0D4C7A7B5491}"); 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); static void InitializeNvClothLibrary(); static void TearDownNvClothLibrary(); //! Returns true when there is no error reported. static bool CheckLastClothError(); //! Resets the last error reported by NvCloth. static void ResetLastClothError(); protected: // AZ::Component overrides ... void Activate() override; void Deactivate() override; // CrySystemEventBus::Handler overrides ... void OnCrySystemInitialized(ISystem& system, const SSystemInitParams& systemInitParams) override; void OnCrySystemShutdown(ISystem& system) override; // IClothSystem overrides ... ISolver* FindOrCreateSolver(const AZStd::string& name) override; void DestroySolver(ISolver*& solver) override; ISolver* GetSolver(const AZStd::string& name) override; ICloth* CreateCloth( const AZStd::vector& initialParticles, const FabricCookedData& fabricCookedData) override; void DestroyCloth(ICloth*& cloth) override; ICloth* GetCloth(ClothId clothId) override; bool AddCloth(ICloth* cloth, const AZStd::string& solverName = DefaultSolverName) override; void RemoveCloth(ICloth* cloth) override; // AZ::TickBus::Handler overrides ... void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; int GetTickOrder() override; private: void InitializeSystem(); void DestroySystem(); FabricId FindOrCreateFabric(const FabricCookedData& fabricCookedData); void DestroyFabric(FabricId fabricId); // Factory that creates all the solvers, fabric and cloths. AZStd::unique_ptr m_factory; // List of all the solvers created. AZStd::vector> m_solvers; // List of all the fabrics created. AZStd::unordered_map> m_fabrics; // List of all the cloths created. AZStd::unordered_map> m_cloths; }; } // namespace NvCloth