Skip to content

Commit 14de024

Browse files
author
Roberto De Ioris
committed
thread safe FARFilter
1 parent 37afc4c commit 14de024

7 files changed

Lines changed: 53 additions & 13 deletions

File tree

Source/UnrealEnginePython/Private/PyCommandlet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int32 UPyCommandlet::Main(const FString& CommandLine)
2222
#if WITH_EDITOR
2323
// this allows commandlet's to use factories
2424
GEditor->Trans = GEditor->CreateTrans();
25+
2526
#endif
2627

2728
TArray<FString> Tokens, Switches;

Source/UnrealEnginePython/Private/SlateApplication/UEPyFSlateApplication.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "UEPyFSlateApplication.h"
33

44
#include "Slate/UEPySWidget.h"
5+
#include "Runtime/SlateRHIRenderer/Public/Interfaces/ISlateRHIRendererModule.h"
56

67
static PyObject *py_ue_get_average_delta_time(PyObject *cls, PyObject * args)
78
{
@@ -151,7 +152,19 @@ static PyObject *py_ue_process_key_char_event(PyObject *cls, PyObject * args)
151152
Py_RETURN_FALSE;
152153
}
153154

155+
static PyObject *py_ue_create(PyObject *cls, PyObject * args)
156+
{
157+
FSlateApplication::InitHighDPI();
158+
FSlateApplication::Create();
159+
160+
TSharedRef<FSlateRenderer> SlateRenderer = FModuleManager::Get().LoadModuleChecked<ISlateRHIRendererModule>("SlateRHIRenderer").CreateSlateRHIRenderer();
161+
FSlateApplication::Get().InitializeRenderer(SlateRenderer);
162+
163+
Py_RETURN_NONE;
164+
}
165+
154166
static PyMethodDef ue_PyFSlateApplication_methods[] = {
167+
{ "create", (PyCFunction)py_ue_create, METH_VARARGS | METH_CLASS, "" },
155168
{ "get_average_delta_time", (PyCFunction)py_ue_get_average_delta_time, METH_VARARGS | METH_CLASS, "" },
156169
{ "get_cursor_radius", (PyCFunction)py_ue_get_cursor_radius, METH_VARARGS | METH_CLASS, "" },
157170
{ "get_delta_time", (PyCFunction)py_ue_get_delta_time, METH_VARARGS | METH_CLASS, "" },

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,21 +823,26 @@ PyObject *py_unreal_engine_get_assets_by_filter(PyObject * self, PyObject * args
823823

824824
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:get_assets_by_filter", kw_names, &pyfilter, &py_return_asset_data))
825825
{
826-
return NULL;
826+
return nullptr;
827827
}
828828

829-
ue_PyFARFilter *filter = py_ue_is_farfilter(pyfilter);
830-
if (!filter)
829+
ue_PyFARFilter *py_filter = py_ue_is_farfilter(pyfilter);
830+
if (!py_filter)
831831
return PyErr_Format(PyExc_Exception, "Arg is not a FARFilter");
832832

833-
if (!GEditor)
834-
return PyErr_Format(PyExc_Exception, "no GEditor found");
833+
FARFilter& Filter = py_filter->filter;
834+
835+
py_ue_sync_farfilter((PyObject *)py_filter);
835836

836-
py_ue_sync_farfilter((PyObject *)filter);
837837
TArray<FAssetData> assets;
838+
839+
Py_BEGIN_ALLOW_THREADS;
840+
838841
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
839842
AssetRegistryModule.Get().SearchAllAssets(true);
840-
AssetRegistryModule.Get().GetAssets(filter->filter, assets);
843+
AssetRegistryModule.Get().GetAssets(Filter, assets);
844+
845+
Py_END_ALLOW_THREADS;
841846

842847
bool return_asset_data = false;
843848
if (py_return_asset_data && PyObject_IsTrue(py_return_asset_data))

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "HAL/PlatformApplicationMisc.h"
2020
#endif
2121

22+
#include "Runtime/Launch/Public/LaunchEngineLoop.h"
23+
2224

2325
PyObject *py_unreal_engine_log(PyObject * self, PyObject * args)
2426
{
@@ -479,21 +481,38 @@ PyObject *py_unreal_engine_guid_to_string(PyObject * self, PyObject * args)
479481

480482
PyObject *py_unreal_engine_slate_tick(PyObject * self, PyObject * args)
481483
{
484+
Py_BEGIN_ALLOW_THREADS;
482485
FSlateApplication::Get().PumpMessages();
483486
FSlateApplication::Get().Tick();
487+
Py_END_ALLOW_THREADS;
484488
Py_RETURN_NONE;
485489
}
486490

487491
PyObject *py_unreal_engine_engine_tick(PyObject * self, PyObject * args)
488492
{
489493
float delta_seconds = FApp::GetDeltaTime();
490-
PyObject *py_bool = nullptr;
491-
if (!PyArg_ParseTuple(args, "|fO:engine_tick", &delta_seconds, &py_bool))
494+
PyObject *py_idle = nullptr;
495+
if (!PyArg_ParseTuple(args, "|fO:engine_tick", &delta_seconds, &py_idle))
492496
{
493-
return NULL;
497+
return nullptr;
494498
}
495499

496-
GEngine->Tick(delta_seconds, (py_bool && PyObject_IsTrue(py_bool)) ? true : false);
500+
bool bIdle = false;
501+
if (py_idle && PyObject_IsTrue(py_idle))
502+
bIdle = true;
503+
504+
Py_BEGIN_ALLOW_THREADS;
505+
GEngine->Tick(delta_seconds, bIdle);
506+
Py_END_ALLOW_THREADS;
507+
508+
Py_RETURN_NONE;
509+
}
510+
511+
PyObject *py_unreal_engine_tick_rendering_tickables(PyObject * self, PyObject * args)
512+
{
513+
Py_BEGIN_ALLOW_THREADS;
514+
TickRenderingTickables();
515+
Py_END_ALLOW_THREADS;
497516

498517
Py_RETURN_NONE;
499518
}
@@ -1250,7 +1269,7 @@ PyObject *py_unreal_engine_clipboard_copy(PyObject * self, PyObject * args)
12501269
FGenericPlatformMisc::ClipboardCopy(UTF8_TO_TCHAR(text));
12511270
#endif
12521271
Py_RETURN_NONE;
1253-
}
1272+
}
12541273

12551274
PyObject *py_unreal_engine_clipboard_paste(PyObject * self, PyObject * args)
12561275
{

Source/UnrealEnginePython/Private/UEPyEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ PyObject *py_unreal_engine_engine_tick(PyObject *, PyObject *);
4747
PyObject *py_unreal_engine_slate_tick(PyObject *, PyObject *);
4848
PyObject *py_unreal_engine_get_delta_time(PyObject *, PyObject *);
4949

50+
PyObject *py_unreal_engine_tick_rendering_tickables(PyObject *, PyObject *);
51+
5052
PyObject *py_unreal_engine_all_classes(PyObject *, PyObject *);
5153
PyObject *py_unreal_engine_all_worlds(PyObject *, PyObject *);
5254
PyObject *py_unreal_engine_tobject_iterator(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ static PyMethodDef unreal_engine_methods[] = {
361361
#endif
362362

363363
{ "engine_tick", py_unreal_engine_engine_tick, METH_VARARGS, "" },
364+
{ "tick_rendering_tickables", py_unreal_engine_tick_rendering_tickables, METH_VARARGS, "" },
364365
#if WITH_EDITOR
365366
{ "all_viewport_clients", py_unreal_engine_all_viewport_clients , METH_VARARGS, "" },
366367
#endif

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ namespace
172172
{
173173
cmdString += argStr.TrimQuotes() + '\n';
174174
}
175-
176175
UPythonBlueprintFunctionLibrary::ExecutePythonString(cmdString);
177176
}
178177
}

0 commit comments

Comments
 (0)