Repository navigation
Expand file tree
/
Copy pathPythonSmartDelegate.cpp
More file actions
90 lines (75 loc) · 1.84 KB
/
Copy pathPythonSmartDelegate.cpp
File metadata and controls
90 lines (75 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "PythonSmartDelegate.h"
#include "UEPyModule.h"
#if WITH_EDITOR
#include "Slate/UEPySWindow.h"
#endif
FPythonSmartDelegate::FPythonSmartDelegate()
{
py_callable = nullptr;
}
void FPythonSmartDelegate::SetPyCallable(PyObject *callable)
{
// do not acquire the gil here as we set the callable in python call themselves
py_callable = callable;
Py_INCREF(py_callable);
}
bool FPythonSmartDelegate::Tick(float DeltaTime)
{
FScopePythonGIL gil;
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"f", DeltaTime);
if (!ret)
{
unreal_engine_py_log_error();
return false;
}
if (PyObject_IsTrue(ret))
{
Py_DECREF(ret);
return true;
}
Py_DECREF(ret);
return false;
}
void FPythonSmartDelegate::Void()
{
FScopePythonGIL gil;
PyObject *ret = PyObject_CallFunction(py_callable, nullptr);
if (!ret)
{
unreal_engine_py_log_error();
return;
}
Py_DECREF(ret);
}
#if WITH_EDITOR
void FPythonSmartDelegate::PyFOnAssetPostImport(UFactory *factory, UObject *u_object)
{
FScopePythonGIL gil;
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"OO", ue_get_python_uobject((UObject *)factory), ue_get_python_uobject(u_object));
if (!ret)
{
unreal_engine_py_log_error();
return;
}
Py_DECREF(ret);
}
void FPythonSmartDelegate::PyFOnMainFrameCreationFinished(TSharedPtr<SWindow> InRootWindow, bool bIsNewProjectWindow)
{
FScopePythonGIL gil;
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"NO", py_ue_new_swidget<ue_PySWindow>(InRootWindow.ToSharedRef(), &ue_PySWindowType), bIsNewProjectWindow ? Py_True : Py_False);
if (!ret)
{
unreal_engine_py_log_error();
return;
}
Py_DECREF(ret);
}
#endif
FPythonSmartDelegate::~FPythonSmartDelegate()
{
FScopePythonGIL gil;
Py_XDECREF(py_callable);
#if defined(UEPY_MEMORY_DEBUG)
UE_LOG(LogPython, Warning, TEXT("PythonSmartDelegate callable XDECREF'ed"));
#endif
}