Skip to content

Commit 9920aac

Browse files
author
Roberto De Ioris
committed
added bytes serialization
1 parent b665a9c commit 9920aac

File tree

7 files changed

+132
-18
lines changed

7 files changed

+132
-18
lines changed

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ PyObject *py_unreal_engine_editor_play_in_viewport(PyObject * self, PyObject * a
7070

7171
}
7272

73+
PyObject *py_unreal_engine_request_play_session(PyObject * self, PyObject * args)
74+
{
75+
76+
PyObject *py_at_player_start = nullptr;
77+
PyObject *py_simulate_in_editor = nullptr;
78+
79+
if (!PyArg_ParseTuple(args, "|OO:request_play_session", &py_at_player_start, &py_simulate_in_editor))
80+
{
81+
return nullptr;
82+
}
83+
84+
bool bAtPlayerStart = py_at_player_start && PyObject_IsTrue(py_at_player_start);
85+
bool bSimulate = py_simulate_in_editor && PyObject_IsTrue(py_simulate_in_editor);
86+
87+
GEditor->RequestPlaySession(bAtPlayerStart, nullptr, bSimulate);
88+
89+
Py_RETURN_NONE;
90+
91+
}
92+
7393

7494
PyObject *py_unreal_engine_get_editor_world(PyObject * self, PyObject * args)
7595
{
@@ -396,7 +416,7 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args)
396416
char * filename = PyString_AsString(PyObject_Str(assetsObject));
397417
#endif
398418
files.Add(UTF8_TO_TCHAR(filename));
399-
}
419+
}
400420
else
401421
{
402422
return PyErr_Format(PyExc_Exception, "Not a string nor valid list of string");

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,6 @@ PyObject *py_unreal_engine_play_preview_sound(PyObject *, PyObject *);
118118
PyObject *py_unreal_engine_register_settings(PyObject *, PyObject *);
119119
PyObject *py_unreal_engine_show_viewer(PyObject *, PyObject *);
120120
PyObject *py_unreal_engine_unregister_settings(PyObject *, PyObject *);
121+
122+
PyObject *py_unreal_engine_request_play_session(PyObject *, PyObject *);
121123
#endif

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ static PyMethodDef unreal_engine_methods[] = {
360360
{ "play_sound", py_unreal_engine_play_sound, METH_VARARGS, "" },
361361
#if WITH_EDITOR
362362
{ "editor_play_in_viewport", py_unreal_engine_editor_play_in_viewport, METH_VARARGS, "" },
363+
{ "request_play_session", py_unreal_engine_request_play_session, METH_VARARGS, "" },
363364
{ "get_editor_pie_game_viewport_client", py_unreal_engine_get_editor_pie_game_viewport_client, METH_VARARGS, "" },
364365
{ "editor_get_active_viewport_screenshot", py_unreal_engine_editor_get_active_viewport_screenshot, METH_VARARGS, "" },
365366
{ "editor_get_pie_viewport_screenshot", py_unreal_engine_editor_get_pie_viewport_screenshot, METH_VARARGS, "" },
@@ -799,6 +800,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
799800
{ "capture_initialize", (PyCFunction)py_ue_capture_initialize, METH_VARARGS, "" },
800801
{ "capture_start", (PyCFunction)py_ue_capture_start, METH_VARARGS, "" },
801802
{ "capture_stop", (PyCFunction)py_ue_capture_stop, METH_VARARGS, "" },
803+
{ "capture_load_from_config", (PyCFunction)py_ue_capture_load_from_config, METH_VARARGS, "" },
802804

803805
// Pawn
804806
{ "get_controller", (PyCFunction)py_ue_pawn_get_controller, METH_VARARGS, "" },
@@ -953,6 +955,11 @@ static PyMethodDef ue_PyUObject_methods[] = {
953955
#if ENGINE_MINOR_VERSION >= 15
954956
{ "enum_user_defined_names", (PyCFunction)py_ue_enum_user_defined_names, METH_VARARGS, "" },
955957
#endif
958+
959+
// serialization
960+
{ "to_bytes", (PyCFunction)py_ue_to_bytes, METH_VARARGS, "" },
961+
{ "to_bytearray", (PyCFunction)py_ue_to_bytearray, METH_VARARGS, "" },
962+
{ "from_bytes", (PyCFunction)py_ue_from_bytes, METH_VARARGS, "" },
956963
{ NULL } /* Sentinel */
957964
};
958965

Source/UnrealEnginePython/Private/UObject/UEPyCapture.cpp

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,92 @@
33
#include "Runtime/MovieSceneCapture/Public/MovieSceneCapture.h"
44

55

6-
PyObject *py_ue_capture_initialize(ue_PyUObject * self, PyObject * args) {
6+
PyObject *py_ue_capture_initialize(ue_PyUObject * self, PyObject * args)
7+
{
78

89
ue_py_check(self);
910

10-
PyObject *py_widget;
11+
PyObject *py_widget = nullptr;
1112

12-
if (!PyArg_ParseTuple(args, "O", &py_widget)) {
13+
if (!PyArg_ParseTuple(args, "|O:capture_initialize", &py_widget))
14+
{
1315
return nullptr;
1416
}
1517

1618
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
1719
if (!capture)
1820
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneCapture");
1921

20-
ue_PySWidget *s_widget = py_ue_is_swidget(py_widget);
21-
if (!s_widget)
22-
return PyErr_Format(PyExc_Exception, "argument is not a SWidget");
23-
2422
#if WITH_EDITOR
25-
if (s_widget->s_widget->GetType().Compare(FName("SPythonEditorViewport")) == 0) {
26-
TSharedRef<SPythonEditorViewport> s_viewport = StaticCastSharedRef<SPythonEditorViewport>(s_widget->s_widget);
27-
capture->Initialize(s_viewport->GetSceneViewport());
28-
capture->StartWarmup();
23+
if (py_widget)
24+
{
25+
ue_PySWidget *s_widget = py_ue_is_swidget(py_widget);
26+
if (!s_widget)
27+
return PyErr_Format(PyExc_Exception, "argument is not a SWidget");
28+
29+
30+
if (s_widget->s_widget->GetType().Compare(FName("SPythonEditorViewport")) == 0)
31+
{
32+
TSharedRef<SPythonEditorViewport> s_viewport = StaticCastSharedRef<SPythonEditorViewport>(s_widget->s_widget);
33+
capture->Initialize(s_viewport->GetSceneViewport());
34+
capture->StartWarmup();
35+
}
36+
else
37+
{
38+
return PyErr_Format(PyExc_Exception, "argument is not a supported Viewport-based SWidget");
39+
}
40+
2941
}
30-
else {
31-
return PyErr_Format(PyExc_Exception, "argument is not a supported Viewport-based SWidget");
42+
else
43+
{
44+
for (const FWorldContext &Context : GEngine->GetWorldContexts())
45+
{
46+
if (Context.WorldType == EWorldType::PIE)
47+
{
48+
if (Context.GameViewport)
49+
{
50+
UE_LOG(LogPython, Error, TEXT("Found Viewport at %p"), Context.GameViewport);
51+
FSlatePlayInEditorInfo *SlatePIEInfo = GEditor->SlatePlayInEditorMap.Find(Context.ContextHandle);
52+
53+
capture->Initialize(SlatePIEInfo->SlatePlayInEditorWindowViewport);
54+
}
55+
}
56+
}
3257
}
3358
#endif
59+
Py_RETURN_NONE;
60+
}
3461

62+
PyObject *py_ue_capture_start(ue_PyUObject * self, PyObject * args)
63+
{
64+
65+
ue_py_check(self);
66+
67+
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
68+
if (!capture)
69+
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneCapture");
70+
71+
capture->StartCapture();
3572

3673
Py_RETURN_NONE;
3774
}
3875

39-
PyObject *py_ue_capture_start(ue_PyUObject * self, PyObject * args) {
76+
PyObject *py_ue_capture_load_from_config(ue_PyUObject * self, PyObject * args)
77+
{
4078

4179
ue_py_check(self);
4280

4381
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
4482
if (!capture)
4583
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneCapture");
4684

47-
capture->StartCapture();
85+
capture->LoadFromConfig();
4886

4987
Py_RETURN_NONE;
5088
}
5189

52-
PyObject *py_ue_capture_stop(ue_PyUObject * self, PyObject * args) {
90+
PyObject *py_ue_capture_stop(ue_PyUObject * self, PyObject * args)
91+
{
5392

5493
ue_py_check(self);
5594

Source/UnrealEnginePython/Private/UObject/UEPyCapture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
PyObject *py_ue_capture_initialize(ue_PyUObject *, PyObject *);
88
PyObject *py_ue_capture_start(ue_PyUObject *, PyObject *);
9+
PyObject *py_ue_capture_load_from_config(ue_PyUObject *, PyObject *);
910
PyObject *py_ue_capture_stop(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,3 +1834,44 @@ PyObject *py_ue_duplicate(ue_PyUObject * self, PyObject * args)
18341834
}
18351835
#endif
18361836

1837+
1838+
PyObject *py_ue_to_bytes(ue_PyUObject * self, PyObject * args)
1839+
{
1840+
1841+
ue_py_check(self);
1842+
1843+
TArray<uint8> Bytes;
1844+
1845+
FObjectWriter(self->ue_object, Bytes);
1846+
1847+
return PyBytes_FromStringAndSize((const char *)Bytes.GetData(), Bytes.Num());
1848+
}
1849+
1850+
PyObject *py_ue_to_bytearray(ue_PyUObject * self, PyObject * args)
1851+
{
1852+
1853+
ue_py_check(self);
1854+
1855+
TArray<uint8> Bytes;
1856+
1857+
FObjectWriter(self->ue_object, Bytes);
1858+
1859+
return PyByteArray_FromStringAndSize((const char *)Bytes.GetData(), Bytes.Num());
1860+
}
1861+
1862+
PyObject *py_ue_from_bytes(ue_PyUObject * self, PyObject * args)
1863+
{
1864+
1865+
Py_buffer py_buf;
1866+
1867+
if (!PyArg_ParseTuple(args, "z*:from_bytes", &py_buf))
1868+
return nullptr;
1869+
1870+
ue_py_check(self);
1871+
1872+
TArray<uint8> Bytes((const uint8 *)py_buf.buf, py_buf.len);
1873+
1874+
FObjectReader(self->ue_object, Bytes);
1875+
1876+
Py_RETURN_NONE;
1877+
}

Source/UnrealEnginePython/Private/UObject/UEPyObject.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ PyObject *py_ue_import_custom_properties(ue_PyUObject *, PyObject *);
8989
#endif
9090

9191
PyObject *py_ue_get_thumbnail(ue_PyUObject *, PyObject *);
92-
PyObject *py_ue_render_thumbnail(ue_PyUObject *, PyObject *);
92+
PyObject *py_ue_render_thumbnail(ue_PyUObject *, PyObject *);
93+
94+
PyObject *py_ue_to_bytes(ue_PyUObject *, PyObject *);
95+
PyObject *py_ue_to_bytearray(ue_PyUObject *, PyObject *);
96+
PyObject *py_ue_from_bytes(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)