DllMain.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #if !defined(AZ_MONOLITHIC_BUILD)
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Component/ComponentApplicationBus.h>
  11. #include <AzCore/EBus/EBus.h>
  12. #include <AzCore/Module/Environment.h>
  13. #include <AzCore/Serialization/SerializeContext.h>
  14. #include <SceneAPI/SceneData/ManifestMetaInfoHandler.h>
  15. #include <SceneAPI/SceneData/ReflectionRegistrar.h>
  16. #include <SceneAPI/SceneData/Behaviors/Registry.h>
  17. namespace AZ {
  18. namespace SceneAPI {
  19. namespace SceneData {
  20. static AZ::SceneAPI::SceneData::ManifestMetaInfoHandler* g_manifestMetaInfoHandler = nullptr;
  21. static AZ::SceneAPI::SceneData::Registry::ComponentDescriptorList g_componentDescriptors;
  22. static AZ::BehaviorContext* g_behaviorContext = nullptr;
  23. void Initialize()
  24. {
  25. if (!g_manifestMetaInfoHandler)
  26. {
  27. g_manifestMetaInfoHandler = aznew AZ::SceneAPI::SceneData::ManifestMetaInfoHandler();
  28. }
  29. }
  30. void Reflect(AZ::SerializeContext* context)
  31. {
  32. if (!context)
  33. {
  34. EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext);
  35. }
  36. if (context)
  37. {
  38. AZ::SceneAPI::RegisterDataTypeReflection(context);
  39. }
  40. // Descriptor registration is done in Reflect instead of Initialize because the ResourceCompilerScene initializes the libraries before
  41. // there's an application.
  42. if (g_componentDescriptors.empty())
  43. {
  44. AZ::SceneAPI::SceneData::Registry::RegisterComponents(g_componentDescriptors);
  45. for (AZ::ComponentDescriptor* descriptor : g_componentDescriptors)
  46. {
  47. AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Handler::RegisterComponentDescriptor, descriptor);
  48. }
  49. }
  50. }
  51. void ReflectBehavior(AZ::BehaviorContext* context)
  52. {
  53. if (!g_behaviorContext)
  54. {
  55. // Reflect instead of Initialize because ResourceCompilerScene initializes the libraries before there's an application
  56. if (context)
  57. {
  58. g_behaviorContext = context;
  59. AZ::SceneAPI::RegisterDataTypeBehaviorReflection(g_behaviorContext);
  60. }
  61. }
  62. }
  63. void Activate()
  64. {
  65. }
  66. void Deactivate()
  67. {
  68. }
  69. void Uninitialize()
  70. {
  71. AZ::SerializeContext* context = nullptr;
  72. EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext);
  73. if (context)
  74. {
  75. context->EnableRemoveReflection();
  76. Reflect(context);
  77. context->DisableRemoveReflection();
  78. context->CleanupModuleGenericClassInfo();
  79. }
  80. if (!g_componentDescriptors.empty())
  81. {
  82. for (AZ::ComponentDescriptor* descriptor : g_componentDescriptors)
  83. {
  84. descriptor->ReleaseDescriptor();
  85. }
  86. g_componentDescriptors.clear();
  87. g_componentDescriptors.shrink_to_fit();
  88. }
  89. delete g_manifestMetaInfoHandler;
  90. g_manifestMetaInfoHandler = nullptr;
  91. }
  92. } // namespace SceneData
  93. } // namespace SceneAPI
  94. } // namespace AZ
  95. static bool g_sceneDataInitialized = false;
  96. extern "C" AZ_DLL_EXPORT void InitializeDynamicModule()
  97. {
  98. if (g_sceneDataInitialized)
  99. {
  100. return;
  101. }
  102. g_sceneDataInitialized = true;
  103. AZ::SceneAPI::SceneData::Initialize();
  104. }
  105. extern "C" AZ_DLL_EXPORT void Reflect(AZ::SerializeContext* context)
  106. {
  107. AZ::SceneAPI::SceneData::Reflect(context);
  108. }
  109. extern "C" AZ_DLL_EXPORT void ReflectBehavior(AZ::BehaviorContext * context)
  110. {
  111. AZ::SceneAPI::SceneData::ReflectBehavior(context);
  112. }
  113. extern "C" AZ_DLL_EXPORT void CleanUpSceneDataGenericClassInfo()
  114. {
  115. AZ::GetCurrentSerializeContextModule().Cleanup();
  116. }
  117. extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
  118. {
  119. if (!g_sceneDataInitialized)
  120. {
  121. return;
  122. }
  123. g_sceneDataInitialized = false;
  124. AZ::SceneAPI::SceneData::Uninitialize();
  125. }
  126. #endif // !defined(AZ_MONOLITHIC_BUILD)