Files
o3de/Code/Tools/Standalone/Source/Driller/DrillerAggregator.cpp
T
Esteban Papp 1f9b284de2 Merge branch 'development' into cmake/SPEC-7179
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>

# Conflicts:
#	Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h
#	Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h
#	Code/Editor/Plugins/EditorCommon/stdafx.cpp
#	Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h
#	Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h
#	Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h
#	Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h
#	Code/Tools/AssetProcessor/native/precompiled.h
#	Code/Tools/Standalone/StandaloneTools_precompiled.h
#	Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h
#	Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h
#	Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h
#	Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake
#	Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h
#	Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h
#	Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp
#	Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake
#	Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h
#	Gems/Blast/Code/Source/StdAfx.cpp
#	Gems/Camera/Code/Source/Camera_precompiled.h
#	Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h
#	Gems/FastNoise/Code/Source/FastNoise_precompiled.h
#	Gems/Gestures/Code/Source/Gestures_precompiled.h
#	Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h
#	Gems/GraphCanvas/Code/precompiled.h
#	Gems/ImGui/Code/Source/ImGui_precompiled.h
#	Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h
#	Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h
#	Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp
#	Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h
#	Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h
#	Gems/LyShine/Code/Source/LyShine_precompiled.h
#	Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h
#	Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h
#	Gems/Maestro/Code/Source/Maestro_precompiled.h
#	Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h
#	Gems/Metastream/Code/Source/Metastream_precompiled.h
#	Gems/Microphone/Code/Source/Microphone_precompiled.h
#	Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h
#	Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h
#	Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h
#	Gems/PhysX/Code/Source/PhysX_precompiled.h
#	Gems/PhysX/Code/physx_unsupported_files.cmake
#	Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h
#	Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h
#	Gems/ScriptCanvas/Code/Editor/precompiled.h
#	Gems/ScriptCanvas/Code/Source/precompiled.h
#	Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h
#	Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h
#	Gems/ScriptEvents/Code/Source/precompiled.h
#	Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp
#	Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h
#	Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h
#	Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h
#	Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h
#	Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h
#	Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h
#	Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h
#	Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h
#	Gems/Twitch/Code/Source/Twitch_precompiled.h
#	Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
2021-07-16 15:42:37 -07:00

