AtlasBuilderComponent.cpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "AtlasBuilderComponent.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. namespace TextureAtlasBuilder
  11. {
  12. // AZ Components should only initialize their members to null and empty in constructor
  13. // Allocation of data should occur in Init(), once we can guarantee reflection and registration of types
  14. AtlasBuilderComponent::AtlasBuilderComponent()
  15. {
  16. }
  17. // Handle deallocation of your memory allocated in Init()
  18. AtlasBuilderComponent::~AtlasBuilderComponent()
  19. {
  20. }
  21. // Init is where you'll actually allocate memory or create objects
  22. // This ensures that any dependency components will have been been created and serialized
  23. void AtlasBuilderComponent::Init()
  24. {
  25. }
  26. // Activate is where you'd perform registration with other objects and systems.
  27. // All builder classes owned by this component should be registered here
  28. // Any EBuses for the builder classes should also be connected at this point
  29. void AtlasBuilderComponent::Activate()
  30. {
  31. AssetBuilderSDK::AssetBuilderDesc builderDescriptor;
  32. builderDescriptor.m_name = "Atlas Worker Builder";
  33. builderDescriptor.m_version = 1;
  34. builderDescriptor.m_patterns.emplace_back(AssetBuilderSDK::AssetBuilderPattern("*.texatlas", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
  35. builderDescriptor.m_busId = azrtti_typeid<AtlasBuilderWorker>();
  36. builderDescriptor.m_createJobFunction = AZStd::bind(&AtlasBuilderWorker::CreateJobs, &m_atlasBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2);
  37. builderDescriptor.m_processJobFunction = AZStd::bind(&AtlasBuilderWorker::ProcessJob, &m_atlasBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2);
  38. m_atlasBuilder.BusConnect(builderDescriptor.m_busId);
  39. AssetBuilderSDK::AssetBuilderBus::Broadcast(&AssetBuilderSDK::AssetBuilderBusTraits::RegisterBuilderInformation, builderDescriptor);
  40. }
  41. // Disconnects from any EBuses we connected to in Activate()
  42. // Unregisters from objects and systems we register with in Activate()
  43. void AtlasBuilderComponent::Deactivate()
  44. {
  45. m_atlasBuilder.BusDisconnect();
  46. // We don't need to unregister the builder - the AP will handle this for us, because it is managing the lifecycle of this component
  47. }
  48. // Reflect the input and output formats for the serializer
  49. void AtlasBuilderComponent::Reflect(AZ::ReflectContext* context)
  50. {
  51. // components also get Reflect called automatically
  52. // this is your opportunity to perform static reflection or type registration of any types you want the serializer to know about
  53. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  54. {
  55. serialize->Class<AtlasBuilderComponent, AZ::Component>()
  56. ->Version(0)
  57. ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector<AZ::Crc32>({ AssetBuilderSDK::ComponentTags::AssetBuilder }))
  58. ;
  59. }
  60. AtlasBuilderInput::Reflect(context);
  61. }
  62. void AtlasBuilderComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  63. {
  64. provided.push_back(AZ_CRC("Atlas Builder Plugin Service", 0x35974d0d));
  65. }
  66. void AtlasBuilderComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  67. {
  68. incompatible.push_back(AZ_CRC("Atlas Builder Plugin Service", 0x35974d0d));
  69. }
  70. void AtlasBuilderComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  71. {
  72. AZ_UNUSED(required);
  73. }
  74. void AtlasBuilderComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  75. {
  76. AZ_UNUSED(dependent);
  77. }
  78. }