[Terrain] Optimize bulk queries to the Terrain System to retrieve height, surface weights, and normals (#7357)
This commit is contained in:
@@ -29,12 +29,6 @@ namespace SurfaceData
|
||||
class SurfaceTagWeights
|
||||
{
|
||||
public:
|
||||
//! The maximum number of surface weights that we can store.
|
||||
//! For performance reasons, we want to limit this so that we can preallocate the max size in advance.
|
||||
//! The current number is chosen to be higher than expected needs, but small enough to avoid being excessively wasteful.
|
||||
//! (Dynamic structures would end up taking more memory than what we're preallocating)
|
||||
static inline constexpr size_t MaxSurfaceWeights = 16;
|
||||
|
||||
SurfaceTagWeights() = default;
|
||||
|
||||
//! Construct a collection of SurfaceTagWeights from the given SurfaceTagWeightList.
|
||||
@@ -65,7 +59,7 @@ namespace SurfaceData
|
||||
// early-out once we pass the location for the entry instead of always searching every entry.
|
||||
if (weightItr->m_surfaceType > tag)
|
||||
{
|
||||
if (m_weights.size() != MaxSurfaceWeights)
|
||||
if (m_weights.size() != AzFramework::SurfaceData::Constants::MaxSurfaceWeights)
|
||||
{
|
||||
// We didn't find the surface type, so add the new entry in sorted order.
|
||||
m_weights.insert(weightItr, { tag, weight });
|
||||
@@ -85,7 +79,7 @@ namespace SurfaceData
|
||||
}
|
||||
|
||||
// We didn't find the surface weight, and the sort order for it is at the end, so add it to the back of the list.
|
||||
if (m_weights.size() != MaxSurfaceWeights)
|
||||
if (m_weights.size() != AzFramework::SurfaceData::Constants::MaxSurfaceWeights)
|
||||
{
|
||||
m_weights.emplace_back(tag, weight);
|
||||
}
|
||||
@@ -188,7 +182,7 @@ namespace SurfaceData
|
||||
//! @return The pointer to the tag that's found, or end() if it wasn't found.
|
||||
const AzFramework::SurfaceData::SurfaceTagWeight* FindTag(AZ::Crc32 tag) const;
|
||||
|
||||
AZStd::fixed_vector<AzFramework::SurfaceData::SurfaceTagWeight, MaxSurfaceWeights> m_weights;
|
||||
AZStd::fixed_vector<AzFramework::SurfaceData::SurfaceTagWeight, AzFramework::SurfaceData::Constants::MaxSurfaceWeights> m_weights;
|
||||
};
|
||||
|
||||
//! SurfacePointList stores a collection of surface point data, which consists of positions, normals, and surface tag weights.
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace SurfaceData
|
||||
AzFramework::SurfaceData::SurfaceTagWeightList SurfaceTagWeights::GetSurfaceTagWeightList() const
|
||||
{
|
||||
AzFramework::SurfaceData::SurfaceTagWeightList weights;
|
||||
weights.reserve(m_weights.size());
|
||||
|
||||
for (auto& weight : m_weights)
|
||||
{
|
||||
weights.emplace_back(weight);
|
||||
|
||||
@@ -275,7 +275,7 @@ namespace UnitTest
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(Entity);
|
||||
|
||||
AZ::Crc32 tags[SurfaceData::SurfaceTagWeights::MaxSurfaceWeights];
|
||||
AZ::Crc32 tags[AzFramework::SurfaceData::Constants::MaxSurfaceWeights];
|
||||
AZ::SimpleLcgRandom randomGenerator(1234567);
|
||||
|
||||
// Declare this outside the loop so that we aren't benchmarking creation and destruction.
|
||||
@@ -316,7 +316,7 @@ namespace UnitTest
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(Entity);
|
||||
|
||||
AZ::Crc32 tags[SurfaceData::SurfaceTagWeights::MaxSurfaceWeights];
|
||||
AZ::Crc32 tags[AzFramework::SurfaceData::Constants::MaxSurfaceWeights];
|
||||
AZ::SimpleLcgRandom randomGenerator(1234567);
|
||||
|
||||
// Declare this outside the loop so that we aren't benchmarking creation and destruction.
|
||||
|
||||
Reference in New Issue
Block a user