/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "Vegetation_precompiled.h" #include #include #include #include #include #include #include namespace Vegetation { namespace AreaDebugUtil { static bool UpdateVersion(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement) { if (classElement.GetVersion() < 1) { classElement.RemoveElementByName(AZ_CRC("PropagateDebug", 0xb5675baa)); classElement.RemoveElementByName(AZ_CRC("InheritDebug", 0xd227cd11)); } return true; } } void AreaDebugConfig::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serialize = azrtti_cast(context); if (serialize) { serialize->Class() ->Version(1, &AreaDebugUtil::UpdateVersion) ->Field("DebugColor", &AreaDebugConfig::m_debugColor) ->Field("CubeSize", &AreaDebugConfig::m_debugCubeSize) ->Field("HideInDebug", &AreaDebugConfig::m_hideDebug) ; AZ::EditContext* edit = serialize->GetEditContext(); if (edit) { edit->Class( "Vegetation Layer Debugger Config", "") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->DataElement(AZ::Edit::UIHandlers::Color, &AreaDebugConfig::m_debugColor, "Debug Visualization Color", "") ->DataElement(AZ::Edit::UIHandlers::Color, &AreaDebugConfig::m_debugCubeSize, "Debug Visualization Cube Size", "") ->Attribute(AZ::Edit::Attributes::Min, 0.0f) ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits::max()) ->DataElement(AZ::Edit::UIHandlers::CheckBox, &AreaDebugConfig::m_hideDebug, "Hide created instance in the Debug Visualization", "") ; } } if (auto behaviorContext = azrtti_cast(context)) { behaviorContext->Class() ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::Preview) ->Attribute(AZ::Script::Attributes::Category, "Vegetation") ->Constructor() ->Property("DebugColor", BehaviorValueProperty(&AreaDebugConfig::m_debugColor)) ->Property("DebugCubeSize", BehaviorValueProperty(&AreaDebugConfig::m_debugCubeSize)) ->Property("HideInDebug", BehaviorValueProperty(&AreaDebugConfig::m_hideDebug)) ; } } void AreaDebugComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services) { services.push_back(AZ_CRC("VegetationAreaDebugService", 0x2c6f3c5c)); } void AreaDebugComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services) { services.push_back(AZ_CRC("VegetationAreaDebugService", 0x2c6f3c5c)); } void AreaDebugComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services) { } void AreaDebugComponent::Reflect(AZ::ReflectContext* context) { AreaDebugConfig::Reflect(context); AZ::SerializeContext* serialize = azrtti_cast(context); if (serialize) { serialize->Class() ->Version(0) ->Field("Configuration", &AreaDebugComponent::m_configuration) ; } } AreaDebugComponent::AreaDebugComponent(const AreaDebugConfig& configuration) : m_configuration(configuration) { } void AreaDebugComponent::Activate() { ResetBlendedDebugDisplayData(); AreaDebugBus::Handler::BusConnect(GetEntityId()); } void AreaDebugComponent::Deactivate() { AreaDebugBus::Handler::BusDisconnect(); } bool AreaDebugComponent::ReadInConfig(const AZ::ComponentConfig* baseConfig) { if (auto config = azrtti_cast(baseConfig)) { m_configuration = *config; return true; } return false; } bool AreaDebugComponent::WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const { if (auto config = azrtti_cast(outBaseConfig)) { *config = m_configuration; return true; } return false; } AreaDebugDisplayData AreaDebugComponent::GetBaseDebugDisplayData() const { AreaDebugDisplayData data; data.m_instanceColor = m_configuration.m_debugColor; data.m_instanceSize = m_configuration.m_debugCubeSize; data.m_instanceRender = !m_configuration.m_hideDebug; return data; } void AreaDebugComponent::ResetBlendedDebugDisplayData() { m_hasBlendedDebugDisplayData = false; m_blendedDebugDisplayData = AreaDebugDisplayData(); } void AreaDebugComponent::AddBlendedDebugDisplayData(const AreaDebugDisplayData& data) { m_hasBlendedDebugDisplayData = true; //do not render if any render flag is disabled m_blendedDebugDisplayData.m_instanceRender = m_blendedDebugDisplayData.m_instanceRender && data.m_instanceRender; //performing a multiply/modulate color blend. m_blendedDebugDisplayData.m_instanceColor *= data.m_instanceColor; //setting size to the last size added m_blendedDebugDisplayData.m_instanceSize = data.m_instanceSize; } AreaDebugDisplayData AreaDebugComponent::GetBlendedDebugDisplayData() const { return m_hasBlendedDebugDisplayData ? m_blendedDebugDisplayData : GetBaseDebugDisplayData(); } }