1f9b284de2
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
194 lines
8.6 KiB
C++
194 lines
8.6 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 <AzCore/Memory/SystemAllocator.h>
|
|
|
|
#include "TickBusOrderViewerSystemComponent.h"
|
|
|
|
#include <IGem.h>
|
|
#include <CryCommon/IConsole.h>
|
|
#include <AzCore/Component/ComponentApplicationBus.h>
|
|
#include <AzCore/Component/Entity.h>
|
|
#include <AzCore/Component/TickBus.h>
|
|
#include <AzCore/Module/ModuleManager.h>
|
|
#include <AzCore/std/string/conversions.h>
|
|
|
|
namespace TickBusOrderViewer
|
|
{
|
|
/**
|
|
* Helper function for finding an entity by ID. Checks both the component application, and loaded modules.
|
|
*/
|
|
AZ::Entity* FindEntity(const AZ::EntityId& entityId)
|
|
{
|
|
// First check the component application for the entity. This is where game, editor, and the root system entities live.
|
|
AZ::Entity* entity = nullptr;
|
|
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, entityId);
|
|
|
|
if (entity == nullptr)
|
|
{
|
|
// The entity was not in the component application's entity list, but it may be a system entity for a module.
|
|
AZ::ModuleManagerRequestBus::Broadcast(&AZ::ModuleManagerRequestBus::Events::EnumerateModules, [&entity, entityId](const AZ::ModuleData& moduleData)
|
|
{
|
|
AZ::Entity* moduleEntity = moduleData.GetEntity();
|
|
if (moduleEntity != nullptr && moduleEntity->GetId() == entityId)
|
|
{
|
|
entity = moduleEntity;
|
|
// The entity was found, so stop the enumeration.
|
|
return false;
|
|
}
|
|
// The matching entity is not in this module, keep looking through the rest of the modules.
|
|
return true;
|
|
});
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
/**
|
|
* Prints out all connected tickbus handlers, in the order they are ticked.
|
|
* @param entityId An optional entity ID used to only display handlers for components on this entity.
|
|
* displays all handlers if this is null.
|
|
*/
|
|
void PrintTickbusHandlers(AZ::EntityId* entityId)
|
|
{
|
|
AZStd::string tickbusPrintoutTitle = "TickBus handlers in tick order";
|
|
|
|
// If an entity ID was given, then update the printout title to contain information about that entity.
|
|
if (entityId != nullptr)
|
|
{
|
|
// Search for the passed in entity, to print out its name.
|
|
// Most people are going to think of their entities in terms of the name, and not the ID.
|
|
AZ::Entity* entity = FindEntity(*entityId);
|
|
|
|
if (entity != nullptr)
|
|
{
|
|
tickbusPrintoutTitle = AZStd::string::format("%s for entity \"%s\" %s",
|
|
tickbusPrintoutTitle.c_str(),
|
|
entity->GetName().c_str(),
|
|
entityId->ToString().c_str());
|
|
}
|
|
else
|
|
{
|
|
// If the entity wasn't found, then print out the ID at least.
|
|
tickbusPrintoutTitle = AZStd::string::format("%s for entity with id %s, entity could not be found",
|
|
tickbusPrintoutTitle.c_str(),
|
|
entityId->ToString().c_str());
|
|
}
|
|
|
|
}
|
|
AZ_Printf("TickBusOrderViewer", tickbusPrintoutTitle.c_str());
|
|
|
|
// Visit every tickbus handler. These are already sorted in the order they will be called.
|
|
AZ::TickBus::EnumerateHandlers([entityId](AZ::TickEvents* handler)
|
|
{
|
|
// If this handler is a component, then it will have an associated entity.
|
|
// This will allow printing additional, useful information for the user.
|
|
AZ::Component* component = azrtti_cast<AZ::Component*>(handler);
|
|
if (component && (entityId == nullptr || component->GetEntityId() == *entityId))
|
|
{
|
|
AZStd::string entityName = component->GetEntity() != nullptr ?
|
|
component->GetEntity()->GetName() : "[No entity found]";
|
|
// Print out everything about this tickbus listener that can help the user debug
|
|
// their tick ordering issue that caused them to call this.
|
|
// This includes:
|
|
// * The component's type as a string and a UUID.
|
|
// * The component's individual ID, which can be useful if the entity has duplicate components of the same type.
|
|
// * The associated entity's name, so the user can trace this tick handler to the entity.
|
|
// * The associated entity's ID, because entity names may not be unique.
|
|
AZ_Printf("TickBusOrderViewer", "\t%d - Entity \"%s\" %s, component %s %s with ID %u",
|
|
handler->GetTickOrder(),
|
|
entityName.c_str(),
|
|
component->GetEntityId().ToString().c_str(),
|
|
component->RTTI_GetTypeName(),
|
|
component->RTTI_GetType().ToString<AZStd::string>().c_str(),
|
|
component->GetId());
|
|
}
|
|
else if(entityId == nullptr)
|
|
{
|
|
// This handler wasn't a component, so print out as much information as can be gathered.
|
|
AZ_Printf("TickBusOrderViewer", "\t%d - Object with type %s %s",
|
|
handler->GetTickOrder(),
|
|
handler->RTTI_GetTypeName(),
|
|
handler->RTTI_GetType().ToString<AZStd::string>().c_str());
|
|
}
|
|
// Return true so the enumeration continues, all handles need to be checked.
|
|
return true;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Console command to print the handlers for the tickbus, in the order they are ticked.
|
|
*/
|
|
void PrintTickbusHandlerOrder(IConsoleCmdArgs* args)
|
|
{
|
|
// If only the command was supplied with no entity ID, then print out information for
|
|
// all tickbus handlers.
|
|
if (args == nullptr || args->GetArgCount() == 1)
|
|
{
|
|
PrintTickbusHandlers(nullptr);
|
|
return;
|
|
}
|
|
// If the passed in argument was not valid, print a warning and then the information for
|
|
// all tickbus handlers.
|
|
const char* entityIdString = args->GetArg(1);
|
|
if (entityIdString == nullptr)
|
|
{
|
|
AZ_Warning("TickBusOrderViewer", false, "print_tickbus_handlers was called with an invalid parameter, printing out all handlers.");
|
|
PrintTickbusHandlers(nullptr);
|
|
return;
|
|
}
|
|
// Convert the passed in string to an entity ID. If this fails, then the user will need
|
|
// to run the command again with a better formatted entity ID.
|
|
AZ::EntityId entityId(AZStd::stoull(AZStd::string(entityIdString)));
|
|
PrintTickbusHandlers(&entityId);
|
|
}
|
|
|
|
class TickBusOrderViewerModule
|
|
: public CryHooksModule
|
|
{
|
|
public:
|
|
AZ_RTTI(TickBusOrderViewerModule, "{DAE8B6D3-23ED-4547-9D0C-9F42CA812A06}", CryHooksModule);
|
|
AZ_CLASS_ALLOCATOR(TickBusOrderViewerModule, AZ::SystemAllocator, 0);
|
|
|
|
TickBusOrderViewerModule()
|
|
: CryHooksModule()
|
|
{
|
|
// Push results of [MyComponent]::CreateDescriptor() into m_descriptors here.
|
|
m_descriptors.insert(m_descriptors.end(), {
|
|
TickBusOrderViewerSystemComponent::CreateDescriptor(),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Add required SystemComponents to the SystemEntity.
|
|
*/
|
|
AZ::ComponentTypeList GetRequiredSystemComponents() const override
|
|
{
|
|
return AZ::ComponentTypeList{
|
|
azrtti_typeid<TickBusOrderViewerSystemComponent>(),
|
|
};
|
|
}
|
|
/**
|
|
* Override for CryHooksModule::OnCrySystemInitialized to add the console commands
|
|
* to print out tick bus information.
|
|
*/
|
|
void OnCrySystemInitialized(ISystem& system, const SSystemInitParams& initParams) override
|
|
{
|
|
CryHooksModule::OnCrySystemInitialized(system, initParams);
|
|
|
|
// Register the command to print the tickbus handlers out.
|
|
REGISTER_COMMAND("print_tickbus_handlers", &PrintTickbusHandlerOrder, 0, "Prints out the handlers for the tickbus in tick order. "
|
|
"With zero parameters, prints all handlers. With one parameter, it converts that to an entity ID and only prints components for that entity.");
|
|
}
|
|
};
|
|
}
|
|
|
|
// DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM
|
|
// The first parameter should be GemName_GemIdLower
|
|
// The second should be the fully qualified name of the class above
|
|
AZ_DECLARE_MODULE_CLASS(Gem_TickBusOrderViewer, TickBusOrderViewer::TickBusOrderViewerModule)
|