Skip to content

Commit f3cfaaf

Browse files
committed
brought up to date with master
2 parents f53a8e5 + 078908e commit f3cfaaf

File tree

6 files changed

+458
-4
lines changed

6 files changed

+458
-4
lines changed

Source/UnrealEnginePython/Private/PyCommandlet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int32 UPyCommandlet::Main(const FString& CommandLine)
9191
#if PY_MAJOR_VERSION >= 3
9292
argv[i] = (wchar_t*)malloc(PyArgv[i].Len() + 1);
9393
#if PLATFORM_MAC || PLATFORM_LINUX
94-
wcsncpy(argv[i], *PyArgv[i].ReplaceEscapedCharWithChar(), PyArgv[i].Len() + 1);
94+
wcsncpy(argv[i], (const wchar_t *) TCHAR_TO_WCHAR(*PyArgv[i].ReplaceEscapedCharWithChar()), PyArgv[i].Len() + 1);
9595
#elif PLATFORM_ANDROID
9696
wcsncpy(argv[i], (const wchar_t *)*PyArgv[i].ReplaceEscapedCharWithChar(), PyArgv[i].Len() + 1);
9797
#else

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "Wrappers/UEPyESlateEnums.h"
5252

5353
#include "Wrappers/UEPyFVector.h"
54+
#include "Wrappers/UEPyFVector2D.h"
5455
#include "Wrappers/UEPyFHitResult.h"
5556
#include "Wrappers/UEPyFRotator.h"
5657
#include "Wrappers/UEPyFTransform.h"
@@ -1657,6 +1658,7 @@ void unreal_engine_init_py_module()
16571658
}
16581659