224 lines
6.5 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
*
*/
#include "DrillerAggregator.hxx"
#include <Source/Driller/moc_DrillerAggregator.cpp>
#include "DrillerEvent.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/UserSettings/UserSettings.h>
#include <AzCore/IO/SystemFile.h>
#include "Source/Driller/CSVExportSettings.h"
#include <QMessageBox>
namespace Driller
{
class AggregatorSavedState
: public AZ::UserSettings
{
public:
AZ_RTTI(AggregatorSavedState, "{9AAB69CE-8061-4CB6-8387-DB60FD8DBB75}", AZ::UserSettings);
AZ_CLASS_ALLOCATOR(AggregatorSavedState, AZ::SystemAllocator, 0);
AggregatorSavedState() {}
static void Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
serialize->Class<AggregatorSavedState>()
->Version(1)
;
}
}
};
//////////////////////////////////////////////////////////////////////////
Aggregator::Aggregator(int identity)
: QObject()
, m_identity(identity)
, m_currentEvent(Driller::kInvalidEventIndex)
, m_isCaptureEnabled(true)
{
DrillerMainWindowMessages::Handler::BusConnect(m_identity);
DrillerWorkspaceWindowMessages::Handler::BusConnect(m_identity);
// subclassed aggregators should work with settingsDocument at this point
// to retrieve state
}
Aggregator::~Aggregator()
{
// subclassed aggregators should work with settingsDocument at this point
// to store the current state so it can be retrieved when constructed again
DrillerWorkspaceWindowMessages::Handler::BusDisconnect(m_identity);
DrillerMainWindowMessages::Handler::BusDisconnect(m_identity);
for (EventListType::iterator it = m_events.begin(); it != m_events.end(); ++it)
{
delete *it;
}
}
void Aggregator::Reset()
{
for (EventListType::iterator it = m_events.begin(); it != m_events.end(); ++it)
{
delete *it;
}
m_events.clear();
m_frameToEventIndex.clear();
m_currentEvent = kInvalidEventIndex;
}
bool Aggregator::IsValid()
{
return m_events.size() > 0;
}
void Aggregator::AddNewFrame()
{
m_frameToEventIndex.push_back(m_events.size());
}
bool Aggregator::DataAtFrame(FrameNumberType frame)
{
return NumOfEventsAtFrame(frame) > 0;
}
void Aggregator::ExportToCSVRequest(const char* filename, CSVExportSettings* exportSettings)
{
AZ::IO::SystemFile exportFile;
if (exportFile.Open(filename, AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY))
{
if (exportSettings == nullptr || exportSettings->ShouldExportColumnDescriptors())
{
ExportColumnDescriptorToCSV(exportFile, exportSettings);
}
for (DrillerEvent* drillerEvent : m_events)
{
ExportEventToCSV(exportFile, drillerEvent, exportSettings);
}
exportFile.Close();
}
else
{
QMessageBox::critical(nullptr, "Error Opening File", QString("Could not open file %1").arg(filename), QMessageBox::Ok);
}
}
size_t Aggregator::NumOfEventsAtFrame(FrameNumberType frame) const
{
size_t numFrames = m_frameToEventIndex.size();
if (numFrames == 1)
{
return m_events.size();
}
if (frame == numFrames - 1)
{
return m_events.size() - m_frameToEventIndex[frame]; // last frame
}
if (numFrames >= 2)
{
EventNumberType ftei1 = m_frameToEventIndex[frame + 1];
EventNumberType ftei0 = m_frameToEventIndex[frame];
size_t fte = (ftei1 - ftei0);
return fte;
}
return 0;
}
QString Aggregator::GetDialogTitle() const
{
return QString("%1 - %2").arg(GetName()).arg(GetInspectionFileName());
}
void Aggregator::FrameChanged(FrameNumberType frame)
{
size_t numFrames = m_frameToEventIndex.size();
if (numFrames)
{
EventNumberType targetEventIndex;
if (frame == numFrames - 1)
{
targetEventIndex = m_events.size() - 1;
}
else
{
targetEventIndex = m_frameToEventIndex[frame + 1];
// the current targetEventIndex belongs to the next frame "frame+1" minus 1
--targetEventIndex;
}
EventChanged(targetEventIndex);
}
}
void Aggregator::EventChanged(EventNumberType eventIndex)
{
if (eventIndex == m_currentEvent)
{
return;
}
// TODO: If we are at the end and we click at the start, we can start from the START as it's a known state
if (eventIndex > m_currentEvent)
{
// forward (m_currentEvent has already been executed so start currentEvent+1)
for (EventNumberType i = m_currentEvent + 1; i <= eventIndex; ++i)
{
m_events[i]->StepForward(this);
}
}
else if (eventIndex < m_currentEvent)
{
// backward (current event has executed so revert it
for (EventNumberType i = m_currentEvent; i > eventIndex; --i)
{
m_events[i]->StepBackward(this);
}
}
m_currentEvent = eventIndex;
emit OnDataCurrentEventChanged();
}
void Aggregator::ExportColumnDescriptorToCSV(AZ::IO::SystemFile& file, CSVExportSettings* exportSettings)
{
(void)file;
(void)exportSettings;
}
void Aggregator::ExportEventToCSV(AZ::IO::SystemFile& file, const DrillerEvent* drillerEvent, CSVExportSettings* exportSettings)
{
(void)file;
(void)drillerEvent;
(void)exportSettings;
}
void Aggregator::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
AggregatorSavedState::Reflect(context);
}
}
}