AreaBlenderComponent.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #pragma once
  9. #include <LmbrCentral/Dependency/DependencyMonitor.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TransformBus.h>
  12. #include <LmbrCentral/Shape/ShapeComponentBus.h>
  13. #include <LmbrCentral/Dependency/DependencyNotificationBus.h>
  14. #include <Vegetation/Ebuses/AreaNotificationBus.h>
  15. #include <Vegetation/Ebuses/AreaBlenderRequestBus.h>
  16. #include <Vegetation/AreaComponentBase.h>
  17. namespace LmbrCentral
  18. {
  19. template<typename, typename>
  20. class EditorWrappedComponentBase;
  21. }
  22. namespace Vegetation
  23. {
  24. class AreaBlenderConfig
  25. : public AreaConfig
  26. {
  27. public:
  28. AZ_CLASS_ALLOCATOR(AreaBlenderConfig, AZ::SystemAllocator);
  29. AZ_RTTI(AreaBlenderConfig, "{ED57731E-2821-4AA6-9BD6-9203ED0B6AB0}", AreaConfig);
  30. static void Reflect(AZ::ReflectContext* context);
  31. bool m_inheritBehavior = true;
  32. bool m_propagateBehavior = true;
  33. AZStd::vector<AZ::EntityId> m_vegetationAreaIds;
  34. size_t GetNumAreas() const;
  35. AZ::EntityId GetAreaEntityId(int index) const;
  36. void RemoveAreaEntityId(int index);
  37. void AddAreaEntityId(AZ::EntityId entityId);
  38. };
  39. inline constexpr AZ::TypeId AreaBlenderComponentTypeId{ "{899AA751-BC3F-45D8-9D66-07CE72FDC86D}" };
  40. /**
  41. * Placement logic for combined vegetation areas
  42. */
  43. class AreaBlenderComponent
  44. : public AreaComponentBase
  45. , private AreaBlenderRequestBus::Handler
  46. {
  47. public:
  48. template<typename, typename> friend class LmbrCentral::EditorWrappedComponentBase;
  49. AZ_COMPONENT(AreaBlenderComponent, AreaBlenderComponentTypeId, AreaComponentBase);
  50. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  51. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  52. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  53. static void Reflect(AZ::ReflectContext* context);
  54. AreaBlenderComponent(const AreaBlenderConfig& configuration);
  55. AreaBlenderComponent() = default;
  56. ~AreaBlenderComponent() = default;
  57. //////////////////////////////////////////////////////////////////////////
  58. // AZ::Component interface implementation
  59. void Activate() override;
  60. void Deactivate() override;
  61. bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
  62. bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
  63. //////////////////////////////////////////////////////////////////////////
  64. // AreaRequestBus
  65. bool PrepareToClaim(EntityIdStack& stackIds) override;
  66. void ClaimPositions(EntityIdStack& stackIds, ClaimContext& context) override;
  67. void UnclaimPosition(const ClaimHandle handle) override;
  68. // AreaInfoBus
  69. AZ::Aabb GetEncompassingAabb() const override;
  70. AZ::u32 GetProductCount() const override;
  71. protected:
  72. //////////////////////////////////////////////////////////////////////////
  73. // AreaBlenderRequestBus
  74. AZ::u32 GetAreaPriority() const override;
  75. void SetAreaPriority(AZ::u32 priority) override;
  76. AZ::u32 GetAreaLayer() const override;
  77. void SetAreaLayer(AZ::u32 layer) override;
  78. AZ::u32 GetAreaProductCount() const override;
  79. bool GetInheritBehavior() const override;
  80. void SetInheritBehavior(bool value) override;
  81. bool GetPropagateBehavior() const override;
  82. void SetPropagateBehavior(bool value) override;
  83. size_t GetNumAreas() const override;
  84. AZ::EntityId GetAreaEntityId(int index) const override;
  85. void RemoveAreaEntityId(int index) override;
  86. void AddAreaEntityId(AZ::EntityId entityId) override;
  87. private:
  88. AreaBlenderConfig m_configuration;
  89. LmbrCentral::DependencyMonitor m_dependencyMonitor;
  90. void SetupDependencies();
  91. };
  92. }