Files
o3de/Gems/Terrain/Code/Source/TerrainSystem/TerrainSystemBus.h
T
Mike Balfour 089391f761 Terrain System cleanups and unit tests (#4119)
* Remove the "TEST_SUPPORTED" traits.
Terrain unit tests should be usable on all platforms, so they shouldn't need a platform-specific trait to enable/disable.

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

* Fix a few misc terrain bugs.
* Change Activate/Deactivate to happen immediately instead of deferring.  There were too many order-of-operation bugs caused by trying to defer this.
* Added implementation for calculating normals.
* Fixed bug where GetHeightSynchronous wasn't stopping at the highest-priority layer.
* Added locks for SurfaceData bus to help ensure we lock our mutexes in the correct order and avoid deadlocks.

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

* Add trivial TerrainSystem tests.
Tests construction, Activate(), Deactivate(), and destruction.

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

* Unified Terrain system calls on single bus.

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

* Added mock for TerrainDataNotificationBus listener.
Also added unit tests to verify the listener, and added in missing notification events.

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

* Removed extra Sampler class.
Fixed up APIs to correctly pass Sampler and terrainExistsPtr around.

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

* Switched MockTerrainSystem to be proper gmock.
This makes it for flexible to use and easier to reuse from other test environments.

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

* Fix settings bug caused by bad order of operations that occurred when the methods moved to a different bus.

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

* Eliminate extra EBus by simplifying area initialization.
Previously, there was a back-and-forth ebus signal used for the terrain system to find any terrain spawners that were created prior to the terrain system activation.  Now it uses the more simple technique of just grabbing all the spawners that are currently hooked up to the spawner ebus.

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

* Switch to NiceMock so that "uninteresting" mock calls get ignored.

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

* Addressed PR feedback.
Filled in terrainExistsPtr at the end, and added it to GetNormal as well.

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

* Fixed shader height calculation.
It was off by half a pixel, and it was interpolating, both of which were wrong.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
2021-09-15 10:57:37 -05:00

115 lines
3.7 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/Math/Vector2.h>
#include <AzCore/Math/Aabb.h>
#include <AzCore/std/functional.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/ComponentBus.h>
#include <AzFramework/Terrain/TerrainDataRequestBus.h>
namespace Terrain
{
/**
* A bus to signal the life times of terrain areas
* Note: all the API are meant to be queued events
*/
class TerrainSystemServiceRequests
: public AZ::EBusTraits
{
public:
////////////////////////////////////////////////////////////////////////
// EBusTraits
// singleton pattern
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
using MutexType = AZStd::recursive_mutex;
////////////////////////////////////////////////////////////////////////
virtual ~TerrainSystemServiceRequests() = default;
virtual void Activate() = 0;
virtual void Deactivate() = 0;
// register an area to override terrain
virtual void RegisterArea(AZ::EntityId areaId) = 0;
virtual void UnregisterArea(AZ::EntityId areaId) = 0;
virtual void RefreshArea(AZ::EntityId areaId) = 0;
};
using TerrainSystemServiceRequestBus = AZ::EBus<TerrainSystemServiceRequests>;
/**
* A bus to signal the life times of terrain areas
* Note: all the API are meant to be queued events
*/
class TerrainAreaHeightRequests
: public AZ::ComponentBus
{
public:
////////////////////////////////////////////////////////////////////////
// EBusTraits
using MutexType = AZStd::recursive_mutex;
////////////////////////////////////////////////////////////////////////
virtual ~TerrainAreaHeightRequests() = default;
enum SurfacePointDataMask
{
POSITION = 0x01,
NORMAL = 0x02,
SURFACE_WEIGHTS = 0x04,
DEFAULT = POSITION | NORMAL | SURFACE_WEIGHTS
};
// Synchronous single input location. The Vector3 input position versions are defined to ignore the input Z value.
virtual void GetHeight(
const AZ::Vector3& inPosition,
AZ::Vector3& outPosition,
AzFramework::Terrain::TerrainDataRequests::Sampler sampleFilter =
AzFramework::Terrain::TerrainDataRequests::Sampler::DEFAULT) = 0;
virtual void GetNormal(
const AZ::Vector3& inPosition,
AZ::Vector3& outNormal,
AzFramework::Terrain::TerrainDataRequests::Sampler sampleFilter =
AzFramework::Terrain::TerrainDataRequests::Sampler::DEFAULT) = 0;
};
using TerrainAreaHeightRequestBus = AZ::EBus<TerrainAreaHeightRequests>;
/**
* A bus for the TerrainSystem to interrogate TerrainLayerSpawners.
*/
class TerrainSpawnerRequests
: public AZ::ComponentBus
{
public:
////////////////////////////////////////////////////////////////////////
// EBusTraits
using MutexType = AZStd::recursive_mutex;
////////////////////////////////////////////////////////////////////////
virtual ~TerrainSpawnerRequests() = default;
virtual void GetPriority(AZ::u32& outLayer, AZ::u32& outPriority) = 0;
virtual bool GetUseGroundPlane() = 0;
};
using TerrainSpawnerRequestBus = AZ::EBus<TerrainSpawnerRequests>;
}