Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the MovieSystem so that it may be moved into a gem #18541

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Code/Editor/AnimationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class CAnimationContextPostRender
};

//////////////////////////////////////////////////////////////////////////
CAnimationContext::CAnimationContext()
CAnimationContext::CAnimationContext(IMovieSystem* movieSystem)
: m_movieSystem(movieSystem)
{
m_paused = 0;
m_playing = false;
Expand Down Expand Up @@ -128,9 +129,9 @@ CAnimationContext::~CAnimationContext()
//////////////////////////////////////////////////////////////////////////
void CAnimationContext::Init()
{
if (gEnv->pMovieSystem)
if (m_movieSystem)
{
gEnv->pMovieSystem->SetCallback(&s_movieCallback);
m_movieSystem->SetCallback(&s_movieCallback);
}

REGISTER_COMMAND("mov_goToFrameEditor", (ConsoleCommandFunc)GoToFrameCmd, 0, "Make a specified sequence go to a given frame time in the editor.");
Expand Down Expand Up @@ -346,9 +347,9 @@ void CAnimationContext::Pause()
SetRecordingInternal(false);
}

if (GetIEditor()->GetMovieSystem())
if (m_movieSystem)
{
GetIEditor()->GetMovieSystem()->Pause();
m_movieSystem->Pause();
}

if (m_pSequence)
Expand All @@ -367,9 +368,9 @@ void CAnimationContext::Resume()
SetRecordingInternal(true);
}

if (GetIEditor()->GetMovieSystem())
if (m_movieSystem)
{
GetIEditor()->GetMovieSystem()->Resume();
m_movieSystem->Resume();
}

if (m_pSequence)
Expand Down Expand Up @@ -414,39 +415,38 @@ void CAnimationContext::SetPlaying(bool playing)
m_recording = false;
SetRecordingInternal(false);

