VegetationSystemComponent.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 "VegetationSystemComponent.h"
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <Vegetation/DescriptorListAsset.h>
  12. #include <Vegetation/AreaComponentBase.h>
  13. #include <AzFramework/Asset/GenericAssetHandler.h>
  14. #include <Vegetation/Ebuses/FilterRequestBus.h>
  15. #include <Vegetation/Ebuses/InstanceSystemRequestBus.h>
  16. #include <Vegetation/InstanceSpawner.h>
  17. #include <Vegetation/EmptyInstanceSpawner.h>
  18. #include <Vegetation/PrefabInstanceSpawner.h>
  19. AZ_DEFINE_BUDGET(Vegetation);
  20. namespace Vegetation
  21. {
  22. void InstanceSpawner::Reflect(AZ::ReflectContext* context)
  23. {
  24. AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
  25. if (serialize)
  26. {
  27. serialize->Class<InstanceSpawner>()
  28. ->Version(0)
  29. ;
  30. }
  31. }
  32. namespace Details
  33. {
  34. AzFramework::GenericAssetHandler<DescriptorListAsset>* s_vegetationDescriptorListAssetHandler = nullptr;
  35. void RegisterAssethandlers()
  36. {
  37. s_vegetationDescriptorListAssetHandler = aznew AzFramework::GenericAssetHandler<DescriptorListAsset>("Vegetation Descriptor List", "Other", "vegdescriptorlist");
  38. s_vegetationDescriptorListAssetHandler->Register();
  39. }
  40. void UnregisterAssethandlers()
  41. {
  42. if (s_vegetationDescriptorListAssetHandler)
  43. {
  44. s_vegetationDescriptorListAssetHandler->Unregister();
  45. delete s_vegetationDescriptorListAssetHandler;
  46. s_vegetationDescriptorListAssetHandler = nullptr;
  47. }
  48. }
  49. }
  50. void VegetationSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  51. {
  52. services.push_back(AZ_CRC_CE("VegetationSystemService"));
  53. }
  54. void VegetationSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  55. {
  56. services.push_back(AZ_CRC_CE("VegetationSystemService"));
  57. }
  58. void VegetationSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  59. {
  60. services.push_back(AZ_CRC_CE("VegetationAreaSystemService"));
  61. services.push_back(AZ_CRC_CE("VegetationInstanceSystemService"));
  62. services.push_back(AZ_CRC_CE("SurfaceDataSystemService"));
  63. }
  64. void VegetationSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  65. {
  66. services.push_back(AZ_CRC_CE("SurfaceDataProviderService"));
  67. }
  68. void VegetationSystemComponent::Reflect(AZ::ReflectContext* context)
  69. {
  70. InstanceSpawner::Reflect(context);
  71. EmptyInstanceSpawner::Reflect(context);
  72. PrefabInstanceSpawner::Reflect(context);
  73. Descriptor::Reflect(context);
  74. AreaConfig::Reflect(context);
  75. AreaComponentBase::Reflect(context);
  76. DescriptorListAsset::Reflect(context);
  77. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  78. {
  79. serialize->Class<VegetationSystemComponent, AZ::Component>()
  80. ->Version(0)
  81. ;
  82. if (AZ::EditContext* editContext = serialize->GetEditContext())
  83. {
  84. editContext->Class<VegetationSystemComponent>("Vegetation System", "Reflects types and defines required services for dynamic vegetation systems to function")
  85. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  86. ->Attribute(AZ::Edit::Attributes::Category, "Vegetation")
  87. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  88. ;
  89. }
  90. }
  91. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  92. {
  93. behaviorContext->EBus<FilterRequestBus>("FilterRequestBus")
  94. ->Attribute(AZ::Script::Attributes::Category, "Vegetation")
  95. ->Event("GetFilterStage", &FilterRequestBus::Events::GetFilterStage)
  96. ->Event("SetFilterStage", &FilterRequestBus::Events::SetFilterStage)
  97. ->VirtualProperty("FilterStage", "GetFilterStage", "SetFilterStage");
  98. ;
  99. }
  100. }
  101. VegetationSystemComponent::VegetationSystemComponent()
  102. {
  103. }
  104. VegetationSystemComponent::~VegetationSystemComponent()
  105. {
  106. }
  107. void VegetationSystemComponent::Activate()
  108. {
  109. Details::RegisterAssethandlers();
  110. }
  111. void VegetationSystemComponent::Deactivate()
  112. {
  113. Details::UnregisterAssethandlers();
  114. }
  115. }