AreaDebugComponent.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/RTTI/RTTI.h>
  10. #include <AzCore/Asset/AssetCommon.h>
  11. #include <AzCore/Casting/lossy_cast.h>
  12. #include <AzCore/Component/Component.h>
  13. #include <AzCore/Math/Color.h>
  14. #include <AzCore/Math/Vector3.h>
  15. #include <AzCore/Component/TickBus.h>
  16. #include <AzCore/PlatformDef.h>
  17. #include <Vegetation/Ebuses/AreaDebugBus.h>
  18. namespace LmbrCentral
  19. {
  20. template<typename, typename>
  21. class EditorWrappedComponentBase;
  22. }
  23. namespace Vegetation
  24. {
  25. AZ_INLINE AZ::Color GetDebugColor()
  26. {
  27. static uint32_t debugColor = 0xff << 8;
  28. AZ::Color value;
  29. value.FromU32(debugColor | (0xff << 24)); // add in alpha 255
  30. // use a golden ratio sequence to generate the next color
  31. // new color = fract(old color * 1.6)
  32. // Treat the 24 bits as normalized 0 - 1
  33. debugColor = azlossy_cast<uint32_t>(((aznumeric_cast<uint64_t>(debugColor) * 0x1999999ull) - 0xffffffull) & 0xffffffull);
  34. return value;
  35. }
  36. class AreaDebugConfig : public AZ::ComponentConfig
  37. {
  38. public:
  39. AZ_CLASS_ALLOCATOR(AreaDebugConfig, AZ::SystemAllocator);
  40. AZ_RTTI(AreaDebugConfig, "{A504D6DA-2825-4A0E-A65E-3FC76FC8AFAC}", AZ::ComponentConfig);
  41. static void Reflect(AZ::ReflectContext* context);
  42. AZ::Color m_debugColor = GetDebugColor();
  43. float m_debugCubeSize = 0.25f;
  44. bool m_hideDebug = false;
  45. };
  46. class AreaDebugComponent
  47. : public AZ::Component
  48. , private AreaDebugBus::Handler
  49. {
  50. public:
  51. template<typename, typename> friend class LmbrCentral::EditorWrappedComponentBase;
  52. AZ_COMPONENT(AreaDebugComponent, "{FEF676D4-BC1C-428E-BC9A-C85CF6CF19A5}", AZ::Component);
  53. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  54. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  55. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  56. static void Reflect(AZ::ReflectContext* context);
  57. AreaDebugComponent(const AreaDebugConfig& configuration);
  58. AreaDebugComponent() = default;
  59. ~AreaDebugComponent() = default;
  60. //////////////////////////////////////////////////////////////////////////
  61. // AZ::Component interface implementation
  62. void Activate() override;
  63. void Deactivate() override;
  64. bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
  65. bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
  66. private:
  67. //////////////////////////////////////////////////////////////////////////
  68. // AreaDebugBus impl
  69. AreaDebugDisplayData GetBaseDebugDisplayData() const override;
  70. void ResetBlendedDebugDisplayData() override;
  71. void AddBlendedDebugDisplayData(const AreaDebugDisplayData& data) override;
  72. AreaDebugDisplayData GetBlendedDebugDisplayData() const override;
  73. bool m_hasBlendedDebugDisplayData = false;
  74. AreaDebugDisplayData m_blendedDebugDisplayData;
  75. AreaDebugConfig m_configuration;
  76. };
  77. }