Files
o3de/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.h
T
AMZN-koppersr 5e4094b258 Revamped AzFramework::Scene (#332)
Updated AzFramework::Scene to allow it to serve as the one-stop location for localized singletons. Localized singletons in this case are instance that can only occur once in an environment but multiple times within an application. As an example, this allows settings up a single camera per viewport for instance.

Highlights of changes:

Replaced the original ebuses with interfaces and events for easy of use and performance.
Removed the Entity Context specific code and moved that to new locations within the Entity Context itself.
Allowed basic inheritance. If a subsystem isn't found in a scene the parent can optionally be searched.
Scenes can enter a zombie state and avoid immediately being deleted. This is needed for situations where subsystems can't be destroyed until async calls have been completed.
2021-04-29 08:50:48 -07:00

135 lines
5.8 KiB
C++

/*
* 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 <AzCore/Component/Component.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzCore/Component/TickBus.h>
#include <AzFramework/Asset/AssetCatalogBus.h>
#include <AzFramework/Scene/Scene.h>
#include <AzFramework/Scene/SceneSystemInterface.h>
#include <AzFramework/Windowing/NativeWindow.h>
#include <AzFramework/Windowing/WindowBus.h>
#include <AtomCore/Instance/Instance.h>
#include <Atom/RPI.Public/Base.h>
#include <Atom/RPI.Public/Scene.h>
#include <Atom/RPI.Public/ViewportContext.h>
#include <Atom/RPI.Public/WindowContext.h>
#include <Atom/RPI.Public/Image/AttachmentImage.h>
#include <Atom/RPI.Public/Pass/Specific/SwapChainPass.h>
#include <Atom/Bootstrap/DefaultWindowBus.h>
#include <Atom/Bootstrap/BootstrapRequestBus.h>
namespace AZ
{
namespace Render
{
namespace Bootstrap
{
class BootstrapSystemComponent
: public Component
, public TickBus::Handler
, public AzFramework::WindowNotificationBus::Handler
, public AzFramework::AssetCatalogEventBus::Handler
, public AzFramework::WindowSystemNotificationBus::Handler
, public AzFramework::WindowSystemRequestBus::Handler
, public Render::Bootstrap::DefaultWindowBus::Handler
, public Render::Bootstrap::RequestBus::Handler
{
public:
AZ_COMPONENT(BootstrapSystemComponent, "{1EAFD87D-A64A-4612-93D8-B3AFFA70F09B}");
BootstrapSystemComponent();
~BootstrapSystemComponent() override;
static void Reflect(ReflectContext* context);
static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible);
static void GetRequiredServices(ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(ComponentDescriptor::DependencyArrayType& required);
// AzFramework::WindowSystemRequestBus::Handler overrides ...
AzFramework::NativeWindowHandle GetDefaultWindowHandle() override;
// Render::Bootstrap::DefaultWindowBus::Handler overrides ...
AZStd::shared_ptr<RPI::WindowContext> GetDefaultWindowContext() override;
void SetCreateDefaultScene(bool create) override;
// Render::Bootstrap::RequestBus::Handler overrides ...
AZ::RPI::ScenePtr GetOrCreateAtomSceneFromAzScene(AzFramework::Scene* scene) override;
bool EnsureDefaultRenderPipelineInstalledForScene(AZ::RPI::ScenePtr scene, AZ::RPI::ViewportContextPtr viewportContext) override;
protected:
// Component overrides ...
void Activate() override;
void Deactivate() override;
// WindowNotificationBus::Handler overrides ...
void OnWindowClosed() override;
// TickBus::Handler overrides ...
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
int GetTickOrder() override;
// AzFramework::AssetCatalogEventBus::Handler overrides ...
void OnCatalogLoaded(const char* catalogFile) override;
// AzFramework::WindowSystemNotificationBus::Handler overrides ...
void OnWindowCreated(AzFramework::NativeWindowHandle windowHandle) override;
private:
void CreateDefaultRenderPipeline();
void CreateDefaultScene();
void DestroyDefaultScene();
void RemoveRenderPipeline();
void CreateWindowContext();
AzFramework::Scene::RemovalEvent::Handler m_sceneRemovalHandler;
AZStd::unique_ptr<AzFramework::NativeWindow> m_nativeWindow;
AzFramework::NativeWindowHandle m_windowHandle = nullptr;
RPI::ViewportContextPtr m_viewportContext;
RPI::ScenePtr m_defaultScene = nullptr;
AZStd::shared_ptr<AzFramework::Scene> m_defaultFrameworkScene = nullptr;
float m_simulateTime = 0;
float m_deltaTime = 0.016f;
bool m_isAssetCatalogLoaded = false;
// The id of the render pipeline created by this component
RPI::RenderPipelineId m_renderPipelineId;
// Variables which are system component configuration
AZStd::string m_defaultPipelineAssetPath = "passes/MainRenderPipeline.azasset";
// Save a reference to the image created by the BRDF pipeline so it doesn't get auto deleted if it's ref count goes to zero
// For example, if we delete all the passes, we won't have to recreate the BRDF pipeline to recreate the BRDF texture
Data::Instance<RPI::AttachmentImage> m_brdfTexture;
bool m_createDefaultScene = true;
// Maps AZ scenes to RPI scene weak pointers to allow looking up a ScenePtr instead of a raw Scene*
AZStd::unordered_map<AzFramework::Scene*, AZStd::weak_ptr<AZ::RPI::Scene>> m_azSceneToAtomSceneMap;
};
} // namespace Bootstrap
} // namespace Render
} // namespace AZ