/* * 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. * */ #include #include // must be included once per DLL so things from CryCommon will function #include #include #include #include #include #if defined(PHYSX_EDITOR) #include #include #include #include #include #include #include #include #include #include #include #include #include #endif // defined(PHYSX_EDITOR) #include namespace PhysX { class Module : public AZ::Module { public: AZ_RTTI(PhysX::Module, "{160C59B1-FA68-4CDC-8562-D1204AB78FC1}", AZ::Module); Module() { LoadModules(); SystemComponent::InitializePhysXSDK(); AZStd::list descriptorsToAdd = GetDescriptors(); m_descriptors.insert(m_descriptors.end(), descriptorsToAdd.begin(), descriptorsToAdd.end()); #if defined(PHYSX_EDITOR) m_descriptors.insert(m_descriptors.end(), { EditorSystemComponent::CreateDescriptor(), EditorTerrainComponent::CreateDescriptor(), EditorRigidBodyComponent::CreateDescriptor(), EditorColliderComponent::CreateDescriptor(), EditorShapeColliderComponent::CreateDescriptor(), EditorForceRegionComponent::CreateDescriptor(), EditorJointComponent::CreateDescriptor(), EditorBallJointComponent::CreateDescriptor(), EditorFixedJointComponent::CreateDescriptor(), EditorHingeJointComponent::CreateDescriptor(), Pipeline::MeshExporter::CreateDescriptor(), Pipeline::MeshBehavior::CreateDescriptor(), Pipeline::CgfMeshAssetBuilderComponent::CreateDescriptor() }); #endif // defined(PHYSX_EDITOR) } virtual ~Module() { SystemComponent::DestroyPhysXSDK(); UnloadModules(); } AZ::ComponentTypeList GetRequiredSystemComponents() const override { return AZ::ComponentTypeList{ azrtti_typeid() #if defined(PHYSX_EDITOR) , azrtti_typeid() #endif }; } private: void LoadModules() { #if defined(PHYSX_EDITOR) && !defined(SCENE_CORE_STATIC) { AZStd::unique_ptr sceneCoreModule = AZ::DynamicModuleHandle::Create("SceneCore"); bool ok = sceneCoreModule->Load(true/*isInitializeFunctionRequired*/); AZ_Error("PhysX::Module", ok, "Error loading SceneCore module"); m_modules.push_back(AZStd::move(sceneCoreModule)); } #endif // defined(PHYSX_EDITOR) // Load PhysX SDK dynamic libraries when running on a non-monolithic build. // The PhysX Gem module was linked with the PhysX SDK dynamic libraries, but // some platforms may not detect the dependency when the gem is loaded, so we // may have to load them ourselves. #if AZ_TRAIT_PHYSX_FORCE_LOAD_MODULES && !defined(AZ_MONOLITHIC_BUILD) { const AZStd::vector physXModuleNames = { "PhysX", "PhysXCooking", "PhysXFoundation", "PhysXCommon" }; for (const auto& physXModuleName : physXModuleNames) { AZ::OSString modulePathName = AZ_TRAIT_PHYSX_LIB_PATH(physXModuleName); AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::ResolveModulePath, modulePathName); AZStd::unique_ptr physXModule = AZ::DynamicModuleHandle::Create(modulePathName.c_str()); bool ok = physXModule->Load(false/*isInitializeFunctionRequired*/); AZ_Error("PhysX::Module", ok, "Error loading %s module", physXModuleName.c_str()); m_modules.push_back(AZStd::move(physXModule)); } } #endif } void UnloadModules() { // Unload modules in reserve order that were loaded for (auto it = m_modules.rbegin(); it != m_modules.rend(); ++it) { it->reset(); } m_modules.clear(); } /// Required modules to load/unload when PhysX Gem module is created/destroyed AZStd::vector> m_modules; }; } // namespace PhysX // DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM // The first parameter should be GemName_GemIdLower // The second should be the fully qualified name of the class above AZ_DECLARE_MODULE_CLASS(PhysX_4e08125824434932a0fe3717259caa47, PhysX::Module)