Visualizer: use template functor over hardcoded lambdas

Signed-off-by: Jacob Hilliard <jhlliar@amazon.com>
This commit is contained in:
Jacob Hilliard
2021-07-29 10:08:19 -07:00
parent a271a85d6e
commit 5a18b24651
2 changed files with 20 additions and 23 deletions
@@ -27,6 +27,20 @@ namespace AZ
//! Stores all the data associated with a row in the table.
struct TableRow
{
template <typename T>
struct TableRowCompareFunctor
{
TableRowCompareFunctor(T memberPointer, bool isAscending) : m_memberPointer(memberPointer), m_ascending(isAscending){};
bool operator()(const TableRow* lhs, const TableRow* rhs)
{
return m_ascending ? lhs->*m_memberPointer < rhs->*m_memberPointer : lhs->*m_memberPointer > rhs->*m_memberPointer;
}
T m_memberPointer;
bool m_ascending;
};
// Update running statistics with new region data
void RecordRegion(const AZ::RHI::CachedTimeRegion& region, AZStd::thread_id threadId);
@@ -208,39 +208,22 @@ namespace AZ
switch (columnToSort)
{
case (0): // Sort by group name
AZStd::sort(m_tableData.begin(), m_tableData.end(), [ascending](const TableRow* lhs, const TableRow* rhs){
return ascending ? lhs->m_groupName < rhs->m_groupName : lhs->m_groupName > rhs->m_groupName;
});
AZStd::sort(m_tableData.begin(), m_tableData.end(), TableRow::TableRowCompareFunctor(&TableRow::m_groupName, ascending));
break;
case (1): // Sort by region name
AZStd::sort(m_tableData.begin(), m_tableData.end(),[ascending](const TableRow* lhs, const TableRow* rhs){
return ascending ? lhs->m_regionName < rhs->m_regionName
: lhs->m_regionName > rhs->m_regionName;
});
AZStd::sort(m_tableData.begin(), m_tableData.end(), TableRow::TableRowCompareFunctor(&TableRow::m_regionName, ascending));
break;
case (2): // Sort by average time
AZStd::sort(m_tableData.begin(), m_tableData.end(), [ascending](const TableRow* lhs, const TableRow* rhs){
return ascending ? lhs->m_runningAverageTicks < rhs->m_runningAverageTicks
: lhs->m_runningAverageTicks > rhs->m_runningAverageTicks;
});
AZStd::sort(m_tableData.begin(), m_tableData.end(), TableRow::TableRowCompareFunctor(&TableRow::m_runningAverageTicks, ascending));
break;
case (3): // Sort by max time
AZStd::sort(m_tableData.begin(), m_tableData.end(), [ascending](const TableRow* lhs, const TableRow* rhs){
return ascending ? lhs->m_maxTicks < rhs->m_maxTicks
: lhs->m_maxTicks > rhs->m_maxTicks;
});
AZStd::sort(m_tableData.begin(), m_tableData.end(), TableRow::TableRowCompareFunctor(&TableRow::m_maxTicks, ascending));
break;
case (4): // Sort by invocations
AZStd::sort(m_tableData.begin(), m_tableData.end(), [ascending](const TableRow* lhs, const TableRow* rhs){
return ascending ? lhs->m_invocationsLastFrame < rhs->m_invocationsLastFrame
: lhs->m_invocationsLastFrame > rhs->m_invocationsLastFrame;
});
AZStd::sort(m_tableData.begin(), m_tableData.end(), TableRow::TableRowCompareFunctor(&TableRow::m_invocationsLastFrame, ascending));
break;
case (5): // Sort by total time
AZStd::sort(m_tableData.begin(), m_tableData.end(), [ascending](const TableRow* lhs, const TableRow* rhs){
return ascending ? lhs->m_lastFrameTotalTicks < rhs->m_lastFrameTotalTicks
: lhs->m_lastFrameTotalTicks > rhs->m_lastFrameTotalTicks;
});
AZStd::sort(m_tableData.begin(), m_tableData.end(), TableRow::TableRowCompareFunctor(&TableRow::m_lastFrameTotalTicks, ascending));
break;
}
sortSpecs->SpecsDirty = false;