77/*
88
99This is taken as-is (more or less) from MovieSceneCaptureDialogModule.cpp
10- to automate sequencer capturing
10+ to automate sequencer capturing. The only relevant implementation is the support
11+ for a queue of UMovieSceneCapture objects
1112
1213*/
1314
@@ -16,44 +17,61 @@ to automate sequencer capturing
1617#include " Slate/SceneViewport.h"
1718#include " AutomatedLevelSequenceCapture.h"
1819
19- struct FInEditorCapture : TSharedFromThis<FInEditorCapture >
20+ struct FInEditorMultiCapture : TSharedFromThis<FInEditorMultiCapture >
2021{
2122
22- static TWeakPtr<FInEditorCapture> CreateInEditorCapture ( UMovieSceneCapture* InCaptureObject )
23+ static TWeakPtr<FInEditorMultiCapture> CreateInEditorMultiCapture (TArray< UMovieSceneCapture*> InCaptureObjects )
2324 {
2425 // FInEditorCapture owns itself, so should only be kept alive by itself, or a pinned (=> temporary) weakptr
25- FInEditorCapture* Capture = new FInEditorCapture;
26- Capture->Start (InCaptureObject);
26+ FInEditorMultiCapture* Capture = new FInEditorMultiCapture;
27+ Capture->CaptureObjects = InCaptureObjects;
28+ for (UMovieSceneCapture *SceneCapture : Capture->CaptureObjects )
29+ {
30+ SceneCapture->AddToRoot ();
31+ }
32+ Capture->Dequeue ();
2733 return Capture->AsShared ();
2834 }
2935
30- UWorld* GetWorld () const
36+ private:
37+ FInEditorMultiCapture ()
3138 {
32- return CapturingFromWorld;
39+ CapturingFromWorld = nullptr ;
3340 }
3441
35- private:
36- FInEditorCapture ()
42+ void Die ()
3743 {
38- CapturingFromWorld = nullptr ;
39- CaptureObject = nullptr ;
44+ for (UMovieSceneCapture *SceneCapture : CaptureObjects)
45+ {
46+ SceneCapture->RemoveFromRoot ();
47+ }
48+ OnlyStrongReference = nullptr ;
4049 }
4150
42- void Start (UMovieSceneCapture* InCaptureObject )
51+ void Dequeue ( )
4352 {
44- check (InCaptureObject);
53+
54+ if (CaptureObjects.Num () < 1 )
55+ {
56+ Die ();
57+ return ;
58+ }
59+
60+ CurrentCaptureObject = CaptureObjects[0 ];
61+
62+ check (CurrentCaptureObject);
4563
4664 CapturingFromWorld = nullptr ;
47- OnlyStrongReference = MakeShareable (this );
4865
49- CaptureObject = InCaptureObject;
66+ if (!OnlyStrongReference.IsValid ())
67+ OnlyStrongReference = MakeShareable (this );
5068
5169 ULevelEditorPlaySettings* PlayInEditorSettings = GetMutableDefault<ULevelEditorPlaySettings>();
5270
5371 bScreenMessagesWereEnabled = GAreScreenMessagesEnabled;
5472 GAreScreenMessagesEnabled = false ;
5573
56- if (!InCaptureObject ->Settings .bEnableTextureStreaming )
74+ if (!CurrentCaptureObject ->Settings .bEnableTextureStreaming )
5775 {
5876 const int32 UndefinedTexturePoolSize = -1 ;
5977 IConsoleVariable* CVarStreamingPoolSize = IConsoleManager::Get ().FindConsoleVariable (TEXT (" r.Streaming.PoolSize" ));
@@ -71,14 +89,18 @@ struct FInEditorCapture : TSharedFromThis<FInEditorCapture>
7189 }
7290 }
7391
92+ // cleanup from previous run
93+ BackedUpPlaySettings.Empty ();
94+
7495 FObjectWriter (PlayInEditorSettings, BackedUpPlaySettings);
96+
7597 OverridePlaySettings (PlayInEditorSettings);
7698
77- CaptureObject ->AddToRoot ();
78- CaptureObject ->OnCaptureFinished ().AddRaw (this , &FInEditorCapture ::OnEnd);
99+ // CurrentCaptureObject ->AddToRoot();
100+ CurrentCaptureObject ->OnCaptureFinished ().AddRaw (this , &FInEditorMultiCapture ::OnEnd);
79101
80- UGameViewportClient::OnViewportCreated ().AddRaw (this , &FInEditorCapture ::OnStart);
81- FEditorDelegates::EndPIE.AddRaw (this , &FInEditorCapture ::OnEndPIE);
102+ UGameViewportClient::OnViewportCreated ().AddRaw (this , &FInEditorMultiCapture ::OnStart);
103+ FEditorDelegates::EndPIE.AddRaw (this , &FInEditorMultiCapture ::OnEndPIE);
82104
83105 FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice ();
84106 if (AudioDevice != nullptr )
@@ -87,12 +109,19 @@ struct FInEditorCapture : TSharedFromThis<FInEditorCapture>
87109 AudioDevice->SetTransientMasterVolume (0 .0f );
88110 }
89111
112+ // play at the next tick
113+ FTicker::GetCoreTicker ().AddTicker (FTickerDelegate::CreateRaw (this , &FInEditorMultiCapture::PlaySession), 0 );
114+ }
115+
116+ bool PlaySession (float DeltaTime)
117+ {
90118 GEditor->RequestPlaySession (true , nullptr , false );
119+ return false ;
91120 }
92121
93122 void OverridePlaySettings (ULevelEditorPlaySettings* PlayInEditorSettings)
94123 {
95- const FMovieSceneCaptureSettings& Settings = CaptureObject ->GetSettings ();
124+ const FMovieSceneCaptureSettings& Settings = CurrentCaptureObject ->GetSettings ();
96125
97126 PlayInEditorSettings->NewWindowWidth = Settings.Resolution .ResX ;
98127 PlayInEditorSettings->NewWindowHeight = Settings.Resolution .ResY ;
@@ -150,7 +179,7 @@ struct FInEditorCapture : TSharedFromThis<FInEditorCapture>
150179
151180 TSharedPtr<SWindow> Window = SlatePlayInEditorSession->SlatePlayInEditorWindow .Pin ();
152181
153- const FMovieSceneCaptureSettings& Settings = CaptureObject ->GetSettings ();
182+ const FMovieSceneCaptureSettings& Settings = CurrentCaptureObject ->GetSettings ();
154183
155184 SlatePlayInEditorSession->SlatePlayInEditorWindowViewport ->SetViewportSize (Settings.Resolution .ResX , Settings.Resolution .ResY );
156185
@@ -171,30 +200,29 @@ struct FInEditorCapture : TSharedFromThis<FInEditorCapture>
171200 FVector2D PreviewWindowPosition (50 , 50 );
172201 Window->ReshapeWindow (PreviewWindowPosition, PreviewWindowSize);
173202
174- if (CaptureObject ->Settings .GameModeOverride != nullptr )
203+ if (CurrentCaptureObject ->Settings .GameModeOverride != nullptr )
175204 {
176205 CachedGameMode = CapturingFromWorld->GetWorldSettings ()->DefaultGameMode ;
177- CapturingFromWorld->GetWorldSettings ()->DefaultGameMode = CaptureObject ->Settings .GameModeOverride ;
206+ CapturingFromWorld->GetWorldSettings ()->DefaultGameMode = CurrentCaptureObject ->Settings .GameModeOverride ;
178207 }
179208
180- CaptureObject ->Initialize (SlatePlayInEditorSession->SlatePlayInEditorWindowViewport , Context.PIEInstance );
209+ CurrentCaptureObject ->Initialize (SlatePlayInEditorSession->SlatePlayInEditorWindowViewport , Context.PIEInstance );
181210 }
182211 return ;
183212 }
184213 }
185214
186- // todo: error?
187215 }
188216
189217 void Shutdown ()
190218 {
191219 FEditorDelegates::EndPIE.RemoveAll (this );
192220 UGameViewportClient::OnViewportCreated ().RemoveAll (this );
193- CaptureObject ->OnCaptureFinished ().RemoveAll (this );
221+ CurrentCaptureObject ->OnCaptureFinished ().RemoveAll (this );
194222
195223 GAreScreenMessagesEnabled = bScreenMessagesWereEnabled;
196224
197- if (!CaptureObject ->Settings .bEnableTextureStreaming )
225+ if (!CurrentCaptureObject ->Settings .bEnableTextureStreaming )
198226 {
199227 IConsoleVariable* CVarStreamingPoolSize = IConsoleManager::Get ().FindConsoleVariable (TEXT (" r.Streaming.PoolSize" ));
200228 if (CVarStreamingPoolSize)
@@ -209,7 +237,7 @@ struct FInEditorCapture : TSharedFromThis<FInEditorCapture>
209237 }
210238 }
211239
212- if (CaptureObject ->Settings .GameModeOverride != nullptr )
240+ if (CurrentCaptureObject ->Settings .GameModeOverride != nullptr )
213241 {
214242 CapturingFromWorld->GetWorldSettings ()->DefaultGameMode = CachedGameMode;
215243 }
@@ -222,46 +250,93 @@ struct FInEditorCapture : TSharedFromThis<FInEditorCapture>
222250 AudioDevice->SetTransientMasterVolume (TransientMasterVolume);
223251 }
224252
225- CaptureObject ->Close ();
226- CaptureObject ->RemoveFromRoot ();
253+ CurrentCaptureObject ->Close ();
254+ // CurrentCaptureObject ->RemoveFromRoot();
227255
228256 }
229257 void OnEndPIE (bool bIsSimulating)
230258 {
231259 Shutdown ();
232- OnlyStrongReference = nullptr ;
260+
261+ Die ();
262+ }
263+
264+ void NextCapture (bool bIsSimulating)
265+ {
266+
267+ FEditorDelegates::EndPIE.RemoveAll (this );
268+ // remove item from the TArray;
269+ CaptureObjects.RemoveAt (0 );
270+
271+ if (CaptureObjects.Num () > 0 )
272+ {
273+ Dequeue ();
274+ }
275+ else
276+ {
277+ Die ();
278+ }
233279 }
234280
235281 void OnEnd ()
236282 {
237283 Shutdown ();
238- OnlyStrongReference = nullptr ;
239284
285+ FEditorDelegates::EndPIE.AddRaw (this , &FInEditorMultiCapture::NextCapture);
240286 GEditor->RequestEndPlayMap ();
241287 }
242288
243- TSharedPtr<FInEditorCapture > OnlyStrongReference;
289+ TSharedPtr<FInEditorMultiCapture > OnlyStrongReference;
244290 UWorld* CapturingFromWorld;
245291
246292 bool bScreenMessagesWereEnabled;
247293 float TransientMasterVolume;
248294 int32 BackedUpStreamingPoolSize;
249295 int32 BackedUpUseFixedPoolSize;
250296 TArray<uint8> BackedUpPlaySettings;
251- UMovieSceneCapture* CaptureObject ;
297+ UMovieSceneCapture* CurrentCaptureObject ;
252298
253299 TSubclassOf<AGameModeBase> CachedGameMode;
300+ TArray<UMovieSceneCapture*> CaptureObjects;
254301};
255302
256- PyObject *py_ue_in_editor_capture (ue_PyUObject * self, PyObject * args)
303+ PyObject *py_unreal_engine_in_editor_capture (PyObject * self, PyObject * args)
257304{
258- ue_py_check (self) ;
305+ PyObject *py_scene_captures ;
259306
260- UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
307+ if (!PyArg_ParseTuple (args, " O:in_editor_capture" , &py_scene_captures))
308+ {
309+ return nullptr ;
310+ }
311+
312+ TArray<UMovieSceneCapture *> Captures;
313+
314+ UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(py_scene_captures);
261315 if (!capture)
262- return PyErr_Format (PyExc_Exception, " uobject is not a UMovieSceneCapture" );
316+ {
317+ PyObject *py_iter = PyObject_GetIter (py_scene_captures);
318+ if (!py_iter)
319+ {
320+ return PyErr_Format (PyExc_Exception, " argument is not a UMovieSceneCapture or an iterable of UMovieSceneCapture" );
321+ }
322+ while (PyObject *py_item = PyIter_Next (py_iter))
323+ {
324+ capture = ue_py_check_type<UMovieSceneCapture>(py_item);
325+ if (!capture)
326+ {
327+ Py_DECREF (py_iter);
328+ return PyErr_Format (PyExc_Exception, " argument is not an iterable of UMovieSceneCapture" );
329+ }
330+ Captures.Add (capture);
331+ }
332+ Py_DECREF (py_iter);
333+ }
334+ else
335+ {
336+ Captures.Add (capture);
337+ }
263338
264- FInEditorCapture::CreateInEditorCapture (capture );
339+ FInEditorMultiCapture::CreateInEditorMultiCapture (Captures );
265340
266341 Py_RETURN_NONE;
267342}
0 commit comments