IMovieSystem* pMovieSystem = GetIEditor()->GetMovieSystem();
if (pMovieSystem)
if (m_movieSystem)
{
if (playing)
{
pMovieSystem->Resume();
m_movieSystem->Resume();

if (m_pSequence)
{
m_pSequence->Resume();

IMovieUser* pMovieUser = pMovieSystem->GetUser();
IMovieUser* pMovieUser = m_movieSystem->GetUser();

if (pMovieUser)
{
m_pSequence->BeginCutScene(true);
}
}
pMovieSystem->ResumeCutScenes();
m_movieSystem->ResumeCutScenes();
}
else
{
pMovieSystem->Pause();
m_movieSystem->Pause();

if (m_pSequence)
{
m_pSequence->Pause();
}

pMovieSystem->PauseCutScenes();
m_movieSystem->PauseCutScenes();
if (m_pSequence)
{
IMovieUser* pMovieUser = pMovieSystem->GetUser();
IMovieUser* pMovieUser = m_movieSystem->GetUser();

if (pMovieUser)
{
Expand Down Expand Up @@ -475,9 +475,9 @@ void CAnimationContext::Update()

if (!m_recording)
{
if (GetIEditor()->GetMovieSystem())
if (m_movieSystem)
{
GetIEditor()->GetMovieSystem()->StillUpdate();
m_movieSystem->StillUpdate();
}
}

Expand All @@ -495,10 +495,10 @@ void CAnimationContext::Update()

if (!m_recording)
{
if (GetIEditor()->GetMovieSystem())
if (m_movieSystem)
{
GetIEditor()->GetMovieSystem()->PreUpdate(frameDeltaTime);
GetIEditor()->GetMovieSystem()->PostUpdate(frameDeltaTime);
m_movieSystem->PreUpdate(frameDeltaTime);
m_movieSystem->PostUpdate(frameDeltaTime);
}
}
}
Expand Down Expand Up @@ -746,9 +746,9 @@ void CAnimationContext::OnEditorNotifyEvent(EEditorNotifyEvent event)

void CAnimationContext::SetRecordingInternal(bool enableRecording)
{
if (GetIEditor()->GetMovieSystem())
if (m_movieSystem)
{
GetIEditor()->GetMovieSystem()->SetRecording(enableRecording);
m_movieSystem->SetRecording(enableRecording);
}

if (m_pSequence)
Expand Down
6 changes: 4 additions & 2 deletions Code/Editor/AnimationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "Undo/Undo.h"
#include "TrackView/TrackViewSequenceManager.h"
#include <Range.h>
#include <IMovieSystem.h>
#include <AzToolsFramework/Prefab/PrefabPublicNotificationBus.h>

struct IMovieSystem;
class CTrackViewSequence;

/** CAnimationContext listener interface
Expand All @@ -44,7 +44,7 @@ class CAnimationContext
//////////////////////////////////////////////////////////////////////////
/** Constructor.
*/
CAnimationContext();
CAnimationContext(IMovieSystem* movieSystem);
~CAnimationContext();

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -261,6 +261,8 @@ class CAnimationContext
bool m_bPostRenderRegistered;
bool m_bForcingAnimation;

IMovieSystem* m_movieSystem;

//! Listeners
std::vector<IAnimationContextListener*> m_contextListeners;
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
Expand Down
9 changes: 8 additions & 1 deletion Code/Editor/CryEditDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "MainWindow.h"
#include "LevelFileDialog.h"
#include "Undo/Undo.h"
#include "Maestro/Bus/MovieSystemBus.h"

#include <Atom/RPI.Public/ViewportContext.h>
#include <Atom/RPI.Public/ViewportContextBus.h>
Expand Down Expand Up @@ -278,7 +279,13 @@ void CCryEditDoc::Load(TDocMultiArchive& /* arrXmlAr */, const QString& szFilena
}

GetIEditor()->Notify(eNotify_OnBeginSceneOpen);
GetIEditor()->GetMovieSystem()->RemoveAllSequences();

IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
if (movieSystem)
{
movieSystem->RemoveAllSequences();
}

{
// Start recording errors
Expand Down
55 changes: 45 additions & 10 deletions Code/Editor/GameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

// CryCommon
#include <CryCommon/MainThreadRenderRequestBus.h>
#include <Maestro/Bus/MovieSystemBus.h>

// Editor
#include "CryEdit.h"
Expand Down Expand Up @@ -242,7 +243,13 @@ CGameEngine::~CGameEngine()
{
AZ_POP_DISABLE_WARNING
GetIEditor()->UnregisterNotifyListener(this);
m_pISystem->GetIMovieSystem()->SetCallback(nullptr);

IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
if (movieSystem)
{
movieSystem->SetCallback(nullptr);
}

delete m_pISystem;
m_pISystem = nullptr;
Expand Down Expand Up @@ -407,9 +414,11 @@ AZ::Outcome<void, AZStd::string> CGameEngine::Init(

SetEditorCoreEnvironment(gEnv);

if (gEnv && gEnv->pMovieSystem)
IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
if (movieSystem)
{
gEnv->pMovieSystem->EnablePhysicsEvents(m_bSimulationMode);
movieSystem->EnablePhysicsEvents(m_bSimulationMode);
}

CLogFile::AboutSystem();
Expand Down Expand Up @@ -497,10 +506,21 @@ void CGameEngine::SwitchToInGame()

GetIEditor()->Notify(eNotify_OnBeginGameMode);

m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(true);
IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
if (movieSystem)
{
movieSystem->EnablePhysicsEvents(true);
}

m_bInGameMode = true;

m_pISystem->GetIMovieSystem()->Reset(true, false);
if (movieSystem)
{
constexpr bool playOnReset = true;
constexpr bool seekToStart = false;
movieSystem->Reset(playOnReset, seekToStart);
}

// Transition to runtime entity context.
AzToolsFramework::EditorEntityContextRequestBus::Broadcast(&AzToolsFramework::EditorEntityContextRequestBus::Events::StartPlayInEditor);
Expand All @@ -522,15 +542,25 @@ void CGameEngine::SwitchToInEditor()
AzToolsFramework::EditorEntityContextRequestBus::Broadcast(&AzToolsFramework::EditorEntityContextRequestBus::Events::StopPlayInEditor);

// Reset movie system
for (int i = m_pISystem->GetIMovieSystem()->GetNumPlayingSequences(); --i >= 0;)
IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
if (movieSystem)
{
m_pISystem->GetIMovieSystem()->GetPlayingSequence(i)->Deactivate();
for (int i = movieSystem->GetNumPlayingSequences(); --i >= 0;)
{
movieSystem->GetPlayingSequence(i)->Deactivate();
}
constexpr bool playOnReset = false;
constexpr bool seekToStart = false;
movieSystem->Reset(playOnReset, seekToStart);
}
m_pISystem->GetIMovieSystem()->Reset(false, false);

CViewport* pGameViewport = GetIEditor()->GetViewManager()->GetGameViewport();

m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(m_bSimulationMode);
if (movieSystem)
{
movieSystem->EnablePhysicsEvents(m_bSimulationMode);
}

m_bInGameMode = false;

Expand Down Expand Up @@ -634,7 +664,12 @@ void CGameEngine::SetSimulationMode(bool enabled, bool bOnlyPhysics)
return;
}

m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(enabled);
IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
if (movieSystem)
{
movieSystem->EnablePhysicsEvents(enabled);
}

if (enabled)
{
Expand Down
1 change: 0 additions & 1 deletion Code/Editor/IEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ struct IEditor
virtual Editor::EditorQtApplication* GetEditorQtApplication() = 0;
virtual const QColor& GetColorByName(const QString& name) = 0;

virtual struct IMovieSystem* GetMovieSystem() = 0;
virtual class CPluginManager* GetPluginManager() = 0;
virtual class CViewManager* GetViewManager() = 0;
virtual class CViewport* GetActiveView() = 0;
Expand Down
7 changes: 6 additions & 1 deletion Code/Editor/IEditorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

#include "Core/QtEditorApplication.h" // for Editor::EditorQtApplication

#include <CryCommon/Maestro/Bus/MovieSystemBus.h>

static CCryEditDoc * theDocument;
#include <QMimeData>
#include <QMessageBox>
Expand Down Expand Up @@ -124,7 +126,10 @@ CEditorImpl::CEditorImpl()
m_pUndoManager = new CUndoManager;
m_pToolBoxManager = new CToolBoxManager;
m_pSequenceManager = new CTrackViewSequenceManager;
m_pAnimationContext = new CAnimationContext;

IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
m_pAnimationContext = new CAnimationContext(movieSystem);
lsemp3d marked this conversation as resolved.
Show resolved Hide resolved

DetectVersion();
RegisterTools();
Expand Down
9 changes: 0 additions & 9 deletions Code/Editor/IEditorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@ class CEditorImpl
const QColor& GetColorByName(const QString& name) override;

//////////////////////////////////////////////////////////////////////////
IMovieSystem* GetMovieSystem() override
{
if (m_pSystem)
{
return m_pSystem->GetIMovieSystem();
}
return nullptr;
};

CPluginManager* GetPluginManager() override { return m_pPluginManager; }
CViewManager* GetViewManager() override;
CViewport* GetActiveView() override;
Expand Down
40 changes: 22 additions & 18 deletions Code/Editor/SelectLightAnimationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// CryCommon
#include <CryCommon/Maestro/Types/AnimNodeType.h> // for AnimNodeType
#include <CryCommon/Maestro/Bus/MovieSystemBus.h>

//////////////////////////////////////////////////////////////////////////
CSelectLightAnimationDialog::CSelectLightAnimationDialog(QWidget* pParent)
Expand All @@ -34,30 +35,33 @@ void CSelectLightAnimationDialog::OnInitDialog()
//////////////////////////////////////////////////////////////////////////
void CSelectLightAnimationDialog::GetItems(std::vector<SItem>& outItems)
{
IMovieSystem* pMovieSystem = GetIEditor()->GetMovieSystem();
if (pMovieSystem)
IMovieSystem* movieSystem = nullptr;
Maestro::MovieSystemRequestBus::BroadcastResult(movieSystem, &Maestro::MovieSystemRequestBus::Events::GetMovieSystem);
if (!movieSystem)
{
for (int i = 0; i < pMovieSystem->GetNumSequences(); ++i)
return;
}

for (int i = 0; i < movieSystem->GetNumSequences(); ++i)
{
IAnimSequence* pSequence = movieSystem->GetSequence(i);
if ((pSequence->GetFlags() & IAnimSequence::eSeqFlags_LightAnimationSet) == 0)
{
IAnimSequence* pSequence = pMovieSystem->GetSequence(i);
if ((pSequence->GetFlags() & IAnimSequence::eSeqFlags_LightAnimationSet) == 0)
{
continue;
}
continue;
}

for (int k = 0; k < pSequence->GetNodeCount(); ++k)
for (int k = 0; k < pSequence->GetNodeCount(); ++k)
{
assert(pSequence->GetNode(k)->GetType() == AnimNodeType::Light);
lsemp3d marked this conversation as resolved.
Show resolved Hide resolved
if (pSequence->GetNode(k)->GetType() != AnimNodeType::Light)
{
assert(pSequence->GetNode(k)->GetType() == AnimNodeType::Light);
if (pSequence->GetNode(k)->GetType() != AnimNodeType::Light)
{
continue;
}
SItem item;
item.name = pSequence->GetNode(k)->GetName();
outItems.push_back(item);
continue;
}
return;
SItem item;
item.name = pSequence->GetNode(k)->GetName();
outItems.push_back(item);
}
return;
}
}

Expand Down
Loading
Loading