From 41dbf69b46327089e95e74557f17fc42075115b0 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Fri, 1 Oct 2021 09:59:11 +0200 Subject: [PATCH] Animation Editor: Move real-time plugin updates from SystemComponent to the main window (#4384) Untangled the system component from editor ticking dependencies and moved it to the main window which is the more logical place for it. Signed-off-by: Benjamin Jillich --- .../EMStudioSDK/Source/MainWindow.cpp | 60 +++++++++++++++-- .../EMStudioSDK/Source/MainWindow.h | 14 +++- .../Integration/System/SystemComponent.cpp | 65 ++----------------- .../Integration/System/SystemComponent.h | 1 - 4 files changed, 74 insertions(+), 66 deletions(-) diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp index 8ca4e1de81..06088790d9 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp @@ -69,6 +69,9 @@ AZ_PUSH_DISABLE_WARNING(4267, "-Wconversion") AZ_POP_DISABLE_WARNING #include +#include +#include + namespace EMStudio { class SaveDirtyWorkspaceCallback @@ -257,10 +260,10 @@ namespace EMStudio m_saveWorkspaceCallback = nullptr; } - - // destructor MainWindow::~MainWindow() { + DisableUpdatingPlugins(); + if (m_nativeEventFilter) { QAbstractEventDispatcher::instance()->removeNativeEventFilter(m_nativeEventFilter); @@ -577,6 +580,8 @@ namespace EMStudio AZ_Assert(!m_nativeEventFilter, "Double initialization?"); m_nativeEventFilter = new NativeEventFilter(this); QAbstractEventDispatcher::instance()->installNativeEventFilter(m_nativeEventFilter); + + EnableUpdatingPlugins(); } MainWindow::MainWindowCommandManagerCallback::MainWindowCommandManagerCallback() @@ -2813,6 +2818,53 @@ namespace EMStudio } } -} // namespace EMStudio + void MainWindow::UpdatePlugins(float timeDelta) + { + EMStudio::PluginManager* pluginManager = EMStudio::GetPluginManager(); + if (!pluginManager) + { + return; + } -#include + const size_t numPlugins = pluginManager->GetNumActivePlugins(); + for (size_t i = 0; i < numPlugins; ++i) + { + EMStudio::EMStudioPlugin* plugin = pluginManager->GetActivePlugin(i); + plugin->ProcessFrame(timeDelta); + } + } + + void MainWindow::EnableUpdatingPlugins() + { + AZ::TickBus::Handler::BusConnect(); + } + + void MainWindow::DisableUpdatingPlugins() + { + AZ::TickBus::Handler::BusDisconnect(); + } + + void MainWindow::OnTick(float delta, AZ::ScriptTimePoint timePoint) + { + AZ_UNUSED(timePoint); + + // Check if we are in game mode. + IEditor* editor = nullptr; + AzToolsFramework::EditorRequestBus::BroadcastResult(editor, &AzToolsFramework::EditorRequests::GetEditor); + const bool inGameMode = editor ? editor->IsInGameMode() : false; + + // Update all the animation editor plugins (redraw viewports, timeline, and graph windows etc). + // But only update this when the main window is visible and we are in game mode. + const bool isEditorActive = !visibleRegion().isEmpty() && !inGameMode; + + if (isEditorActive) + { + UpdatePlugins(delta); + } + } + + int MainWindow::GetTickOrder() + { + return AZ::TICK_UI; + } +} // namespace EMStudio diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h index a11f11c6a8..585101f7d2 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h @@ -9,6 +9,7 @@ #pragma once #if !defined(Q_MOC_RUN) +#include #include #include #include @@ -99,8 +100,9 @@ namespace EMStudio : public AzQtComponents::DockMainWindow , private PluginOptionsNotificationsBus::Router , public EMotionFX::ActorEditorRequestBus::Handler + , private AZ::TickBus::Handler { - Q_OBJECT + Q_OBJECT // AUTOMOC MCORE_MEMORYOBJECTCATEGORY(MainWindow, MCore::MCORE_DEFAULT_ALIGNMENT, MEMCATEGORY_EMSTUDIOSDK) public: @@ -304,6 +306,16 @@ namespace EMStudio MainWindowCommandManagerCallback m_mainWindowCommandManagerCallback; + private: + // AZ::TickBus::Handler overrides + void OnTick(float delta, AZ::ScriptTimePoint timePoint) override; + int GetTickOrder() override; + + void UpdatePlugins(float timeDelta); + + void EnableUpdatingPlugins(); + void DisableUpdatingPlugins(); + public slots: void OnFileOpenActor(); void OnFileSaveSelectedActors(); diff --git a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp index 56c22bb1ff..0f87c488b9 100644 --- a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp @@ -62,7 +62,6 @@ #if defined(EMOTIONFXANIMATION_EDITOR) // EMFX tools / editor includes -# include // Qt # include // EMStudio tools and main window registration @@ -603,31 +602,6 @@ namespace EMotionFX #endif } - ////////////////////////////////////////////////////////////////////////// -#if defined (EMOTIONFXANIMATION_EDITOR) - void SystemComponent::UpdateAnimationEditorPlugins(float delta) - { - if (!EMStudio::GetManager()) - { - return; - } - - EMStudio::PluginManager* pluginManager = EMStudio::GetPluginManager(); - if (!pluginManager) - { - return; - } - - // Process the plugins. - const size_t numPlugins = pluginManager->GetNumActivePlugins(); - for (size_t i = 0; i < numPlugins; ++i) - { - EMStudio::EMStudioPlugin* plugin = pluginManager->GetActivePlugin(i); - plugin->ProcessFrame(delta); - } - } -#endif - ////////////////////////////////////////////////////////////////////////// void SystemComponent::OnTick(float delta, AZ::ScriptTimePoint timePoint) { @@ -635,47 +609,18 @@ namespace EMotionFX #if defined (EMOTIONFXANIMATION_EDITOR) AZ_UNUSED(delta); - const float realDelta = m_updateTimer.StampAndGetDeltaTimeInSeconds(); + delta = m_updateTimer.StampAndGetDeltaTimeInSeconds(); +#endif // Flush events prior to updating EMotion FX. ActorNotificationBus::ExecuteQueuedEvents(); - if (CVars::emfx_updateEnabled) - { - // Main EMotionFX runtime update. - GetEMotionFX().Update(realDelta); - } - - // Check if we are in game mode. - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - const bool inGameMode = editor ? editor->IsInGameMode() : false; - - // Update all the animation editor plugins (redraw viewports, timeline, and graph windows etc). - // But only update this when the main window is visible and we are in game mode. - const bool isEditorActive = - EMotionFX::GetEMotionFX().GetIsInEditorMode() && - EMStudio::GetManager() && - EMStudio::HasMainWindow() && - !EMStudio::GetMainWindow()->visibleRegion().isEmpty() && - !inGameMode; - - if (isEditorActive) - { - UpdateAnimationEditorPlugins(realDelta); - } -#else - // Flush events prior to updating EMotion FX. - ActorNotificationBus::ExecuteQueuedEvents(); - if (CVars::emfx_updateEnabled) { // Main EMotionFX runtime update. GetEMotionFX().Update(delta); } -#endif - const float timeDelta = delta; const ActorManager* actorManager = GetEMotionFX().GetActorManager(); const size_t numActorInstances = actorManager->GetNumActorInstances(); for (size_t i = 0; i < numActorInstances; ++i) @@ -704,7 +649,7 @@ namespace EMotionFX // If we have a physics controller. if (hasCustomMotionExtractionController || hasPhysicsController) { - const float deltaTimeInv = (timeDelta > 0.0f) ? (1.0f / timeDelta) : 0.0f; + const float deltaTimeInv = (delta > 0.0f) ? (1.0f / delta) : 0.0f; AZ::Transform currentTransform = AZ::Transform::CreateIdentity(); AZ::TransformBus::EventResult(currentTransform, entityId, &AZ::TransformBus::Events::GetWorldTM); @@ -719,7 +664,7 @@ namespace EMotionFX } else if (hasCustomMotionExtractionController) { - MotionExtractionRequestBus::Event(entityId, &MotionExtractionRequestBus::Events::ExtractMotion, positionDelta, timeDelta); + MotionExtractionRequestBus::Event(entityId, &MotionExtractionRequestBus::Events::ExtractMotion, positionDelta, delta); AZ::TransformBus::EventResult(currentTransform, entityId, &AZ::TransformBus::Events::GetWorldTM); } @@ -884,7 +829,7 @@ namespace EMotionFX // Register EMotionFX window with the main editor. AzToolsFramework::ViewPaneOptions emotionFXWindowOptions; - emotionFXWindowOptions.isPreview = true; + emotionFXWindowOptions.isPreview = false; emotionFXWindowOptions.isDeletable = true; emotionFXWindowOptions.isDockable = false; #if AZ_TRAIT_EMOTIONFX_MAIN_WINDOW_DETACHED diff --git a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h index a716f0aa9b..5e30820ca3 100644 --- a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h +++ b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h @@ -108,7 +108,6 @@ namespace EMotionFX void SetMediaRoot(const char* alias); #if defined (EMOTIONFXANIMATION_EDITOR) - void UpdateAnimationEditorPlugins(float delta); void NotifyRegisterViews() override; bool IsSystemActive(EditorAnimationSystemRequests::AnimationSystem systemType) override;