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 <jillich@amazon.com>
This commit is contained in:
+56
-4
@@ -69,6 +69,9 @@ AZ_PUSH_DISABLE_WARNING(4267, "-Wconversion")
|
||||
AZ_POP_DISABLE_WARNING
|
||||
#include <LyViewPaneNames.h>
|
||||
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <IEditor.h>
|
||||
|
||||
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 <EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/moc_MainWindow.cpp>
|
||||
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
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <EMotionStudio/EMStudioSDK/Source/EMStudioConfig.h>
|
||||
#include <EMotionStudio/EMStudioSDK/Source/GUIOptions.h>
|
||||
#include <EMotionStudio/EMStudioSDK/Source/PluginOptionsBus.h>
|
||||
@@ -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();
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
|
||||
|
||||
#if defined(EMOTIONFXANIMATION_EDITOR) // EMFX tools / editor includes
|
||||
# include <IEditor.h>
|
||||
// Qt
|
||||
# include <QtGui/QSurfaceFormat>
|
||||
// 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user