Files
o3de/Gems/GradientSignal/Code/Include/GradientSignal/Ebuses/GradientTransformRequestBus.h
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

79 lines
3.1 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
*
*/
#pragma once
#include <AzCore/Component/EntityId.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/Math/Aabb.h>
#include <AzCore/Math/Vector3.h>
#include <GradientSignal/GradientTransform.h>
namespace GradientSignal
{
class GradientTransformRequests
: public AZ::EBusTraits
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = AZ::EntityId;
//! allows multiple threads to call gradient transform requests
using MutexType = AZStd::recursive_mutex;
virtual ~GradientTransformRequests() = default;
//! Get the GradientTransform that's been configured by the bus listener.
//! \return the GradientTransform instance that can be used to transform world points into gradient lookup space.
virtual const GradientTransform& GetGradientTransform() const = 0;
};
using GradientTransformRequestBus = AZ::EBus<GradientTransformRequests>;
/**
* Notifies about changes to the GradientTransform configuration
*/
class GradientTransformNotifications
: public AZ::EBusTraits
{
public:
////////////////////////////////////////////////////////////////////////
// EBusTraits
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = AZ::EntityId;
using MutexType = AZStd::recursive_mutex;
////////////////////////////////////////////////////////////////////////
//! Notify listeners that the GradientTransform configuration has changed.
//! \return the GradientTransform instance that can be used to transform world points into gradient lookup space.
virtual void OnGradientTransformChanged(const GradientTransform& newTransform) = 0;
//! Connection policy that auto-calls OnGradientTransformChanged on connection with the current GradientTransform data.
template<class Bus>
struct ConnectionPolicy : public AZ::EBusConnectionPolicy<Bus>
{
static void Connect(
typename Bus::BusPtr& busPtr,
typename Bus::Context& context,
typename Bus::HandlerNode& handler,
typename Bus::Context::ConnectLockGuard& connectLock,
const typename Bus::BusIdType& id = 0)
{
AZ::EBusConnectionPolicy<Bus>::Connect(busPtr, context, handler, connectLock, id);
GradientTransform transform;
GradientTransformRequestBus::EventResult(transform, id, &GradientTransformRequests::GetGradientTransform);
handler->OnGradientTransformChanged(transform);
}
};
};
using GradientTransformNotificationBus = AZ::EBus<GradientTransformNotifications>;
} //namespace GradientSignal