LYN-6357 Terrain Macro Material tests
Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:011454252e40c927343cce16296412f02f45d1f345c75c036651bdcca473bda5
|
||||
size 2672
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7bafcc4aefab827e1414e64bcdde235500b51392e52c9ccd588b2d7a24b865a0
|
||||
size 20214
|
||||
@@ -27,3 +27,6 @@ class TestAutomation(EditorTestSuite):
|
||||
|
||||
class test_Terrain_SupportsPhysics(EditorSharedTest):
|
||||
from .EditorScripts import Terrain_SupportsPhysics as test_module
|
||||
|
||||
class test_TerrainMacroMaterialComponent_MacroMaterialActivates(EditorSharedTest):
|
||||
from .EditorScripts import TerrainMacroMaterialComponent_MacroMaterialActivates as test_module
|
||||
+2
-1
@@ -93,7 +93,8 @@ namespace Terrain
|
||||
void TerrainMacroMaterialComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
TerrainMacroMaterialConfig::Reflect(context);
|
||||
|
||||
TerrainMacroMaterialRequests::Reflect(context);
|
||||
|
||||
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serialize)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 "TerrainMacroMaterialBus.h"
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
// Create a handler that can be accessed from Python scripts to receive terrain change notifications.
|
||||
class TerrainMacroMaterialNotificationHandler final
|
||||
: public Terrain::TerrainMacroMaterialNotificationBus::Handler
|
||||
, public AZ::BehaviorEBusHandler
|
||||
{
|
||||
public:
|
||||
AZ_EBUS_BEHAVIOR_BINDER(
|
||||
TerrainMacroMaterialNotificationHandler,
|
||||
"{B0ED8B29-0E0D-4567-BEAF-C842C4DB2700}",
|
||||
AZ::SystemAllocator,
|
||||
OnTerrainMacroMaterialCreated,
|
||||
OnTerrainMacroMaterialChanged,
|
||||
OnTerrainMacroMaterialRegionChanged,
|
||||
OnTerrainMacroMaterialDestroyed);
|
||||
|
||||
void OnTerrainMacroMaterialCreated(
|
||||
[[maybe_unused]] AZ::EntityId macroMaterialEntity,
|
||||
[[maybe_unused]] const Terrain::MacroMaterialData& macroMaterial) override
|
||||
{
|
||||
Call(FN_OnTerrainMacroMaterialCreated);
|
||||
}
|
||||
|
||||
void OnTerrainMacroMaterialChanged(
|
||||
[[maybe_unused]] AZ::EntityId macroMaterialEntity,
|
||||
[[maybe_unused]] const Terrain::MacroMaterialData& macroMaterial) override
|
||||
{
|
||||
Call(FN_OnTerrainMacroMaterialChanged);
|
||||
}
|
||||
|
||||
void OnTerrainMacroMaterialRegionChanged(
|
||||
[[maybe_unused]] AZ::EntityId macroMaterialEntity,
|
||||
[[maybe_unused]] const AZ::Aabb& oldRegion,
|
||||
[[maybe_unused]] const AZ::Aabb& newRegion) override
|
||||
{
|
||||
Call(FN_OnTerrainMacroMaterialRegionChanged);
|
||||
}
|
||||
|
||||
void OnTerrainMacroMaterialDestroyed([[maybe_unused]] AZ::EntityId macroMaterialEntity) override
|
||||
{
|
||||
Call(FN_OnTerrainMacroMaterialDestroyed);
|
||||
}
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->EBus<Terrain::TerrainMacroMaterialNotificationBus>("TerrainMacroMaterialAutomationBus")
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
|
||||
->Attribute(AZ::Script::Attributes::Module, "terrain")
|
||||
->Handler<TerrainMacroMaterialNotificationHandler>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void TerrainMacroMaterialRequests::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->EBus<Terrain::TerrainMacroMaterialRequestBus>("TerrainMacroMaterialRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Attribute(AZ::Script::Attributes::Category, "Terrain")
|
||||
->Attribute(AZ::Script::Attributes::Module, "terrain")
|
||||
->Event("GetTerrainMacroMaterialData", &Terrain::TerrainMacroMaterialRequestBus::Events::GetTerrainMacroMaterialData)
|
||||
;
|
||||
|
||||
behaviorContext->EBus<Terrain::TerrainMacroMaterialNotificationBus>("TerrainMacroMaterialNotificationBus")
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Attribute(AZ::Script::Attributes::Category, "Terrain")
|
||||
->Attribute(AZ::Script::Attributes::Module, "terrain")
|
||||
->Event("OnTerrainMacroMaterialCreated", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialCreated)
|
||||
->Event("OnTerrainMacroMaterialChanged", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialChanged)
|
||||
->Event("OnTerrainMacroMaterialRegionChanged", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialRegionChanged)
|
||||
->Event("OnTerrainMacroMaterialDestroyed", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialDestroyed)
|
||||
;
|
||||
|
||||
Terrain::TerrainMacroMaterialNotificationHandler::Reflect(context);
|
||||
}
|
||||
}
|
||||
} // namespace Terrain
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
struct MacroMaterialData
|
||||
struct MacroMaterialData final
|
||||
{
|
||||
AZ_RTTI(MacroMaterialData, "{DC68E20A-3251-4E4E-8BC7-F6A2521FEF46}");
|
||||
|
||||
AZ::EntityId m_entityId;
|
||||
AZ::Aabb m_bounds = AZ::Aabb::CreateNull();
|
||||
|
||||
@@ -35,6 +37,8 @@ namespace Terrain
|
||||
: public AZ::ComponentBus
|
||||
{
|
||||
public:
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits
|
||||
using MutexType = AZStd::recursive_mutex;
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 <AzCore/Component/ComponentApplication.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Memory/MemoryComponent.h>
|
||||
|
||||
#include <AzFramework/Terrain/TerrainDataRequestBus.h>
|
||||
|
||||
#include <TerrainRenderer/Components/TerrainMacroMaterialComponent.h>
|
||||
#include <LmbrCentral/Shape/BoxShapeComponentBus.h>
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
#include <Terrain/MockTerrain.h>
|
||||
#include <MockAxisAlignedBoxShapeComponent.h>
|
||||
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::AtLeast;
|
||||
using ::testing::_;
|
||||
|
||||
|
||||
class TerrainMacroMaterialComponentTest
|
||||
: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
AZ::ComponentApplication m_app;
|
||||
|
||||
UnitTest::MockAxisAlignedBoxShapeComponent* m_shapeComponent;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
AZ::ComponentApplication::Descriptor appDesc;
|
||||
appDesc.m_memoryBlocksByteSize = 20 * 1024 * 1024;
|
||||
appDesc.m_recordingMode = AZ::Debug::AllocationRecords::RECORD_NO_RECORDS;
|
||||
appDesc.m_stackRecordLevels = 20;
|
||||
|
||||
m_app.Create(appDesc);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
m_app.Destroy();
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<AZ::Entity> CreateEntity()
|
||||
{
|
||||
auto entity = AZStd::make_unique<AZ::Entity>();
|
||||
entity->Init();
|
||||
|
||||
return entity;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TerrainMacroMaterialComponentTest, MissingRequiredComponentsActivateFailure)
|
||||
{
|
||||
auto entity = CreateEntity();
|
||||
|
||||
auto macroMaterialComponent = entity->CreateComponent<Terrain::TerrainMacroMaterialComponent>();
|
||||
m_app.RegisterComponentDescriptor(macroMaterialComponent->CreateDescriptor());
|
||||
|
||||
const AZ::Entity::DependencySortOutcome sortOutcome = entity->EvaluateDependenciesGetDetails();
|
||||
EXPECT_FALSE(sortOutcome.IsSuccess());
|
||||
|
||||
entity.reset();
|
||||
}
|
||||
|
||||
TEST_F(TerrainMacroMaterialComponentTest, RequiredComponentsPresentEntityActivateSuccess)
|
||||
{
|
||||
auto entity = CreateEntity();
|
||||
|
||||
auto macroMaterialComponent = entity->CreateComponent<Terrain::TerrainMacroMaterialComponent>();
|
||||
m_app.RegisterComponentDescriptor(macroMaterialComponent->CreateDescriptor());
|
||||
|
||||
auto shapeComponent = entity->CreateComponent<UnitTest::MockAxisAlignedBoxShapeComponent>();
|
||||
m_app.RegisterComponentDescriptor(shapeComponent->CreateDescriptor());
|
||||
|
||||
entity->Activate();
|
||||
EXPECT_EQ(entity->GetState(), AZ::Entity::State::Active);
|
||||
|
||||
entity.reset();
|
||||
}
|
||||
@@ -33,6 +33,7 @@ set(FILES
|
||||
Source/TerrainRenderer/TerrainFeatureProcessor.cpp
|
||||
Source/TerrainRenderer/TerrainFeatureProcessor.h
|
||||
Source/TerrainRenderer/TerrainAreaMaterialRequestBus.h
|
||||
Source/TerrainRenderer/TerrainMacroMaterialBus.cpp
|
||||
Source/TerrainRenderer/TerrainMacroMaterialBus.h
|
||||
Source/TerrainSystem/TerrainSystem.cpp
|
||||
Source/TerrainSystem/TerrainSystem.h
|
||||
|
||||
@@ -14,5 +14,6 @@ set(FILES
|
||||
Tests/SurfaceMaterialsListTest.cpp
|
||||
Tests/MockAxisAlignedBoxShapeComponent.h
|
||||
Tests/TerrainHeightGradientListTests.cpp
|
||||
Tests/TerrainMacroMaterialTests.cpp
|
||||
Tests/TerrainSurfaceGradientListTests.cpp
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user