/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace AZ { namespace AtomBridge { void AtomBridgeSystemComponent::Reflect(ReflectContext* context) { if (SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() ->Version(0) ; if (EditContext* ec = serialize->GetEditContext()) { ec->Class("AtomBridge", "[Description of functionality provided by this System Component]") ->ClassElement(Edit::ClassElements::EditorData, "") ->Attribute(Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b)) ->Attribute(Edit::Attributes::AutoExpand, true) ; } } } AtomBridgeSystemComponent::AtomBridgeSystemComponent() { } AtomBridgeSystemComponent::~AtomBridgeSystemComponent() { } void AtomBridgeSystemComponent::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("AtomBridgeService", 0xdb816a99)); } void AtomBridgeSystemComponent::GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("AtomBridgeService", 0xdb816a99)); } void AtomBridgeSystemComponent::GetRequiredServices(ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ::RHI::Factory::GetComponentService()); required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601)); required.push_back(AZ_CRC("RPISystem", 0xf2add773)); required.push_back(AZ_CRC("BootstrapSystemComponent", 0xb8f32711)); } void AtomBridgeSystemComponent::GetDependentServices(ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } void AtomBridgeSystemComponent::Init() { AZ::RPI::ViewportContextManagerNotificationsBus::Handler::BusConnect(); } void AtomBridgeSystemComponent::Activate() { AzFramework::Render::RenderSystemRequestBus::Handler::BusConnect(); AtomBridgeRequestBus::Handler::BusConnect(); AzFramework::Components::DeprecatedComponentsRequestBus::Handler::BusConnect(); AzFramework::GameEntityContextRequestBus::BroadcastResult(m_entityContextId, &AzFramework::GameEntityContextRequestBus::Events::GetGameEntityContextId); AZ::Render::Bootstrap::NotificationBus::Handler::BusConnect(); m_dynamicDrawManager = AZStd::make_unique(); } void AtomBridgeSystemComponent::Deactivate() { m_dynamicDrawManager.reset(); AZ::RPI::ViewportContextManagerNotificationsBus::Handler::BusDisconnect(); RPI::Scene* scene = AZ::RPI::Scene::GetSceneForEntityContextId(m_entityContextId); // Check if scene is emptry since scene might be released already when running AtomSampleViewer if (scene) { auto auxGeomFP = scene->GetFeatureProcessor(); if (auxGeomFP) { auxGeomFP->ReleaseDrawQueueForView(m_view.get()); } } // Don't want to leave this until our destructor because the AZ::Data::InstanceDatabase may not be valid at that point m_view = nullptr; AZ::Render::Bootstrap::NotificationBus::Handler::BusDisconnect(); AzFramework::Components::DeprecatedComponentsRequestBus::Handler::BusDisconnect(); AtomBridgeRequestBus::Handler::BusDisconnect(); AzFramework::Render::RenderSystemRequestBus::Handler::BusDisconnect(); } AZStd::string AtomBridgeSystemComponent::GetRendererName() const { return "Other"; } void AtomBridgeSystemComponent::EnumerateDeprecatedComponents(AzFramework::Components::DeprecatedComponentsList& list) const { static const AZ::Uuid legacyRenderComponentUuids[] = { AZ::Uuid("{FC315B86-3280-4D03-B4F0-5553D7D08432}"), // EditorMeshComponent }; const AZStd::string deprecatedString = " (DEPRECATED By Atom)"; for (const AZ::Uuid& componentUuid : legacyRenderComponentUuids) { auto deprecatedEntry = list.find(componentUuid); if (deprecatedEntry == list.end()) { list[componentUuid] = AzFramework::Components::DeprecatedInfo{ true, deprecatedString }; } else { deprecatedEntry->second.m_hideComponent = true; deprecatedEntry->second.m_deprecationString += deprecatedString; } } } void AtomBridgeSystemComponent::OnBootstrapSceneReady(AZ::RPI::Scene* bootstrapScene) { // Make default AtomDebugDisplayViewportInterface AZStd::shared_ptr mainEntityDebugDisplay = AZStd::make_shared(AzFramework::g_defaultSceneEntityDebugDisplayId, bootstrapScene); m_activeViewportsList[AzFramework::g_defaultSceneEntityDebugDisplayId] = mainEntityDebugDisplay; } void AtomBridgeSystemComponent::OnViewportContextAdded(AZ::RPI::ViewportContextPtr viewportContext) { AZStd::shared_ptr viewportDebugDisplay = AZStd::make_shared(viewportContext); m_activeViewportsList[viewportContext->GetId()] = viewportDebugDisplay; } void AtomBridgeSystemComponent::OnViewportContextRemoved(AzFramework::ViewportId viewportId) { AZ_Assert(viewportId != AzFramework::g_defaultSceneEntityDebugDisplayId, "Error trying to remove the default scene draw instance"); m_activeViewportsList.erase(viewportId); } } // namespace AtomBridge } // namespace AZ