TerrainLayerSpawnerComponent.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <AzCore/Asset/AssetCommon.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Math/Vector3.h>
  12. #include <AzCore/Jobs/JobManagerBus.h>
  13. #include <AzCore/Jobs/JobFunction.h>
  14. #include <AzFramework/Terrain/TerrainDataRequestBus.h>
  15. #include <TerrainSystem/TerrainSystemBus.h>
  16. #include <LmbrCentral/Shape/ShapeComponentBus.h>
  17. #include <AzCore/Math/Aabb.h>
  18. namespace LmbrCentral
  19. {
  20. template<typename, typename>
  21. class EditorWrappedComponentBase;
  22. }
  23. namespace Terrain
  24. {
  25. namespace AreaConstants
  26. {
  27. static const uint32_t s_backgroundLayer = 0;
  28. static const uint32_t s_foregroundLayer = 1;
  29. static const int32_t s_priorityMin = -10000;
  30. static const int32_t s_priorityMax = 10000;
  31. static const int32_t s_prioritySoftMin = -100; //design specified slider range
  32. static const int32_t s_prioritySoftMax = 100; //design specified slider range
  33. }
  34. class TerrainLayerSpawnerConfig
  35. : public AZ::ComponentConfig
  36. {
  37. public:
  38. AZ_CLASS_ALLOCATOR(TerrainLayerSpawnerConfig, AZ::SystemAllocator);
  39. AZ_RTTI(TerrainLayerSpawnerConfig, "{8E0695DE-E843-4858-BAEA-70953E74C810}", AZ::ComponentConfig);
  40. static void Reflect(AZ::ReflectContext* context);
  41. AZStd::vector<AZStd::pair<AZ::u32, AZStd::string>> GetSelectableLayers() const;
  42. uint32_t m_layer = AreaConstants::s_foregroundLayer;
  43. int32_t m_priority = 0;
  44. bool m_useGroundPlane = true;
  45. };
  46. inline constexpr AZ::TypeId TerrainLayerSpawnerComponentTypeId{ "{3848605F-A4EA-478C-B710-84AB8DCA9EC5}" };
  47. class TerrainLayerSpawnerComponent
  48. : public AZ::Component
  49. , private LmbrCentral::ShapeComponentNotificationsBus::Handler
  50. , private Terrain::TerrainSpawnerRequestBus::Handler
  51. {
  52. public:
  53. template<typename, typename>
  54. friend class LmbrCentral::EditorWrappedComponentBase;
  55. AZ_COMPONENT(TerrainLayerSpawnerComponent, TerrainLayerSpawnerComponentTypeId);
  56. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  57. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  58. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  59. static void Reflect(AZ::ReflectContext* context);
  60. TerrainLayerSpawnerComponent(const TerrainLayerSpawnerConfig& configuration);
  61. TerrainLayerSpawnerComponent() = default;
  62. ~TerrainLayerSpawnerComponent() = default;
  63. //////////////////////////////////////////////////////////////////////////
  64. // AZ::Component interface implementation
  65. void Activate() override;
  66. void Deactivate() override;
  67. bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
  68. bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
  69. protected:
  70. // ShapeComponentNotificationsBus
  71. void OnShapeChanged(ShapeChangeReasons changeReason) override;
  72. // TerrainSpawnerRequestBus
  73. void GetPriority(uint32_t& outLayer, int32_t& outPriority) override;
  74. bool GetUseGroundPlane() override;
  75. void RefreshArea();
  76. private:
  77. TerrainLayerSpawnerConfig m_configuration;
  78. };
  79. }