16591660
ue_python_init_fvector(new_unreal_engine_module);
1661+
ue_python_init_fvector2d(new_unreal_engine_module);
16601662
ue_python_init_frotator(new_unreal_engine_module);
16611663
ue_python_init_ftransform(new_unreal_engine_module);
16621664
ue_python_init_fhitresult(new_unreal_engine_module);
@@ -2106,12 +2108,16 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer, int32 index)
21062108
{
21072109
if (auto casted_struct = Cast<UScriptStruct>(casted_prop->Struct))
21082110
{
2109-
// check for FVector
21102111
if (casted_struct == TBaseStructure<FVector>::Get())
21112112
{
21122113
FVector vec = *casted_prop->ContainerPtrToValuePtr<FVector>(buffer, index);
21132114
return py_ue_new_fvector(vec);
21142115
}
2116+
if (casted_struct == TBaseStructure<FVector2D>::Get())
2117+
{
2118+
FVector2D vec = *casted_prop->ContainerPtrToValuePtr<FVector2D>(buffer, index);
2119+
return py_ue_new_fvector2d(vec);
2120+
}
21152121
if (casted_struct == TBaseStructure<FRotator>::Get())
21162122
{
21172123
FRotator rot = *casted_prop->ContainerPtrToValuePtr<FRotator>(buffer, index);
@@ -2517,6 +2523,19 @@ bool ue_py_convert_pyobject(PyObject *py_obj, UProperty *prop, uint8 *buffer, in
25172523
return false;
25182524
}
25192525

2526+
if (ue_PyFVector2D *py_vec = py_ue_is_fvector2d(py_obj))
2527+
{
2528+
if (auto casted_prop = Cast<UStructProperty>(prop))
2529+
{
2530+
if (casted_prop->Struct == TBaseStructure<FVector2D>::Get())
2531+
{
2532+
*casted_prop->ContainerPtrToValuePtr<FVector2D>(buffer, index) = py_vec->vec;
2533+
return true;
2534+
}
2535+
}
2536+
return false;
2537+
}
2538+
25202539
if (ue_PyFRotator *py_rot = py_ue_is_frotator(py_obj))
25212540
{
25222541
if (auto casted_prop = Cast<UStructProperty>(prop))
@@ -3086,6 +3105,12 @@ UProperty *new_property_from_pyobject(UObject *owner, const char *prop_name, PyO
30863105
prop_struct->Struct = TBaseStructure<FVector>::Get();
30873106
prop = prop_struct;
30883107
}
3108+
else if ((PyTypeObject *)value == &ue_PyFVector2DType)
3109+
{
3110+
UStructProperty *prop_struct = NewObject<UStructProperty>(owner, UTF8_TO_TCHAR(prop_name), RF_Public);
3111+
prop_struct->Struct = TBaseStructure<FVector2D>::Get();
3112+
prop = prop_struct;
3113+
}
30893114
else if ((PyTypeObject *)value == &ue_PyFRotatorType)
30903115
{
30913116
UStructProperty *prop_struct = NewObject<UStructProperty>(owner, UTF8_TO_TCHAR(prop_name), RF_Public);

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ const char *ue4_module_options = "linux_global_symbols";
3434
#include "Runtime/Core/Public/Misc/CommandLine.h"
3535
#include "Runtime/Core/Public/Misc/ConfigCacheIni.h"
3636
#include "Runtime/Core/Public/GenericPlatform/GenericPlatformFile.h"
37+
#include "Runtime/Core/Public/GenericPlatform/GenericPlatformMisc.h"
3738

3839
#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
3940

41+
#if PLATFORM_WINDOWS
42+
#include <fcntl.h>
43+
#endif
44+
4045
#if PLATFORM_ANDROID
4146
#include "Android/AndroidJNI.h"
4247
#include "Android/AndroidApplication.h"
@@ -116,7 +121,7 @@ void FUnrealEnginePythonModule::UESetupPythonInterpreter(bool verbose)
116121
for (int32 i = 0; i < Args.Num(); i++)
117122
{
118123
#if PY_MAJOR_VERSION >= 3
119-
argv[i] = (wchar_t *)(*Args[i]);
124+
argv[i] = (wchar_t *)(TCHAR_TO_WCHAR(*Args[i]));
120125
#else
121126
argv[i] = TCHAR_TO_UTF8(*Args[i]);
122127
#endif
@@ -451,6 +456,22 @@ void FUnrealEnginePythonModule::StartupModule()
451456

452457
Py_Initialize();
453458

459+
#if PLATFORM_WINDOWS
460+
// Restore stdio state after Py_Initialize set it to O_BINARY, otherwise
461+
// everything that the engine will output is going to be encoded in UTF-16.
462+
// The behaviour is described here: https://bugs.python.org/issue16587
463+
_setmode(_fileno(stdin), O_TEXT);
464+
_setmode(_fileno(stdout), O_TEXT);
465+
_setmode(_fileno(stderr), O_TEXT);
466+
467+
// Also restore the user-requested UTF-8 flag if relevant (behaviour copied
468+
// from LaunchEngineLoop.cpp).
469+
if (FParse::Param(FCommandLine::Get(), TEXT("UTF8Output")))
470+
{
471+
FPlatformMisc::SetUTF8Output();
472+
}
473+
#endif
474+
454475
PyEval_InitThreads();
455476

456477
#if WITH_EDITOR

Source/UnrealEnginePython/Private/Wrappers/UEPyFVector.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ static PyObject *ue_py_fvector_div(ue_PyFVector *self, PyObject *value)
277277
return py_ue_new_fvector(vec);
278278
}
279279

280+
static PyObject *ue_py_fvector_floor_div(ue_PyFVector *self, PyObject *value)
281+
{
282+
FVector vec = self->vec;
283+
if (PyNumber_Check(value))
284+
{
285+
PyObject *f_value = PyNumber_Float(value);
286+
float f = PyFloat_AsDouble(f_value);
287+
if (f == 0)
288+
return PyErr_Format(PyExc_ZeroDivisionError, "division by zero");
289+
vec.X = floor(vec.X / f);
290+
vec.Y = floor(vec.Y / f);
291+
vec.Z = floor(vec.Z / f);
292+
Py_DECREF(f_value);
293+
return py_ue_new_fvector(vec);
294+
}
295+
return PyErr_Format(PyExc_TypeError, "value is not numeric");
296+
}
297+
280298
PyNumberMethods ue_PyFVector_number_methods;
281299

282300
static Py_ssize_t ue_py_fvector_seq_length(ue_PyFVector *self)
@@ -363,7 +381,8 @@ void ue_python_init_fvector(PyObject *ue_module)
363381
ue_PyFVector_number_methods.nb_add = (binaryfunc)ue_py_fvector_add;
364382
ue_PyFVector_number_methods.nb_subtract = (binaryfunc)ue_py_fvector_sub;
365383
ue_PyFVector_number_methods.nb_multiply = (binaryfunc)ue_py_fvector_mul;
366-
ue_PyFVector_number_methods.nb_divmod = (binaryfunc)ue_py_fvector_div;
384+
ue_PyFVector_number_methods.nb_true_divide = (binaryfunc)ue_py_fvector_div;
385+
ue_PyFVector_number_methods.nb_floor_divide = (binaryfunc)ue_py_fvector_floor_div;
367386

368387
memset(&ue_PyFVector_sequence_methods, 0, sizeof(PySequenceMethods));
369388
ue_PyFVectorType.tp_as_sequence = &ue_PyFVector_sequence_methods;

0 commit comments

Comments
 (0)