Skip to content

Commit 3e1867c

Browse files
author
Roberto De Ioris
committed
added automation skel infrastructure
1 parent 551c3d0 commit 3e1867c

10 files changed

Lines changed: 211 additions & 30 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
2+
3+
#include "PythonAutomationModule.h"
4+
#include "UnrealEnginePython.h"
5+
#include "UEPyFAutomationEditorCommonUtils.h"
6+
7+
IMPLEMENT_MODULE(FPythonAutomationModule, PythonAutomation);
8+
9+
10+
void FPythonAutomationModule::StartupModule()
11+
{
12+
PyObject *py_automation_module = ue_py_register_module("unreal_engine.automation");
13+
ue_python_init_fautomation_editor_common_utils(py_automation_module);
14+
}
15+
16+
void FPythonAutomationModule::ShutdownModule()
17+
{
18+
19+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
#include "UEPyFAutomationEditorCommonUtils.h"
3+
4+
#include "UnrealEnginePython.h"
5+
#include "Engine/World.h"
6+
7+
8+
static PyObject *py_ue_fautomation_editor_common_utils_run_pie(PyObject *cls, PyObject * args)
9+
{
10+
FAutomationEditorCommonUtils::RunPIE();
11+
Py_RETURN_NONE;
12+
}
13+
14+
static PyObject *py_ue_fautomation_editor_common_utils_load_map(PyObject *cls, PyObject * args)
15+
{
16+
char *map_name;
17+
if (!PyArg_ParseTuple(args, "s:load_map", &map_name))
18+
return nullptr;
19+
FAutomationEditorCommonUtils::LoadMap(FString(UTF8_TO_TCHAR(map_name)));
20+
Py_RETURN_NONE;
21+
}
22+
23+
static PyObject *py_ue_fautomation_editor_common_utils_create_new_map(PyObject *cls, PyObject * args)
24+
{
25+
Py_RETURN_UOBJECT(FAutomationEditorCommonUtils::CreateNewMap());
26+
}
27+
28+
static PyMethodDef ue_PyFAutomationEditorCommonUtils_methods[] = {
29+
{ "run_pie", (PyCFunction)py_ue_fautomation_editor_common_utils_run_pie, METH_VARARGS | METH_CLASS, "" },
30+
{ "load_map", (PyCFunction)py_ue_fautomation_editor_common_utils_load_map, METH_VARARGS | METH_CLASS, "" },
31+
{ "create_new_map", (PyCFunction)py_ue_fautomation_editor_common_utils_create_new_map, METH_VARARGS | METH_CLASS, "" },
32+
33+
{ NULL } /* Sentinel */
34+
};
35+
36+
37+
static PyTypeObject ue_PyFAutomationEditorCommonUtilsType = {
38+
PyVarObject_HEAD_INIT(NULL, 0)
39+
"unreal_engine.FAutomationEditorCommonUtils", /* tp_name */
40+
sizeof(ue_PyFAutomationEditorCommonUtils), /* tp_basicsize */
41+
0, /* tp_itemsize */
42+
0, /* tp_dealloc */
43+
0, /* tp_print */
44+
0, /* tp_getattr */
45+
0, /* tp_setattr */
46+
0, /* tp_reserved */
47+
0, /* tp_repr */
48+
0, /* tp_as_number */
49+
0, /* tp_as_sequence */
50+
0, /* tp_as_mapping */
51+
0, /* tp_hash */
52+
0, /* tp_call */
53+
0, /* tp_str */
54+
0, /* tp_getattro */
55+
0, /* tp_setattro */
56+
0, /* tp_as_buffer */
57+
Py_TPFLAGS_DEFAULT, /* tp_flags */
58+
"Unreal Engine AutomationEditorCommonUtils", /* tp_doc */
59+
0, /* tp_traverse */
60+
0, /* tp_clear */
61+
0, /* tp_richcompare */
62+
0, /* tp_weaklistoffset */
63+
0, /* tp_iter */
64+
0, /* tp_iternext */
65+
ue_PyFAutomationEditorCommonUtils_methods, /* tp_methods */
66+
0,
67+
0,
68+
};
69+
70+
static int py_ue_fautomation_editor_common_utils_init(ue_PyFAutomationEditorCommonUtils *self, PyObject * args)
71+
{
72+
PyErr_SetString(PyExc_Exception, "FAutomationEditorCommonUtils is a singleton");
73+
return -1;
74+
}
75+
76+
void ue_python_init_fautomation_editor_common_utils(PyObject *ue_module)
77+
{
78+
ue_PyFAutomationEditorCommonUtilsType.tp_new = PyType_GenericNew;
79+
ue_PyFAutomationEditorCommonUtilsType.tp_init = (initproc)py_ue_fautomation_editor_common_utils_init;
80+
81+
if (PyType_Ready(&ue_PyFAutomationEditorCommonUtilsType) < 0)
82+
return;
83+
84+
Py_INCREF(&ue_PyFAutomationEditorCommonUtilsType);
85+
PyModule_AddObject(ue_module, "FAutomationEditorCommonUtils", (PyObject *)&ue_PyFAutomationEditorCommonUtilsType);
86+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include "UnrealEnginePython.h"
4+
5+
#include "Tests/AutomationEditorCommon.h"
6+
7+
typedef struct
8+
{
9+
PyObject_HEAD
10+
/* Type-specific fields go here. */
11+
} ue_PyFAutomationEditorCommonUtils;
12+
13+
void ue_python_init_fautomation_editor_common_utils(PyObject *);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 1998-2018 20Tab S.r.l. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include "CoreMinimal.h"
6+
#include "ModuleInterface.h"
7+
8+
class FPythonAutomationModule : public IModuleInterface
9+
{
10+
public:
11+
virtual void StartupModule();
12+
virtual void ShutdownModule();
13+
14+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 1998-2018 20Tab S.r.l All Rights Reserved.
2+
3+
using UnrealBuildTool;
4+
using System.IO;
5+
6+
public class PythonAutomation : ModuleRules
7+
{
8+
#if WITH_FORWARDED_MODULE_RULES_CTOR
9+
public PythonAutomation(ReadOnlyTargetRules Target) : base(Target)
10+
#else
11+
public PythonAutomation(TargetInfo Target)
12+
#endif
13+
{
14+
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
15+
16+
PrivateIncludePaths.AddRange(
17+
new string[] {
18+
"PythonConsole/Private",
19+
// ... add other private include paths required here ...
20+
}
21+
);
22+
23+
PrivateDependencyModuleNames.AddRange(
24+
new string[] {
25+
"Core",
26+
"CoreUObject", // @todo Mac: for some reason it's needed to link in debug on Mac
27+
"Engine",
28+
"UnrealEd",
29+
"UnrealEnginePython"
30+
}
31+
);
32+
33+
}
34+
}

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,21 +1549,10 @@ void unreal_engine_init_py_module()
15491549

15501550
ue_python_init_ivoice_capture(new_unreal_engine_module);
15511551

1552-
PyObject *py_sys = PyImport_ImportModule("sys");
1553-
PyObject *py_sys_dict = PyModule_GetDict(py_sys);
1552+
ue_py_register_magic_module("unreal_engine.classes", py_ue_new_uclassesimporter);
1553+
ue_py_register_magic_module("unreal_engine.enums", py_ue_new_enumsimporter);
1554+
ue_py_register_magic_module("unreal_engine.structs", py_ue_new_ustructsimporter);
15541555

1555-
PyObject *py_sys_modules = PyDict_GetItemString(py_sys_dict, "modules");
1556-
PyObject *u_classes_importer = py_ue_new_uclassesimporter();
1557-
Py_INCREF(u_classes_importer);
1558-
PyDict_SetItemString(py_sys_modules, "unreal_engine.classes", u_classes_importer);
1559-
1560-
PyObject *u_enums_importer = py_ue_new_enumsimporter();
1561-
Py_INCREF(u_enums_importer);
1562-
PyDict_SetItemString(py_sys_modules, "unreal_engine.enums", u_enums_importer);
1563-
1564-
PyObject *u_structs_importer = py_ue_new_ustructsimporter();
1565-
Py_INCREF(u_structs_importer);
1566-
PyDict_SetItemString(py_sys_modules, "unreal_engine.structs", u_structs_importer);
15671556

15681557
PyDict_SetItemString(unreal_engine_dict, "ENGINE_MAJOR_VERSION", PyLong_FromLong(ENGINE_MAJOR_VERSION));
15691558
PyDict_SetItemString(unreal_engine_dict, "ENGINE_MINOR_VERSION", PyLong_FromLong(ENGINE_MINOR_VERSION));
@@ -3187,7 +3176,7 @@ UFunction *unreal_engine_add_function(UClass *u_class, char *name, PyObject *py_
31873176
#endif
31883177

31893178
return function;
3190-
}
3179+
}
31913180

31923181
FGuid *ue_py_check_fguid(PyObject *py_obj)
31933182
{

Source/UnrealEnginePython/Private/UEPyModule.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "UEPyUScriptStruct.h"
77
#include "PythonHouseKeeper.h"
88

9-
// common wrappers
9+
// common wrappersno
1010
#include "Wrappers/UEPyFVector.h"
1111
#include "Wrappers/UEPyFRotator.h"
1212
#include "Wrappers/UEPyFQuat.h"
@@ -15,9 +15,7 @@
1515
#include "Wrappers/UEPyFLinearColor.h"
1616

1717

18-
void unreal_engine_py_log_error();
19-
ue_PyUObject *ue_get_python_uobject(UObject *);
20-
ue_PyUObject *ue_get_python_uobject_inc(UObject *);
18+
2119
UWorld *ue_get_uworld(ue_PyUObject *);
2220
AActor *ue_get_actor(ue_PyUObject *);
2321
PyObject *ue_py_convert_property(UProperty *, uint8 *, int32);

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ void FUnrealEnginePythonModule::RunFileSandboxed(char *filename, void(*callback)
622622
PyThreadState_Swap(_main);
623623
}
624624

625+
void ue_py_register_magic_module(char *name, PyObject *(*func)())
626+
{
627+
PyObject *py_sys = PyImport_ImportModule("sys");
628+
PyObject *py_sys_dict = PyModule_GetDict(py_sys);
629+
630+
PyObject *py_sys_modules = PyDict_GetItemString(py_sys_dict, "modules");
631+
PyObject *u_module = func();
632+
Py_INCREF(u_module);
633+
PyDict_SetItemString(py_sys_modules, name, u_module);
634+
}
635+
636+
PyObject *ue_py_register_module(char *name)
637+
{
638+
return PyImport_AddModule(name);
639+
}
640+
625641
#undef LOCTEXT_NAMESPACE
626642

627643
IMPLEMENT_MODULE(FUnrealEnginePythonModule, UnrealEnginePython)

Source/UnrealEnginePython/Public/UnrealEnginePython.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ typedef struct
4848
int auto_rooted;
4949
} ue_PyUObject;
5050

51+
UNREALENGINEPYTHON_API void ue_py_register_magic_module(char *name, PyObject *(*)());
52+
UNREALENGINEPYTHON_API PyObject *ue_py_register_module(char *);
53+
5154
#if ENGINE_MINOR_VERSION >= 18
5255
#define FStringAssetReference FSoftObjectPath
5356
#endif
@@ -67,6 +70,10 @@ int PyGILState_Check();
6770
#endif
6871
bool PyUnicodeOrString_Check(PyObject *py_obj);
6972

73+
UNREALENGINEPYTHON_API void unreal_engine_py_log_error();
74+
UNREALENGINEPYTHON_API ue_PyUObject *ue_get_python_uobject(UObject *);
75+
UNREALENGINEPYTHON_API ue_PyUObject *ue_get_python_uobject_inc(UObject *);
76+
7077
#define Py_RETURN_UOBJECT(py_uobj) ue_PyUObject *ret = ue_get_python_uobject_inc(py_uobj);\
7178
if (!ret)\
7279
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");\

UnrealEnginePython.uplugin

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,27 @@
1414
"CanContainContent": true,
1515
"IsBetaVersion": true,
1616
"Installed": false,
17-
"Modules": [
17+
"Modules": [
1818
{
1919
"Name": "UnrealEnginePython",
2020
"Type": "Runtime",
2121
"LoadingPhase": "Default"
2222
},
23-
{
24-
"Name": "PythonConsole",
25-
"Type": "Editor",
26-
"LoadingPhase": "PostDefault"
27-
},
28-
{
29-
"Name" : "PythonEditor",
30-
"Type" : "Editor",
31-
"LoadingPhase": "PostDefault"
32-
}
23+
{
24+
"Name": "PythonAutomation",
25+
"Type": "Editor",
26+
"LoadingPhase": "PostDefault"
27+
},
28+
{
29+
"Name": "PythonConsole",
30+
"Type": "Editor",
31+
"LoadingPhase": "PostDefault"
32+
},
33+
{
34+
"Name": "PythonEditor",
35+
"Type": "Editor",
36+
"LoadingPhase": "PostDefault"
37+
}
3338
],
3439
"Plugins": [
3540
{

0 commit comments

Comments
 (0)