123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /*
- * 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
- *
- */
- #if !defined(AZ_MONOLITHIC_BUILD)
- #include <AzCore/Component/Component.h>
- #include <AzCore/Component/ComponentApplicationBus.h>
- #include <AzCore/EBus/EBus.h>
- #include <AzCore/Module/Environment.h>
- #include <AzCore/Serialization/SerializeContext.h>
- #include <SceneAPI/SceneData/ManifestMetaInfoHandler.h>
- #include <SceneAPI/SceneData/ReflectionRegistrar.h>
- #include <SceneAPI/SceneData/Behaviors/Registry.h>
- namespace AZ {
- namespace SceneAPI {
- namespace SceneData {
- static AZ::SceneAPI::SceneData::ManifestMetaInfoHandler* g_manifestMetaInfoHandler = nullptr;
- static AZ::SceneAPI::SceneData::Registry::ComponentDescriptorList g_componentDescriptors;
- static AZ::BehaviorContext* g_behaviorContext = nullptr;
- void Initialize()
- {
- if (!g_manifestMetaInfoHandler)
- {
- g_manifestMetaInfoHandler = aznew AZ::SceneAPI::SceneData::ManifestMetaInfoHandler();
- }
- }
- void Reflect(AZ::SerializeContext* context)
- {
- if (!context)
- {
- EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext);
- }
- if (context)
- {
- AZ::SceneAPI::RegisterDataTypeReflection(context);
- }
- // Descriptor registration is done in Reflect instead of Initialize because the ResourceCompilerScene initializes the libraries before
- // there's an application.
- if (g_componentDescriptors.empty())
- {
- AZ::SceneAPI::SceneData::Registry::RegisterComponents(g_componentDescriptors);
- for (AZ::ComponentDescriptor* descriptor : g_componentDescriptors)
- {
- AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Handler::RegisterComponentDescriptor, descriptor);
- }
- }
- }
- void ReflectBehavior(AZ::BehaviorContext* context)
- {
- if (!g_behaviorContext)
- {
- // Reflect instead of Initialize because ResourceCompilerScene initializes the libraries before there's an application
- if (context)
- {
- g_behaviorContext = context;
- AZ::SceneAPI::RegisterDataTypeBehaviorReflection(g_behaviorContext);
- }
- }
- }
- void Activate()
- {
- }
-
- void Deactivate()
- {
- }
- void Uninitialize()
- {
- AZ::SerializeContext* context = nullptr;
- EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext);
- if (context)
- {
- context->EnableRemoveReflection();
- Reflect(context);
- context->DisableRemoveReflection();
- context->CleanupModuleGenericClassInfo();
- }
- if (!g_componentDescriptors.empty())
- {
- for (AZ::ComponentDescriptor* descriptor : g_componentDescriptors)
- {
- descriptor->ReleaseDescriptor();
- }
- g_componentDescriptors.clear();
- g_componentDescriptors.shrink_to_fit();
- }
- delete g_manifestMetaInfoHandler;
- g_manifestMetaInfoHandler = nullptr;
- }
- } // namespace SceneData
- } // namespace SceneAPI
- } // namespace AZ
- static bool g_sceneDataInitialized = false;
- extern "C" AZ_DLL_EXPORT void InitializeDynamicModule()
- {
- if (g_sceneDataInitialized)
- {
- return;
- }
- g_sceneDataInitialized = true;
- AZ::SceneAPI::SceneData::Initialize();
- }
- extern "C" AZ_DLL_EXPORT void Reflect(AZ::SerializeContext* context)
- {
- AZ::SceneAPI::SceneData::Reflect(context);
- }
- extern "C" AZ_DLL_EXPORT void ReflectBehavior(AZ::BehaviorContext * context)
- {
- AZ::SceneAPI::SceneData::ReflectBehavior(context);
- }
- extern "C" AZ_DLL_EXPORT void CleanUpSceneDataGenericClassInfo()
- {
- AZ::GetCurrentSerializeContextModule().Cleanup();
- }
- extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
- {
- if (!g_sceneDataInitialized)
- {
- return;
- }
- g_sceneDataInitialized = false;
- AZ::SceneAPI::SceneData::Uninitialize();
- }
- #endif // !defined(AZ_MONOLITHIC_BUILD)
|