Files
o3de/Gems/GradientSignal/Code/Source/Editor/EditorGradientTransformComponent.cpp
T
Mike Balfour 48260486fb Change gradients to use cached GradientTransform instance (#6591)
* Change flow so that TerrainSystem stops responding during deactivation.
Some systems might accidentally try to call back to the TerrainSystem inside a DestroyBegin notification, so make sure it stops listening before sending out the notification.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Change gradients to cache and use a GradientTransform instance.
In my local test case, calling EBus on every call took 337 ms, using a lambda to wrap the calls took 197 ms, and using the fully cached version took 170 ms.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Remove the wrappingTransform function and go back to the switch statement.
There was a bit of overhead to each function call due to using AZStd::function that just isn't necessary for this use case.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Add profile markers to the heightfield updates so that they're more visible.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Cleared state while component is deactivated.
The state was getting refreshed even while the component was in a deactivated state, which meant that it wasn't properly notifying of state changes when it became active since it wasn't detecting an actual change.  By clearing the state when deactivated, and ensuring the state isn't getting refreshed *while* deactivated, the notifications work properly.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Fixed compile warning on unit test.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Addressed PR feedback - changed comments, reduced mutex scope

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
2021-12-30 12:43:00 -06:00

68 lines
2.4 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "EditorGradientTransformComponent.h"
#include <LmbrCentral/Dependency/DependencyNotificationBus.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
namespace GradientSignal
{
void EditorGradientTransformComponent::Reflect(AZ::ReflectContext* context)
{
BaseClassType::ReflectSubClass<EditorGradientTransformComponent, BaseClassType>(context, 1, &LmbrCentral::EditorWrappedComponentBaseVersionConverter<typename BaseClassType::WrappedComponentType, typename BaseClassType::WrappedConfigType,1>);
}
void EditorGradientTransformComponent::Activate()
{
BaseClassType::Activate();
AzToolsFramework::EditorVisibilityNotificationBus::Handler::BusConnect(GetEntityId());
LmbrCentral::DependencyNotificationBus::Handler::BusConnect(GetEntityId());
UpdateFromShape();
}
void EditorGradientTransformComponent::Deactivate()
{
//ensure that we disconnect from any observed buses on teardown
LmbrCentral::DependencyNotificationBus::Handler::BusDisconnect();
LmbrCentral::DependencyNotificationBus::Handler::BusDisconnect();
BaseClassType::Deactivate();
}
AZ::u32 EditorGradientTransformComponent::ConfigurationChanged()
{
BaseClassType::ConfigurationChanged();
UpdateFromShape();
// Refresh attributes because changing shapes affects read-only status of bounds
return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
}
void EditorGradientTransformComponent::OnCompositionChanged()
{
UpdateFromShape();
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_AttributesAndValues);
}
void EditorGradientTransformComponent::UpdateFromShape()
{
if (m_runtimeComponentActive)
{
// Update config from shape on game component, copy that back to our config.
bool notifyDependentsOfChange = true;
m_component.UpdateFromShape(notifyDependentsOfChange);
m_component.WriteOutConfig(&m_configuration);
SetDirty();
}
}
} //namespace GradientSignal